Home
Online Help
Statistical Packages
Stata
Reshape World Development Indicators for Stata Analysis
The World Development Indicators is a commonly used dataset that unfortunately comes in a layout that is very inconvenient for analysis. We have developed the following set of steps to convert it into a "long" form, appropriate for analysis as panel data.
WDI data as downloaded from the World Bank web site:
First, open the spreadsheet in Excel and add a "y" in front of the year column headers, so they have the form y1970, y1971 etc. Save the file as as comma separated values (.csv).
Read the file into Stata using the "insheet" command. Next, issue the following commands:
drop ind1 gen id = _n reshape long y, i(id) j(year) encode ind1_desc, gen(varnum) label save varnum using vardesc, replace
The "label save" command creates vardesc.do, a do file for applying the WDI series descriptors as labels to values of the "varnum" variable. We are going to turn each different value of varnum (each WDI series) into a variable. To keep track of which variable holds the data for which series, we will turn vardesc.do into a program for applying the series descriptors to the variables as variable labels. To do this, edit vardesc.do in Word or another editor so each line has the form:
label var data1 `"Adjusted savings: adjusted net savings (% of GNI)"'
Finally, issue the following commands in stata:
drop id ind1_desc rename y data egen id = group(country_name year) reshape wide data, i(id) j(varnum) do vardesc.do