Skip to contents

Appends housing variables from a household-level source to a person-level ENEMDU source using a controlled household-key match. The function preserves the number and order of person rows. It only joins sources; it does not derive NBI components and does not validate official estimates.

Usage

enemdu_join_nbi_sources(
  person_data,
  household_data,
  household_id = "id_hogar",
  housing_vars = c("vi04a", "vi05a", "vi07", "vi09", "vi10", "vi10a"),
  overwrite = FALSE,
  strict = TRUE
)

Arguments

person_data

Person-level ENEMDU data.

household_data

Household- or housing-level ENEMDU data.

household_id

Household identifier used in both sources.

housing_vars

Housing variables to append from household_data.

overwrite

Logical. If TRUE, replace existing housing_vars in person_data.

strict

Logical. If TRUE, abort when a non-missing household in person_data has no match in household_data. If FALSE, unmatched person rows are preserved and receive NA housing values.

Value

A data frame with appended housing variables and an nbi_source_join_diagnostics attribute.

Examples

person <- tibble::tibble(
  id_hogar = c("h1", "h1", "h2"),
  p01 = c(1, 2, 1),
  p03 = c(40, 8, 45)
)
household <- tibble::tibble(
  id_hogar = c("h1", "h2"),
  vi04a = c(7, 1),
  vi05a = c(1, 6),
  vi07 = c(0, 1),
  vi09 = c(5, 1),
  vi10 = c(1, 2),
  vi10a = c(1, 3)
)

joined <- enemdu_join_nbi_sources(person, household)
joined$vi04a
#> [1] 7 7 1