My data resembles the following:
Here, I have a dataset (which I have declared as time series for convenience), and for which I have variables y, x1 and a new variable. The first value of the new variable is to be computed as the value of y in the first year (say 1990) times the value of x1 in the following year. This is straightforward:
However, for every following year for new, I wish to use the previous value of new multiplied with the current value of x1. I run:
or
This works for only the first observation after 1990, i.e. 1991. In other words, values do not cascade down to use new non-missing values of the new variable. Is there something obvious I am missing?
Thanks,
CS
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double(year y x1 new) 1990 23 1.5 . 1991 . 2.1 . 1992 . 2.1 . 1993 . 4.6 . end
Code:
replace new=y*F.x1 if year==1990
Code:
replace new=new[_n]*x1[_n+1] if year>1990
Code:
replace new=new*F.x1if year>1990
Thanks,
CS
Comment