Calculate a weighted mean using the method used to produce official CE estimates.
Arguments
- ce_data
A data frame containing at least a finlwt21 column, 44 replicate weight columns (wtrep01-44), a cost column, and a survey indicator column. All but the survey column must be numeric.
Value
A 1-row dataframe containing the following columns:
agg_exp - The estimated aggregate expenditure
mean_exp - The estimated mean expenditure
se - The estimated standard error of the estimated mean expenditure
cv - The coefficient of variation of the estimated mean expenditure
Note
Estimates produced using PUMD, which is topcoded by the CE and has some records suppressed to protect respondent confidentiality, will not match the published estimates released by the CE in most cases. The CE's published estimates are based on confidential data that are not topcoded nor have records suppressed. You can learn more at CE Protection of Respondent Confidentiality
Examples
# Download the HG file keeping the section for expenditures on utilities
if (FALSE) {
utils_hg <- ce_hg(2017, interview) |>
ce_uccs("Utilities, fuels, and public services", uccs_only = FALSE)
}
# Download and prepare interview data
if (FALSE) {
utils_interview <- ce_prepdata(
2017,
interview,
uccs = ce_uccs(utils_hg, "Utilities, fuels, and public services"),
zp = NULL,
integrate_data = FALSE,
hg = utils_hg,
bls_urbn
)
}
# Calculate the mean expenditure on utilities
if (FALSE) ce_mean(utils_interview)
# Calculate the mean expenditure on utilities by urbanicity
if (FALSE) {
utils_interview |>
tidyr::nest(-bls_urbn) |>
mutate(mean_utils = purrr::map(data, ce_mean)) |>
select(-data) |>
unnest(mean_utils)
}