Is there a way to read a Stata version 13 dataset file in R?
I have tried to do the following:
> library(foreign) > data = read.dta("TEAdataSTATA.dta")
However, I got an error:
Error in read.dta("TEAdataSTATA.dta") :
not a Stata version 5-12 .dta file
Could someone point out if there is a way to fix this?
To import SPSS, Stata, or SAS data files in R, first install and load the package foreign . The functions read. spss() , read. dta() , and read.
The answer is “yes!, R can read Stata (. dta) files. This is easy to do with the Haven package. First, load the package: library(haven) .
Select File > Open... or click on the Open button and navigate to the file. Select File > Recent Datasets > filename. Type use filename in the Command window. Stata will look for filename in the current working directory.
Description. The Stata_dta format (with extension . dta) is a proprietary binary format designed for use as the native format for datasets with Stata, a system for statistics and data analysis. Stata 1.0 was released in 1985 for the IBM PC. Stata is now available for Windows, Mac OS, and Unix.
There is a new package to import Stata 13 files into a data.frame in R.
Install the package and read a Stata 13 dataset with read.dta13():
install.packages("readstata13") library(readstata13) dat <- read.dta13("TEAdataSTATA.dta")
Update: readstata13 imports in version 0.8 also files from Stata 6 to 14
More about the package: https://github.com/sjewo/readstata13
There's a new package called Haven, by Hadley Wickham, which can load Stata 13 dta files (as well as SAS and SPSS files)
library(haven) # haven package now available on cran df <- read_dta('c:/somefile.dta')
See: https://github.com/hadley/haven
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With