Package to read and write all Stata file formats (version 14 and older) into a R data.frame. The dta file format versions 102 to 118 are supported.
The function read.dta
from the foreign package imports only dta files from Stata versions <= 12. Due to the different structure and features of dta 117 files, we wrote a new file reader in Rcpp.
Additionally the package supports many features of the Stata dta format like label sets in different languages (?set.lang
) or business calendars (?as.caldays
).
The package is now hosted on CRAN.
install.packages("readstata13")
library(readstata13)
dat <- read.dta13("path to file.dta")
save.dta13(dat, file="newfile.dta")
To install the current release from github you need the plattform specific build tools. On Windows a current installation of Rtools is necessary, while OS X users need to install Xcode.
# install.packages("devtools")
devtools::install_github("sjewo/readstata13", ref="0.8.5")
Older Versions of devtools require a username option:
install_github("readstata13", username="sjewo", ref="0.8.5")
To install the current development version from github:
devtools::install_github("sjewo/readstata13", ref="testing")
nonint.factors=T
)Since our attributes differ from foreign::read.dta all.equal and identical report false. If you check the values, everything is identical.
library("foreign")
r12 <- read.dta("http://www.stata-press.com/data/r12/auto.dta")
r13 <- read.dta13("http://www.stata-press.com/data/r13/auto.dta")
Map(identical,r12,r13)
att <- names(attributes(r12))
for (i in seq(att))
cat(att[i],":", all.equal(attr(r12,att[i]),attr(r13,att[i])),"\n")
r12 <- read.dta("http://www.stata-press.com/data/r12/auto.dta",convert.factors=F)
r13 <- read.dta13("http://www.stata-press.com/data/r13/auto.dta",convert.factors=F)
Map(identical,r12,r13)
Marvin Garbuszus (JanMarvin) and Sebastian Jeworutzki (both Ruhr-Universität Bochum)
GPL2