Skip to contents

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

Usage

prep_target_workers(
  h_data,
  p_data,
  target_name = "h_workers",
  codebook,
  settings
)

Arguments

h_data

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

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

  • For survey: must include age and employment columns 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, ESR.

  • For survey: must include age and employment columns 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: "h_workers").

codebook

data.table. Codebook for variable mapping; must include age and employment value and label columns.

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 worker bins

  • Row order preserved

Details

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

  • For PUMS:

    • Uses codebook to map ESR codes to employment status labels.

    • Uses regex civilian employed|armed forces to identify workers in val_label (case-insensitive).

    • Aggregates person-level worker flags to household-level counts.

  • For survey:

    • Uses codebook to map age and employment values to labels.

    • Uses regex patterns:

      • label %like% '(18)\s*(-|to)?\s*24' to identify adults (age 18-24, default survey value: 995 for missing/work from home).

      • label %like% 'full-time' → employed_full

      • label %like% 'part-time' → employed_part

      • label %like% 'Self-employed' → employed_self

    • Aggregates flags for full-time, part-time, self-employed, non-working adults, and children.

    • Sums worker flags to household-level counts.

  • Applies cut_and_label to bin worker counts into target levels.

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

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

Examples

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