**Q. How to create a lag variable in Stata?**

# if dataset is not of time series, which is wierd, but anyway

gen varlag=var[_n-1]

# if dataset is of time series or cross-sectional or panel ("L." is the operator)

tsset timevar, panelid

gen varlag=l.var

or

by panelid: gen varlag=var[_n-1]

## 4 comments:

panelvar and datevar are the wrong way around

Thanks for your comment.

Actually it doesn't matter. Stata will know the difference.

necessita di verificare:)

I saw your posting, and am wondering if you can help me with lag variable in STATA 11SE.

I am trying to run a regression for sales=c+beta(newsreporting) + salesL where salesl suppose to be infinitely lagged. but I am having trouble creating the lagged sales variable for some reason

Post a Comment