prepare_birth_data.RdImports and preprocesses CDC natality public use files from 2016-2024.
prepare_birth_data(files, years_separate = FALSE, include_late_term = TRUE)Character vector of paths to CDC natality .txt files.
Each file should contain data for a single birth year.
If TRUE, returns a named list of
processed data frames, one per year. If FALSE (default), combines all
years into a single data frame.
If TRUE (default), late-term pregnancies
(42+ weeks) are included in the NTSV definition.
If FALSE, NTSV is restricted to 37-41 completed gestational weeks.
If years_separate = FALSE, a data frame containing processed natality
records from all supplied files.
If years_separate = TRUE, a named list of processed data frames per year.
The function uses a bundled Python script to extract selected variables from fixed-width natality files, imports the resulting Parquet files into R, and constructs derived variables including cesarean delivery, labor, and an NTSV indicator. NTSV uses cephalic presentation as a proxy variable for vertex presentation, since the latter is not available.
This function requires a Python installation accessible through
reticulate, as well as the Python packages pandas and pyarrow.
synthetic_files <- c(system.file(
"extdata","synthetic_2023.txt",
package = "natalityr"),
system.file("extdata",
"synthetic_2024.txt",
package = "natalityr"))
natality <- prepare_birth_data(synthetic_files)