Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

get.origin.codes

Get Origin Code Numbers for Factors


Description

Recreates the code numbers of a factor as stored in the Stata dataset.

Usage

get.origin.codes(x, label.table)

Arguments

x

factor. Factor to obtain code for

label.table

table. Table with factor levels obtained by get.label.

Details

While converting numeric variables into factors, the original code numbers are lost. This function reconstructs the codes from the attribute label.table.

Value

Returns an integer with original codes

Author(s)

Jan Marvin Garbuszus jan.garbuszus@ruhr-uni-bochum.de

Examples

dat <- read.dta13(system.file("extdata/statacar.dta", package="readstata13"))
labname <- get.label.name(dat,"type")
labtab <- get.label(dat, labname)

# comparsion
get.origin.codes(dat$type, labtab)
as.integer(dat$type)

readstata13

Import 'Stata' Data Files

v0.10.0
GPL-2 | file LICENSE
Authors
Jan Marvin Garbuszus [aut], Sebastian Jeworutzki [aut, cre] (<https://orcid.org/0000-0002-2671-5253>), R Core Team [cph], Magnus Thor Torfason [ctb], Luke M. Olson [ctb], Giovanni Righi [ctb], Kevin Jin [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.