library(ipumsr)
library(dplyr)
library(survey)
library(writexl)Household Income by Home Ownership by Race/Ethnicity in Dallas (2023)
Source: 2023 ACS 5-Year EStimates via IPUMS USA
Dallas City
The data extract was filtered for Dallas City before download.
ddi <- read_ipums_ddi("usa_00057.xml")
city_data <- read_ipums_micro(ddi, data_file = "usa_00057.dat", verbose = FALSE)
city_data <- rename_with(city_data, tolower)library(matrixStats)Warning: package 'matrixStats' was built under R version 4.2.3
Attaching package: 'matrixStats'
The following object is masked from 'package:dplyr':
count
city_data <- city_data %>%
mutate(race_ethnicity = case_when(
hispan == 0 & race == 1 ~ "White, non-Hispanic",
hispan == 0 & race == 2 ~ "Black, non-Hispanic",
hispan == 0 & race == 3 ~ "American Indian and Alaska Native, non-Hispanic",
hispan == 0 & race %in% c(4, 5, 6) ~ "Asian and Pacific Islander, non-Hispanic",
hispan == 0 & race == 7 ~ "Other, non-Hispanic",
hispan == 0 & race %in% c(8, 9) ~ "Two or more races, non-Hispanic",
hispan %in% c(1, 2, 3, 4) ~ "Hispanic",
TRUE ~ NA_character_
))
#drop cases without race/eth info and households with no income
city_data <- city_data %>% filter(!is.na(race_ethnicity), hhincome > 0, ownershp %in% c(1, 2))
#calc weighted median household inc by homeownership and race/eth
city_income_median <- city_data %>%
group_by(ownershp, race_ethnicity) %>%
summarize(
median_income = weightedMedian(hhincome, w = hhwt, na.rm = TRUE)
) %>%
mutate(homeownership = ifelse(ownershp == 1, "Owner", "Renter")) %>%
select(homeownership, race_ethnicity, median_income) %>%
arrange(homeownership, race_ethnicity)`summarise()` has grouped output by 'ownershp'. You can override using the
`.groups` argument.
Adding missing grouping variables: `ownershp`
print(city_income_median)# A tibble: 0 × 4
# Groups: ownershp [0]
# ℹ 4 variables: ownershp <int+lbl>, homeownership <lgl>, race_ethnicity <chr>,
# median_income <dbl>
I got zero observations when filtering for Dallas City, so tried Dallas County below.
Dallas County
The data extract was filtered for Texas (FIPS=48) before download.
library(ipumsr)
library(dplyr)
library(survey)
library(writexl)ddi <- read_ipums_ddi("usa_00058.xml")
county_data <- read_ipums_micro(ddi, data_file = "usa_00058.dat", verbose = FALSE)
county_data <- rename_with(county_data, tolower)library(matrixStats)
county_data <- county_data %>%
filter(countyfip == 113) %>% # filter for Dallas County
mutate(race_ethnicity = case_when(
hispan == 0 & race == 1 ~ "White, non-Hispanic",
hispan == 0 & race == 2 ~ "Black, non-Hispanic",
hispan == 0 & race == 3 ~ "American Indian and Alaska Native, non-Hispanic",
hispan == 0 & race %in% c(4, 5, 6) ~ "Asian and Pacific Islander, non-Hispanic",
hispan == 0 & race == 7 ~ "Other, non-Hispanic",
hispan == 0 & race %in% c(8, 9) ~ "Two or more races, non-Hispanic",
hispan %in% c(1, 2, 3, 4) ~ "Hispanic",
TRUE ~ NA_character_
))
#drop cases without race/eth info and households with no income
county_data <- county_data %>% filter(!is.na(race_ethnicity), hhincome > 0, ownershp %in% c(1, 2))
#calc weighted median household inc by homeownership and race/eth
county_income_median <- county_data %>%
group_by(ownershp, race_ethnicity) %>%
summarize(
median_income = weightedMedian(hhincome, w = hhwt, na.rm = TRUE)
) %>%
mutate(homeownership = ifelse(ownershp == 1, "Owner", "Renter")) %>%
select(homeownership, race_ethnicity, median_income) %>%
arrange(homeownership, race_ethnicity)`summarise()` has grouped output by 'ownershp'. You can override using the
`.groups` argument.
Adding missing grouping variables: `ownershp`
print(county_income_median)# A tibble: 14 × 4
# Groups: ownershp [2]
ownershp homeownership race_ethnicity median_income
<int+lbl> <chr> <chr> <dbl>
1 1 [Owned or being bought (loan)] Owner American Indian… 110927.
2 1 [Owned or being bought (loan)] Owner Asian and Pacif… 134507
3 1 [Owned or being bought (loan)] Owner Black, non-Hisp… 92031
4 1 [Owned or being bought (loan)] Owner Hispanic 84029
5 1 [Owned or being bought (loan)] Owner Other, non-Hisp… 127400
6 1 [Owned or being bought (loan)] Owner Two or more rac… 124048.
7 1 [Owned or being bought (loan)] Owner White, non-Hisp… 141610
8 2 [Rented] Renter American Indian… 54647.
9 2 [Rented] Renter Asian and Pacif… 93051.
10 2 [Rented] Renter Black, non-Hisp… 50661.
11 2 [Rented] Renter Hispanic 53000
12 2 [Rented] Renter Other, non-Hisp… 64635.
13 2 [Rented] Renter Two or more rac… 62960.
14 2 [Rented] Renter White, non-Hisp… 79088.
write_xlsx(county_income_median, "dallas_county_inc_homeownership_race.xlsx")Revised race/eth groups (combined AIAN with other)
library(matrixStats)
county_data2 <- county_data %>%
filter(countyfip == 113) %>% # filter for Dallas County
mutate(race_ethnicity = case_when(
hispan == 0 & race == 1 ~ "White, non-Hispanic",
hispan == 0 & race == 2 ~ "Black, non-Hispanic",
hispan == 0 & race %in% c(4, 5, 6) ~ "Asian and Pacific Islander, non-Hispanic",
hispan == 0 & race %in% c(3, 7) ~ "Other, non-Hispanic",
hispan == 0 & race %in% c(8, 9) ~ "Two or more races, non-Hispanic",
hispan %in% c(1, 2, 3, 4) ~ "Hispanic",
TRUE ~ NA_character_
))
#drop cases without race/eth info and households with no income
county_data2 <- county_data2 %>% filter(!is.na(race_ethnicity), hhincome > 0, ownershp %in% c(1, 2))
#calc weighted median household inc by homeownership and race/eth
county_income_median2 <- county_data2 %>%
group_by(ownershp, race_ethnicity) %>%
summarize(
median_income = weightedMedian(hhincome, w = hhwt, na.rm = TRUE)
) %>%
mutate(homeownership = ifelse(ownershp == 1, "Owner", "Renter")) %>%
select(homeownership, race_ethnicity, median_income) %>%
arrange(homeownership, race_ethnicity)`summarise()` has grouped output by 'ownershp'. You can override using the
`.groups` argument.
Adding missing grouping variables: `ownershp`
print(county_income_median2)# A tibble: 12 × 4
# Groups: ownershp [2]
ownershp homeownership race_ethnicity median_income
<int+lbl> <chr> <chr> <dbl>
1 1 [Owned or being bought (loan)] Owner Asian and Pacif… 134507
2 1 [Owned or being bought (loan)] Owner Black, non-Hisp… 92031
3 1 [Owned or being bought (loan)] Owner Hispanic 84029
4 1 [Owned or being bought (loan)] Owner Other, non-Hisp… 127024
5 1 [Owned or being bought (loan)] Owner Two or more rac… 124048.
6 1 [Owned or being bought (loan)] Owner White, non-Hisp… 141610
7 2 [Rented] Renter Asian and Pacif… 93051.
8 2 [Rented] Renter Black, non-Hisp… 50661.
9 2 [Rented] Renter Hispanic 53000
10 2 [Rented] Renter Other, non-Hisp… 60169.
11 2 [Rented] Renter Two or more rac… 62960.
12 2 [Rented] Renter White, non-Hisp… 79088.
write_xlsx(county_income_median2, "revised_dallas_county_inc_homeownership_race.xlsx")