Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: AW: lag

From   "Klaus Pforr" <>
To   <>
Subject   st: AW: lag
Date   Thu, 31 May 2012 11:06:00 +0200


Dear Fabian,

I think that are correctly expecting that "sale[_n-4]" is missing for the first for observations. The problem is, that "sale[_n-4]" is evaluated as "." for _n<=4, but the boolean expression "sale<=sale[_n-4]" is - at least not necessarily - evaluated as missing for these obs. As sale is probably less than the pseudo-infinitely large "." (See: help missing), you will have "sale_decrease5=1" for these observations.

To catch this problem, you can add the assertion "& sale[_n-4]!=." to you if-condition.




Klaus Pforr
GESIS -- Leibniz Institut für Sozialwissenschaft
Postfach 122155
D - 68072 Mannheim
Tel: +49 621 1246 298
Fax: +49 621 1246 100 

-----Ursprüngliche Nachricht-----
Von: [] Im Auftrag von "Fabian Schönenberger"
Gesendet: Donnerstag, 31. Mai 2012 10:52
Betreff: st: lag

Dear Statalist
With the following command I want to generate a dummy variable; 1 if current sales are lower than 4 years ago, 0 if sales are larger for each company:

by cusip: generate sale_decrease5=0 if sale>sale[_n-4] by cusip: replace sale_decrease5=1 if sale<=sale[_n-4]

I expected for each cusip 4 missings at the beginning, since there is no _n-4. However, the command gives 1 for each cusip in the first four years. 

How do I have to adapt the formula to get dummy variables after the first 4 years passed?

Many thanks in advance.

NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!                                  
Jetzt informieren:
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index