Repository navigation
Conversation
…f the 4.0 aggregate oracle fixture Rebuilds only the EfficientDiD numeric leaves from the public fit() + aggregate() API. --check on the unmodified tree reproduces every leaf at the contract tolerances on both backends (largest relative shift 5.7e-13).
Every (inf, t_pre) moment of Eq 3.9 is the same long difference-in-differences, and Eq 3.12 omits the cross-covariance between its two never-treated terms, so stacking one per baseline gave a wrong Omega*, inefficient PT-All weights and a miscalibrated Hausman pretest (statistic mean 0.667 under the null, 1.7% rejections at the 5% level). enumerate_valid_triples now emits the single pair (inf, period_1), for which Eq 3.12 is exact; the four Omega* builders are unchanged. HRS Table 6 is reproduced to 0.002 published SE (was 0.026).
…s Eq 3.10 does The covariate path subtracted the scalar ATT from each per-unit score. The two centrings share a mean but differ by ATT (G_g/pi_g - 1) unit by unit, a term of variance ATT^2 (1 - pi_g)/pi_g, so covariate-path standard errors grew with the size of the effect (noiseless panel, ATT 2: SE 0.1414 where the no-covariate fit and Callaway-Sant'Anna DR give 0). Point estimates are unchanged.
…PT-All; unsigned labels no longer wrap A cohort with g - anticipation <= period_1 has no untreated baseline. PT-Post already drops it with a warning; PT-All estimated it silently against a baseline that was not one (cell estimates near 0 against a true 2). It is now dropped the same way, so the Hausman pretest compares the same cohorts on both sides. Unsigned period or cohort labels are converted to signed on entry: g - anticipation and t - g wrapped around for them, bypassing the cohort guards.
…te oracle fixture Numeric leaves only, from the public API, once per weight backend. Every other estimator's subtree is byte-identical; the routine reproduced the original capture on the pre-correction tree first.
…r the conditioning, stability, anchor and calibration figures REGISTRY Notes for the single never-treated moment, the Eq 3.10 score centring and the cohort drop; the ridge and Hausman Notes rewritten from re-measured figures; METHODOLOGY_REVIEW correction entry; changelog fragment; TODO rows.
…o labels above 2**53 no longer merge cohorts Float label columns with magnitudes of 2**53 or more raise. Also: the oracle re-capture routine starts a fresh round per commit, the conditioning script counts exactly singular matrices, and the HRS wording says within 0.002 SE.
…aired influence-function differences Theorem A.1's difference of covariances is the variance of the contrast only under exact efficiency, which the ridge, clustering and cross-cell aggregation break in a finite sample. Registry Notes for the variance, the staggered conservativeness and roundoff-level standard errors on noiseless data; TODO rows for a rank-revealing df and a shared roundoff guard.
…est aggregates only cells both fits estimate Narrow floats are widened and refused beyond their exact integer range. On panels with period gaps PT-Post can drop a cohort PT-All keeps; the pretest leaves it out of both sides and warns. The paired variance is the paper's footnote-21 alternative; df is described as an effective rank. The oracle re-capture routine gets explicit rounds.
…man pretest is inconclusive when one side estimates nothing Integer periods of magnitude 2**53 or more beside a float cohort column are converted to integers together (the mixed difference put a period one horizon early); labels that cannot be made exact raise. Pandas nullable floats are accepted. A re-capture round no longer inherits the previous round's record.
…nce, through a shared helper utils.scores_are_roundoff / outcome_scale: scores no larger than 1e4 machine epsilons times the outcome magnitude are residue. EfficientDiD replaces such a cell's scores by exact zeros (SE 0, NaN t/p/CI; constant bootstrap; inconclusive Hausman pretest), applies the same test to every aggregate after its weight-influence term, and warns once per fit. Registry Note, changelog, and a TODO row for adopting the helper in the other influence-function estimators.
…ed support; one exactness rule for labels A bootstrap aggregate whose cell scores cancel gets a constant distribution; scale and scores are taken over positive-weight units; zeroed scores go through the usual variance routine, so an undefined replicate variance stays NaN. Labels below 2**52 are exact in float64 whatever the dtype mix; above it both columns become integers or the input is refused.
…rify label differences are exact; validate label values The roundoff test moves from scores to the standard error about to be reported (utils.se_is_roundoff), so it holds for cluster sums, replicate weights and bootstrap draws alike. Label arithmetic is checked with an error-free transformation instead of magnitude thresholds. Missing or negative cohort labels and non-finite period labels raise.
…ausman roundoff scale from the fits; warnings from the published inference path A rounded label difference matters only if it lands on an integer (event-time bucket) or on a period label (baseline lookup), so decimal labels pass. The Hausman residue check uses the outcome scale the fits recorded. A bootstrapped fit reports its own residue.
… helpers Relative times, baseline lookups and pre-treatment comparisons go through utils.exact_label / label_minus / event_time_bucket / matching_period (ints and Fractions), so they are exact for any dtype mix, magnitude or fractional part, and independent of the order of subtraction. The float-arithmetic validator is removed. A post-fit bootstrap replay warns only about the statistics it returns.
…uilt from A fit records the cells of the overall ATT in the aggregation kit; a kit saved by an earlier release reproduces that release's selection. Comparison pairs are enumerated once per cohort. The label-invariance claim is limited to relabellings that preserve exact label differences. Full two-backend verification of this commit was still running when it was made.
… the stored ATT For a kit with no record of the overall ATT's cells, cells within rounding of the anticipation boundary are resolved by which selection reproduces the stored ATT; an unrecoverable selection raises and asks for a refit. A fit selects the overall ATT's cells once and passes them to the aggregation. Full two-backend verification of this commit was still running when it was made.
…ed ATT
Recovery for kits with no record tries the exact selection, then per-cohort
cut-offs moved by one period, and accepts a set only if its weighted mean is
the stored ATT; otherwise aggregate('total') asks for a refit. No tolerance on
labels. Saved-result tests carry inference consistent with the stored ATT.
…l cell selection
For kits with no record, the post-anticipation cells are selected as native
arithmetic did under each of the two NumPy promotion rules; when the two differ
the stored ATT decides, and aggregate('total') asks for a refit when it cannot.
Replaces the neighbour search, its tolerance and its cohort cap.
…label arithmetic was certainly exact
For a kit with no record of the overall ATT's cells, the exact selection is
used when native label arithmetic cannot have differed from it (integral labels
of ordinary size, or no anticipation); otherwise aggregate('total') asks for a
refit. Replaces the reconstruction of historical NumPy arithmetic.
…rvive the narrowest float type present A Python float compared with a float32 label is rounded to float32 under NumPy 2, so no-anticipation results were not always exact. Labels of mixed precision that do not all fit the narrowest one now ask for a refit.
…name mixed-precision labels; a public-API test for that case
…gh a pickle round trip
Overall assessment⛔ Blocker — Two label-handling regressions can silently change reported estimates. Executive summary
Methodology
Code Quality
Performance
MaintainabilityNo additional findings. Tech Debt
SecurityNo findings in the diff. Documentation/Tests
Path to Approval
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pre-existing
EfficientDiDdefects, found while reviewing the EfficientDiD tutorial in #920. Each reproduces onmain. The first three were the planned scope; the rest surfaced while fixing and testing them.Estimator math (closer to the paper)
(inf, t_pre)per baseline. Without covariates these are all the same long difference-in-differences against the first period, and Eq 3.12 applied to them omits the cross-covariance between their two never-treated terms, soOmega*and the PT-All weights were wrong wherever a never-treated pair entered.enumerate_valid_triplesnow emits the single pair(inf, period_1), for which Eq 3.12 is exact (Eq 3.11's "noncollinear" stacking). The fourOmega*builders are unchanged.(G_g / pi_g) ATT(g, t), addingATT^2 (1 - pi_g) / pi_gto the variance, so covariate-path standard errors grew with the size of the effect.g - anticipation <= period_1was fitted silently against a baseline that was not one. It is now dropped with aUserWarning, as PT-Post already did.Hausman pretest
cluster=and aggregation over cells break that. The estimate is positive semidefinite by construction, so the negative-eigenvalue warning is gone.Numerical robustness (not from the paper)
g - anticipationandt - g; integer labels above2**53were copied tofloat64and merged cohorts; large or fractional float differences rounded onto the wrong horizon; a baseline computed in two rounded steps could match a period it was not equal to. Every label difference and cross-column comparison now goes throughdiff_diff.utils.exact_label/label_minus/event_time_bucket/matching_period(Python ints andFraction). A float label column beyond its dtype's exact integer range raises, as do non-finite period labels and missing or negative cohort labels.p < 0.01. Every reported SE is now tested with the shared helperdiff_diff.utils.se_is_roundoff(se * sqrt(n) <= 1e4 * eps * outcome scale): SE 0 analytically, NaN under the bootstrap, NaN inference in both, with a warning. The helper is written for adoption by the other influence-function estimators (TODO row); onlyEfficientDiDuses it here.aggregate("total")counts the cells the overall ATT was built from, which a fit now records. For a result saved by an earlier release the selection is reconstructed only when the old label arithmetic was certainly exact (ordinary integer labels, or single-dtype floats without anticipation); otherwise it raises aValueErrorasking for a refit.Measured (seeded;
benchmarks/python/edid_omega_conditioning.pyunless noted)maincluster=, 500 panels2**53: ATTKnown limitation, documented, not fixed here. On staggered designs the multi-horizon Hausman pretest is conservative and does not converge to nominal size: 3.0% rejections at the 5% level with 80 units per group and 3.2% with 300 (seven periods, cohorts at 3 and 5). The difference-of-covariances form drifts the same way on those panels. REGISTRY Hausman Note and a
TODO.mdrow (rank-revealingdf) cover it.Deferred to
TODO.md. Adopting the roundoff guard and the exact label helpers in the other staggered estimators; dropping the degenerate self-pair atomega_ridge=0.Oracle fixture
tests/fixtures/v4_aggregate_oracles.jsonpinsEfficientDiDat rtol 1e-12.tests/_recapture_v4_edid_oracles.pyrebuilds only theEfficientDiDarms; on the unmodified tree it reproduced every stored value on both backends (largest relative difference 5.7e-13) before any library change. After the fixes, point estimates in the fixture arms move by at most 0.61 stored SE and standard errors by under 11%, except the two replicate-weight arms (33-43%) and the covariate bootstrap arm (81%, from the centring fix). Every other estimator's entries are byte-identical.Not in this PR
docs/tutorials/15_efficient_did.ipynbonmainsays "Period 1 is excluded ... using it as a baseline adds no information", which this change makes inaccurate. #920 replaces that notebook and is rebased straight after this merges; the notebook onmainstill executes.Methodology references (required if estimator / math changes)
**Note:**entries, together with Notes for the PT-All moment set, the Eq 3.10 centring, cohorts without a pre-treatment period, and theomega_ridgeNote re-measured on the corrected moment set.Validation
tests/test_methodology_efficient_did.py(TestNeverTreatedMoment,TestHausmanStatistic,TestHausmanCalibration,TestCovariateScoreCentring),tests/test_efficient_did.py(TestValidTriples,TestNanInference,TestCohortWithoutPreTreatmentPeriod,TestLargeIntegerLabels,TestRoundoffScores),tests/test_utils.py(TestRoundoffStandardErrorHelpers,TestExactLabelArithmetic),tests/test_efficient_did_validation.py(HRS tolerance 0.05 -> 0.01 SE),tests/test_anticipation_policy.py,tests/test_aggregate_contract.py(re-baselined fixture),tests/_recapture_v4_edid_oracles.py(new).--checkis clean on both.benchmarks/python/edid_omega_conditioning.py(seeded; prints the figures quoted in the REGISTRY Notes);pytest --nbmake docs/tutorials/15_efficient_did.ipynbpasses; Sphinx-Wbuild clean.Security / privacy
Changelog