Skip to contents

Aggregates 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.

Usage

get_hh_person_sums(hhs, persons, value_labels)

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 code

  • employment <integer/character> — employment code

  • education <integer/character> — education code

  • can_drive <integer/character> — driver code

  • relationship <integer/character> — relationship code

  • hh_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.

Settings

None.

Examples

## Not run:
get_hh_person_sums(hhs, persons, value_labels)
#> Error in get_hh_person_sums(hhs, persons, value_labels): could not find function "get_hh_person_sums"
## End(Not run)