[STATA] Lagged variable

Hi all !

I'm new to this forum, and also newbie in Stata....

I try to generate a simple lagged variable using the syntax : l.var but I've got
an error message that my variable is not sorted. Then I sort it but the problem
The only way I succeed is to generate a new variable : gen lvar=var[_n-1]

Why does the "l." command doesn't work ??




TS Contributor
Did you define a time variable?

Hi GuiGui,

The command is used with a capital "L" as in L.var. It is a time series operator, so it can only be used when you have set a time variable. Have you done that?
Hi Terzi !

Well, a capital "L" or a minus "l" should be the same, and in my case the result was the same, it did not work.

In fact, I succeed yesterday after two weeks trying sometimes to debbug the problem. I have a time serie, data organized monthly. The tsset was set, but the month variable was not sorted by a command sort though the data were organized temporally....

So I forced the do file to sort my data (again) and it works !

I just have still an "error", my do file does not execute entirely. I have several graphs to plot (they are plotted), and after that I have several regressions that are apparently not calculated but despite that, the end of the do file is reached so I must execute the regressions manually....
Hi AtlasFrysmith

Well, perhaps the regression is done... but in the result panel, I don't see anything that suggest me that it was performed. Furthermore, the log file (that I close at the end of my do file) is closed but nothing tells me so.
Finally, my log file is empty.:confused:
Maybe there's something in your dofile that turns off the option to report results? This option exists so that if you're running a whole bunch of intermediate steps before the command you really care about, you don't have to clutter up the screen with all the other parts. It's been a while since I've used STATA so others might remember better than I what this option is called and how to change it, but that's my guess. Especially if you didn't write your dofile completely yourself--did you copy and paste any parts of it, and if so, do you understand every bit of that code?

That's my guess--I hope you find your answer.
Yes you're right, it's not my code, my professor gave it to me, but I understand every line.

In fact, there are severals graphs that are plotted and saved as images. After that, there's a serie of regressions and a line to close the log file.

The regressions (their results) are not displayed in the result panel, but the log file is closed (as when I try to close it manually I have an error...) but it is empty.

So I'll search again where the errors are.... :shakehead

Thks again !