AgentSkillsCN

Econometrics

计量经济学

SKILL.md

Econometrics Skill: Difference-in-Differences

Description

Applied econometrics expertise for Difference-in-Differences estimation. Use when running regressions, validating assumptions, or interpreting causal estimates.

DiD Fundamentals

The Setup

  • Treatment group: Countries with high Rule of Law (above-median at baseline)
  • Control group: Countries with low Rule of Law (below-median at baseline)
  • Pre-period: Years before 2023
  • Post-period: Years from 2023 onward
  • Outcome: log(GDP PPP per capita)

Identification Assumptions

  1. Parallel trends: Absent treatment, both groups would have followed the same trend in log GDP PPP pc. This is the key assumption. Validate with:

    • Visual inspection: plot group means over time
    • Event study: regress outcome on leads/lags of treatment, pre-treatment coefficients should be ≈ 0
    • Formal test: interact group dummy with pre-treatment year dummies
  2. No anticipation: Treatment effect is zero before 2023. If countries started preparing for GenAI before 2023, this may be violated.

  3. SUTVA (Stable Unit Treatment Value Assumption): One country's treatment doesn't affect another's outcome. Could be violated through trade linkages or technology spillovers — discuss as limitation.

  4. No differential shocks: No other shock hits one group differently at the same time. COVID-19 (2020-2021) is a major confounder — consider excluding or controlling for it.

TWFE Concerns (Modern DiD Literature)

Per Baker, Callaway, Cunningham, Goodman-Bacon & Sant'Anna (2025) — the practitioner's guide in literature/2503.13323v3 (2).pdf:

  • Our setup is a clean 2×T design (two groups, multiple periods, single treatment date 2023) — this is the simplest case. Classic TWFE is valid here because there is no staggered adoption.
  • However, follow their framework for:
    • Covariate adjustment: Include only pre-treatment covariates or slowly-changing controls. Never condition on post-treatment outcomes.
    • Parallel trends assessment: Use their recommended event study specification with leads/lags. Pre-treatment coefficients should be jointly insignificant.
    • Weighting: Be aware of implicit weighting in TWFE. Consider population-weighted vs. unweighted regressions.
    • Multiple periods extension: With T>2 periods, aggregate ATT(t) estimates appropriately.
  • Report Callaway & Sant'Anna (2021) estimator as robustness — even though it's not strictly necessary with a single treatment date, it signals methodological rigor.
  • Cite \citet{baker2025did} as the methodological reference throughout the paper.

Connection to Acemoglu's Framework

Per Acemoglu (2025) Nobel Lecture in literature/Institutions, Technology and Prosperity (1).pdf:

  • Critical junctures are periods where small institutional differences get amplified. Acemoglu explicitly lists AI as a modern critical juncture alongside colonialism and industrialization.
  • The utility-technology possibilities frontier framework predicts that countries with inclusive institutions (high rule of law) will adopt AI in ways that expand the frontier, while extractive institutions lead to suboptimal technology choices.
  • Our DiD tests the empirical implication: if GenAI is indeed a critical juncture, we should observe diverging GDP trajectories between high-RoL and low-RoL countries starting post-2022.
  • Key quote to frame the paper: Acemoglu argues that "during periods of disruption, existing—and sometimes quite small—differences can have amplified effects on prosperity and institutional trajectories."

Coding Best Practices (Python)

Fixed Effects with linearmodels:

python
from linearmodels.panel import PanelOLS
import statsmodels.api as sm

# Set multi-index
df = df.set_index(['country_code', 'year'])

# TWFE DiD
mod = PanelOLS.from_formula(
    'log_gdp_ppp_pc ~ high_rol_post2022 + controls + EntityEffects + TimeEffects',
    data=df,
    check_rank=False
)
res = mod.fit(cov_type='clustered', cluster_entity=True)

Alternative with pyfixest:

python
import pyfixest as pf

# Cleaner syntax for high-dimensional FE
fit = pf.feols('log_gdp_ppp_pc ~ high_rol_post2022 + controls | country_code + year', 
               data=df, vcov={'CRV1': 'country_code'})
fit.summary()

Event Study:

python
# Create year dummies relative to treatment (2023 = 0)
# Omit t = -1 as reference period
for t in range(-5, 4):  # adjust range to data
    if t != -1:  # reference period
        df[f'rel_year_{t}'] = ((df['year'] - 2023) == t).astype(int) * df['high_rol']

# Estimate with all leads and lags
# Plot coefficients with 95% CI

Reporting Standards

  • Always report clustered SEs (country level)
  • Show progressive specifications: (1) no controls, (2) baseline controls, (3) full controls
  • Report both statistical significance AND economic magnitude
  • Economic interpretation: "A coefficient of 0.05 implies that high-RoL countries experienced 5% higher GDP growth relative to low-RoL countries post-GenAI"