agentsclimarketplace

Causal inference mixtape

Skill Nicowyn/paper-audit-skills/.agents/skills/causal-inference-mixtape

Implement or audit causal inference designs in Python, R, or Stata. Use for difference-in-differences, event studies, instrumental variables, regression discontinuity, synthetic control, matching, randomization inference, parallel-trends diagnostics, weak-instrument diagnostics, or Bacon decomposition. Based on Scott Cunningham's Causal Inference: The Mixtape.From its SKILL.md

Install
npx -y skills add Nicowyn/paper-audit-skills --skill causal-inference-mixtape

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • 23 days oldThe repository was created 23 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

8.3 KB, ~2.0k tokens by cl100k_base, as published. Nobody here has run it

Causal Inference: The Mixtape — Code Skill

Practitioner-oriented causal inference skill adapted from the upstream Causal Inference Mixtape repository. It covers 10 identification strategies with illustrative Python, R, and Stata patterns. Every pattern is an adapt-and-verify scaffold, not a ready-to-run or automatically valid analysis.

Before using a pattern, reconstruct the study's assignment mechanism and estimand, adapt the sample and variance estimator, check the installed package API, and validate the adapted code on a known-answer example or simulation. A syntactically valid template does not establish identification.


Methods Covered

MethodPythonRStataReference
OLS / Regressionstatsmodelsestimatrreg/reghdfeMethod patterns §1
Difference-in-Differencesstatsmodels + C()lfe/fixestxtreg/reghdfeMethod patterns §2
Event Study (Dynamic DiD)manual lead/lagestimatrreghdfeMethod patterns §3
Staggered DiD / TWFEstatsmodelsbacondecompbacondecompMethod patterns §4
Regression Discontinuitystatsmodels local regressionrdrobust/rddensityrdplot/rdrobust/rddensityMethod patterns §5
Instrumental Variableslinearmodels IV2SLSAER/ivregivregress 2slsMethod patterns §6
Synthetic Controlrpy2 → R SynthSynth + SCtoolssynthMethod patterns §7
Matching / PSM / IPWmanual logit + weightsMatchIt + Zeligteffects/cemMethod patterns §8
DAGs / Collider Biasdagitty (conceptual)dagitty/ggdagMethod patterns §9
Randomization Inferenceexplicit assignment drawsri2ritestMethod patterns §10

Core Workflow

Implement a Causal Method

  1. Identify the method from the table above
  2. Load the appropriate illustrative pattern from references/method-patterns.md
  3. Adapt variable names, fixed effects, and clustering to the user's data
  4. Add design-appropriate diagnostics (parallel trends for DiD, density and continuity checks for RDD, and first-stage plus weak-instrument diagnostics 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)

# Omit event time -1 from estimation and use it as the reference period.
def event_term(k):
    return f'rel_m{abs(k)}' if k < 0 else f'rel_{k}'

event_times = [k for k in range(-4, 5) if k != -1]
rel_cols = [event_term(k) for k in event_times]
for k, col in zip(event_times, rel_cols):
    df[col] = (df['relative_time'] == k).astype(int)

formula = 'y ~ ' + ' + '.join(rel_cols) + ' + 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'])

Design and Robustness Check Patterns

MethodChecks to adapt to the design
DiDParallel trends (event study plot), placebo treatment dates
RDDSorting-risk diagnostics (which may include a density-discontinuity test), bandwidth sensitivity, local-polynomial specification checks, and covariate continuity
IVDesign-appropriate first-stage diagnostics, weak-instrument-robust inference, a design/mechanism argument for exclusion with falsifiable implications, and cautious interpretation of over-identification tests when applicable
Synthetic ControlPre-treatment RMSPE, placebo distribution, leave-one-out
MatchingCovariate balance table, caliper sensitivity

Common Pitfalls

  1. TWFE under staggered adoption — variation in treatment timing alone does not prove bias. With heterogeneous or dynamic treatment effects, forbidden comparisons involving already-treated units can make conventional TWFE differ from the target ATT. Diagnose its comparisons and weights; then use an estimator such as Sun–Abraham or Callaway–Sant'Anna when its assumptions match the design.
  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 sorting diagnostics — a density discontinuity can be a signal of sorting or manipulation risk, but it is not a test of researcher or participant intent and is not informative in every design. Choose among McCrary-style, rddensity, heaping/mass-point, institutional, and covariate-continuity checks as the running variable and assignment process warrant.
  4. IV weak instruments — do not treat a first-stage F-statistic cutoff of 10 as universal proof of instrument strength. Match the diagnostic to the number of endogenous regressors, covariance estimator, and design; report weak-instrument-robust confidence sets or tests when appropriate.
  5. Python Synth gap — no mature Python Synth package exists. Use rpy2 to call R's Synth from Python.
  6. IV diagnostic overclaims — exclusion is primarily a design and mechanism claim. A placebo is interpretable only when its outcome or covariate is predetermined, and failure to reject an over-identification test does not prove that every instrument is valid.
  7. Randomization inference mechanism — redraw assignments from the original assignment mechanism. The Python pattern below covers only complete randomization with a fixed treated count; blocked, stratified, paired, or clustered designs need corresponding constrained draws.

Additional Resources

Reference Files

Prompt Files

What ships with it: 6 files

35.0 KB alongside SKILL.md

agents/

Keep looking

Skills are one crate of 326,834. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.