Lutz Hendricks - UNC - Department of Economics

# Working With Data

Unlike in previous classes you may have taken, the data for your thesis are raw. You need to understand the structure of the dataset and “clean” the data.

## Data Steps

1. You need to know how the data are structured, who was surveyed, limitations of the data, etc.
2. Assignment: Browse through the documentation for the Current Population Survey (CPS) here. Also look at the sample design.
2. Figure out the variables that you need.
1. Make sure you read the codebooks, especially if the sample design is complicated.
2. You need to know in which context the questions were asked and who was asked.
3. Assignment: Browse through the CPS codebooks.
4. Convert data into the format you want.
1. Datasets usually come in odd formats, such as nondelimited ascii files.
2. Stats packages, such as Stata can often read those files (data sources often provide programs for this).
3. Stat/Transfer can convert between data formats. Especially useful if you want to work in a real programming language rather than a stats package.
5. Show summary statistics and distributions for all variables.
1. Check for implausible values, outliers, odd distributions (e.g., we would expect a wage distribution to look roughly log-Normal).
2. Look at time series plots. Investigate any suspicious jumps.

## What Can Go Wrong?

1. Not enough observations to get precise answers.
1. Example: The Brazilian census has >1m observations, but only a few thousand immigrants.
2. Questions and coding change over time.
1. Example: CPS records number of years of schooling until 1980s; then highest degree earned.
3. Imputed responses (often not obvious).
1. Example: CPS imputes earnings for quite a few observations, but IPUMS does not tell you for which ones.
4. Top coding, especially for dollar figures (income, wealth).
5. Samples are not representative.
1. Example: New Immigrant Survey only contains Legal permanent residents.
2. Almost all panel datasets omit most of the richest 1% (PSID, NLSY).
6. Attrition in panel data (people drop out non-randomly over the years).

## Choosing Software

Stats packages, such as Stata are great at data handling. But their programming languages are a disaster.

Personally, I refuse to work in poorly designed scripting languages and use Matlab instead. This means that I cannot help you with Stata code (but your advisor likely can).

## Tips

1. Write your code so that you can go from raw data to final results by running a single command without manual intervention. It’s the only way to ensure consistency.
2. Read the questionnaires. You need to know exactly what people were asked to understand their answers.
1. The questionnaire also reveals who is in the “universe” for a question (who was asked).
1. Code and Data for the Social Sciences: A Practitioner’s Guide by Gentzkow and Shapiro.