acs_final <- acs_all %>%
rowwise() %>%
mutate(
# totals
total_population = S0101_C01_001E,
total_population_moe = S0101_C01_001M,
total_households = S1101_C01_001E,
total_households_moe = S1101_C01_001M,
# disability
disability_pct = S1810_C03_001E,
disability_pct_moe = S1810_C03_001M,
amb65_pct = S1810_C03_052E,
amb65_pct_moe = S1810_C03_052M,
# educational attainment - less than HS diploma
pop25_n = S1501_C01_006E,
pop25_moe = S1501_C01_006M,
lths_n = S1501_C01_007E + S1501_C01_008E,
lths_moe = moe_sum(
moe = c(S1501_C01_007M, S1501_C01_008M),
estimate = c(S1501_C01_007E, S1501_C01_008E),
na.rm = TRUE
),
lths_pct = if_else(
pop25_n > 0,
100 * lths_n / pop25_n,
NA_real_
),
lths_pct_moe = 100 * moe_ratio(
num = lths_n,
denom = pop25_n,
moe_num = lths_moe,
moe_denom = pop25_moe
),
# income
med_hh_income = B19013_001E,
med_hh_income_moe = B19013_001M,
# internet
no_internet_n = B28002_013E,
no_internet_n_moe = B28002_013M,
hh_total_internet = B28002_001E,
hh_total_internet_moe = B28002_001M,
no_internet_pct = if_else(
hh_total_internet > 0,
no_internet_n / hh_total_internet * 100,
NA_real_
),
no_internet_pct_moe = 100 * moe_ratio(
no_internet_n,
hh_total_internet,
no_internet_n_moe,
hh_total_internet_moe
),
# limited English-speaking households
lesh_pct = S1602_C04_001E,
lesh_pct_moe = S1602_C04_001M,
# poverty
poverty_pct = S1701_C03_001E,
poverty_pct_moe = S1701_C03_001M,
# preK
prek_pct = S1401_C04_014E,
prek_pct_moe = S1401_C04_014M,
# uninsured
uninsured_pct = S2701_C05_001E,
uninsured_pct_moe = S2701_C05_001M,
# HH risk (harmonized 2016 PR vs 2024 DP)
pct_female_hh_kids = if_else(
year == 2016,
DP02PR_0009PE,
DP02_0011PE
),
pct_female_hh_kids_moe = if_else(
year == 2016,
DP02PR_0009PM,
DP02_0011PM
),
pct_hh_with_kids = if_else(
year == 2016,
DP02PR_0013PE,
DP02_0014PE
),
pct_hh_with_kids_moe = if_else(
year == 2016,
DP02PR_0013PM,
DP02_0014PM
),
pct_seniors_alone = B11007_003E / B11007_001E * 100,
pct_seniors_alone_moe = 100 * moe_ratio(
B11007_003E,
B11007_001E,
B11007_003M,
B11007_001M
),
# underemployment
total_worked = B23022_003E + B23022_027E,
total_worked_moe = moe_sum(
moe = c(B23022_003M, B23022_027M),
estimate = c(B23022_003E, B23022_027E),
na.rm = TRUE
),
underemp_n = B23022_016E + B23022_017E + B23022_023E + B23022_024E +
B23022_040E + B23022_041E + B23022_047E + B23022_048E,
underemp_n_moe = moe_sum(
moe = c(
B23022_016M,B23022_017M,B23022_023M,B23022_024M,
B23022_040M,B23022_041M,B23022_047M,B23022_048M
),
estimate = c(
B23022_016E,B23022_017E,B23022_023E,B23022_024E,
B23022_040E,B23022_041E,B23022_047E,B23022_048E
),
na.rm = TRUE
),
underemp_pct = if_else(
total_worked > 0,
underemp_n / total_worked * 100,
NA_real_
),
underemp_pct_moe = 100 * moe_ratio(
num = underemp_n,
denom = total_worked,
moe_num = underemp_n_moe,
moe_denom = total_worked_moe
),
# ======================
# RACE / ETH (DP05)
# ======================
# race harmonized (2016 PR vs 2024 DP)
pct_nh_white = if_else(year==2016, DP05_0072PE, DP05_0096PE),
pct_nh_white_moe = if_else(year==2016, DP05_0072PM, DP05_0096PM),
pct_nh_black = if_else(year==2016, DP05_0073PE, DP05_0097PE),
pct_nh_black_moe = if_else(year==2016, DP05_0073PM, DP05_0097PM),
pct_nh_asian = if_else(year==2016, DP05_0075PE, DP05_0099PE),
pct_nh_asian_moe = if_else(year==2016, DP05_0075PM, DP05_0099PM),
pct_nh_multi = if_else(year==2016, DP05_0078PE, DP05_0102PE),
pct_nh_multi_moe = if_else(year==2016, DP05_0078PM, DP05_0102PM),
pct_hispanic = if_else(year==2016, DP05_0066PE, DP05_0090PE),
pct_hispanic_moe = if_else(year==2016, DP05_0066PM, DP05_0090PM),
race_total_pop = if_else(year==2016, DP05_0065E, DP05_0089E),
race_total_pop_moe = if_else(year==2016, DP05_0065M, DP05_0089M),
# NH Other (AIAN + NHPI + Some Other) — harmonized 2016 PR vs 2024 DP
pct_nh_other = if_else(
year == 2016,
DP05_0074PE + DP05_0076PE + DP05_0077PE,
DP05_0098PE + DP05_0100PE + DP05_0101PE
),
pct_nh_other_moe = if_else(
year == 2016,
moe_sum(
c(DP05_0074PM, DP05_0076PM, DP05_0077PM),
estimate = c(DP05_0074PE, DP05_0076PE, DP05_0077PE)
),
moe_sum(
c(DP05_0098PM, DP05_0100PM, DP05_0101PM),
estimate = c(DP05_0098PE, DP05_0100PE, DP05_0101PE)
)
),
# ======================
# AGE BANDS (COUNTS)
# ======================
est_age_total = B01001_001E,
moe_age_total = B01001_001M,
est_under18 = sum(
B01001_003E, B01001_027E,
B01001_004E, B01001_028E,
B01001_005E, B01001_029E,
B01001_006E, B01001_030E,
na.rm = TRUE
),
moe_under18 = moe_sum(
c(
B01001_003M, B01001_027M,
B01001_004M, B01001_028M,
B01001_005M, B01001_029M,
B01001_006M, B01001_030M
),
estimate = c(
B01001_003E, B01001_027E,
B01001_004E, B01001_028E,
B01001_005E, B01001_029E,
B01001_006E, B01001_030E
),
na.rm = TRUE
),
est_18_24 = sum(
B01001_007E, B01001_031E,
B01001_008E, B01001_032E,
B01001_009E, B01001_033E,
B01001_010E, B01001_034E,
na.rm = TRUE
),
moe_18_24 = moe_sum(
c(
B01001_007M, B01001_031M,
B01001_008M, B01001_032M,
B01001_009M, B01001_033M,
B01001_010M, B01001_034M
),
estimate = c(
B01001_007E, B01001_031E,
B01001_008E, B01001_032E,
B01001_009E, B01001_033E,
B01001_010E, B01001_034E
),
na.rm = TRUE
),
est_25_44 = sum(
B01001_011E, B01001_035E,
B01001_012E, B01001_036E,
B01001_013E, B01001_037E,
B01001_014E, B01001_038E,
na.rm = TRUE
),
moe_25_44 = moe_sum(
c(
B01001_011M, B01001_035M,
B01001_012M, B01001_036M,
B01001_013M, B01001_037M,
B01001_014M, B01001_038M
),
estimate = c(
B01001_011E, B01001_035E,
B01001_012E, B01001_036E,
B01001_013E, B01001_037E,
B01001_014E, B01001_038E
),
na.rm = TRUE
),
est_45_64 = sum(
B01001_015E, B01001_039E,
B01001_016E, B01001_040E,
B01001_017E, B01001_041E,
B01001_018E, B01001_042E,
B01001_019E, B01001_043E,
na.rm = TRUE
),
moe_45_64 = moe_sum(
c(
B01001_015M, B01001_039M,
B01001_016M, B01001_040M,
B01001_017M, B01001_041M,
B01001_018M, B01001_042M,
B01001_019M, B01001_043M
),
estimate = c(
B01001_015E, B01001_039E,
B01001_016E, B01001_040E,
B01001_017E, B01001_041E,
B01001_018E, B01001_042E,
B01001_019E, B01001_043E
),
na.rm = TRUE
),
est_65p = sum(
B01001_020E, B01001_044E,
B01001_021E, B01001_045E,
B01001_022E, B01001_046E,
B01001_023E, B01001_047E,
B01001_024E, B01001_048E,
B01001_025E, B01001_049E,
na.rm = TRUE
),
moe_65p = moe_sum(
c(
B01001_020M, B01001_044M,
B01001_021M, B01001_045M,
B01001_022M, B01001_046M,
B01001_023M, B01001_047M,
B01001_024M, B01001_048M,
B01001_025M, B01001_049M
),
estimate = c(
B01001_020E, B01001_044E,
B01001_021E, B01001_045E,
B01001_022E, B01001_046E,
B01001_023E, B01001_047E,
B01001_024E, B01001_048E,
B01001_025E, B01001_049E
),
na.rm = TRUE
),
# ======================
# AGE PERCENTS
# ======================
age_under18 = 100 * est_under18 / est_age_total,
age_moe_under18 = 100 * moe_ratio(est_under18, est_age_total, moe_under18, moe_age_total),
age_18_24 = 100 * est_18_24 / est_age_total,
age_moe_18_24 = 100 * moe_ratio(est_18_24, est_age_total, moe_18_24, moe_age_total),
age_25_44 = 100 * est_25_44 / est_age_total,
age_moe_25_44 = 100 * moe_ratio(est_25_44, est_age_total, moe_25_44, moe_age_total),
age_45_64 = 100 * est_45_64 / est_age_total,
age_moe_45_64 = 100 * moe_ratio(est_45_64, est_age_total, moe_45_64, moe_age_total),
age_65p = 100 * est_65p / est_age_total,
age_moe_65p = 100 * moe_ratio(est_65p, est_age_total, moe_65p, moe_age_total)
) %>%
ungroup()