Commit 0328b4a
Address PR #396 R2 review (1 P1)
P1: The "Resolved estimand is not what I expected" inspection snippet
computed `d.min()` over `had_data['dose']` (the full panel column),
but HAD's `_detect_design()` resolves on `D_{g,F}` — per-unit dose at
the first treated period — not the full panel. Per
`diff_diff/had.py:1834-1888` (event-study path) and
`diff_diff/had.py:4089-4091` (`_detect_design(d_arr)` where `d_arr`
is `D_{g,F}`), the detector ignores the structural pre-period zeros
that HAD requires (`D_{g,t} = 0` for `t < F`). Consequence: on every
valid HAD panel, `had_data['dose'].min()` is always 0 and the
snippet would report "Design 1' (WAS)" regardless of the true
resolution — exactly the false sense of confirmation the
troubleshooting page is meant to dispel.
Fix: rewrote the snippet to extract `d_at_F = had_data.loc[
had_data['period'] == F].set_index('unit')['dose']` (per-unit
post-period dose, mirroring `had.py:1886-1888`) and compute the
threshold check on that series. Renamed printed labels from
`d.min()` to `D_{g,F}.min()` and `0.01 * median(|d|)` to
`0.01 * median(|D_{g,F}|)` so the diagnostic syntactically matches
the registry's rule statement.
Updated the surrounding **Cause** prose at `docs/troubleshooting.rst
:486-495` to (a) state explicitly that detection runs on `D_{g,F}`
not the panel column, (b) note that pre-period zeros on the panel
column are structural and uninformative for design choice, and (c)
restate the threshold rule and modal-fraction check on `D_{g,F}`.
Verification: PYTHONPATH=. DIFF_DIFF_BACKEND=python pytest
tests/test_doc_snippets.py reports 111 passed, 4 skipped, 0 failed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 8ccfadf commit 0328b4a
1 file changed
Lines changed: 27 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
483 | 483 | | |
484 | 484 | | |
485 | 485 | | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
494 | | - | |
495 | | - | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
496 | 500 | | |
497 | 501 | | |
498 | 502 | | |
| |||
516 | 520 | | |
517 | 521 | | |
518 | 522 | | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
525 | 533 | | |
526 | 534 | | |
527 | 535 | | |
| |||
530 | 538 | | |
531 | 539 | | |
532 | 540 | | |
533 | | - | |
534 | | - | |
535 | | - | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
536 | 544 | | |
537 | 545 | | |
538 | 546 | | |
| |||
0 commit comments