Hello all,

I did two posts about this, but I am having trouble swimming through the data. The value is the PPI industry prices with base year 2015. I want to deflate the industry investment I have, therefore, I can create an index.

I need to create the index so I can get the gross investment and then deflate it by the appropriate price deflator. Previosuly I created this code below (with the help of some fellow people from statalist). However, I have a few questions.

1. When I try to do the index by country (closdate_year): replace index2 = index[_n-1] * (1+ppi_value/100) if _n > 1, I get a very wierd, cumulative number. How can I get this to do be non cumulative?
2. Is the def_2007 value correct? That means, I have to do: realinvestment = nominalinvestment/ def_2007 ?
3. If I would like to not touch the base year of 2015, and do an index from there, what would I need to do to get the real investment?



Code:
egen ppi_value = group(value), label
*** Creating the index for which we will have to deflate later, with base year 2007
bysort country (closdate_year): gen def_2007 = ppi_value / ppi_value[1] // creating the deflator with base year == 2007
gen value_base_2007 = def_2007 * 100

*** Other way of indexing
by country (closdate_year), sort: gen index2 = 1 if _n == 1
by country (closdate_year): replace index2 = index[_n-1] * (1+ppi_value/100) if _n > 1






Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int closdate_year str5 value str48 country float(ppi_value def_2007 value_base_2007 index2)
2007 "94.2"  "AUSTRIA"  118          1       100         1
2008 "97.5"  "AUSTRIA"  146   1.237288 123.72881      2.46
2009 "96.0"  "AUSTRIA"  132  1.1186441  111.8644    5.7072
2010 "98.6"  "AUSTRIA"  155  1.3135593 131.35593  14.55336
2011 "102.6" "AUSTRIA"   27  .22881356 22.881355 18.482767
2012 "103.5" "AUSTRIA"   35  .29661018  29.66102 24.951736
2013 "102.6" "AUSTRIA"   27  .22881356 22.881355 31.688705
2014 "101.5" "AUSTRIA"   16  .13559322 13.559322   36.7589
2015 "100.0" "AUSTRIA"    1 .008474576  .8474576 37.126488
2016 "98.2"  "AUSTRIA"  152  1.2881356 128.81357  93.55875
2017 "100.1" "AUSTRIA"    2 .016949153 1.6949153  95.42992
2007 "88.7"  "BELGIUM"   97          1       100         1
2008 "95.8"  "BELGIUM"  130   1.340206 134.02061       2.3
2009 "90.6"  "BELGIUM"  105  1.0824742 108.24742 4.7149997
2010 "97.0"  "BELGIUM"  141  1.4536083 145.36082  11.36315
2011 "105.6" "BELGIUM"   49   .5051546  50.51546 16.931093
2012 "109.5" "BELGIUM"   70   .7216495  72.16495  28.78286
2013 "109.0" "BELGIUM"   67   .6907216  69.07217  48.06737
2014 "105.2" "BELGIUM"   46   .4742268  47.42268  70.17836
2015 "100.0" "BELGIUM"    1 .010309278 1.0309278  70.88014
2016 "98.6"  "BELGIUM"  155  1.5979382 159.79382 180.74437
2017 "107.0" "BELGIUM"   59   .6082474  60.82474 287.38354
2007 "82.3"  "BULGARIA"  82          1       100         1
2008 "90.8"  "BULGARIA" 106   1.292683  129.2683      2.06
2009 "84.5"  "BULGARIA"  85  1.0365853 103.65853     3.811
2010 "92.1"  "BULGARIA" 110  1.3414634 134.14635  8.003099
2011 "100.9" "BULGARIA"  10  .12195122 12.195122   8.80341
2012 "105.0" "BULGARIA"  44   .5365854  53.65854  12.67691
2013 "103.3" "BULGARIA"  34   .4146341  41.46341 16.987059
2014 "102.0" "BULGARIA"  21  .25609756 25.609756  20.55434
2015 "100.0" "BULGARIA"   1 .012195121  1.219512 20.759884
2016 "96.9"  "BULGARIA" 140   1.707317  170.7317  49.82372
2017 "101.7" "BULGARIA"  18   .2195122  21.95122  58.79199
2007 "87.0"  "CROATIA"   91          1       100         1
2008 "92.9"  "CROATIA"  113  1.2417582 124.17582      2.13
2009 "90.8"  "CROATIA"  106  1.1648352 116.48352    4.3878
2010 "94.6"  "CROATIA"  122  1.3406594 134.06593  9.740916
2011 "101.4" "CROATIA"   15  .16483517 16.483517 11.202054
2012 "106.7" "CROATIA"   57   .6263736  62.63736 17.587225
2013 "106.5" "CROATIA"   55   .6043956  60.43956   27.2602
2014 "103.8" "CROATIA"   38   .4175824  41.75824 37.619076
2015 "100.0" "CROATIA"    1  .01098901 1.0989012 37.995266
2016 "96.0"  "CROATIA"  132  1.4505495 145.05495  88.14902
2017 "98.0"  "CROATIA"  150  1.6483517 164.83517 220.37254
2007 "87.2"  "CYPRUS"    92          1       100         1
2008 "96.7"  "CYPRUS"   138        1.5       150      2.38
2009 "95.1"  "CYPRUS"   125  1.3586956 135.86957     5.355
2010 "98.7"  "CYPRUS"   156   1.695652  169.5652   13.7088
2011 "103.6" "CYPRUS"    36   .3913043  39.13044  18.64397
2012 "110.8" "CYPRUS"    73   .7934783  79.34782  32.25407
2013 "108.5" "CYPRUS"    66   .7173913  71.73913  53.54176
2014 "105.4" "CYPRUS"    47  .51086956  51.08696  78.70638
2015 "100.0" "CYPRUS"     1 .010869565 1.0869565  79.49345
2016 "95.9"  "CYPRUS"   131   1.423913  142.3913 183.62987
2017 "98.8"  "CYPRUS"   157  1.7065217 170.65218  471.9288
end
label values ppi_value ppi_value
label def ppi_value 1 "100.0", modify
label def ppi_value 2 "100.1", modify
label def ppi_value 10 "100.9", modify
label def ppi_value 15 "101.4", modify
label def ppi_value 16 "101.5", modify
label def ppi_value 18 "101.7", modify
label def ppi_value 21 "102.0", modify
label def ppi_value 27 "102.6", modify
label def ppi_value 34 "103.3", modify
label def ppi_value 35 "103.5", modify
label def ppi_value 36 "103.6", modify
label def ppi_value 38 "103.8", modify
label def ppi_value 44 "105.0", modify
label def ppi_value 46 "105.2", modify
label def ppi_value 47 "105.4", modify
label def ppi_value 49 "105.6", modify
label def ppi_value 55 "106.5", modify
label def ppi_value 57 "106.7", modify
label def ppi_value 59 "107.0", modify
label def ppi_value 66 "108.5", modify
label def ppi_value 67 "109.0", modify
label def ppi_value 70 "109.5", modify
label def ppi_value 73 "110.8", modify
label def ppi_value 82 "82.3", modify
label def ppi_value 85 "84.5", modify
label def ppi_value 91 "87.0", modify
label def ppi_value 92 "87.2", modify
label def ppi_value 97 "88.7", modify
label def ppi_value 105 "90.6", modify
label def ppi_value 106 "90.8", modify
label def ppi_value 110 "92.1", modify
label def ppi_value 113 "92.9", modify
label def ppi_value 118 "94.2", modify
label def ppi_value 122 "94.6", modify
label def ppi_value 125 "95.1", modify
label def ppi_value 130 "95.8", modify
label def ppi_value 131 "95.9", modify
label def ppi_value 132 "96.0", modify
label def ppi_value 138 "96.7", modify
label def ppi_value 140 "96.9", modify
label def ppi_value 141 "97.0", modify
label def ppi_value 146 "97.5", modify
label def ppi_value 150 "98.0", modify
label def ppi_value 152 "98.2", modify
label def ppi_value 155 "98.6", modify
label def ppi_value 156 "98.7", modify
label def ppi_value 157 "98.8", modify