Bookmark and Share

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


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

st: RE: Lag Operator


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: Lag Operator
Date   Fri, 24 Jun 2011 10:31:06 +0100

Suppose I observe firm Raychaudhuri Corporation at times 1, 2, 3 and 5, so that there is a gap in the data at time 4. The gap is what bites for this and other examples. 

_n-1 is the subscript for the previous observation. After -sort-ing appropriately, the previous observation for time 5 is that for time 3. 

L. gives you the value for the previous time. For time 5, that would be time 4, but time 4 is not present in the data, so L. for any variable will return missing for time 5. 

Nick 
[email protected] 

Jibonayan Raychaudhuri

I am a bit confused about the way the L (lag) operator
behaves in Stata.


For a panel of firms I first create the following lagged
varaibles: 

#delimit;
iis compname;
tis newyear;
gsort +compname +newyear;
#delimit;
local varlist1 
sales 
forexsales;
foreach var of local varlist1{;
by compname: generate L1log`var'= log`var'[_n-1]; 

by compname: generate L2log`var'= log`var'[_n-2]; 

by compname: gen D1log`var'= log`var'[_n]-log`var'[_n-1]; 

};


Next I create :

#delimit;
iis compname;
tis newyear;
gsort +compname +newyear;
xtset compname newyear;
#delimit;
local varlist1 
sales 
forexsales;
foreach var of local varlist1{;
by compname: generate L1log`var'_n= L1.log`var'; 

by compname: generate L2log`var'_n= L2.log`var'; 

by compname: gen D1log`var'_n= D1.log`var'; 

};


The two do not give me the same result. I find a something
more confusing on listing the variables (please see row 8) :

Any help appreciated.

Best,
Jibonayan



list compname nic newyear logforexsales L1logforexsales L1logforexsales_new in 1/30

     +-----------------------------------------------------------------------------------------+
     |                            compname   nic   newyear   logfo~les   L1~xsales   L1logfo.. |
     |-----------------------------------------------------------------------------------------|
  1. |                     20 Microns Ltd.   269      1997   -1.752332           .           . |
  2. |                     20 Microns Ltd.   269      1998   -1.930396   -1.752332   -1.752332 |
  3. |                     20 Microns Ltd.   269      1999   -2.167871   -1.930396   -1.930396 |
  4. |                     20 Microns Ltd.   269      2000    -2.09666   -2.167871   -2.167871 |
  5. |                     20 Microns Ltd.   269      2001   -2.181683    -2.09666    -2.09666 |
     |-----------------------------------------------------------------------------------------|
  6. |                     20 Microns Ltd.   269      2002   -1.852771   -2.181683   -2.181683 |
  7. |                     20 Microns Ltd.   269      2003   -1.910348   -1.852771   -1.852771 |
  8. |                     20 Microns Ltd.   269      2005   -1.855497   -1.910348           . |
  9. |                     20 Microns Ltd.   269      2006   -2.300922   -1.855497   -1.855497 |
 10. | A B B Instrumentation Ltd. [Merged]   331      1990    -3.08322           .           . |
     |-----------------------------------------------------------------------------------------|
 11. | A B B Instrumentation Ltd. [Merged]   331      1991   -3.543726    -3.08322    -3.08322 |
 12. | A B B Instrumentation Ltd. [Merged]   331      1992   -2.775719   -3.543726   -3.543726 |
 13. | A B B Instrumentation Ltd. [Merged]   331      1993   -3.566005   -2.775719   -2.775719 |
 14. | A B B Instrumentation Ltd. [Merged]   331      1994   -3.640079   -3.566005   -3.566005 |
 15. | A B B Instrumentation Ltd. [Merged]   331      1995   -2.996687   -3.640079   -3.640079 |
     |-----------------------------------------------------------------------------------------|
 16. | A B B Instrumentation Ltd. [Merged]   331      1996   -2.698229   -2.996687   -2.996687 |


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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