Hello,
I have GDP per capita data for the USA and USSR, along with the year, country codes and a dummy variable that I generated. I have a variable, rgdpnapc, GDP per capita, that I want to divide for each year between the two countries. For example, 1917 Soviet GDP per Capita/1917 US GDP per Capita. I am trying to do it with loops, but am stuck If I could get some help, that would be great. I have attached the data set and the code
**Load, Rename and Describe Historical GDP Data**
clear
import excel "C\filepath.xlsx", sheet("Full data") firstrow
label var cgdppc "Real GDP per Capita - 2011 Income Comp"
label var rgdpnapc "Real GDP per Capita - 2011 Growth Comp"
gen popmil = pop/1000
label var popmil "Population - Millions"
keep countrycode country year cgdppc rgdpnapc popmil
list countrycode year cgdppc if countrycode == "USA" | countrycode == "SUN"
**Compare the USA and USSR**
keep if countrycode == "USA" | countrycode == "SUN"
keep if year >= 1917 & year <= 1991
gen GDPCompDummy = 0 if countrycode == "USA"
replace GDPCompDummy = 1 if countrycode == "SUN"
gen SOVGDP = rgdpnapc if GDPCompDummy == 1
gen USAGDP = rgdpnapc if GDPCompDummy == 0
foreach x of SOVGDP USAGDP {
gen percGDP = `SOVGDP'/`USAGDP'
}
0 Response to Question about How to Divide Observations within a Single Variable using Loops
Post a Comment