Skip to contents

Merge a list of surveys into a list with harmonized variable names, variable labels, and survey identifiers.

Usage

merge_surveys(survey_list, var_harmonization)

merge_waves(waves, var_harmonization)

Arguments

survey_list

A list of surveys.

var_harmonization

A metadata table describing how variables should be harmonized. It must contain at least the columns filename, var_name_orig, var_name_target, and var_label.

waves

Deprecated.

Value

A list of surveys with harmonized variable names and labels.

Details

Prior to version 0.2.0 this function was called merge_waves(), reflecting the terminology used in Eurobarometer surveys.

See also

metadata_create

Examples

# \donttest{
examples_dir <- system.file("examples", package = "retroharmonize")
survey_files <- dir(examples_dir, pattern = "\\.rds$", full.names = TRUE)

example_surveys <- read_surveys(
  survey_files,
  save_to_rds = FALSE
)

# Create metadata from surveys
metadata <- metadata_create(survey_list = example_surveys)

# Select and harmonize a subset of variables
to_harmonize <- metadata %>%
  dplyr::filter(
    var_name_orig %in% c("rowid", "w1") |
      grepl("^trust", var_label_orig)
  ) %>%
  dplyr::mutate(
    var_label = var_label_normalize(var_label_orig),
    var_name_target = val_label_normalize(var_label),
    var_name_target = ifelse(
      .data$var_name_orig %in% c("rowid", "w1", "wex"),
      .data$var_name_orig,
      .data$var_name_target
    )
  )

merged_surveys <- merge_surveys(
  survey_list = example_surveys,
  var_harmonization = to_harmonize
)

merged_surveys[[1]]
#> Unknown (2026): Untitled Dataset [dataset]
#>    rowid    trust_in_institution…¹ trust_in_institution…² trust_in_institution…³ 
#>    <chr>    <retroh_dbl>           <retroh_dbl>           <retroh_dbl>          
#>  1 ZA5913_1 2 [Tend not to trust]  2 [Tend not to trust]  2 [Tend not to trust] 
#>  2 ZA5913_2 2 [Tend not to trust]  2 [Tend not to trust]  2 [Tend not to trust] 
#>  3 ZA5913_3 1 [Tend to trust]      1 [Tend to trust]      1 [Tend to trust]     
#>  4 ZA5913_4 2 [Tend not to trust]  1 [Tend to trust]      1 [Tend to trust]     
#>  5 ZA5913_5 1 [Tend to trust]      1 [Tend to trust]      2 [Tend not to trust] 
#>  6 ZA5913_6 1 [Tend to trust]      2 [Tend not to trust]  2 [Tend not to trust] 
#>  7 ZA5913_7 2 [Tend not to trust]  3 (NA) [DK]            2 [Tend not to trust] 
#>  8 ZA5913_8 1 [Tend to trust]      1 [Tend to trust]      1 [Tend to trust]     
#>  9 ZA5913_9 2 [Tend not to trust]  2 [Tend not to trust]  2 [Tend not to trust] 
#> 10 ZA5913_… 2 [Tend not to trust]  2 [Tend not to trust]  2 [Tend not to trust] 
#> # ℹ 25 more rows
#> # ℹ abbreviated names: ¹​trust_in_institutions_european_union,
#> #   ²​trust_in_institutions_national_government,
#> #   ³​trust_in_institutions_national_parliament
#> # ℹ 3 more variables: trust_in_institutions_political_parties <retroh_dbl>,
#> #   trust_in_institutions_reg_loc_authorities <retroh_dbl>, w1 <dbl> 
# }