skills/10-Jill0099-causal-inference-mixtape/SKILL.md
This skill should be used when the user asks to "implement a DiD regression", "write a causal inference pipeline", "set up an event study", "implement instrumental variables", "run a regression discontinuity design", "build a synthetic control model", "implement propensity score matching", "write parallel trends test", "implement Bacon decomposition", or needs code templates for causal inference methods in Python, R, or Stata. Based on Scott Cunningham's Causal Inference: The Mixtape.
npx skillsauth add brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research causal-inference-mixtapeInstall 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.
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.
| Method | Python | R | Stata | Reference |
|--------|--------|---|-------|-----------|
| OLS / Regression | statsmodels | estimatr | reg/reghdfe | references/method-patterns.md §1 |
| Difference-in-Differences | statsmodels + C() | lfe/fixest | xtreg/reghdfe | references/method-patterns.md §2 |
| Event Study (Dynamic DiD) | manual lead/lag | estimatr | reghdfe | references/method-patterns.md §3 |
| Staggered DiD / TWFE | statsmodels | bacondecomp | bacondecomp | references/method-patterns.md §4 |
| Regression Discontinuity | statsmodels polynomial | rdrobust | rdplot/rdrobust | references/method-patterns.md §5 |
| Instrumental Variables | linearmodels IV2SLS | AER/ivreg | ivregress 2sls | references/method-patterns.md §6 |
| Synthetic Control | rpy2 → R Synth | Synth + SCtools | synth | references/method-patterns.md §7 |
| Matching / PSM / IPW | manual logit + weights | MatchIt + Zelig | teffects/cem | references/method-patterns.md §8 |
| DAGs / Collider Bias | dagitty (conceptual) | dagitty/ggdag | — | references/method-patterns.md §9 |
| Randomization Inference | permutation loop | ri2 | ritest | references/method-patterns.md §10 |
references/method-patterns.md| Scenario | Recommendation | |----------|---------------| | ML pipeline integration | Python (statsmodels + linearmodels) | | Synthetic Control | R (Synth package) or Stata (synth) — Python lacks mature implementation | | Bacon decomposition | R (bacondecomp) or Stata — no Python equivalent | | Publication-ready tables | Stata (outreg2/esttab) or R (stargazer/modelsummary) | | Coarsened Exact Matching | Stata (cem) or R (MatchIt) — no Python equivalent | | Quick prototyping | Python with statsmodels |
| Task | Python | R | Stata |
|------|--------|---|-------|
| OLS with robust SE | smf.ols().fit(cov_type='HC1') | lm_robust() | reg y x, robust |
| Cluster SE | fit(cov_type='cluster', cov_kwds={'groups': g}) | felm(y ~ x | 0 | 0 | cluster) | reg y x, cluster(id) |
| Two-way FE | C(id) + C(time) in formula | felm(y ~ x | id + time) | reghdfe y x, absorb(id time) |
| IV / 2SLS | IV2SLS.from_formula('y ~ 1 + exog + [endog ~ inst]') | ivreg(y ~ exog | inst) | ivregress 2sls y exog (endog = inst) |
| DiD | C(treat)*C(post) | treat:post in formula | did_multiplegt or interaction |
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']})
# 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)'
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'])
| Method | Required Checks | |--------|----------------| | DiD | Parallel trends (event study plot), placebo treatment dates | | RDD | McCrary density test, bandwidth robustness (half/double IK optimal), polynomial robustness | | IV | First-stage F > 10, exclusion restriction argument, over-identification test | | Synthetic Control | Pre-treatment RMSPE, placebo distribution, leave-one-out | | Matching | Covariate balance table, caliper sensitivity |
rpy2 to call R's Synth from Python.references/method-patterns.md — Detailed code templates for all 10 methods with full examplesreferences/r-stata-comparison.md — Cross-language package comparison and method coverage gapsprompts/01-implement-method.md — Copy-paste prompt for implementing any causal methodprompts/02-robustness-checks.md — Copy-paste prompt for generating robustness check codetools
Recommend AND run open-source AI tools, agents, Claude Code / Codex skills, and MCP servers for any stage of a literature review — searching, reading, extracting, synthesizing, screening, citation-checking, and paper writing. Use when the user asks "what tool should I use to..." OR "install/run/use <tool> to ..." for research/lit-review work: automating a survey or related-work section, PDF→Markdown extraction for LLMs (MinerU/marker/docling), PRISMA / systematic review (ASReview), citation-backed Q&A over PDFs (PaperQA2), wiring papers into Claude/Cursor via MCP (arxiv/paper-search/zotero servers), or chatting with a Zotero library. Ships a launcher (scripts/litrun.py) that installs each tool in an isolated venv and runs it. Curated catalog of 70+ vetted projects. 支持中英文(用于「文献综述工具选型」与「一键安装/运行」)。
development
Route empirical-research requests through the Auto-Empirical Research Skills catalog when this whole repository is installed as one skill in Codex, CodeBuddy, Claude Code, or another IDE. Use to choose and load the right vendored AERS skill for causal inference, econometrics, replication, data acquisition, manuscript writing, peer review and referee responses, citation checking, de-AIGC editing, or full empirical-paper workflows without reading the entire repository at once.
documentation
Use when the project collects primary data or runs a field, lab, or survey experiment, before the intervention begins — write the pre-analysis plan, size the sample from a power calculation, and register with the AEA RCT Registry. Apply after the design is chosen in aer-identification and before any outcome data are seen.
tools
Guide economists to authoritative data sources with explicit, confirmed data specifications before retrieval; interfaces with Playwright MCP to navigate portals and extract real data, not articles about data.