Skip to contents

Tabulates a target variable using the specified method, supporting custom preparation, direct tabulation, or pass-through. Use to generate summary tables for targets, with optional weighting and method selection.

Usage

run_tabulate_method(
  method,
  target_name,
  h_data,
  p_data,
  codebook,
  weight = FALSE,
  settings
)

Arguments

method

character(1). Name of method to use. Must match a function in get_target_methods(), or be "tabulate" or "pass_through".

target_name

character(1). Name of target variable to tabulate. Must match column in input data.

h_data

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

  • For person-level targets: must include SERIALNO, PWGTP if weighted.

  • For household-level targets: must include SERIALNO, WGTP if weighted. Rows: one per household. Modified by reference: no (returns copy).

p_data

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

  • For person-level targets: must include person_id, target column.

  • For household-level targets: not required. Rows: one per person. Modified by reference: no (returns copy).

codebook

data.table. Codebook for variable mapping (passed to target prep functions).

weight

logical(1). If TRUE, tabulates weighted counts using PUMS weights if available.

settings

list. Project settings; must include target configs and method definitions.

Value

data.table. Tabulated summary of target variable.

  • Columns: ID column (person_id or hh_id), target variable, and optionally weighted counts.

  • Row order: by ID and target value.

Details

  • Selects ID column using regex ^p_ for person-level targets, else household-level.

  • If PUMS and weight = TRUE, selects weight column using regex ^p_ for PWGTP, else WGTP.

  • If method matches a function in get_target_methods(), calls that function to prepare the target variable, then tabulates using tabulate_target().

  • If method == "tabulate", tabulates directly from input data.

  • If method == "pass_through", returns input data columns for ID and target only.

  • Error handling: stops if method is invalid or not implemented.

  • Uses %like% for regex matching of target names and method selection.

Settings

Examples

## Not run:
run_tabulate_method("prep_target_gender", "p_gender", h_data, p_data, codebook, weight = TRUE, settings)
#> Error: object 'h_data' not found
run_tabulate_method("tabulate", "h_income", h_data, p_data, codebook, weight = FALSE, settings)
#> Error: object 'h_data' not found
## End(Not run)