#WARNING — this is very draft.
I’m posting code for the adventurous among you, but I’m not sure how useful it is without more elaboration in the text. That elaboration is forthcoming … someday.
Note: this work was completed while working for Professor John Casterline.
The World Fertility Surveys are archived here, as a set of fixed-width data files and data dictionaries. That is, sans code for making the files readily usable for analysis.
When faced with a problem like this, perhaps any problem where one can conceive of more and less sophisticated solutions, one is also faced with the sad fact that we only get to live in one universe at once, even if we can conceive of many. Should I just slog it out, writing code by hand to pull the variables I need for this particular task, or even go all out and write the whole thing? Or, should I try to make a robot that does it for me? The former is tedious but probably gets the desired result almost all the time; the latter isn’t a sure thing, and one could spend a lot of time and end up empty.
I built a robot this time around, and it’s inelegant but basically gets the job done.
What it Does
Given original WFS data and dictionary files from Princeton’s OPR archive or wherever, the code below:
- Produces a set of do-files to convert the delimited data files into Stata-format files,
- Produces a set of do-files to apply variable and value labels to the Stata files,
- Executes the aforementioned do-files.
Manual Front-End Stuff
Pick a folder in which to work and adjust the code I’ve posted accordingly. In the code I’ve posted, fix the paths so they match your environment. Note that UNIX/Mac paths require forward-slashes (/), but Stata for Windows can use either them or backslashes (\) — unlike Windows itself, which is essentially backslash-only.
Download data and dictionary files from the WFS archive: as of 9 Sept 2013, it’s here: http://opr.princeton.edu/archive/wfs
You’ll benefit from a tool like DownloadThemAll for Firefox when downloading lots of files.
It’s convenient to save all the files to a single folder, and we’ll let Stata sort them out. They’re zip files, however, so we’ll need to batch-unzip everything:
Continue reading Turning the World Fertility Surveys’ raw data into a set of Stata dta files →