Aggregate person-level variables to household totals
get_hh_person_sums.RdAggregates key person-level variables to household totals for use in weighting targets and income imputation. Uses explicit regex patterns to match value labels for age, employment, education, and relationship fields.
Arguments
- hhs
data.table. Household records. Required columns:
hh_id— household identifier Rows: one per household. Keys: ( hh_id). Modified by reference: no (returns copy).
- persons
data.table. Person records. Required columns:
age<integer/character> — age codeemployment<integer/character> — employment codeeducation<integer/character> — education codecan_drive<integer/character> — driver coderelationship<integer/character> — relationship codehh_id— household identifier Rows: one per person. Keys: ( hh_id). Modified by reference: no (returns copy).
- value_labels
data.table. Value labels for variables. Required columns:
variable— variable name label— value label value<integer/character> — coded value
Value
data.table. Household-level totals for person variables. Columns:
hh_id— household identifier ft_employ_n— number of full-time employed adults pt_employ_n— number of part-time employed adults nonworking_adult_n— number of nonworking adults child_n— number of children ft_grad_n— number of full-time employed graduates pt_grad_n— number of part-time employed graduates ft_bachelors_n— number of full-time employed with bachelor's degree pt_bachelors_n— number of part-time employed with bachelor's degree ft_no_college_n— number of full-time employed with no college degree pt_no_college_n— number of part-time employed with no college degree head_under_35_n— head of household under age 35 (0 or 1) head_35_64_n— head of household age 35–64 (0 or 1) head_65_plus_n— head of household age 65+ (0 or 1) driver_n— number of household members who can drive Rows: one per household. Keys: ( hh_id).
Details
Copies person table and computes binary flags for:
Age/employment: full-time, part-time, self-employed, nonworking adult, child
Driver status: matches 'Yes' (case-insensitive) using regex
str_detect(str_to_lower(label), 'Yes|yes')Education: matches 'Graduate' and 'Bachelor' using regex
%like% 'Graduate'and%like% 'Bachelor'Age of head: matches '35' and '65' using regex
%like% '35'and%like% '65'Relationship: matches 'Self' using exact match
Uses regex patterns for age bins:
(18)\\s*(?:-|to)?\\s*(24)Aggregates flags to household level by
hh_id.Returns a data.table with household totals for each variable, one row per household.
Errors if any required value label is missing or empty.
See also
impute_income_pnta, prep_hhs_for_income_imputation
Other imputation utilities:
calculate_acs_proportions(),
get_acs_ethnicity(),
get_acs_race(),
impute_ethnicity(),
impute_gender(),
impute_income_nonrelatives(),
impute_income_pnta(),
impute_race(),
make_binary(),
prep_hhs_for_income_imputation(),
prepare_acs_income(),
prepare_ethnicity_labels(),
prepare_ethnicity_survey_data(),
prepare_impute_targets(),
prepare_income_fit_dt(),
prepare_persons_dt(),
update_hh_income_imputed()