Build validated social bonus variables
Source:R/optional_bonuses.R
enemdu_build_optional_bonuses.RdBuilds validated social bonus variables from ENEMDU amount variables and their corresponding receipt questions. The function supports, by registry:
Usage
enemdu_build_optional_bonuses(
data,
bonus_vars = NULL,
registry = enemdu_optional_bonus_registry(),
household_id = "idhogar",
hsize = "hsize",
base_individual_income_var = "ingrltot",
output_total_var = "bonos_sociales_total",
output_recipient_var = "bonos_sociales_recibe",
scenario_add_var = "bonos_scenario_add_total",
create_income_scenario = TRUE,
scenario_suffix = "_plus_optional_bonos",
keep_raw = TRUE,
create_flags = TRUE,
overwrite = FALSE,
strict = FALSE
)Arguments
- data
A data frame.
- bonus_vars
Character vector of bonus amount variables. If
NULL, all registered bonus variables are considered.- registry
Optional bonus registry.
- household_id
Household identifier. Defaults to
"idhogar"and falls back to"id_hogar"when needed.- hsize
Household-size variable. If absent and scenario income is requested, it is built.
- base_individual_income_var
Base individual income variable used to build the alternative scenario. Defaults to
"ingrltot".- output_total_var
Output variable for row-level total social bonuses.
- output_recipient_var
Output variable for any social bonus receipt.
- scenario_add_var
Output variable containing only bonuses to add to the alternative income scenario.
- create_income_scenario
Logical. If
TRUE, creates alternative income variables: individual, household total, and household per-capita income with non-base bonuses added.- scenario_suffix
Suffix for alternative income variables.
- keep_raw
Logical. If
TRUE, keeps raw copies of source amount variables.- create_flags
Logical. If
TRUE, creates audit flags for sentinels, receipt validation, and amount/receipt inconsistencies.- overwrite
Logical. If
TRUE, overwrites existing output variables.- strict
Logical. If
TRUE, errors when registered amount or receipt variables are absent. IfFALSE, incomplete pairs are skipped with warning.
Value
A data frame with validated social bonus variables and scenario income variables when requested.
Details
p75/p76: Bono de Desarrollo Humanop77/p78: Bono de Discapacidad
The amount is not read as analytically valid unless the corresponding receipt question confirms that the person received the bonus. If the receipt question says the person did not receive the bonus, the amount is treated as structural zero. If the receipt question says the person did receive the bonus but the amount is missing, invalid, or a sentinel code, the amount remains missing because it cannot be safely assumed to be zero.
The scenario income variables add only bonuses marked in the registry with
scenario_income_inclusion = TRUE. This prevents duplicating the Bono de
Desarrollo Humano, which is already part of the base income construction
through p75 / p76.