Skip to contents

Cleans and formats household data for income imputation, ensuring income bins are properly labeled and missing responses are handled. Use to generate model-ready household data for imputation and reporting.

Usage

prep_hhs_for_income_imputation(households, value_labels)

Arguments

households

data.table. Household records to impute. Required columns:

  • hh_id — household identifier

  • income_broad <integer/character> — income bin

  • income_broad_label — income bin label

  • residence_rent_own <integer/character> — rent/own code

  • residence_type <integer/character> — residence type code

  • num_people — household size Rows: one per household. 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 data for imputation. Columns:

  • hh_id — household identifier

  • income_imputed_pnta <integer/numeric> — imputed income bin

  • income_imputed_pnta_label — imputed income label

  • Additional columns for home ownership and residence type flags. Rows: one per household. Keys: (hh_id).

Details

  • Assumes income_broad is a factor with labels for income levels, combining income_detailed and income_followup.

  • If missing, creates income_broad_factor from income_broad_label.

  • Updates income bin labels using value_labels if not already a factor.

  • Handles missing or "Prefer Not to Answer" values by returning imputed columns or prepping for imputation.

  • Adds home ownership and single-family home flags using value_labels and regex matching.

  • Returns a data.table with household ID, imputed income, and label columns.

  • Assumes value_labels are current and complete; errors if factor levels or labels are missing.

Settings

None.

Examples

## Not run:
prep_hhs_for_income_imputation(households, value_labels)
#> Error in prep_hhs_for_income_imputation(households, value_labels): could not find function "prep_hhs_for_income_imputation"
## End(Not run)