Dear Stata Users,
I have a dataset about GDP of several years (1980—2000), the dataset has GDP in current price (curregdp) and GDP growth rate (growth).
Now I want to generate a variable that represents GDP calculated in 1990 year price, let's name the variable gdpbase1990.
According to economic theory, gdpbase1990 can be generated by multiplying GDP of 1990 and GDP growth rate of responding years.
eg. gdpbase1990 of year 1991=gdp1990*growth[1991]
gdpbase1990 of year 1992=gdp1990*growth[1991]*growth[1992]
gdpbase1990 of year 1989=gdp1990/growth[1989]
gdpbase1990 of year 1988=gdp1990/growth[1989]/growth[1988], and so on.
So it takes the following forms:
Y[1]=A*X[1]
Y[2]=A*X[1]*X[2]
Y[3]=A*X[1]*X[2]*X[3]
Y[_n]=A*X[1]*X[2]*......*X[_n-1]*X[_n]
Y[-1]=A*X[-1]
Y[-2]=A*X[-1]/X[-2]
Y[-3]=A*X[-1]/X[-2]/X[-3]
Y[-_n]=A*X[-1]/X[-2]/....../X[-_n-1]/X[-_n]
However, I couldn't find a fast solution in Stata. The codes I use is so clumsy and error-prone. Can anyone help me providing clever codes? Thank you.
Addtionaly, the resulting product would approximately equal to variable constgdp in 1990—2000 which represents GDP calculated in constant price. And sorry for the stupid codes that follows.
I have a dataset about GDP of several years (1980—2000), the dataset has GDP in current price (curregdp) and GDP growth rate (growth).
Now I want to generate a variable that represents GDP calculated in 1990 year price, let's name the variable gdpbase1990.
According to economic theory, gdpbase1990 can be generated by multiplying GDP of 1990 and GDP growth rate of responding years.
eg. gdpbase1990 of year 1991=gdp1990*growth[1991]
gdpbase1990 of year 1992=gdp1990*growth[1991]*growth[1992]
gdpbase1990 of year 1989=gdp1990/growth[1989]
gdpbase1990 of year 1988=gdp1990/growth[1989]/growth[1988], and so on.
So it takes the following forms:
Y[1]=A*X[1]
Y[2]=A*X[1]*X[2]
Y[3]=A*X[1]*X[2]*X[3]
Y[_n]=A*X[1]*X[2]*......*X[_n-1]*X[_n]
Y[-1]=A*X[-1]
Y[-2]=A*X[-1]/X[-2]
Y[-3]=A*X[-1]/X[-2]/X[-3]
Y[-_n]=A*X[-1]/X[-2]/....../X[-_n-1]/X[-_n]
However, I couldn't find a fast solution in Stata. The codes I use is so clumsy and error-prone. Can anyone help me providing clever codes? Thank you.
Addtionaly, the resulting product would approximately equal to variable constgdp in 1990—2000 which represents GDP calculated in constant price. And sorry for the stupid codes that follows.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(year constgdp curregdp growth) 1980 4567.9 4545.6 107.8 1981 4807.4 4891.6 105.2 1982 5242.8 5323.4 109.1 1983 5811.8 5962.7 110.9 1984 6693.8 7208.1 115.2 1985 7595.2 9016 113.5 1986 8267.1 10275.2 108.8 1987 9224.7 12058.6 111.6 1988 10265.3 15042.8 111.3 1989 10682.4 16992.3 104.1 1990 18547.9 18667.8 103.8 1991 20250.4 21781.5 109.2 1992 23134.2 26923.5 114.2 1993 26364.7 35333.9 114 1994 29813.4 48197.9 113.1 1995 33070.5 60793.7 110.9 1996 36380.4 71176.6 110 1997 39762.7 78973 109.3 1998 42877.4 84402.3 107.8 1999 46144.6 89677.1 107.6 2000 50035.2 99214.6 108.4 end label var constgdp "GDP calculated at constant prices (base year are 1980,1990)" label var curregdp "GDP calculated at current prices" label var growth "Real GDP growth rate"
Code:
gen gdpbase1990=curregdp[11] /*gdpbase1990: years after 1990 (1991—2000)*/ replace gdpbase1990=curregdp[11]*(growth[11]/100)*(growth[12]/100) in 12 replace gdpbase1990=curregdp[11]*(growth[11]/100)*(growth[12]/100)*(growth[13]/100) in 13 replace gdpbase1990=curregdp[11]*(growth[11]/100)*(growth[12]/100)*(growth[13]/100)*(growth[14]/100) in 14 replace gdpbase1990=curregdp[11]*(growth[11]/100)*(growth[12]/100)*(growth[13]/100)*(growth[14]/100)*(growth[15]/100) in 15 replace gdpbase1990=curregdp[11]*(growth[11]/100)*(growth[12]/100)*(growth[13]/100)*(growth[14]/100)*(growth[15]/100)*(growth[16]/100) in 16 replace gdpbase1990=curregdp[11]*(growth[11]/100)*(growth[12]/100)*(growth[13]/100)*(growth[14]/100)*(growth[15]/100)*(growth[16]/100)*(growth[17]/100) in 17 replace gdpbase1990=curregdp[11]*(growth[11]/100)*(growth[12]/100)*(growth[13]/100)*(growth[14]/100)*(growth[15]/100)*(growth[16]/100)*(growth[17]/100)*(growth[18]/100) in 18 replace gdpbase1990=curregdp[11]*(growth[11]/100)*(growth[12]/100)*(growth[13]/100)*(growth[14]/100)*(growth[15]/100)*(growth[16]/100)*(growth[17]/100)*(growth[18]/100)*(growth[19]/100) in 19 replace gdpbase1990=curregdp[11]*(growth[11]/100)*(growth[12]/100)*(growth[13]/100)*(growth[14]/100)*(growth[15]/100)*(growth[16]/100)*(growth[17]/100)*(growth[18]/100)*(growth[19]/100)*(growth[20]/100) in 20 replace gdpbase1990=curregdp[11]*(growth[11]/100)*(growth[12]/100)*(growth[13]/100)*(growth[14]/100)*(growth[15]/100)*(growth[16]/100)*(growth[17]/100)*(growth[18]/100)*(growth[19]/100)*(growth[20]/100)*(growth[21]/100) in 21 /*gdpbase1990: years before 1990 (1980—1989)*/ replace gdpbase1990=curregdp[11]/(growth[10]/100) in 10 replace gdpbase1990=curregdp[11]/(growth[10]/100)/(growth[9]/100) in 9 replace gdpbase1990=curregdp[11]/(growth[10]/100)/(growth[9]/100)/(growth[8]/100) in 8 replace gdpbase1990=curregdp[11]/(growth[10]/100)/(growth[9]/100)/(growth[8]/100)/(growth[7]/100) in 7 replace gdpbase1990=curregdp[11]/(growth[10]/100)/(growth[9]/100)/(growth[8]/100)/(growth[7]/100)/(growth[6]/100) in 6 replace gdpbase1990=curregdp[11]/(growth[10]/100)/(growth[9]/100)/(growth[8]/100)/(growth[7]/100)/(growth[6]/100)/(growth[5]/100) in 5 replace gdpbase1990=curregdp[11]/(growth[10]/100)/(growth[9]/100)/(growth[8]/100)/(growth[7]/100)/(growth[6]/100)/(growth[5]/100)/(growth[4]/100) in 4 replace gdpbase1990=curregdp[11]/(growth[10]/100)/(growth[9]/100)/(growth[8]/100)/(growth[7]/100)/(growth[6]/100)/(growth[5]/100)/(growth[4]/100)/(growth[3]/100) in 3 replace gdpbase1990=curregdp[11]/(growth[10]/100)/(growth[9]/100)/(growth[8]/100)/(growth[7]/100)/(growth[6]/100)/(growth[5]/100)/(growth[4]/100)/(growth[3]/100)/(growth[2]/100) in 2 replace gdpbase1990=curregdp[11]/(growth[10]/100)/(growth[9]/100)/(growth[8]/100)/(growth[7]/100)/(growth[6]/100)/(growth[5]/100)/(growth[4]/100)/(growth[3]/100)/(growth[2]/100)/(growth[1]/100) in 1

Comment