Prepare commute mode target variable for weighting
prep_target_commutemode.RdCreates a standardized commute mode target variable for person-level weighting and expansion, using either PUMS or survey input. Use when preparing commute mode targets for synthetic population or survey analysis.
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,JWTRNS_label.For survey: must include work mode and job type 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: "p_commutemode").
- codebook
data.table. Codebook for variable mapping; must include work mode and job type value and label columns.
- settings
list. Project settings; must include
targets[[target_name]]withlevels.
Value
data.table. Copy of person-level input with new target variable column (target_name).
Columns: all original plus
target_name(character)Values: standardized commute mode levels
Row order preserved
Details
Detects input type (PUMS vs. survey) by presence of
SERIALNOcolumn.For PUMS:
Uses
JWTRNS_labelcolumn, converts to lowercase, truncates to 40 chars.Uses regex patterns:
label %like% "home"→ "home"label %like% "walk"→ "walk"label %like% "bike|bicycle"→ "bike"label %like% "bus|rail"→ "transit"label %like% "n/a"→ "none"else → "other"
For survey:
Uses codebook to map work mode values to labels.
Uses regex patterns:
label %like% "walk"→ "walk"label %like% "bike|bicycle"→ "bike"label %like% "bus|rail"→ "transit"label %like% "missing"→ "none"else → "other"
Uses job type labels to assign "home" for "work only from home".
Checks that observed levels match expected target levels from settings.
Renames output column to
target_name(default:p_commutemode).Returns a copy of the input data.table with the new target variable.
Error handling: stops if levels do not match expected values.
See also
get_target_methods, prep_target_gender, prep_target_employment
Other target preparation:
get_target_methods(),
prep_target_adults(),
prep_target_age(),
prep_target_cross(),
prep_target_edulevel(),
prep_target_employment(),
prep_target_ethnicity(),
prep_target_gender(),
prep_target_h_size(),
prep_target_income(),
prep_target_kids(),
prep_target_race(),
prep_target_univstudent(),
prep_target_vehicles(),
prep_target_workers(),
prep_transit_target(),
prepare_targets(),
run_tabulate_method()