read.dta(file, convert.dates = TRUE, convert.factors = TRUE, missing.type = FALSE, convert.underscore = FALSE, warn.missing.labels = TRUE)Date class, and
date-times to POSIXct class?"_" in Stata variable names
to "." in R names?"datalabel",
"time.stamp", "formats", "types",
"val.labels", "var.labels" and "version" and may
include "label.table" and "expansion.table".
Possible versions are 5, 6, 7,
-7 (Stata 7SE, format-111), 8 (Stata 8 and 9,
format-113), 10 (Stata 10 and 11, format-114).
and 12 (Stata 12, format-115).The value labels in attribute "val.labels" name a table for
each variable, or are an empty string. The tables are elements of the
named list attribute "label.table": each is an integer vector with
names.
By default Stata dates (%d and %td formats) are converted to R's
Date class, and variables with Stata value labels are
converted to factors. Ordinarily, read.dta will not convert
a variable to a factor unless a label is present for every level. Use
convert.factors = NA to override this. In any case the value
label and format information is stored as attributes on the returned
data frame. Stata's date formats are sketchily documented: if
necessary use convert.dates = FALSE and examine the attributes
to work out how to post-process the dates.
Stata 8 introduced a system of 27 different missing data values. If
missing.type is TRUE a separate list is created with the
same variable names as the loaded data. For string variables the list
value is NULL. For other variables the value is NA
where the observation is not missing and 0--26 when the observation is
missing. This is attached as the "missing" attribute of the
returned value.
The default file format for Stata 13, format-115, is
substantially different from those for Stata 5--12.
Stata.file, at the time of writing not for Stata 12 or
later.
Package readstata13 for Stata 13 files.data(swiss)
write.dta(swiss,swissfile <- tempfile())
read.dta(swissfile)
Run the code above in your browser using DataLab