A First Course in Causal Inference

Executable chapter examples with crabbymetrics

These pages translate selected examples from Peng Ding’s A First Course in Causal Inference into Python. They use crabbymetrics for estimation and NumPy for explicit randomization and potential-outcomes calculations. They are companions to the book, not a complete translation.

Chapters

Chapter Topic
1 Correlation, association, and Simpson’s paradox
2 Potential outcomes
3 Completely randomized experiments and Fisher tests
4 Neyman repeated-sampling inference
5 Stratification and post-stratification
6 Regression adjustment and rerandomization
7 Matched-pairs experiments
8 Fisher and Neyman comparisons
9 Finite-population and superpopulation inference
11 Propensity scores
12 Doubly robust ATE estimation
13 ATT and other estimands
21 Experimental instrumental variables
23 Econometric instrumental variables
27 Mediation through sequential regressions

Grouped reading routes: foundations, design and adjustment, observational adjustment, and instrumental variables.

Data and scope

The real-data inputs come from Ding’s replication archive, with the matched-pairs data from HistData::ZeaMays. The small files used here are bundled under docs/data/ding/; data provenance records the sources and checksums. No external-drive symlink is needed.

Chapter 27 illustrates the additional identifying assumptions behind mediation; its regressions are not a general mediation estimator. Chapters without a link above are not covered by this documentation. Matching, sensitivity-analysis, regression-discontinuity, and principal-stratification extensions remain outside the current chapter collection.