Last updated: 2026-04-24

Checks: 7 0

Knit directory: USC-QCB-IPUMS/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20230130) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 5634d2b. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/hunt_paper2_figures_cache/
    Ignored:    analysis/state_fertility_cache/

Untracked files:
    Untracked:  Rplots.pdf
    Untracked:  analysis/hunt_paper2_figures.Rmd

Unstaged changes:
    Modified:   .claude/settings.local.json

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/exploratory.Rmd) and HTML (docs/exploratory.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 109563e Tina Lasisi 2024-03-02 New analysis of birthrate
html 165a569 Tina Lasisi 2023-03-06 Build site.
Rmd ef5986b Tina Lasisi 2023-03-06 publish website
Rmd 3c70f8e Tina Lasisi 2023-02-06 Publish first analyses

Introduction

# open data

library(ipumsr)

setwd("data")
ddi <- read_ipums_ddi("usa_00006.xml")
data <- read_ipums_micro(ddi)
Use of data from IPUMS USA is subject to conditions including that users should cite the data appropriately. Use command `ipums_conditions()` for more details.
setwd("../")

head(data)
# A tibble: 6 × 26
   YEAR SAMPLE           SERIAL CBSERIAL  HHWT    CLUSTER STRATA GQ      NFAMS  
  <int> <int+lbl>         <dbl>    <dbl> <dbl>      <dbl>  <dbl> <int+l> <int+l>
1  1850 185001 [1850 1%]    101       NA    97    1.85e12 1.10e8 1 [Hou… 1 [1 f…
2  1850 185001 [1850 1%]    101       NA    97    1.85e12 1.10e8 1 [Hou… 1 [1 f…
3  1850 185001 [1850 1%]    101       NA    97    1.85e12 1.10e8 1 [Hou… 1 [1 f…
4  1850 185001 [1850 1%]    101       NA    97    1.85e12 1.10e8 1 [Hou… 1 [1 f…
5  1850 185001 [1850 1%]    101       NA    97    1.85e12 1.10e8 1 [Hou… 1 [1 f…
6  1850 185001 [1850 1%]    101       NA    97    1.85e12 1.10e8 1 [Hou… 1 [1 f…
# ℹ 17 more variables: NMOTHERS <int+lbl>, NFATHERS <int+lbl>, PERNUM <dbl>,
#   PERWT <dbl>, FAMSIZE <int+lbl>, NCHILD <int+lbl>, NCHLT5 <int+lbl>,
#   NSIBS <int+lbl>, SEX <int+lbl>, AGE <int+lbl>, BIRTHYR <dbl+lbl>,
#   MARRNO <int+lbl>, CHBORN <int+lbl>, RACE <int+lbl>, RACED <int+lbl>,
#   HISPAN <int+lbl>, HISPAND <int+lbl>
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.6.0
✔ ggplot2   3.5.2     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.2.0     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(data.table)

Attaching package: 'data.table'

The following objects are masked from 'package:lubridate':

    hour, isoweek, mday, minute, month, quarter, second, wday, week,
    yday, year

The following objects are masked from 'package:dplyr':

    between, first, last

The following object is masked from 'package:purrr':

    transpose
# Fix labels
vars_to_factor <- c("RACE", "HISPAN", "SEX", "CHBORN", "MARRNO")
data[vars_to_factor] <- lapply(data[vars_to_factor], as_factor)

vars_to_zap <- c("YEAR", "SERIAL", "AGE", "BIRTHYR", "NCHILD", "NCHLT5")
data[vars_to_zap] <- lapply(data[vars_to_zap], zap_labels)

# Specify the years to filter
# years_to_filter <- c(1870, 1900, 1930, 1960, 1990)
years_to_filter <- seq(1850, 2020, by=10)
keepvars = c("YEAR", "SEX", "AGE", "BIRTHYR", "RACE", "CHBORN", "NCHILD", "NCHLT5")
data_filtered <- data %>% 
  # Filter data for only the specified years
  # filter(YEAR %in% years_to_filter) %>% 
  # Filter data for non-Hispanic only White and Black
  filter(HISPAN == "Not Hispanic",
         RACE == "White" | RACE == "Black/African American") %>% 
  select(all_of(keepvars)) %>% 
  mutate(AGE_RANGE = case_when(
    AGE < 15 ~ "<15",
    AGE >= 15 & AGE < 20 ~ "15-20",
    AGE >= 20 & AGE < 25 ~ "20-25",
    AGE >= 25 & AGE < 30 ~ "25-30",
    AGE >= 30 & AGE < 40 ~ "30-40",
    AGE >= 40 & AGE < 50 ~ "40-50",
    AGE >= 50 ~ "50+"
  )) 
data_grouped <- data_filtered %>% 
  group_by(YEAR, RACE, SEX, AGE_RANGE) %>% 
  mutate(CHBORN_num = as.numeric(CHBORN))
data_grouped_subset <- data_grouped %>% 
  sample_n(150)
mean_cl_normal <- function(y) {
  mean_y <- mean(y)
  sd_y <- sd(y)
  ymin <- max(mean_y - sd_y, 0)
  ymax <- mean_y + sd_y
  c(y = mean_y, ymin = ymin, ymax = ymax)
}
data_grouped_subset %>% 
  filter(SEX == "Female") %>% 
  ggplot(aes(x = YEAR, y = CHBORN_num, group = RACE, color = RACE, fill = RACE)) +
  stat_summary(fun.data = mean_cl_normal, geom = "ribbon", alpha = 0.3) +
  stat_summary(fun.y = mean, geom = "line") +
  scale_color_discrete(name = "Race") +
  labs(x = "Year", y = "Number of Children", title = "Distribution of children born to Women across the years") +
  theme_classic() +
  facet_grid(rows = vars(AGE_RANGE), cols = vars(RACE))
Warning: The `fun.y` argument of `stat_summary()` is deprecated as of ggplot2 3.3.0.
ℹ Please use the `fun` argument instead.
This warning is displayed once every 8 hours.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
generated.
Warning: Removed 23100 rows containing non-finite outside the scale range
(`stat_summary()`).
Removed 23100 rows containing non-finite outside the scale range
(`stat_summary()`).

Version Author Date
165a569 Tina Lasisi 2023-03-06
data_grouped_subset %>% 
  ggplot(aes(x = YEAR, y = NCHILD, group = RACE, color = RACE)) + stat_summary(fun = mean, geom = "line") +
  facet_grid(rows = vars(AGE_RANGE), cols = vars(SEX))+
  labs(x = "Year", y = "Number of Children", title = "Mean number of own children per household")+
  theme(legend.position = "bottom") +
  theme_classic()

Version Author Date
165a569 Tina Lasisi 2023-03-06
data_grouped_subset %>% 
  ggplot(aes(x = YEAR, y = NCHILD, group = RACE, color = RACE, fill = RACE)) +
  stat_summary(fun.data = mean_cl_normal, geom = "ribbon", alpha = 0.3) +
  stat_summary(fun.y = mean, geom = "line") +
  scale_color_discrete(name = "Race") +
  labs(x = "Year", y = "Number of Children", title = "Number of own children per household") +
  theme_classic() +
  facet_grid(rows = vars(AGE_RANGE), cols = vars(SEX))+
  theme(legend.position = "bottom")

Version Author Date
165a569 Tina Lasisi 2023-03-06
data_grouped_subset %>% 
  ggplot(aes(x = factor(YEAR), y = NCHILD, color = RACE)) +
  geom_boxplot(alpha = 0.3, outlier.size = 0.5) +
  scale_color_discrete(name = "Race") +
  labs(x = "Year", y = "Number of Children", title = "Number of own children per household") +
  theme_classic() +
  theme(legend.position = "bottom") +
  facet_grid(rows = vars(AGE_RANGE), cols = vars(SEX))

Version Author Date
165a569 Tina Lasisi 2023-03-06
ggplot(data_grouped_subset %>% filter(SEX == "Male"), aes(x = factor(YEAR), y = NCHILD, fill = RACE, color = RACE)) +
  geom_boxplot(alpha = 0.3, outlier.size = 0.5) +
  scale_color_discrete(name = "Race") +
  labs(x = "Year", y = "Number of Children", title = "Number of own children per household (Males)") +
  theme_classic() +
  theme(legend.position = "bottom") +
  facet_grid(rows = vars(AGE_RANGE), cols = vars(SEX))

Version Author Date
165a569 Tina Lasisi 2023-03-06
ggplot(data_grouped_subset %>% filter(SEX == "Female"), aes(x = factor(YEAR), y = NCHILD, fill = RACE, color = RACE)) +
  geom_boxplot(alpha = 0.3, outlier.size = 0.5) +
  scale_color_discrete(name = "Race") +
  labs(x = "Year", y = "Number of Children", title = "Number of own children per household (Females)") +
  theme_classic() +
  theme(legend.position = "bottom") +
  facet_grid(rows = vars(AGE_RANGE), cols = vars(SEX))

Version Author Date
165a569 Tina Lasisi 2023-03-06
data_grouped_subset %>% 
  ggplot(aes(x = YEAR, y = NCHLT5, group = RACE, color = RACE, fill = RACE)) +
  stat_summary(fun.data = mean_cl_normal, geom = "ribbon", alpha = 0.3) +
  stat_summary(fun.y = mean, geom = "line") +
  scale_color_discrete(name = "Race") +
  labs(x = "Year", y = "Number of Children", title = "Number of own children under 5 per household") +
  theme_classic() +
  facet_grid(rows = vars(AGE_RANGE), cols = vars(SEX))

Version Author Date
165a569 Tina Lasisi 2023-03-06
data_grouped_subset %>% 
  ggplot(aes(x = factor(YEAR), y = NCHLT5, color = RACE)) +
  geom_boxplot(alpha = 0.3, outlier.size = 0.5) +
  scale_color_discrete(name = "Race") +
  labs(x = "Year", y = "Number of Children", title = "Number of own children under 5 per household") +
  theme_classic() +
  theme(legend.position = "bottom") +
  facet_grid(rows = vars(AGE_RANGE), cols = vars(SEX))

Version Author Date
165a569 Tina Lasisi 2023-03-06
data_sum <- data_grouped %>% 
  summarize(mean_child = mean(CHBORN_num),
            sd_child = sd(CHBORN_num)) %>% 
  drop_na() %>% 
  ungroup()
`summarise()` has grouped output by 'YEAR', 'RACE', 'SEX'. You can override
using the `.groups` argument.

sessionInfo()
R version 4.5.3 (2026-03-11)
Platform: aarch64-apple-darwin20
Running under: macOS Tahoe 26.4.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] C.UTF-8/C.UTF-8/C.UTF-8/C/C.UTF-8/C.UTF-8

time zone: America/Detroit
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] data.table_1.17.6 lubridate_1.9.4   forcats_1.0.0     stringr_1.6.0    
 [5] dplyr_1.1.4       purrr_1.2.0       readr_2.1.5       tidyr_1.3.1      
 [9] tibble_3.3.0      ggplot2_3.5.2     tidyverse_2.0.0   ipumsr_0.10.0    
[13] workflowr_1.7.1  

loaded via a namespace (and not attached):
 [1] sass_0.4.10        utf8_1.2.6         generics_0.1.4     xml2_1.3.8        
 [5] stringi_1.8.7      hms_1.1.3          digest_0.6.37      magrittr_2.0.4    
 [9] timechange_0.3.0   RColorBrewer_1.1-3 grid_4.5.3         evaluate_1.0.4    
[13] hipread_0.2.6      fastmap_1.2.0      rprojroot_2.1.1    jsonlite_2.0.0    
[17] processx_3.8.6     whisker_0.4.1      ps_1.9.1           promises_1.3.3    
[21] httr_1.4.7         scales_1.4.0       codetools_0.2-20   jquerylib_0.1.4   
[25] cli_3.6.5          rlang_1.1.6        crayon_1.5.3       withr_3.0.2       
[29] cachem_1.1.0       yaml_2.3.10        tools_4.5.3        tzdb_0.5.0        
[33] zeallot_0.2.0      httpuv_1.6.16      vctrs_0.6.5        R6_2.6.1          
[37] lifecycle_1.0.4    git2r_0.36.2       fs_1.6.6           pkgconfig_2.0.3   
[41] callr_3.7.6        gtable_0.3.6       pillar_1.11.1      bslib_0.9.0       
[45] later_1.4.2        glue_1.8.0         Rcpp_1.1.0         haven_2.5.5       
[49] xfun_0.54          tidyselect_1.2.1   dichromat_2.0-0.1  rstudioapi_0.17.1 
[53] knitr_1.50         farver_2.1.2       htmltools_0.5.8.1  labeling_0.4.3    
[57] rmarkdown_2.29     compiler_4.5.3     getPass_0.2-4