NA446A Python for data you can trust

Further topics

Optional self-study for those who want to go further. Not examined.

These modules take you beyond the four sessions, into the econometrics you already know from Stata, now done in Python. Each has a short deck, one script that reproduces every number on the slides, the data (offline) and a README. Unzip a module inside your course folder and work through the deck with the script open beside it.

Module What you learn After Time Download
F1 Panel regressions Pooled OLS, person and two-way fixed effects, clustered standard errors, one table; the Python version of reghdfe (random effects in an appendix) Sessions 3–4 about 75 min zip
F2 Binary outcomes Linear probability model, logit, odds ratios, average marginal effects, and the trap of perfect separation Sessions 2 and 4 60–75 min zip
F4 Difference-in-differences and event studies The 2×2 DiD by hand, the same as a two-way fixed-effects regression, an event study with pre-trends, Poisson with fixed effects for counts; on synthetic register-style data where the true effect is known Sessions 3–4, F1 about 75 min zip
F3 Time series Months to quarters, a Phillips curve with Newey–West standard errors, autocorrelation, AR(1), and why these are correlations Session 4 60–75 min zip

F1 and F4 use pyfixest, the package the AI-Econ Lab uses in its own papers. In the VS Code terminal of your course folder, type uv add pyfixest once (F1’s optional appendix also uses uv add linearmodels). These modules use the same tools and conventions as the lab’s published replication packages.

A whole project, start to finish (Stata and Python)

A small but complete empirical project, written twice, once in Stata and once in Python: how much more do men earn for each extra year of schooling (a Mincer wage equation on a panel of 545 young American men, 1980–87). Each version goes from the raw data file to the tables and the figure of a short report, one step per file (import, clean, describe, estimate, figures), run in order by one master file. Both give the same numbers, and a small script checks that they do. Use it as the model for your thesis: copy the version you prefer and replace the question and the data; START_YOUR_THESIS.md in the zip says how.

mini-project.zip. Unzip it anywhere (inside your course folder is easiest for the Python version) and start with README.md. Needs Stata 18 or newer for the Stata version; the Python version installs its own packages with uv run run_all.py.

Coming later: causal machine learning. A module on methods that estimate how the effect of a programme differs across people.