Demographic Data for the Texas Women’s Foundation Project.
I am using IPUMS 5-Year Estimates for 2022 and 2014: Steven Ruggles, Sarah Flood, Matthew Sobek, Daniel Backman, Annie Chen, Grace Cooper, Stephanie Richards, Renae Rodgers, and Megan Schouweiler. IPUMS USA: Version 15.0 [dataset]. Minneapolis, MN: IPUMS, 2024. https://doi.org/10.18128/D010.V15.0
library(dplyr)txw_data1 <- txw_data %>%filter(sex ==2)%>%filter(!is.na (educd) &!is.na(hispan) &!is.na(race) &!is.na(age) &!is.na(marst)) %>%mutate(educ_level =case_when( educd %in%c(0, 1) ~NA_character_, # N/A educd ==2~"None", # No school educd %in%c(10:17, 20:26, 30, 40, 50, 61) ~"LT_HS", # Nursery school to grade 4, Grade 5, 6, 7, or 8, Grade 9, Grade 10, Grade 11, 12th grade, no diploma educd %in%c(62:64) ~"HSD_GED", # High school graduate or GED, Regular high school diploma, GED or alternative credential educd %in%c(65, 70:71, 80, 90, 100) ~"SomeColl", # Some college, but less than 1 year, 1 year of college, 1 or more years of college credit, no degree, 2 years of college, 3 years of college, 4 years of college educd %in%c(81:83) ~"AssocDegree", # Associate's degree, type not specified, Associate's degree, occupational program, Associate's degree, academic program educd ==101~"BachelorDegree", # Bachelor's degree educd %in%c(110:116) ~"GradDegree", # 5+ years of college, 6 years of college (6+ in 1960-1970), 7 years of college, 8+ years of college, Master's degree, Professional degree beyond a bachelor's degree, Doctoral degreeTRUE~NA_character_# Other cases ),race_ethnicity =case_when( hispan %in%1:4~"Hispanic", race ==1& hispan ==0~"NH White", race ==2& hispan ==0~"NH Black", race ==3& hispan ==0~"NH AIAN", race %in%c(4, 5, 6) & hispan ==0~"NH Asian", race %in%c(7, 8, 9) & hispan ==0~"NH Other Race",TRUE~"Unknown" ), age_group =case_when( age <=17~"0-17", age <=24& age >=18~"18-24", age <=64& age >=25~"25-64", age >=65~"65+",TRUE~"Unknown" ),marst_recode =ifelse(marst %in%c(1, 2), "Married", ifelse(marst %in%c(3, 4, 5), "Separated/Divorced/Widowed", ifelse(marst ==6, "Never married/single", "Missing/Blank"))))# str(txw_data1)
Age Breakdown
library(dplyr)library(tidyr)library(survey)
Loading required package: grid
Loading required package: Matrix
Attaching package: 'Matrix'
The following objects are masked from 'package:tidyr':
expand, pack, unpack
Loading required package: survival
Attaching package: 'survey'
The following object is masked from 'package:graphics':
dotchart
library(writexl)txw_design <-svydesign(ids =~1, data = txw_data1, weights =~perwt)# Age Group Summaryage_summary <-svytable(~ year + age_group, design = txw_design)# Marital Status Summarymarital_status_summary <-svytable(~ year + marst_recode, design = txw_design)# Combined Age Group and Marital Status Summarycombined_summary <-svytable(~ year + age_group + marst_recode, design = txw_design)# Convert svytable to data frameage_summary_df <-as.data.frame(age_summary)marital_status_summary_df <-as.data.frame(marital_status_summary)combined_summary_df <-as.data.frame(combined_summary)# Write to Excelwrite_xlsx(list(age_summary = age_summary_df, marital_status_summary = marital_status_summary_df, combined_summary = combined_summary_df), "age_summary.xlsx")
By Race/Ethnicity
library(dplyr)library(survey)library(writexl)txw_design <-svydesign(ids =~1, data = txw_data1, weights =~perwt)# Summarize data to get the count of women by race_ethnicity and yearrace_ethnicity_summary <-svytable(~ year + race_ethnicity, design = txw_design)# Convert to a data framerace_ethnicity_df <-as.data.frame(race_ethnicity_summary)# Calculate the total women per year for normalizationtotal_women_per_year <-aggregate(Freq ~ year, data = race_ethnicity_df, FUN = sum)# Merge to calculate percentagesrace_ethnicity_df <-merge(race_ethnicity_df, total_women_per_year, by ="year", suffixes =c("", "_total"))# Calculate %race_ethnicity_df$percentage <- (race_ethnicity_df$Freq / race_ethnicity_df$Freq_total) *100# clean uprace_ethnicity_df <- race_ethnicity_df %>%select(year, race_ethnicity, percentage) %>%arrange(year, race_ethnicity)print(race_ethnicity_df)
year race_ethnicity percentage
1 2012 Hispanic 37.415109
2 2012 NH AIAN 0.255130
3 2012 NH Asian 4.017370
4 2012 NH Black 11.867968
5 2012 NH Other Race 1.519564
6 2012 NH White 44.924859
7 2022 Hispanic 39.404874
8 2022 NH AIAN 0.173619
9 2022 NH Asian 5.250103
10 2022 NH Black 12.126077
11 2022 NH Other Race 2.863694
12 2022 NH White 40.181632