I'm trying to generalize a program to be able to create a new variable
out of a specified number of lagged variables.
gen sumx=x+x.l1+x.l2+x.l3 ...
I'd like to generalize this to be able to use various lags without
having to type out the entire sequence in the program. Essentially, I'd
like to specify "lag=3" and generate sumx=x+x.l1+x.l2+x.l3 or "lag=2"
and generate sumx=x+x.l1+x.l2
I've tried building this expression into a macro and then evaluating the
results of the macro, but as I'm sure the more advanced people know,
this doesn't work. Instead it creates a string variable
sumx="sumx=x+x.l1+x.l2+x.l3". I've never figured out exactly how to
properly evaluate macros as directives within a program, but I don't
even know if that's the best way to handle this problem anyways.
Any advice?
*
* 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/