I have a panel data set (the identifiers are the variables of cc and year).
I have all the values for the Y variable but I have only the initial (X_{1996}) values of the X variable.
I would like to replace the missing values of X with this pattern:
X_{1997} = Y_{1996} + 0.95*X_{1996}
X_{1998} = Y_{1997} + 0.95*X_{1997}
.
.
.
X_{2015} = Y_{2014} + 0.95*X_{2014}
I would like to iteratively replace X starting from 1997, that is using the last generated value.
Is it possible to write a loop for this purpose?
Example data:
clear
input str3 cc year X Y
"ABW" 1996 467.5953 28.46004
"ABW" 1997 . 30.23142
"ABW" 1998 . 31.70577
"ABW" 1999 . 30.870903
"ABW" 2000 . 25.495903
"ABW" 2001 . 23.71254
"ABW" 2002 . 26.906475
"ABW" 2003 . 29.215036
"ABW" 2004 . 28.77914
"ABW" 2005 . 33.581017
"ABW" 2006 . 35.16129
"ABW" 2007 . 32.51442
"ABW" 2008 . 33.251934
"ABW" 2009 . 30.29287
"ABW" 2010 . 28.931993
"ABW" 2011 . 28.5057
"ABW" 2012 . 26.647564
"ABW" 2013 . 23.999134
"ABW" 2014 . 22.917984
"ABW" 2015 . 21.481943
"AFG" 1996 362.353 11.51442
"AFG" 1997 . 11.557285
"AFG" 1998 . 12.19376
"AFG" 1999 . 14.557285
"AFG" 2000 . 12.906254
"AFG" 2001 . 13.156855
"AFG" 2002 . 11.557285
"AFG" 2003 . 15.758896
"AFG" 2004 . 19.005346
"AFG" 2005 . 23.193766
"AFG" 2006 . 26.407976
"AFG" 2007 . 20.068926
"AFG" 2008 . 19.021326
"AFG" 2009 . 17.991436
"AFG" 2010 . 17.959072
"AFG" 2011 . 16.674591
"AFG" 2012 . 16.906254
"AFG" 2013 . 17.343513
"AFG" 2014 . 18.156855
"AFG" 2015 . 19.454687
xtsetortssetyour data first and exploit time series operators, which not only respect panels but also do the right thing if there are gaps in your data. For that you need a numeric panel identifier, whichencodecan do for you.