Read Stata 13 file in R

Is there any way to read the Stata version 13 dataset file in R?

I tried to do the following:

> library(foreign) > data = read.dta("TEAdataSTATA.dta") 

However, I got the error:

Error in read.dta ("TEAdataSTATA.dta"):
not a Stata file version 5-12.dta

Can someone point out if there is a way to fix this?

+48
r stata
May 27 '14 at 21:10
source share
6 answers

If you have Stata 13, you can download it there and save it as a Stata 12 format using the saveold (see help saveold ). Then pass it to R.

If you have Stata 10 - 12, you can use the use13 user command (Sergey Radyakin) to load it and save it there; then in R. You can install use13 running ssc install use13 .

Details can be found at http://radyakin.org/transfer/use13/use13.htm

Other alternatives still containing Stata include exporting the Stata format to something else that R will read, for example. text files. See help export in Stata.

Update

Starting Stata 14, saveold has a version() parameter that allows you to save in Stata.dta formats as old as Stata 11.

+13
May 27 '14 at 21:24
source share

There is a new package for importing Stata 13 files into data.frame file in R.

Install the package and read the Stata 13 dataset using 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 details about the package: https://github.com/sjewo/readstata13

+85
Sep 24 '14 at 13:32
source share

Hadley Wickham's new Haven package that can download 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

+27
Feb 10 '15 at 15:34
source share

Meanwhile, the savespss team has become a member of the SSC archive and can be installed in Stata with: findit savespss

The home page http://www.radyakin.org/transfer/savespss/savespss.htm continues to work, but now the program should be installed from SSC, and not from the beta version.

+6
Nov 22 '14 at 5:37
source share

I have the same problem. I tried read.dta13 , read.dta but nothing read.dta . Then I tried the simplest and least expected: MS Excel! It opened wonderfully. I saved it as .csv and used it in R !!! Hope this helps !!!!

+2
Aug 10 '17 at 6:14
source share

I am not familiar with the current state of R programs regarding their ability to read files of other formats, but if someone does not have Stata installed on their computer and R cannot read a specific version of Stata dta files, Pandas in Python can now perform the vast majority of such conversions.

Basically, data from a dta file dta first loaded using the pandas.read_stata function. Starting with version 0.23.0 , the supported encoding and formats can be found in the answer related to my .

Then you can save the data as a csv file and import it. using the standard R functions, or instead use the pandas.DataFrame.to_feather function, which exports data using a serialization format built on Apache Arrow. The latter has extensive support in R since it was conceived to allow interaction with Pandas .

+1
May 23 '18 at 12:58
source share



All Articles