Harmonize the numeric values and the value labels of variables. Currently works only with binary values.

harmonize_value_labels(labelled_var, categories = 2)

Arguments

labelled_var

A vector (survey variable) coded in with labelled class.

categories

The number of valid categories in the value range.

Value

A labelled vector containing harmonized numeric values and labels, and in attr(v, num_orig) the original numeric values, attr(v, labels_orig) the original labelling.

See also

Other harmonization functions: eurobarometer_special_values()

Examples

v <- labelled::labelled( c(3,4,4,3,8, 9), c(YES = 3, NO = 4, wrong_label = 8, refused = 9) ) harmonize_value_labels(v, 2)
#> <labelled<double>[6]> #> [1] 1 0 0 1 99000 99998 #> #> Labels: #> value label #> 1 yes #> 0 no #> 99000 wrong_label #> 99998 decline
v3 <- labelled::labelled(c(3,4,5,3,8, 9), c(`BETTER`= 3, `WORSE`= 4, `SAME` = 5, wrong_label = 8, refused = 9)) harmonize_value_labels( labelled_var = v3,categories = 3)
#> <labelled<double>[6]> #> [1] 1 -1 0 1 99000 99998 #> #> Labels: #> value label #> 1 better #> -1 worse #> 0 same #> 99000 wrong_label #> 99998 decline