# Natality Atlas local extract

Install R packages `haven`, `jsonlite`, and `digest`. Download `run_extract.R` and the specification JSON from the website. Supply a folder containing annual `natalityYYYYus.dta` files and a new output folder outside the source folder:

```sh
Rscript run_extract.R natality-extract-spec.json /path/to/annual-stata /path/to/new-output
```

The specification selects years, source variables, U.S.-resident or all occurrence births, and optionally singletons. No data are uploaded. The script refuses existing output directories and missing source fields. It produces one RDS per year with data, original imported types/labels, source-code frequencies, dictionary, specification, and provenance receipt. The final manifest appears only after all years finish. Individual verified outputs remain as checkpoints if a later year fails; choose a fresh output directory to retry.

```r
extract <- readRDS('new-output/natality_2024_source_extract.rds')
births <- extract$data
extract$receipt
extract$source_code_frequencies
```

Original imported columns receive a `source_` prefix. The script does not recover raw-byte formatting or distinctions lost during an earlier Stata conversion. Sentinels and source missing codes are retained. Inspect reporting flags and annual guides before analysis. No pooled or independently reviewed harmonized release is created.

Outputs may be large when all fields or many years are chosen. The runner processes one year at a time and verifies each saved RDS by reloading it. Keep sufficient memory for an annual source selection and its round-trip verification.
