# Where US midterm campaign money went: close races, safe races, 2026 and 2022

How did campaign money differ between US midterm races that looked close beforehand and races that looked safe, and how
did 2026 compare with 2022 at the same point before election day? This study labels every Senate seat and House district
from the last election for that seat, before any money is counted, then measures independent spending and candidates'
own spending by category, for both major parties with the same code. It is not a forecast, it reads no 2026 vote, and it
makes no claim that money won or lost a race: money goes where a race is expected to be close. The page is `index.html`.

## Data

- Federal Election Commission bulk files for the 2022 and 2026 cycles (candidate master, candidate-committee linkage,
  operating expenditures, independent expenditures, the all-candidates and committee summaries), and the 2018 operating
  expenditures and committee master, used only to write the category rules. https://www.fec.gov/data/browse-data/?tab=bulk-data
- The Clerk of the House's statistics of the 2024 election, for House prior margins.
- The MIT Election Data and Science Lab's Senate and presidential returns (CC0), for Senate and state prior margins.
- The Census Bureau's Vintage 2025 state population estimates by single year of age (`sc-est2025-alldata6.csv`, with its
  layout PDF), for the Senate check against voting-age residents.
  https://www2.census.gov/programs-surveys/popest/datasets/2020-2025/state/asrh/

Every URL, byte count and sha256 is in `data/sources.json` and, for the Census file, `data/sources-r3.json`. The files are not copied here. The FEC refreshes its bulk
files, so a later download holds more reports and will not match the recorded hashes. No contributor file is read; payee
names are dropped on read and never stored; results are aggregates per race, party and category.

Use of FEC data: under the Federal Election Campaign Act, information about individual contributors taken from FEC
reports cannot be sold or used for soliciting contributions or for any commercial purpose. This study reads no
contributor information and sells nothing. The FEC's statement is quoted in the page's method section.

## Reproduce

Python 3.12. The pipeline, checks, summary, tests and page need only the standard library; `pypdf` extracts the Clerk's
PDF text.

```
python3 -I -B tools/get_data.py /path/to/new/dir
python3 -I -B tools/prior_margins.py /path/to/new/dir data/prior_margins.json
python3 -I -B tools/pipeline.py /path/to/new/dir/fec results
python3 -I -B tools/checks.py /path/to/new/dir/fec results
python3 -I -B tools/summarize.py
python3 -I -B tools/after_review_raw.py /path/to/new/dir/fec results
python3 -I -B tools/after_review.py
python3 -I -B tools/after_review2.py
python3 -I -B tools/population.py /path/to/new/dir data/population_18plus.json
python3 -I -B tools/after_review3.py
python3 -I -B tests/test_study.py
python3 -I -B site/render.py
```

`summarize.py`, `after_review.py`, `after_review2.py`, `after_review3.py`, the tests and the page read only `results/`,
`data/prior_margins.json`, `data/population_18plus.json`, `assumptions.json` and the protocol files, so they run with no
download. The bootstrap uses one fixed seed, so the summary replays byte for byte. With freshly downloaded FEC
files the pipeline's figures will differ, by as much as the reports filed since the study's download.

## Files

- `DESIGN-r1.md`, `protocol-r1.json`, `predictions-r1.json`: the design, the frozen protocol and the ten predictions,
  committed before any 2022 or 2026 spending was read.
- `protocol-changes-r1.json`: the four changes to the protocol, each committed before it was used and before any
  close-against-safe figure was computed.
- `after-results-r1.json`: what was decided after the first close-against-safe figures were seen, with its effect.
- `tools/prior_margins.py`: the close or safe label of every race, from results before the cycle (`data/prior_margins.json`).
- `tools/classify.py`: the eleven spending categories, ordered rules over the filer's own purpose text.
- `tools/pipeline.py`: reads the FEC files and writes the aggregate CSVs and `results/coverage.json`.
- `tools/checks.py`: reconciliations against the FEC's own summaries. Each fails only when the file is above its summary,
  so it catches over-counting, not missing rows.
- `tools/summarize.py`: every figure on the page, the intervals and the scored predictions, in `results/summary.json`.
- `tools/after_review_raw.py`, `tools/after_review.py`: the next set of analyses, decided after the ones in
  `after-results-r1.json`
  (the close-line sweep, intervals on the 2026 minus 2022 differences, the digital recount, web-form rows by size, coverage
  scaling and summary end dates), in `results/after_review_raw.json` and `results/after_review.json`. They were declared in a
  file committed before their figures were computed, with exceptions: two figures, the 2026 Senate share with Texas counted
  safe and at a 9.5-point line, were computed from stored results before that file, and the narrower digital recount, the
  independent against candidate spending measure were decided after it. That file is not in this download.
- `after-review-r2.json`, `tools/after_review2.py`: a third set, decided after that and
  declared in that file before its figures were computed, except one (the 2026 Senate share at a 6.11-point line): every
  split of the close line from 5 to 15 points with its interval, and a rule that an interval resting on fewer than 5 races
  in a group is shown and not read. Results in `results/after_review2.json`.
- `after-review-r3.json`, `tools/population.py`, `tools/after_review3.py`: a fourth set, decided after the third and
  declared in that file before the population file was downloaded: the Senate against voting-age
  residents at every split of the third set, with an interval on the gap. `population.py` sums residents aged 18 and
  over per state; results in `data/population_18plus.json` and `results/after_review3.json`.
- `DESIGN-r1.md` is frozen and ships as committed, so it keeps its failure-mode labels and one path into a private folder.
- `tools/get_data.py`, `tools/vendor_kit.py`: downloads with hash checks; the chart kit copied from its pinned release.
- `assumptions.json`: the declared assumptions behind the page's rollout and value sections.
- `site/render.py`, `site/page.css`: the page. Every number on it comes from `results/` or `assumptions.json`, and the
  claims the text makes are asserted in `render.py`.
- `vendor/viz-design-system/`: the chart kit (version 2.3.0) with its licences.

## Licence of the data

FEC filings, the Clerk's statistics and the Census Bureau's estimates are US government works; the Census Bureau's terms
bar using its data to identify any person, household or business, which aggregate state totals cannot do. The MIT Election Data and Science Lab's returns are
CC0. Results here are derived from them and credited to their publishers.

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