set.label: Assign Stata Labels to a Variable

View source: R/tools.R

set.labelR Documentation

Assign Stata Labels to a Variable

Description

Assign value labels from a Stata label set to a variable. If duplicated labels are found, unique labels will be generated according the following scheme: "label_(integer code)". Levels without labels will become <NA>.

Usage

set.label(dat, var.name, lang = NA)

Arguments

dat

data.frame. Data.frame created by read.dta13.

var.name

character. Name of the variable in the data.frame

lang

character. Label language. Default language defined by get.lang is used if NA

Value

Returns a labeled factor

Examples

dat <- read.dta13(system.file("extdata/statacar.dta", package="readstata13"),
                  convert.factors=FALSE)

# compare vectors
set.label(dat, "type")
dat$type

# German label
set.label(dat, "type", "de")

readstata13 documentation built on March 7, 2023, 6:12 p.m.