跳到正文
cccskills
免费在 GitHub 公开

event-study

Analyze changes before and after an intervention in R, estimate how effects develop over time, and plot results. Choose methods suited to different adoption dates and check assumptions behind comparisons between treated and untreated groups.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

Use this skill whenever the user wants to conduct an event study, create event study plots, test for parallel trends, implement difference-in-differences designs, or work with any panel data estimation that involves pre/post treatment comparisons. Trigger on phrases like "event study", "parallel trends", "pre-trends", "dynamic treatment effects", "leads and lags", "TWFE", "two-way fixed effects", "staggered adoption", "staggered treatment", "difference-in-differences", "DiD", "Sun and Abraham", "Callaway and Sant'Anna", "de Chaisemartin", "Borusyak", "did_multiplegt", "fixest", "did2s", "bacon decomposition", or any reference to plotting coefficients around a treatment event. Also trigger when the user uploads panel data and wants to estimate treatment effects with variation in treatment timing. All code is in R.

查看安装方法

适用场景

  • Plotting effects before and after a policy starts
  • Checking whether groups followed similar trends before treatment
  • Comparing methods when treatment starts at different times
  • Diagnosing problems with traditional effect estimates

包含的文件(4)

  • SKILL.md6.7 KB
  • diagnostics-and-testing.md12.4 KB
  • modern-extensions.md15.3 KB
  • traditional-event-study.md7.1 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Event Study Skill

This skill covers everything needed to conduct event studies in R - from the traditional two-way fixed effects (TWFE) approach through modern robust estimators that handle staggered treatment timing and heterogeneous treatment effects.

When to Use This Skill

Use this skill when the user wants to:

  • Create event study plots (coefficient plots around a treatment event)
  • Test for parallel pre-trends in a difference-in-differences design
  • Estimate dynamic treatment effects
  • Work with staggered treatment adoption (units treated at different times)
  • Implement any of the modern DiD estimators (Callaway & Sant'Anna, Sun & Abraham, etc.)
  • Diagnose problems with TWFE under treatment effect heterogeneity

Quick Decision Tree

Before writing any code, determine the user's situation:

  1. Is treatment timing the same for all treated units?

    • Yes → Traditional TWFE event study is fine. See traditional-event-study.md
    • No (staggered) → Go to step 2.
  2. Is there reason to expect heterogeneous treatment effects across cohorts or over time?

    • No strong reason → Traditional TWFE may still be OK, but consider robust alternatives.
    • Yes or unsure → Use a robust estimator. See modern-extensions.md
  3. What is the user's goal?

    • Quick visualization of pre-trends → Traditional approach, fast and familiar.
    • Publication-quality estimation → Recommend a robust estimator + traditional as comparison.
    • Diagnostic check → Bacon decomposition to understand TWFE weights.

Core Concepts (Brief)

An event study plot displays estimated coefficients for leads (pre-treatment periods) and lags (post-treatment periods) relative to a baseline period (typically one period before treatment). The key elements are:

  • Relative time: Time reindexed so that treatment occurs at period 0 for each unit.
  • Baseline/reference period: Usually t = -1 (omitted from regression, normalized to zero).
  • Pre-trend coefficients: Periods before treatment. If these are close to zero, it supports the parallel trends assumption.
  • Post-treatment coefficients: These capture the dynamic treatment effect over time.

The parallel trends assumption states that, absent treatment, treated and control units would have followed the same trajectory. Pre-trend coefficients near zero are necessary (but not sufficient) evidence for this.

Workflow

For any event study request, follow this general workflow:

  1. Understand the data: Identify the panel structure (unit ID, time variable, treatment indicator, outcome). Ask the user if not clear.
  2. Determine treatment timing: Is it uniform or staggered?
  3. Choose the estimator: Use the decision tree above.
  4. Estimate the model: Follow the relevant reference file.
  5. Create the plot: Always produce a clean, publication-ready event study plot.
  6. Interpret results: Discuss pre-trends, post-treatment dynamics, and any concerns.

Reference Files

Read these as needed based on the user's situation:

  • traditional-event-study.md - Traditional TWFE event study with fixest. Read this for any event study request. It covers the baseline approach, plotting, and the assumptions behind it.

  • modern-extensions.md - Modern robust estimators for staggered designs. Read this when treatment timing varies across units or when the user asks about heterogeneous treatment effects, or any of the newer DiD methods.

  • diagnostics-and-testing.md - Pre-trend testing, placebo checks, Bacon decomposition, sensitivity analysis. Read this when the user wants to validate their design or when you spot potential issues.

Key R Packages

PackagePurposeWhen to use
fixestTWFE event studies, Sun & AbrahamDefault starting point
didCallaway & Sant'Anna estimatorStaggered treatment, heterogeneous effects
did2sGardner (2022) two-stage DiDStaggered treatment, clean decomposition
DIDmultiplegtde Chaisemartin & D'HaultfoeuilleStaggered, robust to heterogeneity
bacondecompBacon decompositionDiagnosing TWFE problems
HonestDiDSensitivity analysis for pre-trendsRobustness checks on parallel trends
ggplot2PlottingAlways
modelsummaryRegression tablesWhen user needs tables

Plotting Standards

All event study plots should follow these defaults (user can override):

  • Use ggplot2 with theme_minimal() or a clean custom theme
  • Include a vertical dashed line at t = 0 (treatment onset)
  • Include a horizontal dashed line at y = 0 (null effect)
  • IMPORTANT: Use discrete point estimates with vertical error bars (geom_point + geom_errorbar), NOT connected lines with shaded ribbons (geom_line + geom_ribbon). Each period t should show an individual point with its own error bar. This is the standard format in economics journals.
  • Show 95% confidence intervals as error bars (vertical lines at each point)
  • Label axes clearly: "Periods Relative to Treatment" (x) and the outcome name (y)
  • Normalize the reference period coefficient to 0 explicitly
  • Use colorblind-friendly palettes when comparing multiple groups
  • If comparing estimators, use facets or distinct colors/shapes with a legend

Common Pitfalls to Watch For

  • Forgetting to set the reference period: Always drop one pre-treatment period.
  • Binning endpoint periods: With limited pre/post periods, bin the endpoints (e.g., "-5+" and "5+") to avoid small-sample noise.
  • Not-yet-treated as controls: In staggered settings, TWFE uses not-yet-treated units as controls, which can introduce bias if treatment effects are heterogeneous.
  • Interpreting pre-trends as proof of parallel trends: Pre-trends being zero is necessary but not sufficient. Absence of evidence is not evidence of absence.
  • Unbalanced panels: Missing observations can distort event study estimates, especially at the endpoints.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

a1

免费

Turn a broad research idea into clear, testable questions. Compare familiar and less conventional approaches, structure the selected question around its population and methods, and assess variables, feasibility, and potential theoretical contributions.

中文简介正在准备中。当前显示英语简介。

  • Turn a research topic into testable questions
  • Narrow an overly broad research question
  • Compare alternative research angles
brycewang-stanford/Auto-Empirical-Research-Skills47422026年10月20日 更新

a2

免费

Helps build a research framework by comparing theories, mapping relationships between variables, and deriving testable hypotheses. Explores less conventional options, examines weaknesses and competing explanations, and produces diagrams with anticipated reviewer objections.

中文简介正在准备中。当前显示英语简介。

  • Comparing theories for a research question
  • Deriving hypotheses from relationships between variables
  • Examining weaknesses and anticipated reviewer objections
brycewang-stanford/Auto-Empirical-Research-Skills47422026年10月20日 更新

a5

免费

Clarify the philosophical assumptions behind a research project and check whether they fit the proposed methods. Get a reasoned research stance, draft proposal wording, and guidance for explaining how the researcher's background and values shape the study.

中文简介正在准备中。当前显示英语简介。

  • Clarifying philosophical foundations for a research proposal
  • Explaining why the chosen research methods fit the study
  • Drafting a statement about the researcher's position
brycewang-stanford/Auto-Empirical-Research-Skills47422026年10月20日 更新

Plan and draft academic papers through specialized agent roles covering literature, arguments, citations, and review. Get chapter guidance, revision roadmaps, Traditional Chinese and English abstracts, and documents formatted as LaTeX, DOCX, PDF, or Markdown.

中文简介正在准备中。当前显示英语简介。

  • Planning a paper chapter by chapter
  • Drafting a paper from research materials
  • Turning reviewer comments into a revision roadmap
brycewang-stanford/Auto-Empirical-Research-Skills47422026年10月20日 更新

Turn a detailed outline into a philosophy or interdisciplinary manuscript. Draft chapters with repeated quality reviews, check terminology and arguments across sections, and prepare the manuscript, evaluation reports, abstract, and metadata for submission.

中文简介正在准备中。当前显示英语简介。

  • Draft a full paper from a detailed outline
  • Review argument and citation quality chapter by chapter
  • Check terminology and argument flow across chapters
brycewang-stanford/Auto-Empirical-Research-Skills47422026年10月20日 更新

Simulate academic peer review through five reviewer roles tailored to the paper's field. Receive separate critiques, an editorial decision, and a prioritized revision roadmap, or check whether a revised manuscript addresses earlier comments.

中文简介正在准备中。当前显示英语简介。

  • Review a manuscript before journal submission
  • Examine research methods and statistical validity
  • Challenge core arguments and alternative explanations
brycewang-stanford/Auto-Empirical-Research-Skills47422026年10月20日 更新

查看 brycewang-stanford 的全部技能

报告此技能的问题