Hi,
I'm struggling to come up with the code for this thing that I'm trying to do, and I was wondering if you had any ideas.
I need GDP growth for the years of 2014, 2017 and 2021. However, to reduce noise/ shocks, I want to take the average of five years before each of these years. For instance, for 2014, I’d associate it with the growth rate over 2009-2014; 2012-2017 for 2017 data; and 2016-2021 for 2021 data. To leave it even clearer, basically, all I need is an average of 1) the years from 2009 to 2014 (this would be the value I'd use for 2014), 2) the years from 2012 to 2017 (this would be my 2017 value), and 3) 2016 to 2021 (this would be my 2021 value).
I initially had this but didn't work:
egen avg_GDP = mean(ny_gdp_mktp_kd_zg) if inrange(year, year-5, year)
I also tried:
rolling avg_GDP = (sum(GDP) - sum(GDP[_n-6])) / 6, window(6) by(year)
but I get an error: '' found where ':' expected
I attached my .do file where you can actually get the data directly from the world bank using the wbopendata function
Any thoughts?
Thank you!
I'm struggling to come up with the code for this thing that I'm trying to do, and I was wondering if you had any ideas.
I need GDP growth for the years of 2014, 2017 and 2021. However, to reduce noise/ shocks, I want to take the average of five years before each of these years. For instance, for 2014, I’d associate it with the growth rate over 2009-2014; 2012-2017 for 2017 data; and 2016-2021 for 2021 data. To leave it even clearer, basically, all I need is an average of 1) the years from 2009 to 2014 (this would be the value I'd use for 2014), 2) the years from 2012 to 2017 (this would be my 2017 value), and 3) 2016 to 2021 (this would be my 2021 value).
I initially had this but didn't work:
egen avg_GDP = mean(ny_gdp_mktp_kd_zg) if inrange(year, year-5, year)
I also tried:
rolling avg_GDP = (sum(GDP) - sum(GDP[_n-6])) / 6, window(6) by(year)
but I get an error: '' found where ':' expected
I attached my .do file where you can actually get the data directly from the world bank using the wbopendata function
Any thoughts?
Thank you!
Comment