harmonize_waves: Harmonize waves

Description Usage Arguments Value See Also Examples

View source: R/harmonize_waves.R

Description

Harmonize the values of surveys. It binds together variables that are all present in the surveys, and applies a harmonization function on them.

Usage

1
harmonize_waves(waves, .f, status_message = FALSE)

Arguments

waves

A list of surveys

.f

A function to apply for the harmonization.

status_message

Defaults to FALSE. If set to TRUE it shows the id of the survey that is being joined.

Value

A natural full join of all surveys into a data frame.

See Also

Other harmonization functions: collect_val_labels(), harmonize_na_values(), harmonize_values(), label_normalize(), merge_waves(), na_range_to_values()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
## Not run: 
examples_dir <- system.file("examples", package = "retroharmonize")

example_surveys <- read_surveys(
  here( examples_dir, survey_list))

metadata <- lapply ( X = example_surveys, FUN = metadata_create )
metadata <- do.call(rbind, metadata)

to_harmonize <- metadata %>%
  filter ( var_name_orig %in% 
             c("rowid", "w1") |
             grepl("trust ", label_orig ) ) %>%
  mutate ( var_label = var_label_normalize(label_orig)) %>%
  mutate ( var_name = val_label_normalize(var_label))

harmonize_eb_trust <- function(x) {
  label_list <- list(
    from = c("^tend\\snot", "^cannot", "^tend\\sto", "^can\\srely",
             "^dk", "^inap", "na"), 
   to = c("not_trust", "not_trust", "trust", "trust",
           "do_not_know", "inap", "inap"), 
    numeric_values = c(0,0,1,1, 99997,99999,99999)
  )
  
  harmonize_values(x, 
                   harmonize_labels = label_list, 
                   na_values = c("do_not_know"=99997,
                                 "declined"=99998,
                                 "inap"=99999)
                   )
}

merged_surveys <- merge_waves ( example_surveys, var_harmonization = to_harmonize  )

harmonized <- harmonize_waves(waves = merged_surveys, 
                              .f = harmonize_eb_trust,
                              status_message = FALSE)
                              
# For details see Afrobarometer and Eurobarometer Case Study vignettes.

## End(Not run)

antaldaniel/retroharmonize documentation built on Aug. 15, 2020, 10:13 a.m.