undefined

Coding in Economics

By Otis Reid

I’m a PhD student in economics at MIT. I studied economics in undergrad and after spending a year as a consultant, came to MIT in 2013. I focus on development — why are poor countries poor? — and political economy — why do political leaders make the decisions that they do? Most of my work involves traveling to different countries to collect data, most recently Uganda and the Democratic Republic of the Congo, but I also work with existing data sets that have been collected by other researchers or organizations like the World Bank.

One secret of economics, like any data-based science, is that there is a lot of coding that goes into producing our final analyses.

One secret of economics, like any data-based science, is that there is a lot of coding that goes into producing our final analyses. I mostly work in Stata, a data analysis program, but I also do some work in Python. Most of the coding I do is to combine and clean data sets. A simple example would be that I do two different surveys with the same set of people and then I want to have all of the answers that one person gave in a single file for analysis. A more complicated example might involve combining data from different agencies, which use different identifiers: one of the agencies writes “Tennessee” and another writes “TN”. Maybe a third agency even has data at the level of cities or counties. Combining this data means writing code that not only merges the files, but also gives them all a common set of IDs so that all of the data can work together — writing good code can be the difference between having all your data in one place versus scattered across many files.

Knowing how to code can save tens or hundreds of hours and makes projects like analyzing the complete history of a huge Indian public works program possible.

The other way I use coding is to collect data. Even working on development topics, there is a surprising amount of data that’s online. More and more countries are posting data to webpages as part of transparency efforts. I use Python to make simple web-scrapers to download this data in batches. Knowing how to code can save tens or hundreds of hours and makes projects like analyzing the complete history of a huge Indian public works program possible.

By hand, that would have taken days if not weeks — with Python I did it overnight. As data sets grow larger and larger, knowing how to code effectively is only getting more important in economics.

Knowing programming languages like Python can also save you tons of time in surprising ways: in February, I needed to rapidly format thousands of assignment sheets for my survey teams to take with them into the field. By hand, that would have taken days if not weeks — with Python I did it overnight. As data sets grow larger and larger, knowing how to code effectively is only getting more important in economics. Today’s grad students are much better equipped if they have programming experience in high school and college, since it makes learning new techniques easier — and they can often leverage their existing knowledge. Plus, it’s always pretty cool to be able to go for a walk outside and tell people “I’m working right now: my code is running.” Always good to have the computer working for you!

Otis Reid is a PhD student at MIT in economics, studying development and political economy.

Tools and Languages Mentioned: Stata and Python