Skip to contents

Creates a standardized number of children target variable for household-level weighting and expansion, using either PUMS or survey input. Use when preparing children targets for synthetic population or survey analysis.

Usage

prep_target_kids(
  h_data,
  p_data = NULL,
  target_name = "h_kids",
  codebook,
  settings
)

Arguments

h_data

data.table. Household-level input. Required columns:

  • For PUMS: must include SERIALNO and children columns as specified in settings.

  • For survey: must include children column as specified in settings. Rows: one per household. Modified by reference: no (returns copy).

p_data

data.table. Person-level input. Required columns:

  • For PUMS: must include SERIALNO, AGEP.

  • For survey: not required. Rows: one per person. Modified by reference: no (returns copy).

target_name

character(1). Name of the target variable to create (default: "h_kids").

codebook

data.table. Codebook for variable mapping (not used in this function).

settings

list. Project settings; must include targets[[target_name]] with levels, pums_input, and survey_input.

Value

data.table. Copy of household-level input with new target variable column (target_name).

  • Columns: all original plus target_name (character)

  • Values: standardized children bins

  • Row order preserved

Details

  • Detects input type (PUMS vs. survey) by presence of SERIALNO column in h_data.

  • For PUMS:

    • If pre-computed, uses survey input column directly.

    • Otherwise, aggregates number of children from person-level data (AGEP < 18).

  • For survey:

    • Uses survey input column as specified in settings.

  • Applies cut_and_label to bin number of children into target levels.

  • Renames output column to target_name (default: h_kids).

  • Returns a copy of the input data.table with the new target variable.

  • Error handling: stops if levels do not match expected values.

Settings

  • targets[["h_kids"]] (direct): must include levels, pums_input, and survey_input.

Examples

## Not run:
prep_target_kids(h_data, p_data, target_name = "h_kids", codebook, settings)
#> Error: object 'h_data' not found
## End(Not run)