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   Nick Winter <[email protected]>
To   [email protected]
Subject   Re: st: simulataneous foreach loops
Date   Mon, 15 Nov 2010 13:01:58 -0500

It sounds like you want something that the old, out-of-date-and-no-longer-supported -for- command made easy:

for num 101 102 103 \ num 3 5 3 : di "team X will have Y members"

-for- is no longer documented, so you'll have to guess how to use it if you want something more complicated than that.

In modern Stata, you could do something like:

local tnums 101 102 103
local tsizes 3 5 3

forval i=1/3 {
  local team : word `i' of `tnums'
  local size : word `i' of `tsizes'
  di "Team `team' will have `size' members"
}

- Nick Winter


On 11/12/2010 2:45 PM, Lim, Raymond wrote:
Austin,
I preserve before the loop in my actual code. The loop right now creates team 101 with 3 members, team 102 with 5 members, team 103 with 3 members, etc. Yes, there's a one-to-one mapping from tt to NN. I basically need two loop indices to change simultaneously. For example, first round (i=103, j=3), second round (i=139, j=5), third round (i=230, j=3). Of course, the real thing is a couple hundred pairs.

-Raymond

preserve
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
        }

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

--
--------------------------------------------------------------
Nicholas Winter                                 434.924.6994 t
Assistant Professor                             434.924.3359 f
Department of Politics                  [email protected] e
University of Virginia          faculty.virginia.edu/nwinter w
S385 Gibson Hall, South Lawn
*
*   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