Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 36 ยท Projects and Practice

Project: A Wage Regression from Raw Data to Table

Plan and write a complete Stata analysis: clean a survey, explore wages, fit a sequence of log-wage models, check diagnostics and export a table, with a Python rehearsal.

This project ties the course together. You will take a survey-style dataset of workers and answer a question that economists ask all the time: how much do wages rise with education, after accounting for experience, gender and region? You will write the analysis as a set of do-files, record every decision, and produce a regression table ready for a paper.

Stata cannot run on this site, so the Stata code below is read-only and we show no Stata output. To let you rehearse the whole workflow, the runnable blocks are Python stand-ins that create a simulated dataset and carry out each step: clean, describe, model and report. Use the Python to understand the logic and then write the Stata version in your own copy of Stata.

The question and the plan

Question: what is the percentage change in hourly wage associated with one more year of schooling?

Plan (one do-file per step):

  1. 01_clean.do: import, label, recode, drop impossible values, save.
  2. 02_describe.do: summary statistics, histograms, correlations.
  3. 03_models.do: a sequence of regressions with vce(robust).
  4. 04_tables.do: export the table and a figure.
  5. master.do: run all four in order (see the workflow lesson).

Step 1: cleaning

STATA
* 01_clean.do
version 18
clear all
set seed 20250101
log using "logs/01_clean.log", replace text

import delimited "data/raw/workers.csv", clear
rename (hrwage yrsschool yrsexper) (wage educ exper)
label variable wage  "Hourly wage (USD)"
label variable educ  "Years of schooling"
label variable exper "Years of experience"

encode sex, gen(female)           // string to labelled numeric
recode female (1 = 0 "Male") (2 = 1 "Female"), gen(woman)
isid id
assert !missing(id)

count if wage <= 0 | missing(wage)
drop if wage <= 0 | missing(wage)  // document how many you dropped
gen lnwage = ln(wage)
gen exper2 = exper^2
assert inrange(educ, 0, 25)

save "data/clean/workers.dta", replace
log close

Notice the checks: isid for the identifier, assert for ranges, and an explicit count before the drop, so the log says how many rows were removed and why.

Step 2: describing

STATA
use "data/clean/workers.dta", clear
summarize wage lnwage educ exper, detail
tabstat wage, by(woman) stat(mean sd p50 n)
histogram wage, normal
histogram lnwage, normal
twoway scatter lnwage educ || lfit lnwage educ
correlate lnwage educ exper

Wages are right-skewed, so analysts model lnwage: a coefficient on educ then approximates a percentage change. The histogram of lnwage should be far more symmetric than that of wage.

Step 3: models

STATA
use "data/clean/workers.dta", clear
regress lnwage educ, vce(robust)
estimates store m1
regress lnwage educ exper c.exper#c.exper, vce(robust)
estimates store m2
regress lnwage educ exper c.exper#c.exper i.woman, vce(robust)
estimates store m3
regress lnwage educ exper c.exper#c.exper i.woman i.region, vce(robust)
estimates store m4

Each model adds controls. Watch how the educ coefficient moves; if it changes a lot, the omitted variables mattered. Then run estat vif, rvfplot, and look at influential cases (diagnostics). Using c.exper#c.exper keeps the quadratic tied to exper so margins works.

Step 4: tables

STATA
esttab m1 m2 m3 m4 using "output/tables/wages.rtf", replace ///
    b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) label ///
    indicate("Region FE = *region*") ///
    stats(N r2, labels("Observations" "R-squared")) ///
    mtitles("Education" "+ Experience" "+ Gender" "+ Region") ///
    addnotes("Robust standard errors in parentheses. Dependent variable: log hourly wage.")

Rehearsal in Python

This block creates a simulated worker dataset with a true return to schooling of 8% per year, a gender gap and an experience profile, applies the cleaning rules, and fits the same four models. It is a stand-in: the numbers are from the simulation, not from Stata or real data.

Python Simulate, clean and fit four models (Python stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You should see the education coefficient near 0.08 in the full model. In the first model it is biased upward or downward only if educ is correlated with the omitted terms; here it is nearly unchanged because the simulation makes education independent of experience. In real data it usually moves, which is the whole point of showing the sequence.

Interpreting and reporting

Python From a log coefficient to a percentage (Python stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For the write-up: state the sample (N after cleaning), the dependent variable, the standard-error type, the key coefficient with its confidence interval, and one sentence on limits. A regression of this kind shows an association, not necessarily a causal effect: ability and family background influence both schooling and wages, which is why labour economists use instruments and panel methods (fixed effects).

Extensions

  • Add an interaction c.educ##i.woman and use margins woman, at(educ=(10 12 16)) (factor variables).
  • Cluster by region or firm if the data have groups.
  • Loop over industries and store results with postfile (loops).
  • Write a program retsum that prints the percentage return for any model.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why model the log of wage?

    Log wages are closer to symmetric and a coefficient b means roughly 100*b percent change.
  2. 2. What is the purpose of count before drop if wage <= 0?

    Documenting dropped rows makes data decisions transparent and reproducible.
  3. 3. Why show a sequence of models with added controls?

    A coefficient that moves a lot reveals omitted-variable sensitivity.
  4. 4. A coefficient of 0.081 on educ in a log-wage model means about

    Multiply by 100 for an approximate percentage; the exact value is exp(0.081)-1 = 8.4%.

Summary

  • Structure the project as numbered do-files plus a master file, with logs, asserts and documented drops.
  • Model lnwage, add controls in steps, use vce(robust) and export with esttab.
  • Interpret log coefficients as percentages and be modest about causality.
  • The Python rehearsal is a stand-in; run the Stata version yourself.

Next: Project: policy evaluation with difference-in-differences