Dear all,
I have different variables in rows for different countries over many years in wide form. A very short part of my data is as below:
I want to convert the data into long form. If there was only one variable, the below code would have get the job done:
However, in the above dataset I have 3 different variables: life expectancy, GDP per capita and unemployment rate. Here is my question: how can I convert this dataset into long format that variables are listed in columns?
Many thanks in advance.
I have different variables in rows for different countries over many years in wide form. A very short part of my data is as below:
Code:
clear input str48 CountryName str3 CountryCode str67 SeriesName double(YR2019 YR2020 YR2021 YR2022) "Belgium" "BEL" "Life expectancy at birth, total (years)" 81.99512195121952 80.69512195121952 81.79024390243904 81.69756097560978 "Belgium" "BEL" "GDP per capita (current US$)" 46641.72140170868 45587.96830831899 51863.83115650539 49942.090642488656 "Belgium" "BEL" "Unemployment, total (% of total labor force) (modeled ILO estimate)" 5.36 5.555 6.264 5.558 "Austria" "AUT" "Life expectancy at birth, total (years)" 81.89512195121951 81.19268292682928 81.19024390243904 81.09268292682928 "Austria" "AUT" "GDP per capita (current US$)" 50067.58572658923 48789.49784988721 53517.89045096115 52084.68119533723 "Austria" "AUT" "Unemployment, total (% of total labor force) (modeled ILO estimate)" 4.56 5.201 6.459 4.992 "United Kingdom" "GBR" "Life expectancy at birth, total (years)" 81.40487804878049 80.35121951219514 80.7 82.05853658536587 "United Kingdom" "GBR" "GDP per capita (current US$)" 42662.535374031075 40217.00901169857 46869.75905841103 45564.15694480128 "United Kingdom" "GBR" "Unemployment, total (% of total labor force) (modeled ILO estimate)" 3.737 4.472 4.826 3.73 end
Code:
reshape long YR, i(CountryName CountryCode) j(date)
Many thanks in advance.
Comment