pums_pull$race_c <-Recode(pums_pull$HHLDRRAC1P, recodes ="1='White'; 2='Black'; 3:5='Other or 2+'; 6:7='Asian/PI'; 8:9='Other or 2+'; else=NA", as.factor=T)#Creating Interaction Term for Race/Ethnicity to create simplified categoriespums_pull$race_eth <-interaction(pums_pull$hisp_HH, pums_pull$race_c, sep ="_")# Redefining Race/Eth Categories from Interaction Termspums_pull$race_eth <-as.factor(ifelse(substr(as.character(pums_pull$race_eth),1,8) =="Hispanic", "Hispanic, Any Race", as.character(pums_pull$race_eth)))pums_pull$race_eth <-Recode(pums_pull$race_eth, recodes="'Not Hispanic_Other or 2+'='Other NH'; 'Not Hispanic_White'='White NH';'Not Hispanic_Black'='Black NH';'Not Hispanic_Native American'='Other NH'; 'Not Hispanic_Asian/PI'='Asian/PI NH'", as.factor=T)#not weighted yet - just testing#table(pums_pull$CostBurd,pums_pull$tenure_c, pums_pull$race_eth)
Housing burden by homeownership status and age of HHder
library(dplyr)
Attaching package: 'dplyr'
The following object is masked from 'package:car':
recode
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
#HOUSEHOLD WEIGHTS DESIGNlibrary(srvyr)
Attaching package: 'srvyr'
The following object is masked from 'package:stats':
filter
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
#filter for only householders SPORDER = 1pums_pull_headHH<-pums_pull[pums_pull$SPORDER==1,]pums_design <- pums_pull_headHH %>%to_survey(type ="housing", design ="rep_weights")#filter(!is.na(pums_pull$CostBurd)) #gets rid of any values where we have no info#Housing burden by homeownership status and ageburden_tot <-svyby(formula =~CostBurd_d, by =~hhder_age_c+tenure_c, pums_design, svytotal, na.rm=TRUE)burden_pct <-svyby(formula =~CostBurd_d, by =~hhder_age_c+tenure_c, pums_design, svymean, na.rm=TRUE)#install.packages("writexl")library(writexl)sheets <-list("burden_tot"= burden_tot, "burden_pct"= burden_pct) write_xlsx(sheets, "../2025_Homeownership/Housing_CostBurden_Tenure_Age.xlsx")#Housing burden by homeownership status and age ADD RACEburden_tot <-svyby(formula =~CostBurd_d, by =~hhder_age_c+tenure_c+race_eth, pums_design, svytotal, na.rm=TRUE)burden_pct <-svyby(formula =~CostBurd_d, by =~hhder_age_c+tenure_c+race_eth, pums_design, svymean, na.rm=TRUE)#install.packages("writexl")library(writexl)sheets2 <-list("burden_tot"= burden_tot, "burden_pct"= burden_pct) write_xlsx(sheets2, "../2025_Homeownership/Housing_CostBurden_Tenure_Age_Race.xlsx")