read.dta13
reads a Stata dta-file and imports the data into a
data.frame.
read.dta13(file, convert.factors = TRUE, generate.factors = FALSE, encoding = "UTF-8", fromEncoding = NULL, convert.underscore = FALSE, missing.type = FALSE, convert.dates = TRUE, replace.strl = TRUE, add.rownames = FALSE, nonint.factors = FALSE)
TRUE
, factors from Stata
value labels are created.TRUE
and convert.factors is
TRUE, missing factor labels are created from integers.TRUE
, "_" in variable
names will be changed to "."TRUE
, attribute missing
will be
created.TRUE
, Stata dates are
converted.TRUE
, replace the reference to
a strL string in the data.frame with the actual value. The strl attribute
will be removed from the data.frame (see details).TRUE
, the first column will be
used as rownames. Variable will be dropped afterwards.TRUE
, factors labels
will be assigned to variables of type float and double.Stata files are encoded in ansinew. Depending on your system's default encoding certain characters may appear wrong. Using a correct encoding may fix these.
Variable names stored in the dta-file will be used in the resulting
data.frame. Stata types char, byte, and int will become integer; float and
double will become numerics. R only knows a single missing type, while Stata
knows 27, so all Stata missings will become NA in R. If you need to keep
track of Statas original missing types, you may use
missing.type=TRUE
.
Stata dates are converted to R's Date class the same way foreign handles dates.
Stata 13 introduced a new character type called strL. strLs are able to store
strings up to 2 billion characters. While R is able to store
strings of this size in a character vector, the printed representation of such
vectors looks rather cluttered, so it's possible to save only a reference in the
data.frame with option replace.strl=FALSE
.
In R, you may use rownames to store characters (see for instance
data(swiss)
). In Stata, this is not possible and rownames have to be
stored as a variable. If you want to use rownames, set add.rownames to TRUE.
Then the first variable of the dta-file will hold the rownames of the resulting
data.frame.
Reading dta-files of older and newer versions than 13 was introduced with version 0.8.
read.dta
in package foreign
and memisc
for dta files from Stata
versions < 13 and read_dta
in package haven
for Stata version >= 13.