Skip to contents

This function extracts formatted response option labels for AmericasBarometer variables, using label tables stored as attributes. The labels are formatted with their corresponding numeric codes and can be pulled in multiple languages.

Usage

lpr_set_ros(data, lang_id = "en", attribute_name = "roslabel")

Arguments

data

A data frame loaded using readstata13 containing label.table attributes.

lang_id

Language identifier for the labels ("en" for English, "es" for Spanish, "pt" for Portuguese). Default is "en" (English).

attribute_name

The name of the attribute where the formatted response options string will be stored. Default is "roslabel".

Value

The input data frame with response option labels added to variables

Details

The function looks for label tables stored as attributes of the data frame, with names following the pattern "VARNAME_lang_id" (e.g., "ing4_en" for English labels of variable ing4). Each label table should be a named numeric vector where names are the response labels and values are the corresponding codes.

Special codes (values ≥ 1000) are excluded from the response options string.

Examples

# Apply the function
if (FALSE) { # \dontrun{
bra23 <- lpr_set_ros(bra23) # Default English
bra23 <- lpr_set_ros(bra23, lang_id = "es", attribute_name = "respuestas") # Spanish
bra23 <- lpr_set_ros(bra23, lang_id = "pt", attribute_name = "ROsLabels_pt") # Portuguese

# View the resulting attribute
attr(bra23$ing4, "roslabel")
attr(bra23$ing4, "respuestas")
attr(bra23$ing4, "ROsLabels_pt")
} # }