Logo : Causal Did

Causal Did

Communauté
RobsonTigre
causal-did

Met en œuvre la méthode des différences-en-différences en R ou Python, avec test des tendances parallèles, vérifications de robustesse et interprétation en langage clair. À utiliser lorsque l’utilisateur pose des questions sur DiD, le déploiement échelonné, TWFE, les études événementielles ou les tendances parallèles. Ne convient pas à une simple comparaison avant/après sans groupe témoin.

Présentation

ÉditeurRobsonTigre
Dépôteveryday-causal-skills
Nom de la compétencecausal-did
Étoiles
83
Forks
10
Fichiers inclus
Instructions uniquement
LicenceMIT
Liens
  • Instructions en Markdown

    Un fichier SKILL.md que le modèle charge à la demande : il ne consomme donc des tokens que lorsqu’une demande correspond réellement à la compétence.

  • Compatible avec tous les LLM

    Les compétences IA sont rédigées en Markdown et non sous forme de code propre à un fournisseur. Elles fonctionnent donc avec GPT, Claude, Gemini, Grok ou un modèle local.

  • Tout dans les instructions

    Tout ce dont le modèle a besoin se trouve dans les instructions : aucun fichier supplémentaire à synchroniser.

  • Open source

    Publiée par RobsonTigre sur GitHub. Consultez les sources avant de l’installer.

Installation

Installez la compétence IA Causal Did dans TypingMind pour l’utiliser avec n’importe quel LLM, ou ajoutez-la à un autre agent capable de lire SKILL.md.

1

Installer dans TypingMind

TypingMind installe une compétence directement depuis son dossier GitHub : l’application lit SKILL.md, regroupe les fichiers de ressources et enregistre le tout localement.

  1. Ouvrez l’application et accédez à Plugins → Compétences.
  2. Choisissez « Installer depuis GitHub ».
  3. Copiez l’URL ci-dessous, qui pointe vers le dossier de la compétence, puis collez-la et confirmez.
    https://github.com/RobsonTigre/everyday-causal-skills/tree/main/skills/causal-did
  4. Activez la compétence dans chaque discussion où vous souhaitez pouvoir l’utiliser.
Plugins → Compétences → Ajouter une compétence → Via une URL GitHub, puis collez l’URL du dossier et appuyez sur Continuer.
2

Installer dans un autre agent

Tout agent capable de lire le format Agent Skills peut utiliser cette compétence : copiez le dossier dans le répertoire des compétences de cet agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/RobsonTigre/everyday-causal-skills.git /tmp/everyday-causal-skills
mkdir -p .claude/skills
cp -r /tmp/everyday-causal-skills/skills/causal-did .claude/skills/causal-did
Redémarrez Claude Code après la copie pour que la nouvelle compétence soit prise en compte.

Utilisez cette compétence dans TypingMind

Activez Causal Did dans n’importe quelle discussion TypingMind et le modèle s’occupe du reste. Le nom et la description de la compétence figurent dans le prompt système. Dès qu’une demande correspond, le modèle charge lui-même l’intégralité des instructions : vous n’avez jamais à l’invoquer manuellement, et elle ne consomme aucun token tant qu’elle n’est pas utilisée.

Le modèle charge automatiquement Causal Did dès qu’une demande correspond à cette compétence.

Compatible avec tous les modèles IA

Les compétences IA sont de simples instructions Markdown, et non du code propre à un fournisseur. Ainsi, la compétence Causal Did n’est pas liée au modèle pour lequel elle a été conçue. Installez-la une seule fois dans TypingMind et utilisez-la avec GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama ou un modèle local que vous exécutez vous-même, le tout avec vos propres clés API.

  • Chargée uniquement en cas de besoin

    Le prompt système ne contient que le nom et la description. Les instructions sont récupérées à la première demande correspondante : une compétence inutilisée ne coûte donc rien.

  • Changez de modèle en cours de discussion

    La compétence étant constituée d’instructions et non de code, elle reste fonctionnelle lorsque vous changez de modèle : le nouveau modèle lit le même fichier SKILL.md.

Instructions de la compétence

Voici le contenu de SKILL.md que le modèle charge. Lisez-le avant l’installation : une compétence contient des instructions que votre modèle suivra.

Causal DiD

You guide users through a complete difference-in-differences analysis following a 5-stage pattern.

Before You Begin

  1. Read references/lessons.md — known mistakes. Do not repeat them.
  2. Read references/assumptions/did.md — the assumption checklist for DiD.
  3. Read references/method-registry.md → "Difference-in-Differences" section.
  4. Check if a plan exists at docs/causal-plans/*/plan.md. If it does, read it for context.
  • Explain the why: When walking through assumptions, recommending methods, or flagging concerns, always explain why it matters — not just what to do. Help the user build intuition, not just follow instructions.

Quality Standards

  • Complete every stage. Do not skip assumption checks or robustness tests.
  • Quality over speed. A thorough analysis with caveats beats a fast one without.
  • When uncertain, say so. Flag limitations rather than presenting weak evidence as strong.

Stage 1: Setup

If a plan document from /causal-planner is provided: Extract the study design (treatment, population, outcome, data structure, language) directly from the plan. Do not re-ask questions the planner already answered. Acknowledge the plan and build on it.

If plan exists: Read it. Extract business objective, treatment, population, outcome, language, data structure. Confirm: "I've read your analysis plan. You're looking at [treatment] on [outcome] using DiD. Does that sound right?"

If no plan: Ask:

  1. "What's the treatment and when did it start?"
  2. "What's the outcome metric?"
  3. "Do you have panel data (same units observed over time)?"
  4. "Is this a staggered rollout (units treated at different times) or a single treatment date?"
  5. "How many units and time periods?"
  6. "R or Python?"

When the prompt already supplies the design and data schema: Do not make the complete analysis wait behind a repeated intake checklist. Briefly confirm the variant, explain that DiD subtracts the control group's change from the treated group's change to remove shared time shocks, and distinguish assumed parallel trends from diagnostics that have actually been observed. Then provide the immediate deliverable appropriate to the available evidence: runnable main-model and event-study code when no fatal violation is established, or the explicit severity verdict and diagnostic/repair path when one is.

For a valid staggered design, name the ATT target and why not-yet-treated or never-treated units form the comparison group. Always leave the user with a specific artifact to run or inspect, not only a promise to provide one later.

Determine variant:

  • Single treatment date, 2 groups → Classic 2x2 DiD
  • Single date, panel → TWFE with unit + time FE
  • Staggered dates → Staggered DiD: R did::att_gt() / Python diff_diff.CallawaySantAnna (Callaway-Sant'Anna). Not naive TWFE.
  • Want dynamics → Event study

Stage 2: Assumptions

Read references/assumptions/did.md. Walk through each assumption interactively:

For each assumption:

  1. Explain in plain language what it means for their specific context.
  2. Ask if it's plausible.
  3. If testable, offer diagnostic code.
  4. Note the concern level.

Key assumptions to walk through:

  1. Parallel trends: "Without the treatment, would the treated and control groups have followed similar trends? Let's check with a pre-trends test."

    • Offer event study plot code.
    • Say plainly that the assumption itself is untestable, however clean the pre-trends look. The pre-period test checks trends that already happened; DiD needs the treated group's counterfactual trend after treatment, which is never observed. Passing pre-trends makes the assumption more credible — it does not establish it. State this even when the user has many pre-periods and the test passes, not only when pre-periods are too few to test.
  2. No anticipation: "Did treated units change behavior before treatment actually started?"

  3. Stable composition: "Did units enter or leave the sample because of treatment?"

  4. No spillovers (SUTVA): "Could treated units affect control units' outcomes?"

  5. Functional form (for staggered): "Standard TWFE can be biased with heterogeneous treatment effects across cohorts. I'll use a robust estimator — did::att_gt() in R or diff_diff.CallawaySantAnna in Python. (Classic single-date 2×2 does not need this; plain TWFE/PanelOLS is correct there.)"

After all assumptions, summarize with status indicators per assumption.

If fatal violations exist, warn clearly and suggest alternatives. If you cannot yet confirm the violation (because the user hasn't run diagnostic code), use the CONDITIONAL FATAL verdict format from Red Flags. Do not generate full analysis code before a fatal-level diagnostic has been resolved — require the user to report the diagnostic result first.

Stage 3: Implementation

Generate complete analysis code. Read the appropriate template from templates/r/did.md or templates/python/did.md for code patterns.

Missing-package preflight: The template's Prerequisites block detects (never installs) missing packages. Follow references/preflight.md: report what's missing, then ask the user whether they want you to install it for them or do it themselves — install only on an explicit yes.

IMPORTANT — Template adherence: Copy the code pattern from the appropriate template (templates/r/did.md or templates/python/did.md) exactly, then adapt only variable names to match the user's data. Do not restructure the code, use alternative function APIs, or improvise accessor patterns. The templates have been tested; deviations introduce bugs.

Common pitfall — entity fixed effects and time-invariant variables: When using entity (unit) fixed effects, do NOT include time-invariant variables as regressors (e.g., a treated dummy that never changes within a unit). Entity FE already absorb all time-invariant unit characteristics. Including them causes perfect multicollinearity and will crash PanelOLS / feols or silently drop the variable. The interaction term treated * post (or treated:post in formula syntax) is fine because it varies over time.

Always include:

  • Data preparation / reshaping
  • Main estimation with proper specification
  • Clustered standard errors (at unit level) — and say in one line why they are clustered: repeated observations on the same unit are correlated over time, so unclustered errors come out too small and overstate significance. Emitting cluster = ~unit without explaining it teaches the user nothing.
  • Effect size with 95% confidence interval
  • What the estimate is, and what it is not: name it as the ATT — the average effect on the units that actually received treatment — and say what it does not tell them: what the effect would have been for untreated units, or under a different rollout or population. Do this when you present the estimate, not only in Stage 5, which the user may never reach.
  • Event study plot (for visual dynamics)
  • Results summary table

For classic 2x2 DiD (R):

r
library(fixest)
library(modelsummary)

model <- feols(outcome ~ treated:post | unit + time, data = df,
               cluster = ~unit)
summary(model)
modelsummary(model, stars = TRUE)

For staggered DiD (R):

r
library(did)
att_gt <- att_gt(yname = "outcome", tname = "time", idname = "unit",
                  gname = "first_treat", data = df)
summary(att_gt)
ggdid(att_gt)
agg <- aggte(att_gt, type = "simple")
summary(agg)

For classic DiD (Python):

python
from linearmodels.panel import PanelOLS
import statsmodels.formula.api as smf

# PanelOLS approach
mod = PanelOLS.from_formula('outcome ~ treated_post + EntityEffects + TimeEffects',
                             data=df.set_index(['unit', 'time']))
res = mod.fit(cov_type='clustered', cluster_entity=True)
print(res)

For staggered DiD (Python) — parity with R's did::att_gt(); do NOT hand-roll a per-cohort TWFE loop:

python
from diff_diff import CallawaySantAnna

cs = CallawaySantAnna(control_group="never_treated", base_period="universal")
res = cs.fit(df, outcome="outcome", unit="unit", time="time",
             first_treat="first_treat", aggregate="all")
print(res.overall_att, res.overall_se, res.overall_conf_int)

Use control_group="not_yet_treated" when there are no never-treated units, and covariates=[...] for conditional parallel trends. csdid is broken for this project — do not use it.

Required program versus optional diagnostics: The main estimator, its confidence interval, and the required ESTIMATE: output must form a self-contained program that exits successfully. Keep optional event-study, anticipation, plotting, and comparison diagnostics out of the required execution path unless their API and estimability have been verified for the supplied fixture. If an optional diagnostic can be unavailable in late cohorts or final periods, check that it is estimable or handle the exception without invalidating an already successful main estimate. Put the exact line # EVAL_EXECUTABLE as the first nonblank program line inside exactly one correct-language code fence containing that complete required program. Do not indent it or add other text on that line. Do not mark preflight or illustrative alternatives.

Adapt code to the user's variable names and data structure.

Stage 4: Falsification / Robustness

Propose at least one check. Generate the code.

Options (offer the most relevant):

  1. Placebo test (pre-treatment): Run DiD on pre-treatment data with a fake treatment date midway through.
  2. Placebo outcome: Run DiD on an outcome that should NOT be affected.
  3. Pre-trends test: Test if event study pre-treatment coefficients are jointly zero.
  4. Specification robustness: Different controls, different clustering, different sample windows.

Verification Gate

Before proceeding to interpretation, confirm ALL of the following from actual code output:

  • Main estimation ran without errors
  • You can quote the point estimate from the output
  • You can quote the standard error and 95% CI from the output
  • At least one robustness/falsification check ran and you can compare its result to the main estimate
  • Assumption diagnostics produced output (not just discussed)

If any box is unchecked: Flag it to the user — explain which evidence is missing and why it matters. Offer to run the missing step before interpreting. If the user chooses to continue anyway, carry the gap forward as a caveat in the interpretation.

Watch for premature conclusions — phrases like "The results suggest..." or "Based on the analysis..." before the gate passes. These imply conclusions without evidence. Quote actual output instead.

Severity verdicts must appear BEFORE this gate. If a Fatal or Serious issue was identified during Stage 2 (Assumptions) or Stage 3 (Implementation), the severity verdict block must already be visible in the output above. Do not defer severity communication to after the user runs the code if the data or context already reveals the violation.

Red Flags

Data Diagnostic Signals

SignalSeverityAction
Pre-treatment coefficients show a clear trend🚨 FatalParallel trends assumption is violated. Warn user before continuing.
Treatment timing correlates with outcome shocks🚨 FatalSelection into treatment invalidates DiD. Warn user before continuing.
Large compositional change around treatment⚠️ SeriousFlag survivorship/attrition bias. Report bounds if possible.
Only 1-2 pre-periods available⚠️ SeriousParallel trends untestable. State as strong caveat.

🚨 Fatal = Emit this verdict block immediately after the diagnostic that reveals the violation:

FATAL: [violation name] [One sentence: what was found in the data.] This analysis should not proceed without addressing this issue. Results produced under this violation are not trustworthy. If you cannot yet confirm the violation (because the user hasn't run diagnostic code), use CONDITIONAL FATAL: [violation name] with the same format but replace the consequence line with: "If [specific diagnostic condition], this analysis should not proceed. Run the diagnostic above and report the result before continuing." If the user chooses to continue despite a Fatal verdict, repeat the verdict verbatim in Stage 5 interpretation.

⚠️ Serious = Emit this block:

SERIOUS: [limitation name] [One sentence: what was found.] Proceeding is possible, but the interpretation must prominently acknowledge this limitation and its consequences.

Use only FATAL and SERIOUS severity labels. Do not invent additional tiers (Critical, Yellow, Minor, etc.). When in doubt, round UP to the next severity level.

Rationalization Shortcuts

ShortcutReality
"This is just an exploratory analysis"If results will influence a decision, it's not exploratory. Apply full rigor.
"We don't need robustness checks -- the main result is strong"Strong results without robustness checks are more suspicious, not less.
"The sample is too small for formal tests"Small samples need more caution, not less. Flag the limitation explicitly.
"Parallel trends look close enough""Close" isn't a statistical concept. Run the formal pre-test and report the result.
"We only have 2 pre-periods, so we can't test trends"Then parallel trends is an untestable assumption. Say so clearly -- don't skip it.
"TWFE is fine for staggered rollout"TWFE with heterogeneous effects and staggered timing is biased. Use Callaway-Sant'Anna — did::att_gt() (R) or diff_diff.CallawaySantAnna (Python).

Stage 5: Interpretation

Help write a plain-language summary:

"Based on the DiD analysis:

  • The estimated treatment effect is [coefficient] (95% CI: [lower, upper]).
  • This means [plain-language interpretation in their specific context].
  • [Business metric translation if applicable.]

Caveats:

  • [Weakest assumptions from Stage 2]
  • [What the estimate does NOT tell us]"

Reading Your Results

Pre-treatment coefficients (event study): If any pre-treatment coefficient is individually significant, tell the user: "This period shows a significant effect before treatment — which shouldn't happen. Small blips may be noise, but a clear upward or downward trend suggests the groups were already diverging, which undermines parallel trends."

Parallel trends test: If the joint test rejects (p < 0.05): "The formal test rejects parallel trends — the core assumption for DiD. If treated and control groups were on different trajectories, the estimated effect absorbs that pre-existing difference." If p > 0.05: "The test doesn't reject parallel trends, but this test has low power with few pre-treatment periods. The event study plot matters as much as the p-value — look for visual patterns."

ATT interpretation: "The ATT of [X] means treated units changed by [X] more than control units after treatment. This is the effect on those who were actually treated — it doesn't tell you what would happen if you treated a different group."

Confounding time trends: "If something else changed at the same time as treatment (a policy, a season, a market shift), DiD can't separate the treatment effect from that event. Look for concurrent changes and consider whether they affect treated and control groups differently."

Saving Output

Save alongside the plan (or create a new directory if standalone):

docs/causal-plans/YYYY-MM-DD-<project>/
├── plan.md              # From planner (or created here if standalone)
├── implementation.md    # This skill's stage-by-stage summary
└── analysis.[R|py]      # Generated code

Use the Write tool. Tell the user where files are saved.

Handoff

"Your DiD analysis is complete. Recommended next steps:

  1. Audit: /causal-auditor to stress-test for threats.
  2. Refine: If assumptions were concerning, we can explore mitigations.
  3. Report: I can help write up findings for a non-technical audience."

Common Issues

  • Post-treatment controls included: Controlling for variables affected by treatment biases the estimate. Audit covariates against treatment timing.

Integration

Before this skill:

  • /causal-planner -- Identifies method and saves analysis plan (recommended)

After this skill:

  • /causal-auditor -- Stress-test results for threats to validity (recommended)
  • /causal-hte -- Explore who benefits more or less from treatment (heterogeneous effects)
  • /causal-exercises -- Practice a similar analysis on simulated data (optional)

If assumptions fail:

  • /causal-sc -- Few treated units with long pre-period
  • /causal-matching -- Cross-sectional data with rich covariates

Self-Correction

If the user corrects you, append to references/lessons.md:

### DiD: [Short description]
**Trigger**: [When this tends to happen]
**Mistake**: [What went wrong]
**Rule**: [What to do instead]
**Source**: User correction, [date]

Foire aux questions

À quoi sert la compétence IA Causal Did ?

Met en œuvre la méthode des différences-en-différences en R ou Python, avec test des tendances parallèles, vérifications de robustesse et interprétation en langage clair. À utiliser lorsque l’utilisateur pose des questions sur DiD, le déploiement échelonné, TWFE, les études événementielles ou les tendances parallèles. Ne convient pas à une simple comparaison avant/après sans groupe témoin.

Pourquoi utiliser Causal Did sur TypingMind ?

Parce que vous l’installez une seule fois pour l’utiliser avec n’importe quel modèle. Causal Did se compose de simples instructions en Markdown plutôt que de code propre à un fournisseur. La même compétence fonctionne donc avec GPT-5, Claude, Gemini, Grok ou un modèle local, et vous pouvez changer de modèle en cours de discussion sans perturber son fonctionnement. TypingMind utilise vos propres clés API : vous payez donc directement les fournisseurs plutôt qu’un abonnement par siège, et vos compétences et discussions restent dans votre propre espace de stockage.

Comment installer Causal Did dans TypingMind ?

Dans TypingMind, ouvrez Plugins → Compétences → Installer depuis GitHub et collez https://github.com/RobsonTigre/everyday-causal-skills/tree/main/skills/causal-did. TypingMind lit le fichier SKILL.md et l’installe sous forme de compétence que vous pouvez activer pour chaque discussion.

Quels modèles d’IA peuvent utiliser Causal Did ?

N’importe quel modèle que vous connectez dans TypingMind. Les compétences IA sont de simples instructions en Markdown, et non du code propre à un fournisseur. GPT, Claude, Gemini, Grok et les modèles locaux peuvent donc tous charger cette compétence lorsqu’une demande lui correspond.

Combien de modèles d’IA puis-je utiliser avec Causal Did ?

Autant que vous le souhaitez. Vous pouvez utiliser Causal Did avec tout modèle qui prend en charge les compétences : GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama et bien d’autres, le tout dans TypingMind avec vos propres clés API.

La compétence IA Causal Did est-elle gratuite ?

Oui. Cette compétence est publiée sur GitHub par RobsonTigre sous licence MIT. Vous ne payez que votre propre fournisseur d’IA pour les tokens utilisés.

Que sont les compétences IA ?

Une compétence IA est un ensemble d’instructions réutilisables qui apprend à un modèle d’IA à accomplir une tâche précise. Elle suit le format ouvert Agent Skills : un fichier SKILL.md contenant un nom et une description, ainsi que les éventuels scripts, gabarits ou fichiers de référence dont le modèle peut avoir besoin. Le modèle ne lit les instructions que lorsque votre demande correspond à la compétence. Une compétence installée ne coûte donc rien tant qu’elle n’est pas utilisée.

En quoi les compétences IA diffèrent-elles des plugins ou des serveurs MCP ?

Un plugin ou un serveur MCP fournit au modèle de nouveaux outils à appeler : du code qui s’exécute quelque part et renvoie un résultat. Une compétence IA lui apporte plutôt des connaissances et une méthode : comment aborder une tâche, quelles étapes suivre et à quoi ressemble un bon résultat. Les compétences sont de simples instructions en Markdown. Elles ne nécessitent donc ni serveur, ni clé API, ni environnement d’exécution, et fonctionnent avec n’importe quel modèle.

Tout voir

Créez votre propre espace de travail IA dès maintenant

Abonnez-vous à notre newsletter pour être informé des nouvelles fonctionnalités et des prochains cadeaux à gagner 👇