I want to refer to a certain value when generating a new variable.
My panel dataset looks as follows:
| year | country_num | gdp_deflator | 
| 2002 | 36 | 62.241596 | 
| 2003 | 36 | 64.179539 | 
| 2004 | 36 | 66.304613 | 
| 2005 | 36 | 68.822255 | 
| 2006 | 36 | 72.326928 | 
| 2007 | 36 | 75.951745 | 
| 2008 | 36 | 79.388969 | 
| 2009 | 36 | 83.359849 | 
| 2010 | 36 | 84.332893 | 
| 2011 | 36 | 89.606027 | 
| 2012 | 36 | 91.269587 | 
| 2013 | 36 | 91.15623 | 
| 2014 | 36 | 92.504954 | 
| 2015 | 36 | 91.996491 | 
| 2016 | 36 | 91.50615 | 
| 2017 | 36 | 94.923676 | 
| 2018 | 36 | 96.713572 | 
| 2019 | 36 | 100 | 
| 2020 | 36 | 101.96804 | 
| 2002 | 50 | 81.621139 | 
| 2003 | 50 | 86.368075 | 
| 2004 | 50 | 90.308304 | 
| 2005 | 50 | 94.450169 | 
| 2006 | 50 | 100 | 
| 2007 | 50 | 106.47126 | 
| 2008 | 50 | 114.84093 | 
| 2009 | 50 | 122.60918 | 
| 2010 | 50 | 131.36919 | 
gdp_deflator contains the GDP deflator for the country in the respective year. However, the base year varies by country.
Hence, I want to calculate a new GDP deflator which has the same base year (2010) for every year and country.
To do so, I use the following formula for every year t: new_deflator(t) = 100 * gdp_deflator(t) / gdp_deflator(2010)
Thus, for every country and year, I want to divide the GDP deflator of the year by its GDP deflator of the year 2010. For example, the calculation for the first observation would be 100 * 62.241596 / 84.332893 = 73.8.
How can I implement this formula when using generate or egen or even replace?
For example, I tried something like
Code:
generate new_deflator = 100 * gdp_deflator / gdp_deflator[year==2010]
Thank you for your help!
0 Response to Referring to a certain value when generating a new variable
Post a Comment