I guess that you want
foreach item in X Y {
bysort ID (DATE): gen `item'5=`item'[_n+5]
}
as otherwise the groups defined by -ID DATE- will just be single observations.
Nick
n.j.cox@durham.ac.uk
John Litfiba
I do not know what is wrong in the following code:
X and Y are variables in my database
foreach item in "X" "Y" {
bysort ID DATE: gen `item'5=`item'[_n+5]
}
That is, I would like to use a loop over these 2 variables names X and
Y that would allow the creation of new numeric variables called "X5"
and "Y5" and whose value are lagged copies of existing variables X and
Y... (5 row later)
It seems that the new variable are created correctly, but Stata do not
understand that it must EVALUATE the variable stored in `item[_n+5] :
so I get a missing value instead of the numeric value stored at the
nth+5 row...
*
* 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/