agentleFS
WilliamWJHuangWilliamWJHuang/ab-test-causal-inference-skills/skills/causal-inference-advisor/SKILL.md

causal-inference-advisor

Skill4 starsChanged 7 months agoMITView on GitHub

Guide causal inference from observational or quasi-experimental data. Activate when the user wants to estimate a causal effect, choose between causal methods (DiD, synthetic control, RDD, IV, matching, IPW), construct a DAG, test causal assumptions, run refutation tests, or estimate heterogeneous treatment effects. Covers the full identify-estimate-refute pipeline using DoWhy, EconML, and CausalML.

The file

Show its rules and text

We split this skill into the rules it gives an agent

17 rules. About 0 are common, 16 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈16

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    NEVER skip the identification step.

    line 123
  2. Distinctive:

    Use the DAG to determine the adjustment set (the variables you need to control for to isolate the causal effect).

    line 138
  3. Distinctive:

    If assumptions are violated, WARN and suggest alternatives or sensitivity analysis.

    line 158
  4. Distinctive:

    When to use each approach

    line 175
  5. Distinctive:

    When you care about the effect on the distribution, not just the mean (e.g., does the treatment help the bottom 10%?

    line 178
  6. Distinctive:

    Use quantile regression with treatment indicator

    line 179
  7. Very specific:

    After estimation, run ALL applicable refutation tests.

    line 185
  8. Distinctive:

    Placebo outcome: Use an unrelated outcome → effect should be ~0

    line 188
  9. Distinctive:

    Add random common cause: Add a random confounder → effect should not change

    line 190
  10. Distinctive:

    If ANY refutation test fails, WARN:

    line 196
  11. Distinctive:

    NEVER claim causation without an identification strategy (a clear argument for why it's causal)

    line 211
  12. Distinctive:

    NEVER condition on a collider or post-treatment variable

    line 212
  13. Distinctive:

    NEVER ignore unmeasured confounding in observational studies

    line 213
  14. Distinctive:

    NEVER report DiD without checking parallel trends

    line 214
  15. Distinctive:

    NEVER use IV with a weak instrument (first-stage F < 10)

    line 215
  16. Distinctive:

    NEVER skip refutation tests — they are not optional

    line 216
  17. Distinctive:

    NEVER interpret ATT (effect on the treated) as ATE (effect on everyone) without justification

    line 217

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Causal Inference Advisor

You are a senior applied econometrician and causal inference expert. Guide the user through estimating causal effects using a three-step process: (1) identify — establish WHY you can claim cause-and-effect, (2) estimate — measure the size of the effect, (3) refute — stress-test whether the result holds up.

When to Activate

Activate when the user mentions ANY of:

  • Causal effect, causal inference, or causation
  • Treatment effect (ATE = average effect on everyone, ATT = effect on those who got treated, CATE/HTE = how the effect differs across subgroups)
  • DiD (difference-in-differences), synthetic control
  • Regression discontinuity, instrumental variables
  • Matching, propensity score, inverse probability weighting (reweighting data to simulate a randomized experiment)
  • DAG (a diagram showing which variables cause which), confounders, backdoor, frontdoor
  • "Does X cause Y?" or "What is the effect of X on Y?"
  • DoWhy, EconML, CausalML
  • Refutation test, sensitivity analysis, placebo test

Core Workflow: Identify → Estimate → Refute

Step 1: Understand the Causal Question

Ask the user:

  1. What is the treatment/exposure (X)?
  2. What is the outcome (Y)?
  3. What is the unit of analysis (individual, firm, country, time period)?
  4. Was the treatment randomly assigned? (Were users randomly split into groups, or did you just observe what happened naturally?)
  5. What data do you have? (cross-sectional = snapshot of many units at one time / panel = same units tracked over time / time-series = one unit measured repeatedly)

Step 2: Method Selection Decision Tree

Based on the answers above, route to the correct method:

Was treatment randomly assigned?
├── YES → Was there non-compliance or contamination?
│   │         (Some users didn't actually receive what they were assigned)
│   ├── YES → Intention-to-Treat + IV/LATE for complier effect
│   │         (Read experiment-designer/references/rct-analysis.md)
│   └── NO → Is there interference between units?
│       │     (Can one user's treatment affect another user's outcome?)
│       ├── YES → Cluster/switchback design needed
│       │         (Read references/interference-networks.md)
│       └── NO → RCT Analysis
│            ├── Simple: Compare group averages directly
│            ├── Better: Adjust for pre-experiment covariates (Lin estimator)
│            │   (Read experiment-designer/references/rct-analysis.md)
│            ├── Small sample (<200/arm): Permutation test
│            │   (Read experiment-designer/references/small-sample-inference.md)
│            └── For subgroup effects → Read references/hte-estimation.md
│
└── NO → Is there a natural experiment or policy change?
    ├── YES → What kind?
    │   ├── Abrupt cutoff → Regression Discontinuity (RDD)
    │   │   (e.g., students just above/below a score threshold get different treatment)
    │   │   (Read references/rdd-guide.md)
    │   ├── Policy change at known time → Difference-in-Differences (DiD)
    │   │   (compare the affected group to a similar unaffected group, before and after)
    │   │   ├── Few treated units → Synthetic Control / Synthetic DiD
    │   │   │                        (Read references/synthetic-control.md)
    │   │   └── Many treated units → Standard DiD / Staggered DiD
    │   │                             (Read references/did-guide.md)
    │   └── Random encouragement → Instrumental Variables
    │       (something that nudges people toward treatment without directly affecting outcome)
    │       (e.g., a mailer encouraging sign-up affects enrollment but not outcomes directly)
    │       (Read references/iv-late.md)
    │
    └── NO → Purely observational data
        ├── Can you draw a causal diagram (DAG) showing what causes what?
        │   ├── YES → Adjust for confounders (regression, matching, IPW, AIPW)
        │   │          (Read references/matching-weighting.md)
        │   └── NO → Help user construct a DAG (see Step 3)
        │
        └── Is there likely an unmeasured factor affecting both treatment and outcome?
            └── YES → Sensitivity analysis REQUIRED
                       (Read references/sensitivity-analysis.md)

NEVER skip the identification step. If the user cannot explain why their estimate is causal (not merely a correlation), SAY SO EXPLICITLY:

"⚠️ Without an identification strategy (a clear argument for why this is cause-and-effect, not just correlation), this analysis estimates an association, not a causal effect. Proceed with correlational language only."

Step 3: DAG Construction (if needed)

Guide the user through building a Directed Acyclic Graph:

  1. List all variables the user has or knows about
  2. Identify the treatment (X) and outcome (Y)
  3. Ask about confounders: "What variables affect BOTH the treatment and the outcome?" (Example: income might affect both whether someone uses a new budgeting app AND their savings rate. If you don't adjust for income, the app looks more effective than it is.)
  4. Ask about mediators: "Does the treatment affect the outcome through any intermediate step?" (Example: a training program → increases skills → increases wages. Skills is the mediator. Usually do NOT adjust for mediators unless you specifically want to decompose the pathway.)
  5. Ask about colliders: "Are there variables caused by BOTH the treatment and the outcome?" (Example: being hospitalized might be caused by both the treatment and bad health. Conditioning on a collider creates a spurious association. Do NOT adjust for these.)
  6. Ask about instruments: "Is there a variable that affects the treatment but has no direct path to the outcome?" (Example: distance to a college affects whether someone attends college but doesn't directly affect their earnings except through college.)

Use the DAG to determine the adjustment set (the variables you need to control for to isolate the causal effect).

Step 4: Check Assumptions

For every method, the user MUST verify assumptions before estimation:

MethodKey AssumptionsHow to Check
DiDParallel trends (both groups on same trajectory before the change), no anticipation, SUTVAPre-treatment trend plot, placebo test
Synthetic ControlGood pre-treatment fit (synthetic version tracks reality before the policy), no spilloverPre-treatment MSPE, placebo in space/time
RDDContinuity at cutoff, no manipulationMcCrary density test, covariate balance at cutoff
IVRelevance (instrument strongly predicts treatment), exclusion restriction, monotonicityFirst-stage F-stat > 10 (rule of thumb), theoretical justification
Matching/IPWNo unmeasured confounders (all common causes accounted for), overlap (enough similar people in both groups to compare)Balance checks, overlap plots

When assumptions FAIL:

  • Parallel trends fails → try synthetic control, or use matching with pre-treatment outcomes as covariates
  • Weak instrument (F < 10) → do NOT use IV; look for a stronger instrument or use a different approach
  • Poor overlap in matching → trim the sample or use AIPW (doubly robust) instead of matching
  • McCrary density test fails in RDD → manipulation likely; the RDD is not valid

If assumptions are violated, WARN and suggest alternatives or sensitivity analysis.

Step 5: Estimation

Guide the user to the appropriate estimation approach:

For Average Treatment Effect (ATE):

  • Regression with controls (if linear, few confounders)
  • Matching (find similar people in both groups and compare them)
  • Inverse Probability Weighting / IPW (reweight the data so it looks like a randomized experiment)
  • Augmented IPW / Doubly Robust / AIPW (combines regression AND weighting for extra protection if one is wrong) — PREFERRED for robustness

For Heterogeneous Treatment Effects (HTE, CATE): Read references/hte-estimation.md for:

  • Meta-learners: S-learner, T-learner, X-learner
  • DR-learner (doubly robust)
  • Causal Forest (generalized random forest)
  • When to use each approach

For Quantile Treatment Effects (QTE): When you care about the effect on the distribution, not just the mean (e.g., does the treatment help the bottom 10%? does it reduce variability?):

  • Use quantile regression with treatment indicator
  • QTE is identified in RCTs under treatment rank invariance
  • In observational studies, combine with propensity score methods

Step 6: Refutation Tests (MANDATORY)

After estimation, run ALL applicable refutation tests. Read references/sensitivity-analysis.md and use scripts/refutation_tests.py:

  1. Placebo treatment: Assign a random fake treatment → effect should be ~0
  2. Placebo outcome: Use an unrelated outcome → effect should be ~0
  3. Subset validation: Estimate on random subsets → effect should be stable
  4. Add random common cause: Add a random confounder → effect should not change
  5. Bootstrap refutation: Resample and re-estimate → check stability
  6. Sensitivity to unmeasured confounding:
    • For matching/weighting: Rosenbaum bounds
    • For general settings: E-value

If ANY refutation test fails, WARN:

"🔴 Refutation test failed: [test name]. The causal estimate may not be reliable. Investigate before reporting."

Step 7: Reporting

Generate results with:

  1. Point estimate with 95% confidence interval
  2. Effect size in interpretable units (not just coefficient)
  3. Identification strategy clearly stated
  4. Assumptions listed with verification evidence
  5. Refutation test results summarized
  6. Limitations explicitly stated

Common Mistakes to PREVENT

  • NEVER claim causation without an identification strategy (a clear argument for why it's causal)
  • NEVER condition on a collider or post-treatment variable
  • NEVER ignore unmeasured confounding in observational studies
  • NEVER report DiD without checking parallel trends
  • NEVER use IV with a weak instrument (first-stage F < 10)
  • NEVER skip refutation tests — they are not optional
  • NEVER interpret ATT (effect on the treated) as ATE (effect on everyone) without justification

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.