#Read in ACS data from IPUMS
usa_ddi <- read_ipums_ddi("usa_00031.xml")
data <- read_ipums_micro("usa_00031.xml", data_file = ("usa_00031.csv.gz"), verbose = FALSE)Texas households by poverty status, health insurance, race/ethnicity, and couple type in 2021 - 5-Year Estimates
#Filter for same-sex couple households and for one persone from each household
ss_hh <- data %>%
filter(PERNUM==1) %>%
#Mutate vrace/ethnicity and couple type variables
mutate(race_eth = case_when(HISPAN %in% c(1:4) & RACE %in% c(1:9) ~ "Hispanic",
HISPAN == 0 & RACE == 1 ~ "White, non-Hispanic",
HISPAN == 0 & RACE == 2 ~ "Black, non-Hispanic",
HISPAN == 0 & RACE == 3 ~ "AIAN, non-Hispanic",
HISPAN == 0 & RACE %in% c(4:6) ~ "Asian or Pacific Islander, non-Hispanic",
HISPAN == 0 & RACE == 7 ~ "Other, non-Hispanic",
HISPAN == 0 & RACE %in% c(8, 9) ~ "Multiracial, non-Hispanic",
TRUE ~ NA_character_),
pov = case_when(POVERTY %in% c(001:100) ~ "At or Below 100% Poverty",
POVERTY %in% c(101:501)~ "Above 100% Poverty",
TRUE ~ NA_character_),
insurance = case_when(HCOVANY == 1 ~ "No HI",
HCOVANY == 2 ~ "With HI",
TRUE ~ NA_character_),
hh_type = case_when(COUPLETYPE %in% c(2, 4) ~ "Same-Sex",
COUPLETYPE %in% c(1,3) ~ "Opposite-Sex",
TRUE ~ NA_character_)
)## Survey Design
#install.packages("survey")
library(survey)Loading required package: grid
Loading required package: Matrix
Loading required package: survival
Attaching package: 'survey'
The following object is masked from 'package:graphics':
dotchart
options(survey.lonely.psu = "adjust")
#HOUSEHOLD WEIGHTS DESIGN
des_hh <- svydesign(id=~CLUSTER, strata=~interaction(STRATA, YEAR), weights=~HHWT, data=ss_hh) # Calculate table for same-sex and opposite-sex couple households by race/ethnicity, poverty status, and household type
ss_table_poverty_hh_type <- svytable(~race_eth + pov + hh_type, design = des_hh)
# Convert table to data frame
ss_table_poverty_hh_type_df <- as.data.frame(ss_table_poverty_hh_type)
# Export table for same-sex and opposite-sex couple households by race/ethnicity, poverty status, and household type
write_xlsx(ss_table_poverty_hh_type_df, "households_race_eth_poverty_hh_type_5year.xlsx")
# Calculate table for race/ethnicity by health insurance status and household type
ss_table_insurance_hh_type <- svytable(~race_eth + insurance + hh_type, design = des_hh)
# Convert table to data frame
ss_table_insurance_hh_type_df <- as.data.frame(ss_table_insurance_hh_type)
# Export table for race/ethnicity by health insurance status and household type
write_xlsx(ss_table_insurance_hh_type_df, "households_race_ethnicity_health_insurance_hh_type_5year.xlsx")