Skip to contents

Cleans and reshapes person-level data to create model-ready targets for non-relative income imputation, using codebook/value labels and settings. Use to generate predictors for quantile regression or other imputation models.

Usage

prepare_impute_targets(dt, target_names, codebook, settings)

Arguments

dt

data.table. Person-level data to prepare. Required columns:

  • person_id — unique person identifier

  • hh_id — household identifier Rows: one per person. Keys: (person_id, hh_id). Modified by reference: no (returns copy).

target_names

character vector. Names of target variables to prepare (e.g., 'p_employment', 'p_age', 'p_univstudent').

codebook

data.table. PUMS codebook or value labels for variable reference.

settings

list. Settings object with configs.

Value

data.table. Person-level data with model targets. Columns:

  • person_id — unique person identifier

  • hh_id — household identifier

  • model target columns for each variable in target_names Rows: one per person. Keys: (person_id, hh_id).

Details

  • Calls prepare_targets to tabulate model variables for each person.

  • Merges tabulated targets back to person data by person_id and hh_id.

  • Reshapes model variables to long format and assigns target values.

  • Handles multiple target variables and merges them to design data.

  • Returns a data.table with model-ready predictors for imputation.

  • Assumes valid input data and codebook/value labels; errors if merge fails.

Settings

None.

Examples

## Not run:
prepare_impute_targets(dt, target_names = c('p_employment', 'p_age'), codebook, settings)
#> Error in prepare_impute_targets(dt, target_names = c("p_employment", "p_age"),     codebook, settings): could not find function "prepare_impute_targets"
## End(Not run)