skills/43-wentorai-research-plugins/skills/analysis/econometrics/python-causality-guide/SKILL.md
Learn causal inference with Python using the Brave and True handbook
npx skillsauth add brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research python-causality-guideInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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:
git 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:
jupyter 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:
import 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:
import 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:
from 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:
# 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.
development
Conduct rigorous thematic analysis (TA) of qualitative data following Braun and Clarke's (2006) six-phase framework. Use whenever the user mentions 'thematic analysis', 'TA', 'Braun and Clarke', 'qualitative coding', 'identifying themes', or asks for help analysing interviews, focus groups, open-ended survey responses, or transcripts to identify patterns. Also trigger for questions about inductive vs theoretical coding, semantic vs latent themes, essentialist vs constructionist epistemology, building a thematic map, or writing up a qualitative findings section. Covers all six phases, the four upfront analytic decisions, the 15-point quality checklist, and the five common pitfalls. Produces a Word document write-up and an annotated thematic map. Does NOT cover IPA, grounded theory, discourse analysis, conversation analysis, or narrative analysis — use a different method for those.
development
Guide users through writing a systematic literature review (SLR) following the PRISMA 2020 framework. Use this skill whenever the user mentions 'systematic review', 'systematic literature review', 'SLR', 'PRISMA', 'PRISMA 2020', 'PRISMA flow diagram', 'PRISMA checklist', or asks for help writing, structuring, or auditing a literature review that follows reporting guidelines. Also trigger when the user asks about inclusion/exclusion criteria for a review, search strategies for databases like Scopus/WoS/PubMed, study selection processes, risk of bias assessment, or narrative synthesis for a review paper. This skill covers the full PRISMA 2020 checklist (27 items), produces a Word document manuscript in strict journal article format, generates an annotated PRISMA flow diagram, and enforces APA 7th Edition referencing throughout. It does NOT cover meta-analysis or statistical pooling. By Chuah Kee Man.
testing
Performs placebo-in-time sensitivity analysis with hierarchical null model and optional Bayesian assurance. Use when checking model robustness, verifying lack of pre-intervention effects, or estimating study power.
data-ai
Fit, summarize, plot, and interpret a chosen CausalPy experiment. Use after the causal method has been selected, including when configuring PyMC/sklearn models and scale-aware custom priors.