Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • The Deflator index, again.

    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

  • #2
    I don't understand all that you're doing, but the first step looks like a bad step from which you can't recover except by doing the right thing.

    Look at the long list of value labels. You've mapped a string value with numeric content to integers 1 up.

    So, in fact numbers 100 up in strings in or after "100.0" will get put before numbers in strings "82.9" to "99.9". egen, group() just sees string values and puts them in dictionary order, sorting by first character, then second character, etc. There is no homunculus looking inside and saying "Ah, these are really numbers wrapped in string form!"

    Here's the correspondence you've created. There should be other values outside your data example, but the principle is the same.
    Click image for larger version

Name:	bad_idea.png
Views:	1
Size:	18.1 KB
ID:	1480271



    I don't know how closdate_year was ever string in the first place, but my guess is that what you need starts with
    Code:
    destring closdate_year, replace

    Comment


    • #3
      Cox,

      You are correct. In my dataset i would see ppi_value and value (the stringed value) as the same. But when I was posting the dataex, the number changed, to what you said. I wasn't aware of that. Huge mistake. Sorry Benson and Clyde!

      So starting from 0, below is the original dataset, data from: http://appsso.eurostat.ec.europa.eu/...inpp_a&lang=en


      The first thing I want is to change the value from strings to real numbers. How do I do that? I just realized I was overlooking some ":" symbols I had in the rest of the dataset and stata could not replace it. so:
      replace value = "." if value == ":"
      destring value, replace

      Okay. Now, I need to generate a price index, to be able to deflate the investment nominal values (which are not in this dataset).

      I do, which does the trick and is correct.
      bysort country (closdate_year): gen def_2007 = value / value[1] // creating the deflator with base year == 2007
      gen value_base_2007 = def_2007 * 100


      This was given to me by Clyde, but I'm not sure what it does, as it seems to accumulate and I don't understand why.
      by country (closdate_year), sort: gen index2 = 1 if _n == 1
      by country (closdate_year): replace index2 = index[_n-1] * (1+value/100) if _n > 1

      I think I got it now. The error was at the start. Thanks for putting up with this!




      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input int closdate_year str5 value str48 country
      2007 "94.2"  "AUSTRIA" 
      2008 "97.5"  "AUSTRIA" 
      2009 "96.0"  "AUSTRIA" 
      2010 "98.6"  "AUSTRIA" 
      2011 "102.6" "AUSTRIA" 
      2012 "103.5" "AUSTRIA" 
      2013 "102.6" "AUSTRIA" 
      2014 "101.5" "AUSTRIA" 
      2015 "100.0" "AUSTRIA" 
      2016 "98.2"  "AUSTRIA" 
      2017 "100.1" "AUSTRIA" 
      2007 "88.7"  "BELGIUM" 
      2008 "95.8"  "BELGIUM" 
      2009 "90.6"  "BELGIUM" 
      2010 "97.0"  "BELGIUM" 
      2011 "105.6" "BELGIUM" 
      2012 "109.5" "BELGIUM" 
      2013 "109.0" "BELGIUM" 
      2014 "105.2" "BELGIUM" 
      2015 "100.0" "BELGIUM" 
      2016 "98.6"  "BELGIUM" 
      2017 "107.0" "BELGIUM" 
      2007 "82.3"  "BULGARIA"
      2008 "90.8"  "BULGARIA"
      2009 "84.5"  "BULGARIA"
      2010 "92.1"  "BULGARIA"
      2011 "100.9" "BULGARIA"
      2012 "105.0" "BULGARIA"
      2013 "103.3" "BULGARIA"
      2014 "102.0" "BULGARIA"
      2015 "100.0" "BULGARIA"
      2016 "96.9"  "BULGARIA"
      2017 "101.7" "BULGARIA"
      2007 "87.0"  "CROATIA" 
      2008 "92.9"  "CROATIA" 
      2009 "90.8"  "CROATIA" 
      2010 "94.6"  "CROATIA" 
      2011 "101.4" "CROATIA" 
      2012 "106.7" "CROATIA" 
      2013 "106.5" "CROATIA" 
      2014 "103.8" "CROATIA" 
      2015 "100.0" "CROATIA" 
      2016 "96.0"  "CROATIA" 
      2017 "98.0"  "CROATIA" 
      2007 "87.2"  "CYPRUS"  
      2008 "96.7"  "CYPRUS"  
      2009 "95.1"  "CYPRUS"  
      2010 "98.7"  "CYPRUS"  
      2011 "103.6" "CYPRUS"  
      2012 "110.8" "CYPRUS"  
      2013 "108.5" "CYPRUS"  
      2014 "105.4" "CYPRUS"  
      2015 "100.0" "CYPRUS"  
      2016 "95.9"  "CYPRUS"  
      2017 "98.8"  "CYPRUS"  
      2007 "95.6"  "CZECHIA" 
      2008 "95.6"  "CZECHIA" 
      2009 "94.4"  "CZECHIA" 
      2010 "94.3"  "CZECHIA" 
      2011 "97.6"  "CZECHIA" 
      2012 "99.9"  "CZECHIA" 
      2013 "101.0" "CZECHIA" 
      2014 "102.4" "CZECHIA" 
      2015 "100.0" "CZECHIA" 
      2016 "96.8"  "CZECHIA" 
      2017 "97.6"  "CZECHIA" 
      2007 "85.6"  "DENMARK" 
      2008 "96.5"  "DENMARK" 
      2009 "86.5"  "DENMARK" 
      2010 "92.9"  "DENMARK" 
      2011 "100.9" "DENMARK" 
      2012 "103.2" "DENMARK" 
      2013 "104.9" "DENMARK" 
      2014 "103.8" "DENMARK" 
      2015 "100.0" "DENMARK" 
      2016 "98.6"  "DENMARK" 
      2017 "101.1" "DENMARK" 
      2007 "84.8"  "ESTONIA" 
      2008 "90.8"  "ESTONIA" 
      2009 "90.2"  "ESTONIA" 
      2010 "93.2"  "ESTONIA" 
      2011 "97.4"  "ESTONIA" 
      2012 "99.6"  "ESTONIA" 
      2013 "103.7" "ESTONIA" 
      2014 "102.1" "ESTONIA" 
      2015 "100.0" "ESTONIA" 
      2016 "99.3"  "ESTONIA" 
      2017 "102.9" "ESTONIA" 
      2007 "94.5"  "FINLAND" 
      2008 "98.9"  "FINLAND" 
      2009 "91.7"  "FINLAND" 
      2010 "96.8"  "FINLAND" 
      2011 "101.9" "FINLAND" 
      2012 "103.3" "FINLAND" 
      2013 "102.8" "FINLAND" 
      2014 "101.9" "FINLAND" 
      2015 "100.0" "FINLAND" 
      2016 "97.7"  "FINLAND" 
      2017 "101.2" "FINLAND" 
      2007 "94.3"  "FRANCE"  
      end

      Comment

      Working...
      X