# Did paid engagement with prescribers move prescribing?

Real public CMS data for two branded drugs in one prescription drug class, each sold by a different maker: every
general payment that names either drug (Open Payments, program years 2022 and 2023), joined on the National Provider
Identifier to each prescriber's Medicare Part D claims for the class (2021 to 2023). The study asks how much of the gap between paid and unpaid
prescribers survives adjustment, matching and a year-before check, and sizes the randomized holdout that would settle
it. The page is `index.html`; the design, committed before the payment and prescribing files were opened or filtered, is
`DESIGN.md` (what was read before it is logged in `results/collection.json`).

Aggregates only. The class is withheld, and no prescriber, maker, brand or product is named; the two drugs are Drug A
and Drug B. `DESIGN.md` and `plan/protocol.json` here are public copies with the class and its uses replaced by
[withheld] and a bracketed public note, one each in DESIGN.md and protocol.json; `results/estimates.json`, `posthoc.json`, `holdout.json` and `collection.json`
are public copies with counts rounded (below) and the specialty names replaced by a count. The originals are kept
privately. No file here holds a prescriber identifier or a prescriber-level row, and every published figure covers at
least 11 prescribers.

## Results

Points of the drug's share of each prescriber's class claims, with 95% intervals.

| Comparison | Drug A | Drug B |
|---|---:|---:|
| Raw gap, paid in 2023 against not paid | −10.6 (−11.0 to −10.2) | 18.5 (18.0 to 18.9) |
| Adjusted by regression | −3.1 (−3.4 to −2.8) | 5.9 (5.6 to 6.2) |
| Adjusted by matching | −2.4 (−2.7 to −2.1) | 4.6 (4.3 to 4.9) |
| First paid in 2023 against matched never paid, change from 2022 | −2.2 (−2.9 to −1.7) | 4.2 (3.7 to 4.8) |
| Same groups the year before, matched on 2021 | −2.7 (−3.4 to −2.1) | 2.7 (2.1 to 3.3) |
| Net of the year before | 0.5 (−0.5 to 1.3) | 1.5 (0.7 to 2.4) |
| Year before as declared, matched on 2022 (its end point) | 0.2 (−0.7 to 1.0) | −0.7 (−1.4 to −0.1) |

Most of the raw gap is who gets paid. Prescribers first paid for Drug B moved toward it, but the same groups were
already moving apart from 2021 to 2022, before these payments (payments before 2022 were not checked); net of that, about 1.5 points remain for Drug B and none clearly for Drug A. This is an
observational comparison: it cannot rule out that the makers chose whom to pay on things the files do not show. A
holdout of 750 to 1,500 prescribers per arm for one year would settle it, wrong at most 20% of the time each way in
simulated trials.

## What is here

- `pe/collect.py`: fetches the official CMS files in byte ranges and keeps the class rows.
- `pe/build.py`: joins payments and prescribing into a prescriber table (outside the repository, never published).
- `pe/estimators.py`, `pe/analyze.py`: the declared estimates, written to `results/estimates.json`.
- `pe/posthoc.py`: the comparisons added after the results (`plan/amendment-2.json`), in `results/posthoc.json`.
- `pe/holdout.py`: the holdout sizing and its simulated error rates; `results/holdout.json` publishes only their
  overall range across settings (per-arm sizes and wrong-call rates, the rates to a whole percent).
- `pe/summarize.py`: gathers everything into `results/results.json` and scores the predictions mechanically.
- `pe/report.py`, `pe/pagekit.py`, `pe/text.py`, `pe/text_tail.py`: build `index.html` and `results/page-numbers.json`.
- `plan/protocol.json`, `plan/amendment-1.json`, `plan/amendment-2.json`, `plan/sources.json`: the frozen design
  parameters, the two labelled additions and the official file addresses.
- `tests/`: the estimators on constructed tables with known effects, the small-cell rule, and a replay that rebuilds the
  results and the page from the published aggregates and compares bytes.
- `pe/public.py`: what the published aggregates may carry (see "Rounded counts" below).
- `tools/check_numbers.py`: every number a reader sees on the page must come from `results/results.json`.

## Rounded counts

Exact counts and share levels could be matched against the public Open Payments and Part D files to look the two drugs
up, so the published aggregates round every count to two significant figures, publish no drug's share level in any
year (each group's change since 2021 instead), leave out paid shares, payment mixes, money levels and record and product
totals. No group size for either drug is published (a group
size over the population would give a paid share back): each group cell carries `n_at_least_11: true` in place of its
count, and the matched and dropped counts are left out. No SD, variance or standard error is published for either
drug, and the holdout's per-setting sizes and wrong-call rates are left out (they solve back for the spread), leaving
their overall range. Share changes (every estimate and interval) are
published as computed. The exact counts stay private. The replay here runs
on the rounded files and rebuilds the same `results/results.json`, because the rounding gives the same result applied
once or twice; the tests check the estimates, the rounded counts and the at-least-11 flags, never an exact count.

## Reproduce

Python 3.12 with numpy and pandas; the tests need pytest. From the committed aggregates, with no download:

```
python -B -m pe.summarize && python -B -m pe.report
python -B -m pytest tests -q
python -I tools/check_numbers.py
```

The drug list is withheld. Replaying the results and the page from the committed aggregates (above) needs nothing
else. A full rebuild from the CMS files needs your own class definition: a class and two drugs of your choosing, in a
JSON file of the shape
`{"class_generic_tokens": [...], "families": {"A": {"generic_token": "...", "payment_product_names": [...]}, "B": {...}}}`,
named by `PE_DRUGS`, with `PE_RAW` and `PE_WORK` set to folders outside the repository. It reproduces the method, not these figures:

```
python -B -m pe.collect fetch payments 2023 --parts 0-3      # one call per few parts; parts already fetched are skipped
python -B -m pe.collect filter payments 2023
# the same for payments 2022 and prescribing 2021, 2022 and 2023
python -B -m pe.build
python -B -m pe.analyze && python -B -m pe.posthoc && python -B -m pe.holdout
```

The names that define the class and the two drugs are not in this download, so the collection cannot be re-run for
these drugs from the download alone.

## Limits

- Observational: payments are not assigned at random, and prescribing can draw payments as well as follow them.
- Payments before 2022 were not checked: "first paid in 2023" means no payment for that drug recorded in 2022, and
  "never paid" means none recorded in 2022 or 2023.
- The net figures subtract a year-before comparison matched on 2021 from a change matched on 2022.
- Only paid contact is visible; visits, samples and emails leave no Open Payments record.
- Medicare Part D only, and a product with fewer than 11 claims for a prescriber reads as zero.
- One class, three years, and prescribers present in all three.
- The holdout sizes rest on assumed practice sizes and within-practice correlations.

## Data

CMS Open Payments General Payment Data and CMS Medicare Part D Prescribers by Provider and Drug, public works of the
U.S. government (openpaymentsdata.cms.gov, data.cms.gov), joined on the National Provider Identifier. Not endorsed by
or affiliated with CMS.

Some files are packed in prescriber-engagement-data-1.zip; unzip it here to restore the full export, which the manifest lists file by file.
