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 <>
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.


* For searches and help try:

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