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]
st: RE: looping over several macros
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
st: RE: looping over several macros
Date
Tue, 15 Feb 2011 16:30:06 +0000
Something like this:
local i = 1
foreach c of local change {
local y : word `i' of `1994'
local s : word `i' of `1994_shift'
replace drating06 = drating * `c' if drating >= `y' & drating < `s'
local ++i
}
The code could be made shorter at the expense of being made more cryptic.
There was a discussion within
SJ-3-2 pr0009 . . . . . . . . . . . . . Speaking Stata: Problems with lists
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
Q2/03 SJ 3(2):185--202 (no commands)
discusses ways of working through lists held in macros
Nick
[email protected]
John Holmes
I want to perform a transformation on the variable 'drating' based on
the values of three local macros as below
gen drating06 = .
replace drating06 = drating * `change' if drating >= `1994' & drating
< `1994_shift'
On the first loop, I want to use the first values in all of the macros
`change', `1994' and `1994_shift', on the second loop I want to use
the second values in all of the macros and so on. Can somebody tell
me the right code to use so Stata loops on all three macros
simultaneously rather than looping the first, then the second and then
the third.
*
* 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/