Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Learn causal inference with Python using the Brave and True handbook
.claude/skills/brycewang-stanford-python-causality-guide/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-17 | ✗→✓ | ▲ Improved | 54% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 405% | 0% |
| case-21 | ✓→✓ | = Same ✓ | 50% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 43% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 73% | 0% |
Causal Inference for the Brave and True is an open-source, Python-based textbook by Matheus Facure that teaches causal inference methods through practical implementations. The book bridges the gap between theoretical econometrics textbooks and hands-on data science practice, presenting each method with runnable Python code, real-world datasets, and intuitive explanations that demystify the mathematics behind causal reasoning.
The handbook covers the full spectrum of causal inference techniques used in modern empirical research, from foundational concepts like potential outcomes and directed acyclic graphs (DAGs) through advanced methods including instrumental variables, regression discontinuity, difference-in-differences, and synthetic control. Each chapter builds on the previous one, constructing a coherent framework for thinking about causation from observational data.
With over 3,000 GitHub stars, this resource has become a standard reference for graduate students, applied researchers, and data scientists seeking to add causal reasoning to their analytical toolkit. The emphasis on Python implementation makes it directly applicable to modern research workflows.
The handbook runs as Jupyter notebooks. Set up the environment:
bashgit clone https://github.com/matheusfacure/python-causality-handbook.git cd python-causality-handbook # Create a virtual environment python -m venv causal-env source causal-env/bin/activate # Install dependencies pip install numpy pandas matplotlib seaborn scikit-learn statsmodels pip install linearmodels causalinference pip install jupyter
Launch the notebook server:
bashjupyter notebook
The chapters are organized as numbered Jupyter notebooks, starting from foundational concepts and progressing to advanced methods. Each notebook is self-contained with all data loading and analysis code included.
Potential Outcomes Framework: The book begins by establishing the Neyman-Rubin potential outcomes model, defining treatment effects and the fundamental problem of causal inference:
pythonimport pandas as pd import numpy as np from scipy.stats import ttest_ind # Estimate ATE from randomized experiment treated = data[data["treatment"] == 1]["outcome"] control = data[data["treatment"] == 0]["outcome"] ate = treated.mean() - control.mean() t_stat, p_value = ttest_ind(treated, control) print(f"ATE: {ate:.3f}, p-value: {p_value:.4f}")
Regression and Matching: OLS regression for causal estimation, understanding omitted variable bias, propensity score methods, and matching estimators:
pythonimport statsmodels.formula.api as smf # OLS with controls model = smf.ols("outcome ~ treatment + age + income + education", data=data) results = model.fit(cov_type="HC1") print(results.summary().tables[1])
Instrumental Variables: Two-stage least squares and the local average treatment effect, with practical guidance on instrument validity and weak instrument diagnostics:
pythonfrom linearmodels.iv import IV2SLS # Two-stage least squares iv_formula = "outcome ~ 1 + [treatment ~ instrument]" iv_model = IV2SLS.from_formula(iv_formula, data=data) iv_results = iv_model.fit(cov_type="robust") print(iv_results.summary)
Difference-in-Differences: Parallel trends assumption, two-way fixed effects, event study designs, and staggered treatment adoption:
python# Difference-in-Differences with two-way fixed effects did_model = smf.ols( "outcome ~ treated_post + C(unit_id) + C(time_period)", data=panel_data ) did_results = did_model.fit(cov_type="cluster", cov_kwds={"groups": panel_data["unit_id"]})
Regression Discontinuity: Sharp and fuzzy RD designs, bandwidth selection, and local polynomial estimation for identifying causal effects at policy thresholds.
Synthetic Control: Constructing counterfactual units from donor pools for comparative case studies, with inference via placebo tests.
Graduate Coursework: The handbook maps directly to applied econometrics and causal inference course syllabi. Students can follow along with lectures by running the corresponding notebooks, experimenting with parameter changes, and observing how different assumptions affect estimates.
Method Selection Guide: Use the decision framework presented across chapters to choose the appropriate method for your research question:
Replication and Extension: Each chapter uses real or realistic datasets. Researchers can adapt the code to their own data by replacing data loading steps while preserving the analytical pipeline.
Teaching Tool: Instructors can assign chapters as interactive homework, asking students to modify assumptions, change specifications, or apply methods to new datasets. The notebook format makes it straightforward to create assignments with embedded solutions.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-04 | pass→pass | 1,965 | 2,421 | +23% | 1 | 1 | 0% | 359 | 1,813 | +405% | 0 | 0 | — |
case-21 | pass→pass | 17,065 | 17,404 | +2% | 1 | 1 | 0% | 3,158 | 4,731 | +50% | 0 | 0 | — |
case-01 | pass→pass | 12,515 | 19,002 | +52% | 1 | 1 | 0% | 2,566 | 3,663 | +43% | 0 | 0 | — |
case-02 | pass→pass | 6,918 | 5,335 | -23% | 1 | 1 | 0% | 1,311 | 2,267 | +73% | 0 | 0 | — |
case-03 | pass→pass | 8,034 | 5,603 | -30% | 1 | 1 | 0% | 1,435 | 2,366 | +65% | 0 | 0 | — |
case-05 | pass→pass | 6,683 | 4,523 | -32% | 1 | 1 | 0% | 1,307 | 2,118 | +62% | 0 | 0 | — |
case-06 | pass→pass | 7,001 | 3,884 | -45% | 1 | 1 | 0% | 1,219 | 2,089 | +71% | 0 | 0 | — |
case-07 | pass→pass | 3,503 | 4,811 | +37% | 1 | 1 | 0% | 681 | 2,203 | +223% | 0 | 0 | — |
case-08 | pass→pass | 15,930 | 14,551 | -9% | 1 | 1 | 0% | 2,662 | 3,956 | +49% | 0 | 0 | — |
case-22 | pass→pass | 15,724 | 15,694 | -0% | 1 | 1 | 0% | 2,944 | 4,143 | +41% | 0 | 0 | — |
case-09 | pass→pass | 5,808 | 8,045 | +39% | 1 | 1 | 0% | 954 | 2,626 | +175% | 0 | 0 | — |
case-10 | pass→pass | 5,782 | 6,936 | +20% | 1 | 1 | 0% | 940 | 2,580 | +174% | 0 | 0 | — |
case-11 | pass→pass | 5,125 | 7,363 | +44% | 1 | 1 | 0% | 887 | 2,628 | +196% | 0 | 0 | — |
case-12 | pass→pass | 7,829 | 5,599 | -28% | 1 | 1 | 0% | 1,380 | 2,305 | +67% | 0 | 0 | — |
case-13 | pass→pass | 17,038 | 21,581 | +27% | 1 | 1 | 0% | 2,828 | 5,209 | +84% | 0 | 0 | — |
case-14 | pass→pass | 18,471 | 18,397 | -0% | 1 | 1 | 0% | 3,256 | 4,756 | +46% | 0 | 0 | — |
case-15 | pass→pass | 9,628 | 8,353 | -13% | 1 | 1 | 0% | 1,707 | 2,929 | +72% | 0 | 0 | — |
case-16 | pass→pass | 18,227 | 17,383 | -5% | 1 | 1 | 0% | 2,946 | 4,402 | +49% | 0 | 0 | — |
case-17 | fail→pass | 13,448 | 10,125 | -25% | 1 | 1 | 0% | 1,957 | 3,014 | +54% | 0 | 0 | — |
case-18 | pass→pass | 9,801 | 3,429 | -65% | 1 | 1 | 0% | 1,660 | 2,011 | +21% | 0 | 0 | — |
case-19 | pass→pass | 3,511 | 3,792 | +8% | 1 | 1 | 0% | 533 | 1,969 | +269% | 0 | 0 | — |
case-20 | pass→pass | 11,503 | 10,872 | -5% | 1 | 1 | 0% | 2,106 | 3,286 | +56% | 0 | 0 | — |
case-23 | pass→pass | 13,432 | 11,148 | -17% | 1 | 1 | 0% | 2,480 | 3,308 | +33% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +4 percentage points is the difference between those two pass rates over the 23 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.