Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Generating new variables with lags


From   Malcolm Wardlaw <malcolm@mail.utexas.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Generating new variables with lags
Date   Sun, 05 Oct 2008 12:50:05 -0500

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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index