Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: simulataneous foreach loops


From   Austin Nichols <[email protected]>
To   [email protected]
Subject   Re: st: simulataneous foreach loops
Date   Fri, 12 Nov 2010 14:21:52 -0500

Raymond <[email protected]>:
Yes, but you need to specify further how the two loops interact or
mesh... and in the code below you need to -preserve- before you
-bsample- the first time through.  Is there a one to one mapping from
tt to NN?  As written, it just cycles through  3 5 3 4 over and
over...

On Fri, Nov 12, 2010 at 2:08 PM, Lim,  Raymond <[email protected]> wrote:
> Hello Statalisters,
> Is it possible to have two foreach loops running simultaneously? For example, I'm creating simulated teams of particularly sizes. I have team 102 to have 3 members, team 108 to have 5 members, team 202 to have 3 members, etc. The team numbers do NOT have a particular pattern. If it did I would use the loop below. Hence, I need to somehow index by (102, 3), (108, 5), (202,3), etc.
>
> local tt=100
> qui foreach NN of numlist 3 5 3 4 {
>        bsample `NN'
>        local tt=`tt'+1
>        replace team=`tt'
>        save simteam_`tt'.dta, replace
>        restore
>        preserve
>        }
>
> Thanks!
> -Raymond
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index