skills/23-Learning-Bayesian-Statistics-baygent-skills/causal-inference/SKILL.md
Production-grade Bayesian causal inference with PyMC, CausalPy, and DoWhy. Enforces DAG-first thinking, mandatory user checkpoints for assumptions, design-specific refutation, and defensible reporting with causal language guardrails. Trigger on: causal inference, causal effect estimation, treatment effects, counterfactuals, difference-in-differences (DiD), synthetic control, regression discontinuity (RDD), interrupted time series (ITS), instrumental variables (IV), propensity scores, DAGs, causal graphs, confounders, backdoor criterion, do-calculus, interventional distributions, pm.do(), pm.observe(), CausalPy, DoWhy, mediation analysis, refutation, sensitivity analysis, parallel trends, placebo tests, or any question of the form "does X cause Y" or "what is the effect of X on Y."
npx skillsauth add brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research causal-inferenceInstall 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.
This skill requires the bayesian-workflow skill for all PyMC modeling steps (priors, sampling, diagnostics, calibration, reporting).
Detect it:
ls ~/.claude/skills/bayesian-workflow/SKILL.md 2>/dev/null || ls .claude/skills/bayesian-workflow/SKILL.md 2>/dev/null
If not found, install it:
git clone https://github.com/Learning-Bayesian-Statistics/baygent-skills.git /tmp/baygent-skills
cp -r /tmp/baygent-skills/bayesian-workflow ~/.claude/skills/
For all PyMC modeling steps (priors, sampling, diagnostics, calibration, reporting), follow the bayesian-workflow skill.
Every causal analysis follows this sequence. Steps 1-4 are the thinking phase (no code). Steps 5-8 are the doing phase. Think before you do.
| Design | Use when | Key assumption | Tool | |---|---|---|---| | DiD | Treatment at known time, control group available | Parallel trends | CausalPy | | Staggered DiD | Treatment rolls out at different times | Parallel trends per cohort | CausalPy | | Synthetic Control | Single treated unit, donor pool available | Weighted donors approximate counterfactual | CausalPy | | ITS | Time series, intervention at known time, no control | No confounding event at treatment time | CausalPy | | RDD | Treatment by threshold on running variable | No manipulation at threshold | CausalPy | | IV | Endogenous treatment, valid instrument | Exclusion restriction, relevance | CausalPy | | IPSW | Observational data, treatment modeled | No unmeasured confounders, positivity | CausalPy | | Structural (do/observe) | Full causal theory, model mechanisms | Correct DAG specification | PyMC | | Counterfactual | "What would Y have been if X differed?" | Correct structural model | PyMC |
These are battle-tested lessons that save hours of debugging:
C() for categoricals. Passing a string column directly without
C() will silently produce wrong dummy coding. Always wrap categorical treatment and group
variables: "y ~ C(treatment) + C(group)".U nodes for unobserved confounders. Omitting them from the graph
will make DoWhy treat your model as fully identified when it isn't. Add latent nodes explicitly
and mark them as unobserved.pm.compute_log_likelihood(idata, model=model) after sampling if
you need it for model comparison.unit column.df.pivot(index="date", columns="unit", values="outcome").| Symptom | Likely cause | Fix |
|---|---|---|
| Refutation fails | Assumption violated | Diagnose which assumption, try alternative design or sensitivity bounds |
| DiD effect at placebo time | Parallel trends violated | Try synthetic control or add group-specific time trends |
| RDD: bunching at threshold | Manipulation of running variable | Design is invalid for this threshold — report and stop |
| SC: poor pre-treatment fit | Donors don't span treated unit | Add donors, expand donor pool, or reconsider design |
| DoWhy says "not identifiable" | Insufficient adjustment set | Revise DAG, add measured variables, or change design |
| CausalPy formula error | Wrong formula syntax | Use C() for categoricals, check variable names match dataframe columns |
tools
Show mcp-stata identity, connected tools, and status. Use when the user asks if mcp-stata is available, asks about access to the toolkit, or asks what Stata tools are connected.
tools
Activate when users mention Stata commands, .do files, regressions, econometrics, stored results, graphs, dataset inspection, replication, or Stata errors. Route the task through mcp-stata tools and the specialized research skills instead of treating it as plain text coding.
development
Build and review paper-ready regression, balance, and summary tables from Stata outputs. Use when the user needs a clean table for a draft, appendix, or coauthor share-out.
tools
Install, configure, update, or verify mcp-stata across Claude Code, Codex, Gemini CLI, Cursor, Windsurf, and VS Code. Activate when users ask to set up the Stata toolkit or troubleshoot the installation.