I would like to ask the following. I have a time series with missing data for certain years, and I would like to calculate the growth rate for the variable median for each year based on a specific base year (the first year for which data for median is available). In other words, I would like create an index series for the median variable (base year=100). I have calculated the growth rate of median using log first differences, where the code looks as follows:
Code:
gen logmedian=log(median) gen growthmedian= logmedian[_n] - logmedian[_n-1] /// if country[_n] == country[_n-1]
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str38 country double year float PPPrealgdi double(gdpcap hhexp median) float(logmedian growthmedian) "Brazil" 1981 . . . 1531.68 7.33412 . "Brazil" 1982 . . . 1541.3999999999999 7.340446 .006326199 "Brazil" 1983 . . . 1266.72 7.144186 -.19626045 "Brazil" 1984 . . . 1275.3600000000001 7.150984 .00679779 "Brazil" 1985 . . . 1454.6399999999999 7.282514 .13152981 "Brazil" 1986 . . . 2435.64 7.797965 .51545143 "Brazil" 1987 . . . 1858.3200000000002 7.527428 -.2705369 "Brazil" 1988 . . . 1741.08 7.462261 -.06516743 "Brazil" 1989 . . . 1877.16 7.537515 .07525444 "Brazil" 1990 . 10344.86438961035 720147699317.049 1616.3999999999999 7.387957 -.14955854 "Brazil" 1991 . 10319.92933521456 779750705063.36 . . . "Brazil" 1992 . 10099.77561998418 774717151172.519 1625.52 7.393583 . "Brazil" 1993 . 10398.16035761199 809876320756.008 1670.88 7.421106 .02752304 "Brazil" 1994 . 10776.43311211532 870158244588.953 . . . "Brazil" 1995 8.49598e+11 11072.7252903522 945180706038.132 2219.3999999999996 7.704992 . "Brazil" 1996 8.860042e+11 11137.58926300037 974140377103.669 2253.48 7.720231 .015238762 "Brazil" 1997 9.292225e+11 11334.82075340726 1003685800287.16 2228.88 7.709254 -.01097679 "Brazil" 1998 9.614585e+11 11197.70193788836 996459125418.385 2311.44 7.745626 .036371708 "Brazil" 1999 9.802891e+11 11081.65462053813 1000228307626.96 2222.04 7.706181 -.03944492 "Brazil" 2000 9.933006e+11 11370.97093925103 1040563838430.28 . . . "Brazil" 2001 9.76703e+11 11368.46644957097 1048589775648.83 2529.36 7.835721 . "Brazil" 2002 1.0052062e+12 11559.56059660686 1062419071054.17 2562 7.848544 .01282215 "Brazil" 2003 1.016476e+12 11541.97503234461 1056618339648.85 2492.2799999999997 7.820953 -.027590275 "Brazil" 2004 1.1615509e+12 12058.2077119511 1098074697769.69 2569.32 7.851397 .03044319 "Brazil" 2005 1.1970837e+12 12298.58794846535 1146630208256.88 2717.7599999999998 7.907563 .05616665 "Brazil" 2006 1.2698414e+12 12643.56500898064 1207226170587.02 2960.64 7.993161 .08559752 "Brazil" 2007 1.374465e+12 13268.41390244003 1284202177161.98 3172.32 8.062219 .06905794 "Brazil" 2008 1.4525213e+12 13802.81799242376 1367216409264.71 3394.44 8.129894 .06767559 "Brazil" 2009 1.5419716e+12 13649.86584029567 1428144990218.13 3544.68 8.173203 .04330921 "Brazil" 2010 1.787638e+12 14537.56719309033 1517109456849.07 . . . "Brazil" 2011 1.9028176e+12 14973.09847367468 1590210762172.73 3903.12 8.269531 . "Brazil" 2012 2.0173075e+12 15119.91213817678 1645859403527.4 4244.76 8.35344 .08390903 "Brazil" 2013 2.1333167e+12 15432.89363081413 1702987902524.9 4472.4 8.405681 .05224037 "Brazil" 2014 2.2029756e+12 15374.2615071807 1741310567302.85 4621.08 8.438384 .0327034 "Brazil" 2015 2.1500094e+12 14702.59126803164 1685301439554.04 4398.4800000000005 8.389014 -.04936981 "Brazil" 2016 . 14077.12140855444 1612150747594.78 . . . "Brazil" 2017 . 14103.45153134036 1627686451678.68 . . . end
Thank you for your time.
Best,
Ryan
0 Response to Creating an index with missing data in time series
Post a Comment