Hi Matthew, I wanted to give sample R code for identifying mothers of children under 14 y/o. Please let me know if this looks errored at all!!
It seems to me that the R code given at the bottom of the page you mention (IPUMS USA) for connecting parents with children is a bit flawed. While I don’t read the other languages offered, I was able to come up with this R alternative:
This code chunk makes a df that takes the characteristics of children and renames PERNUM to be able to be merged back onto mothers of own children living in their same HH.
temp ← data %>%
select(YEAR, SERIAL, MOMLOC, AGE) %>%
rename(PERNUM = MOMLOC) %>%
filter(AGE < 14 & PERNUM > 0) %>% # captures children under 14 y/o who live with their mothers
group_by(YEAR, SERIAL, PERNUM) %>%
summarize(own_kids_u14 = n(), .groups = “drop”)
This code chunk joins the number of children back on to the original df and connects the number of children with their mother.
data_moth ← data %>%
left_join(temp, by = c(“YEAR”, “SERIAL”, “PERNUM”)) %>%
mutate(own_kids_u14 = if_else(is.na(own_kids_u14), 0, own_kids_u14)) %>%
filter(own_kids_u14 > 0)