Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: creating a lag variable


From   Christopher F Baum <[email protected]>
To   [email protected]
Subject   st: Re: creating a lag variable
Date   Wed, 9 Jun 2004 10:28:19 +0100

On Jun 9, 2004, at 7:33 AM, Richard wrote:

gen y = x[_n-1]
Bad idea; that says that y is the previous value of x, which may or may not be associated with the previous time unit. Better to tsset the data (establish a time series calendar) and then

gen y = L.x

which will ensure that if there are gaps in the time series they are respected. This can save you a LOT of time in debugging situations where there may be a discontinuity on the time axis.

Kit

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




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