Skip to content

Review follow-ups: LP-DiD non-absorbing rules, collinear shocks, first-stage fixes - #5

Merged
andrerecio merged 1 commit into
mainfrom
dev
Nov 18, 2026
Merged

andrerecio merged 1 commit into
mainfrom
dev

Conversation

@andrerecio

Copy link
Copy Markdown
Owner

Summary

Follow-ups to 0.2.1 from the last part of the package review: the fourth lens (black-box use and documentation), which had not reported when 0.2.1 went out, and the three behaviours that 0.2.1 listed as "reported and left as they are". The version stays 0.2.1; the changes are under "Unreleased" in the CHANGELOG.

Estimates change in the cases below. On balanced panels without missing values whose units all start untreated, LP-DiD results are unchanged.

LP-DiD: non-absorbing rules

Both problems were inherited from the Stata command lpdid, whose output the implementation matched.

  • Switches hidden in a gap. Switches were summed from the observed first differences, so one in an absent period or behind a missing value was not seen. A unit observed untreated and then treated could serve as a not-yet-treated control (13 of the 260 rows at h = 0 on the unbalanced test panel), its next switch counted as the first, and an absorbing treatment switching off in a gap was accepted. Switches are now counted between consecutive observed treatment values.
  • Switch-off rows under the first-treatment estimator. With firsttreat and control = :notyet or :nevertreated, a unit treated from its first row that later exits entered the regression with a regressor of −1 (on a noise-free panel with a true effect of 2, the estimate was 1.05). A control is now a row with ΔD = 0.
  • LPDiD(compat = :lpdid) reproduces the command where it differs, including the reweighting count of 0.2.1; reweight = :lpdid still works, as a shorthand. The lpdid cross-check runs with it and also checks that the defaults agree with it on the balanced panel.
  • A response with a lag inside (ldiff(lags(y, 1))) is read at its own periods; a clear error when no horizon has both treated rows and clean controls.

The three behaviours 0.2.1 left as they were

  • A shock in the span of the other regressors makes the horizon :singular, whatever the order of the formula. Before, x + x2 (with x2 = 2x) gave the shock a coefficient and x2 + x an error.
  • Clustered(:unit, :time; ssc = :mss) with a negative factor gives a NaN variance with a warning. psd = :raw still clips it, as the authors' code does.
  • With a tol looser than the default, nearly absorbed columns are re-absorbed at the default tolerance before the absorbed-column screen. Without it, an aggregate regressor with time effects gets a coefficient on a slowly mixing panel (about 12 on the test panel).

Other fixes

  • CDOLS(): the checks crashed with a path term leads(z) written before the shock.
  • A lead of a path term cannot be the shock: a clear error.
  • firststage(r; vcov = Homoskedastic()) returned NaN; it is now the classical first-stage variance (its F equals the Cragg–Donald F with one endogenous regressor).
  • firststage with a first-stage variance that is exactly zero reported an F of order 1e33; it is NaN with the warning.
  • synthetic on a weighted fit says why it has no series.
  • Docs: the pmd base needs k + L − 1 clean periods with nonabsorbing = L; nonabsorbing = 0 is 1; the audit and deviations pages list the new differences from lpdid.
  • Tests: the runner only takes the items of this repository's test/ directory.

Test plan

  • Pkg.test() on Julia 1.13.3 and 1.10.13: 45,789 tests pass, including the local MSS and Ilzetzki items
  • New tests: hand-built clean-control samples for the corrected rules on the unbalanced panel; each fix has a regression test, and the loose-tol test was checked to fail without the fix
  • The lpdid cross-check (47 option sets × 2 panels) passes with compat = :lpdid
  • dev/format.jl --check, dev/make_fixtures.jl --check, docs build
  • CI on this PR

🤖 Generated with Claude Code

…t-stage fixes

LP-DiD (estimates change on panels with gaps, missing treatment values, or units treated
from their first row; nothing changes on balanced panels whose units all start untreated).
- Switches are counted between consecutive observed treatment values. Summed from the
  observed first differences, as lpdid does, a switch in a gap was not seen: a unit
  observed untreated and then treated could be a not-yet-treated control, its next switch
  counted as the first, and an absorbing treatment switching off in a gap was accepted.
- A control is a row with ΔD = 0: the first-treatment estimator no longer keeps the rows
  where a unit treated from its first row switches off (regressor −1).
- LPDiD(compat = :lpdid) reproduces the Stata command where it differs, including the
  reweighting count of 0.2.1; reweight = :lpdid is short for reweight = true,
  compat = :lpdid. The lpdid cross-check runs with it (and checks that the defaults agree
  on the balanced panel).
- A response with a lag inside is read at its own periods; a clear error when no horizon
  has both treated rows and clean controls.

The three behaviours that 0.2.1 reported and left as they were.
- A shock in the span of the other regressors is :singular whatever the formula's order.
- Clustered(:unit, :time; ssc = :mss) with a negative factor gives a NaN variance
  (psd = :raw still clips it, as the authors' code).
- With a tol looser than the default, nearly absorbed columns are re-absorbed at the
  default tolerance before the absorbed-column screen.

Other fixes from the black-box review.
- CDOLS(): the checks crashed with a path term before the shock.
- A lead of a path term cannot be the shock (a clear error).
- firststage with Homoskedastic() is the classical first-stage variance (it returned NaN);
  a first-stage variance that is exactly zero gives NaN with the warning, not F ≈ 1e33.
- synthetic on a weighted fit says why it has no series.
- Docs: the pmd base needs k + L − 1 clean periods with nonabsorbing = L;
  nonabsorbing = 0 is 1; audit and deviations pages list the new differences from lpdid.
- Tests: the runner only takes the items of this repository's test/ directory.

Pkg.test() passes on Julia 1.13.3 and 1.10.13 (45,789 tests); format, fixtures and the
docs build are clean. The changes are under "Unreleased" in the CHANGELOG; the version
stays 0.2.1.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@andrerecio
andrerecio merged commit 174491f into main Nov 18, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant