I have a variable for gdp and for survey wave. I have three survey years and for each survey wave its corresponding gdp (a 3-year average of preceding years i.e. if survey year is 1999/2001, then gdp for that survey year is the average of 96,97, 98 gdp).The assumption is the effect of x (gdp) on y (yes – no outcome variable) depends on the previous (year/years gdp). I want to lag the gdp variable. I have tried the code below but I am not sure if it achieves what I need.
Code:
sort SW by SW: gen lag1 = gdp[_n-1] by SW: gen lag2 = gdp[_n-2] by SW: gen lag3 = gdp[_n-3]
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte SW float(gdp lag1 lag2 lag3) 0 5.2 . . . 0 5.2 5.2 . . 0 5.2 5.2 5.2 . 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 5.2 0 5.2 5.2 5.2 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2 5.2 0 5.2 5.2 5.2 5.2 end label values SW per label def per 0 "1999/2001", modify
(I have three survey waves but dataex doesn’t show enough of the data: 0 "1999/2001" 1 "2002/2005" 2 "2006/2009")
My data is a repeated cross section.
0 Response to lagged variables
Post a Comment