Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
brycewang-stanford avatar

Causal Inference Mixtape

  • 17 installs
  • 3.2k repo stars
  • Updated August 4, 2026
  • brycewang-stanford/auto-empirical-research-skills

causal-inference-mixtape is a skill that provides ready-to-run code templates for 10 causal-inference methods in Python, R, and Stata, based on Scott Cunningham's The Mixtape.

About

causal-inference-mixtape is a practitioner code skill built from Scott Cunningham's Causal Inference: The Mixtape. It provides ready-to-run templates for 10 identification strategies (OLS, DiD, event study, staggered DiD, RDD, IV, synthetic control, matching/PSM/IPW, DAGs, randomization inference) in Python, R, and Stata, with cross-language equivalents and required robustness checks. A quantitative analyst uses it to implement a causal method quickly in their language of choice.

  • Code templates for 10 causal-inference methods in Python, R, and Stata
  • Based on Scott Cunningham's Causal Inference: The Mixtape
  • Cross-language equivalents and required robustness checks per method

Causal Inference Mixtape by the numbers

  • 17 all-time installs (skills.sh)
  • Ranked #1,288 of 2,064 Data Science & ML skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
At a glance

causal-inference-mixtape capabilities & compatibility

Capabilities
data analysis · research
Use cases
data analysis · research
Pricing
Free
From the docs

What causal-inference-mixtape says it does

Covers 10 identification strategies with ready-to-run code templates in Python, R, and Stata.
SKILL.md
**TWFE with staggered treatment** — standard two-way FE is biased when treatment timing varies.
SKILL.md
npx skills add https://github.com/brycewang-stanford/auto-empirical-research-skills --skill causal-inference-mixtape

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs17
repo stars3.2k
Last updatedAugust 4, 2026
Repositorybrycewang-stanford/auto-empirical-research-skills

What it does

Implement a causal-inference method like DiD, IV, or RDD from a ready-to-run code template in Python, R, or Stata.

Who is it for?

Getting a ready-to-run causal-method template in the right language with robustness checks.

Skip if: Bayesian causal modeling or deciding whether a causal claim is identified (use causal-inference).

When should I use this skill?

The user asks to implement a DiD regression, set up an event study, run RDD, build a synthetic control, or implement IV / PSM.

What you get

Working estimation code for the chosen method in Python, R, or Stata with the required robustness checks added.

  • method code template
  • robustness-check code
  • cross-language equivalents

By the numbers

  • 10 identification strategies covered
  • 3 languages (Python, R, Stata)

Files

SKILL.mdMarkdownGitHub ↗

Causal Inference: The Mixtape — Code Skill

Practitioner-oriented causal inference skill built from Scott Cunningham's Causal Inference: The Mixtape repository. Covers 10 identification strategies with ready-to-run code templates in Python, R, and Stata.

---

Methods Covered

MethodPythonRStataReference
OLS / Regressionstatsmodelsestimatrreg/reghdfereferences/method-patterns.md §1
Difference-in-Differencesstatsmodels + C()lfe/fixestxtreg/reghdfereferences/method-patterns.md §2
Event Study (Dynamic DiD)manual lead/lagestimatrreghdfereferences/method-patterns.md §3
Staggered DiD / TWFEstatsmodelsbacondecompbacondecompreferences/method-patterns.md §4
Regression Discontinuitystatsmodels polynomialrdrobustrdplot/rdrobustreferences/method-patterns.md §5
Instrumental Variableslinearmodels IV2SLSAER/ivregivregress 2slsreferences/method-patterns.md §6
Synthetic Controlrpy2 → R SynthSynth + SCtoolssynthreferences/method-patterns.md §7
Matching / PSM / IPWmanual logit + weightsMatchIt + Zeligteffects/cemreferences/method-patterns.md §8
DAGs / Collider Biasdagitty (conceptual)dagitty/ggdagreferences/method-patterns.md §9
Randomization Inferencepermutation loopri2ritestreferences/method-patterns.md §10

---

Core Workflow

Implement a Causal Method

1. Identify the method from the table above 2. Load the appropriate template from references/method-patterns.md 3. Adapt variable names, fixed effects, and clustering to the user's data 4. Add robustness checks (parallel trends for DiD, McCrary for RDD, first-stage F for IV)

Choose the Right Language

ScenarioRecommendation
ML pipeline integrationPython (statsmodels + linearmodels)
Synthetic ControlR (Synth package) or Stata (synth) — Python lacks mature implementation
Bacon decompositionR (bacondecomp) or Stata — no Python equivalent
Publication-ready tablesStata (outreg2/esttab) or R (stargazer/modelsummary)
Coarsened Exact MatchingStata (cem) or R (MatchIt) — no Python equivalent
Quick prototypingPython with statsmodels

Cross-Language Equivalents

TaskPythonRStata
OLS with robust SEsmf.ols().fit(cov_type='HC1')lm_robust()reg y x, robust
Cluster SEfit(cov_type='cluster', cov_kwds={'groups': g})`felm(y ~ x0
Two-way FEC(id) + C(time) in formula`felm(y ~ xid + time)`
IV / 2SLSIV2SLS.from_formula('y ~ 1 + exog + [endog ~ inst]')`ivreg(y ~ exoginst)`
DiDC(treat)*C(post)treat:post in formuladid_multiplegt or interaction

---

Key Python Patterns

DiD with Cluster-Robust SE

import statsmodels.formula.api as smf

model = smf.ols('y ~ C(treated)*C(post) + controls', data=df)
results = model.fit(cov_type='cluster', cov_kwds={'groups': df['firm_id']})

Event Study (Lead/Lag)

# Create relative time dummies
for k in range(-4, 5):
    col = f'rel_{k}' if k >= 0 else f'rel_m{abs(k)}'
    df[col] = (df['relative_time'] == k).astype(int)

# Drop t=-1 as reference
formula = 'y ~ ' + ' + '.join([c for c in rel_cols if c != 'rel_m1']) + ' + C(id) + C(year)'

IV / 2SLS

from linearmodels.iv import IV2SLS

model = IV2SLS.from_formula('y ~ 1 + exog + [endog ~ instrument]', data=df)
results = model.fit(cov_type='clustered', clusters=df['cluster_var'])

---

Robustness Check Patterns

MethodRequired Checks
DiDParallel trends (event study plot), placebo treatment dates
RDDMcCrary density test, bandwidth robustness (half/double IK optimal), polynomial robustness
IVFirst-stage F > 10, exclusion restriction argument, over-identification test
Synthetic ControlPre-treatment RMSPE, placebo distribution, leave-one-out
MatchingCovariate balance table, caliper sensitivity

---

Common Pitfalls

1. TWFE with staggered treatment — standard two-way FE is biased when treatment timing varies. Use Bacon decomposition or Sun & Abraham / Callaway & Sant'Anna estimators. 2. Synthetic Control with many treated units — the Synth package handles one treated unit. For multiple, use augmented synthetic control or stacked approach. 3. RDD without McCrary test — always test for manipulation at the cutoff before estimating. 4. IV weak instruments — report first-stage F-statistic. Below 10 indicates weak instrument bias. 5. Python Synth gap — no mature Python Synth package exists. Use rpy2 to call R's Synth from Python.

---

Additional Resources

Reference Files

  • `references/method-patterns.md` — Detailed code templates for all 10 methods with full examples
  • `references/r-stata-comparison.md` — Cross-language package comparison and method coverage gaps

Prompt Files

  • `prompts/01-implement-method.md` — Copy-paste prompt for implementing any causal method
  • `prompts/02-robustness-checks.md` — Copy-paste prompt for generating robustness check code

Related skills

FAQ

Which languages are covered?

Python (statsmodels, linearmodels), R (fixest, rdrobust, Synth), and Stata (reghdfe, ivregress, synth), with cross-language equivalents for each task.

How many methods does it cover?

10 identification strategies, from OLS and DiD through RDD, IV, synthetic control, matching, DAGs, and randomization inference.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.