Read Stata 13 file in R

匿名 (未验证) 提交于 2019-12-03 02:49:01

问题:

Is there a way to read a Stata 13 file in R?

I tried the following, and I got the following error:

> library(foreign) > data = read.dta("TEAdataSTATA.dta")  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?

回答1:

If you have Stata 13, then you can load it there and save it as a Stata 12 format using the command saveold (see help saveold). Afterwards, take it to R.

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

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

Other alternatives, still with Stata, involve exporting the Stata format to something else that R will read, e.g. text-based files. See help export within Stata.

Update

Starting Stata 14, saveold has a version() option, allowing one to save in Stata .dta formats as old as Stata 11.



回答2:

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 

Update: readstata13 imports in version 0.8 also files from Stata 6 to 14

More about the package: https://github.com/sjewo/readstata13



回答3:

There's a new package called Haven, by Hadley Wickham, which can load Stata 13 dta files (as well as SAS and SPSS files)

# install.packages("devtools") devtools::install_github("hadley/haven")  require(haven) df 

See: https://github.com/hadley/haven



回答4:

In the meanwhile savespss command became a member of the SSC archive and can be installed to Stata with: findit savespss

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



回答5:

I had the same problem. Tried read.dta13, read.dta but nothing worked. Then tried the easiest and least expected: MS Excel! It opened marvelously. I saved it as a .csv and used in R!!! Hope this helps!!!!



转载请标明出处:Read Stata 13 file in R
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!