**Code is for the PWT 8.0 database
**Compute RGDP per Capita
**gen rgdp_capita = rgdpo/pop
**Keep only the countrycode, year, and RGDP per Capita variables in the dataset
keep countrycode year rgdp_capita
**Reshape the dataset to be wide
reshape wide rgdp_capita, i(countrycode) j(year)
**loop through all years between 1951 and 2011, compute the gdp growth for each year
foreach year of numlist 1951/2011 {
local prevyear = `year'-1
gen rgdp_capita_growth`prevyear' = rgdp_capita`year'/rgdp_capita`prevyear'-1
}
**compute the volatility of gdp per capita for each country over 1990-2005
**egen stands for "extended generate", use "help egen" to see everything the command can do
egen gdp_1yr_sd_1990_2005 = rowsd(rgdp_capita_growth1990-rgdp_capita_growth2005)
**count the number of years with non-missing data between 2005 and 1990, we won't use this, but can be used as a check to make sure we aren't computing volatility with a three years of data
egen count_gdp_1yr_sd_1990_2005 = rownonmiss(rgdp_capita_growth1990-rgdp_capita_growth2005)
**list the volatility for USA, Korea, and China
list countrycode gdp_1yr_sd_1990_2005 if countrycode == "USA" | countrycode == "KOR" | countrycode == "CHN"
**generate a variable called mean volatility with the average volatility across countries
egen mean_volatility = mean(gdp_1yr_sd_1990_2005)
**browse the data to find the mean volatility
browse
save volatilities, replace
****WAIT TO RUN THIS UNTIL YOU WANT THE KERNEL DENSITY PLOT FOR USA ALONE
**keep only data for the USA
keep if countrycode == "USA"
**keep only the variables with real GDP growth rates
keep countrycode rgdp_capita_growth*
**Reshape the data back to long
reshape long rgdp_capita_growth, i(countrycode) j(year)
kdensity rgdp_capita_growth, normal