Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions METHODOLOGY_REVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,17 @@ and covariate-adjusted specifications.)
- [x] Bootstrap SE (Rademacher/Mammen/Webb)
- [x] Control group composition (never_treated/not_yet_treated)
- [x] All documented edge cases from REGISTRY.md
- [x] Cluster jackknife `vcov_type="jackknife"` (2026-11-25; Karim, Nielsen,
MacKinnon & Webb 2026, eq. 20): full-sample centering, `(H - 1)/H` factor,
full re-estimation, `t(H - 1)` reference. Overall, event-study and group
standard errors match R `did` 2.5.1 on delete-one-cluster samples to 1e-8
(`benchmarks/R/generate_cs_jackknife_golden.R`); every quantity equals a
by-hand delete-one loop. Element-wise extension beyond the overall ATT is a
documented library choice backed by `benchmarks/data/cs_jackknife_size.json`

**Test Coverage:**
- 61 methodology verification tests in `tests/test_methodology_callaway.py`
- Cluster jackknife: `tests/test_staggered_jackknife.py`
- Existing unit-test coverage in `tests/test_staggered.py`
- R benchmark tests (skip if R not available)

Expand Down
5 changes: 4 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ Related tracking surfaces:
| diagnostic_report admission for `EventStudyResults` surfaces (the TWFE event-study mode + `aggregate('event_study')` containers): DiagnosticReport/BusinessReport now REJECT the surface explicitly (Phase 3(a); previously a silent zero-check report / all-null headline) and practitioner_next_steps serves the generic fall-through - admission needs source-aware routing (the type-name-keyed `_APPLICABILITY`/`_HANDLERS` registries cannot discriminate the unified container's producers) and a scalar-vs-per-period headline design; MPD-native results received {parallel_trends, pretrends_power, sensitivity, bacon, design_effect}. PR 4c-ii (2026-10-25) DELETED the MPD-native branches that logic lived in (DiagnosticReport's `interaction_indices`+`vcov` joint-Wald covariance source, the `post_period_effects` heterogeneity source, the `pre_period_effects` Bonferroni/NaN-filter collector branch, the `avg_att` alias row, practitioner's `_handle_multi_period`) - recover them from git history (`git show 5a10b847^:diff_diff/diagnostic_report.py`) when admission lands; event-study results reach `_handle_generic` meanwhile | `diff_diff/diagnostic_report.py`, `diff_diff/business_report.py`, `diff_diff/practitioner.py` | 3(a) | Mid | Medium |
| DiagnosticReport public skip bookkeeping omits RUNNER-level skips: `applicable_checks` reflects only gate outcomes, so a check whose runner returns `status="skipped"` (heterogeneity's empty/non-finite branches, `_pt_event_study`'s empty-coefs branch - a pre-existing pattern, now also reachable via a failed post-fit event-study derivation on bootstrapped / kit-less ImputationDiD/TwoStageDiD/ContinuousDiD fits) stays listed as applicable while `skipped_checks`/`schema["skipped"]` omit it, so automation reading the public fields can misclassify the check as completed; reconcile runner-returned skipped sections into the public bookkeeping (all checks, one convention) or resolve those availabilities at the gate | `diff_diff/diagnostic_report.py` | derived-ES review | Mid | Low |
| Align the two pretrends container routes' `pre_periods=` contracts (the native MPD branch died in PR 4c-ii, so only the relative and calendar routes remain): the relative route silently collapses DUPLICATE requested labels (the calendar route rejects them, 3(a) R8), and it filters on SE only while the calendar route additionally requires a finite EFFECT (3(a) R9); one contract across both routes, with pinned rejection messages | `diff_diff/pretrends.py` | 3(a) R8 | Quick | Low |
| `EventStudyResults` inference-provenance fields: the container records no `vcov_type`/`cluster_name`/`n_clusters`/`df_convention`/Conley metadata, so a serialized surface cannot distinguish unit auto-clustering from explicit clustering, survey, Conley, or the one-way carve-out (3(a) R9 review). Adding them is a cross-producer M-092 schema amendment (six builders, to_dict/summary rendering, surface-suite pins) - follow the pre-cut amendment convention (optional fields appended last, ledger note same-diff) rather than bolting onto one producer | `diff_diff/results_base.py` | 3(a) R9 | Mid | Low |
| `EventStudyResults` inference-provenance fields: the container records no `vcov_type`/`cluster_name`/`n_clusters`/`df_convention`/Conley metadata, so a serialized surface cannot distinguish unit auto-clustering from explicit clustering, survey, Conley, or the one-way carve-out (3(a) R9 review). Adding them is a cross-producer M-092 schema amendment (six builders, to_dict/summary rendering, surface-suite pins) - follow the pre-cut amendment convention (optional fields appended last, ledger note same-diff) rather than bolting onto one producer. A consumer of the gap: `compute_pretrends_power` called on the container of a cluster-jackknife `CallawaySantAnna` fit cannot tell that the covariance is a jackknife one, so only `DiagnosticReport` (which sees the results object) skips the power calculation there | `diff_diff/results_base.py` | 3(a) R9 | Mid | Low |
| Cluster jackknife (`vcov_type="jackknife"`) for the other staggered estimators (`SunAbraham`, `ImputationDiD`, `TwoStageDiD`, `StackedDiD`, `EfficientDiD`). Karim, Nielsen, MacKinnon & Webb (2026) cover CSDID only, so each needs its own size simulation on the pattern of `benchmarks/python/cs_jackknife_size.py`. `SunAbraham` / `ImputationDiD` / `TwoStageDiD` already have a weight-based refit closure (`survey.compute_replicate_refit_variance`); `StackedDiD` accepts only `cluster="unit"` or `"unit_subexp"` and would need a cluster column first | `diff_diff/staggered_jackknife.py` | CS cluster jackknife | Heavy | Medium |
| `CallawaySantAnna(vcov_type="jackknife", allow_unbalanced_panel=True)`: refused today because `allow_unbalanced_panel` picks the repeated-cross-section route from the balance of the data and deleting a cluster can balance the panel, so delete-one refits could run a different estimator than the full sample. Needs the route pinned in the refits (run the RC levels estimator on every delete-one sample) with an equality test against a by-hand loop | `diff_diff/staggered.py` | CS cluster jackknife | Mid | Low |
| `DiagnosticReport` joint pre-trend test over-rejects on clustered fits with few clusters: for a `CallawaySantAnna(cluster=...)` `hc1` fit it compares the event-study Wald statistic with a chi-square (a finite denominator df is used only for `survey_design=` fits), ignoring the `t(G-1)` reference the per-row inference uses. In `benchmarks/data/cs_jackknife_size.json` (no violation, nominal 5%) it rejected 13-22% with 6 or more treated clusters per cohort and 62-78% with 2. Use an F reference with the cluster df (as the `df_survey` branch does) or fall back to Bonferroni below a cluster count, and re-run the simulation; check the other estimators that reach this branch | `diff_diff/diagnostic_report.py` | CS cluster jackknife | Mid | Medium |
| Opt-in singleton-group pruning for TwoWayFixedEffects (static + event-study mode; reghdfe parity): singleton units/periods are currently RETAINED class-wide - the within-demeaned row is zero so points are unchanged, but N/G/residual-df count it and CR1/finite-sample SEs shift (~0.41019 -> 0.40962 measured; REGISTRY "Deviation from R" Note, R5 review) - reghdfe iteratively drops singletons by default while fixest retains them (diff-diff matches fixest); an opt-in knob needs iterative unit+period pruning with consistent cluster/survey/replicate/Conley array subsetting and a default-flip decision protocol (moves published SEs) | `diff_diff/twfe.py`, `diff_diff/estimators.py`, `diff_diff/utils.py` | 3(a) R5 | Mid | Low |
| Cohort-timing validation input for the simultaneous-adoption event-study family (TWFE `event_study=True`; MultiPeriodDiD through 3.9): an optional `first_treat=`/`cohort=` column so simultaneous adoption becomes checkable under the contract-valid time-invariant `D_i` indicator - today the staggered-adoption advisory derives timing from within-unit 0->1 transitions, so it can only fire on off-contract time-varying `D_it` input, and with valid `D_i` adoption timing is not observable in the inputs at all (REGISTRY "staggered-adoption detection limit" Notes, both sections); design questions: validate-only vs steering error (the M-011 removal shipped in PR 4c-ii, so only the TWFE surface is in play) | `diff_diff/twfe.py`, `diff_diff/estimators.py` | 3(a) R2 | Mid | Medium |
| `balance_e` replay on bootstrapped ImputationDiD/TwoStageDiD fits: the unrestricted ES/group surface is relayed since 4.0 PR 3c (computed at fit, `balance_e=None`; M-021/M-022), but `aggregate('event_study', balance_e=k)` still raises there - a balanced-window replay needs retained per-target psi (ImputationDiD: the panel-backed kit retains everything the psi precompute reads, so a seeded replay is tractable) / retained per-level GMM scores (TwoStageDiD: function-locals today) | `diff_diff/imputation_results.py`, `diff_diff/two_stage_results.py`, `diff_diff/aggregation.py` | 2(b) PR-3b | Mid | Low |
Expand Down
140 changes: 140 additions & 0 deletions benchmarks/R/generate_cs_jackknife_golden.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/usr/bin/env Rscript
# Golden values for CallawaySantAnna(vcov_type="jackknife"): the cluster
# jackknife (CV3) of Karim, Nielsen, MacKinnon & Webb (2026, arXiv:2602.12043),
# equation (20), computed with R `did` on delete-one-cluster samples.
#
# Usage: Rscript benchmarks/R/generate_cs_jackknife_golden.R
# Output: benchmarks/data/cs_jackknife_golden.json
#
# The procedure is the one the paper's R package `didjack` implements
# (https://github.com/liu-yunhan/didjack, MIT): refit did::att_gt on each
# delete-one-cluster sample, re-aggregate with did::aggte, and take
# CV3 = ((H - 1) / H) * sum_h (theta^(h) - theta)^2
# around the full-sample estimate, with a t(H - 1) reference. `didjack`
# reports the overall ATT only; the same formula is applied here element-wise
# to the dynamic and group aggregates, which is the library's documented
# extension. `didjack` itself is not on CRAN and is not required: only `did`
# point estimates enter, so no clustering option is passed to att_gt.
#
# The panel is embedded in the JSON so the Python test refits exactly it.
suppressMessages({
library(did)
library(jsonlite)
})

set.seed(20261125)

n_states <- 12L
units_per <- 3L
n_periods <- 6L
cohort_of_state <- c(3, 3, 3, 5, 5, 5, rep(0, 6))

rows <- list()
k <- 1L
for (s in seq_len(n_states)) {
shock <- cumsum(rnorm(n_periods, 0, 0.4))
g <- cohort_of_state[s]
for (j in seq_len(units_per)) {
u <- (s - 1L) * units_per + j
ufe <- rnorm(1)
for (t in seq_len(n_periods)) {
eff <- if (g != 0 && t >= g) 0.8 + 0.2 * (t - g) else 0
rows[[k]] <- data.frame(
unit = u, state = sprintf("s%02d", s), t = t, g = g,
y = ufe + 0.3 * t + shock[t] + eff + rnorm(1, 0, 0.5)
)
k <- k + 1L
}
}
}
df <- do.call(rbind, rows)
clusters <- unique(df$state)
H <- length(clusters)

estimates <- function(data, est_method, control_group, base_period) {
out <- suppressWarnings(att_gt(
yname = "y", tname = "t", idname = "unit", gname = "g", data = data,
control_group = control_group, est_method = est_method,
base_period = base_period, bstrap = FALSE, cband = FALSE
))
simple <- aggte(out, type = "simple", na.rm = TRUE, bstrap = FALSE, cband = FALSE)
dyn <- aggte(out, type = "dynamic", na.rm = TRUE, bstrap = FALSE, cband = FALSE)
grp <- aggte(out, type = "group", na.rm = TRUE, bstrap = FALSE, cband = FALSE)
list(
overall = simple$overall.att,
dyn_e = dyn$egt, dyn_att = dyn$att.egt,
grp_g = grp$egt, grp_att = grp$att.egt
)
}

cv3_se <- function(full, reps) sqrt((H - 1) / H * sum((reps - full)^2))

configurations <- list(
reg_nevertreated_varying = list("reg", "nevertreated", "varying"),
dr_nevertreated_varying = list("dr", "nevertreated", "varying"),
reg_notyettreated_varying = list("reg", "notyettreated", "varying"),
dr_nevertreated_universal = list("dr", "nevertreated", "universal")
)
library_control_group <- c(nevertreated = "never_treated", notyettreated = "not_yet_treated")

golden_cfg <- list()
for (name in names(configurations)) {
cfg <- configurations[[name]]
full <- estimates(df, cfg[[1]], cfg[[2]], cfg[[3]])
reps <- lapply(clusters, function(cl) {
estimates(df[df$state != cl, ], cfg[[1]], cfg[[2]], cfg[[3]])
})
for (r in reps) {
stopifnot(identical(r$dyn_e, full$dyn_e), identical(r$grp_g, full$grp_g))
}
overall_loo <- vapply(reps, function(r) r$overall, numeric(1))
se <- cv3_se(full$overall, overall_loo)
t_stat <- full$overall / se
crit <- qt(0.975, H - 1)
dyn_loo <- do.call(rbind, lapply(reps, function(r) r$dyn_att))
grp_loo <- do.call(rbind, lapply(reps, function(r) r$grp_att))
dyn_se <- vapply(seq_along(full$dyn_e), function(j) cv3_se(full$dyn_att[j], dyn_loo[, j]), numeric(1))
grp_se <- vapply(seq_along(full$grp_g), function(j) cv3_se(full$grp_att[j], grp_loo[, j]), numeric(1))
# A universal base period makes one horizon a reference (estimate 0 in every
# sample, hence a zero jackknife variance); the library reports NaN there.
live <- dyn_se > 0
golden_cfg[[name]] <- list(
est_method = cfg[[1]],
control_group = unname(library_control_group[cfg[[2]]]),
base_period = cfg[[3]],
df = H - 1,
overall_att = full$overall,
overall_att_loo = overall_loo,
overall_se = se,
overall_p = 2 * pt(-abs(t_stat), H - 1),
overall_lci = full$overall - crit * se,
overall_uci = full$overall + crit * se,
event_times = full$dyn_e[live],
event_study_att = full$dyn_att[live],
event_study_se = dyn_se[live],
group_labels = full$grp_g,
group_att = full$grp_att,
group_se = grp_se
)
}

golden <- list(
meta = list(
did_version = as.character(packageVersion("did")),
r_version = R.version.string,
n_clusters = H,
note = paste0(
"Cluster jackknife (CV3, Karim et al. 2026 eq. 20) from did::att_gt + ",
"aggte on delete-one-cluster samples; t(H-1) reference. Overall ATT as ",
"in the didjack package; dynamic and group standard errors by the same ",
"formula element-wise."
)
),
clusters = clusters,
data = as.list(df),
configurations = golden_cfg
)

out_path <- file.path("benchmarks", "data", "cs_jackknife_golden.json")
write_json(golden, out_path, digits = NA, auto_unbox = TRUE, pretty = TRUE)
cat("Wrote", out_path, "\n")
Loading
Loading