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: RE: A simple Stata Macro trick?!... I need your help please
From
John Litfiba <[email protected]>
To
[email protected]
Subject
Re: st: RE: A simple Stata Macro trick?!... I need your help please
Date
Wed, 27 Jul 2011 20:25:51 +0200
Dear Nick
Of course!
Many thanks
John
On 27 July 2011 19:59, Nick Cox <[email protected]> wrote:
> 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
> [email protected]
>
> 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/
>
*
* 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/