Hello Stata-listers,
I am trying to calculate 5 year compound growth rates of gdppc (ie [(End val/beg val) ^(1/totyears)]-1 ). After lots of hunting, I could not find the code that I am looking for. Eventually, I will also calculate 10, 15, 20 year spans, as well.
I am using Stata 13.1 for Mac, the data is panel with typical gdp data (country, year, gdppc). I have a much longer timespan for this (1962 - present) for 160 countries, but for simplicity I am providing the past 14 years of data for one country.
Please note that I do not use the string isocode, but rather ccode (encoded isocode, but for the sake of understanding, I presented the data with the country codes)
My input data:
My code:
My output:
What I am trying to calculate is the compound growth rate for every five years. So I would like my data to end up looking like:
"USA" 2000 .03046135
"USA" 2001 .
"USA" 2002 .
"USA" 2003 .
"USA" 2004 .
"USA" 2005 .016008312
"USA" 2006 .
"USA" 2007 .
"USA" 2008 .
"USA" 2009 .
"USA" 2010 -.001490759
"USA" 2011 .
"USA" 2012 .
"USA" 2013 .
"USA" 2014 .
[/CODE]
I am willing to settle for a dummy variable generation where the year ends with a 5 or 0, but not sure how to code that.
Thank you for your help!
I am trying to calculate 5 year compound growth rates of gdppc (ie [(End val/beg val) ^(1/totyears)]-1 ). After lots of hunting, I could not find the code that I am looking for. Eventually, I will also calculate 10, 15, 20 year spans, as well.
I am using Stata 13.1 for Mac, the data is panel with typical gdp data (country, year, gdppc). I have a much longer timespan for this (1962 - present) for 160 countries, but for simplicity I am providing the past 14 years of data for one country.
Please note that I do not use the string isocode, but rather ccode (encoded isocode, but for the sake of understanding, I presented the data with the country codes)
My input data:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long code int year float gdpwtc "USA" 2000 45866.84 "USA" 2001 45844.46 "USA" 2002 46230.65 "USA" 2003 47114.27 "USA" 2004 48477.21 "USA" 2005 49657.54 "USA" 2006 50517.59 "USA" 2007 50939.59 "USA" 2008 50321.09 "USA" 2009 48485.1 "USA" 2010 49288.5 "USA" 2011 49674.8 "USA" 2012 50390.96 "USA" 2013 50764.77 "USA" 2014 51620.79 end
Code:
bys ccode: gen g5pwt = [(gdpwt/l5.gdpwtc)^(1/5)]-1
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str3 isocode int year float g5pwt "USA" 2000 .03046135 "USA" 2001 .02516414 "USA" 2002 .020465866 "USA" 2003 .018027034 "USA" 2004 .016984068 "USA" 2005 .016008312 "USA" 2006 .019603074 "USA" 2007 .019588867 "USA" 2008 .013256771 "USA" 2009 .000032567954 "USA" 2010 -.001490759 "USA" 2011 -.003359077 "USA" 2012 -.0021633469 "USA" 2013 .001757208 "USA" 2014 .012612472
"USA" 2000 .03046135
"USA" 2001 .
"USA" 2002 .
"USA" 2003 .
"USA" 2004 .
"USA" 2005 .016008312
"USA" 2006 .
"USA" 2007 .
"USA" 2008 .
"USA" 2009 .
"USA" 2010 -.001490759
"USA" 2011 .
"USA" 2012 .
"USA" 2013 .
"USA" 2014 .
[/CODE]
I am willing to settle for a dummy variable generation where the year ends with a 5 or 0, but not sure how to code that.
Thank you for your help!
Comment