Hello,
I am trying to reshape my data to long; it is currently organized as follows: each observation is a certain variable for a certain country and the variables (columns) are years (see before dataex).
I want to achieve a long data with variables country, year, GDP per capita, Natural Rents (see desired dataex); but instead I get variables: country, seriescode, year, value (see after dataex).
Thank you!
This is the code I used:
Before dataex:
After dataex:
Desired dataex:
I am trying to reshape my data to long; it is currently organized as follows: each observation is a certain variable for a certain country and the variables (columns) are years (see before dataex).
I want to achieve a long data with variables country, year, GDP per capita, Natural Rents (see desired dataex); but instead I get variables: country, seriescode, year, value (see after dataex).
Thank you!
This is the code I used:
Code:
reshape long yr, i(countrycode seriescode) j(year)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str3 countrycode str17 seriescode float(yr1971 yr1972 yr1973 yr1974) "AFG" "GDPPC" .3739563 .4352624 .8714833 1.1527195 "AFG" "NR" 159.5675 135.31723 143.14465 173.65363 "ALB" "GDPPC" . . . . "ALB" "NR" . . . . end
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str3 countrycode str17 seriescode int year float yr "AFG" "GDPPC" 1971 .3739563 "AFG" "GDPPC" 1972 .4352624 "AFG" "GDPPC" 1973 .8714833 "AFG" "GDPPC" 1974 1.1527195 "AFG" "NR" 1971 159.5675 "AFG" "NR" 1972 135.31723 "AFG" "NR" 1973 143.14465 "AFG" "NR" 1974 173.65363 "ALB" "GDPPC" 1971 . "ALB" "GDPPC" 1972 . "ALB" "GDPPC" 1973 . "ALB" "GDPPC" 1974 . "ALB" "NR" 1971 . "ALB" "NR" 1972 . "ALB" "NR" 1973 . "ALB" "NR" 1974 . end
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str3 countrycode int year float(gdppc nr) "AFG" 1971 .3739563 159.5675 "AFG" 1972 .4352624 135.31723 "AFG" 1973 .8714833 143.14465 "AFG" 1974 1.1527195 173.65363 "ALB" 1971 . . "ALB" 1972 . . "ALB" 1973 . . "ALB" 1974 . . end
Comment