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   Sergiy Radyakin <[email protected]>
To   [email protected]
Subject   Re: st: simulataneous foreach loops
Date   Fri, 12 Nov 2010 14:24:48 -0500

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.

yes, see arrays
loop over array indices.
Best, Sergiy

>
> 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/
>

*
*   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