Skip to content

Instantly share code, notes, and snippets.

@vapniks
Created April 11, 2018 04:14
Show Gist options
  • Save vapniks/6bf232d5a78485f7b68358c8208bc7be to your computer and use it in GitHub Desktop.
Save vapniks/6bf232d5a78485f7b68358c8208bc7be to your computer and use it in GitHub Desktop.
This file reshapes world bank data that has been downloaded into stata using the wbopendata command.
/* This file reshapes world bank data that has been downloaded into stata using the wbopendata command. */
/* It will reshape from wide to long format that can be used in panel data models */
/* First read the file into Stata, e.g: */
/* (replace this command if necessary) */
/* wbopendata, topics(2 - Aid Effectiveness) clear */
use
/* and then, issue the following commands */
drop indicatorcode /* replace this with the name of the appropriate variable */
gen id = _n
reshape long yr, i(id) j(year)
encode indicatorname, gen(varnum) /* create variable different indicatorname values */
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 indicatorname
rename yr data
egen id = group(countryname year)
reshape wide data, i(id) j(varnum)
do vardesc.do
/* Save the data */
save world-bank_aid-effectiveness_2012_long.dta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment