Skip to contents

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

Usage

prep_target_gender(
  h_data,
  p_data,
  target_name = "p_gender",
  codebook,
  settings
)

Arguments

h_data

data.table. Household-level input (not used, included for interface consistency).

p_data

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

  • For PUMS: must include SERIALNO and gender label column (e.g., SEX_label).

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

target_name

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

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 person-level input with new target variable column (target_name).

  • Columns: all original plus target_name (character)

  • Values: standardized gender levels

  • Row order preserved

Details

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

  • For PUMS:

    • Uses target_list$pums_input and appends _label to select gender label column.

    • Converts to lowercase and assigns to target variable.

  • For survey:

    • Uses target_list$survey_input to select gender column.

  • Checks that observed levels match expected target levels from settings.

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

  • 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[["p_gender"]] (direct): must include levels, pums_input, and survey_input.

Examples

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