Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Stata 14 file in R

Tags:

r

stata

I have tried a thousand different times to read a Stata14 file on R, and for some reason I keep getting weird things happening (like variables dropped and such.)

The original file is saved in Stata 13 or 14, so the read.dta() command does not work. I also tried read.dta13() and it reads it sometimes but it cuts off the database at a certain spot and does not give me all the variables contained in the data set (which I can see and work with perfectly on Stata). The original file can be found here and scrolling down to Uruguay.

Anyone got any ideas on how to fix this issue? I am tired of arguing with R to read my Stata file correctly, when it works perfectly in Stata.

like image 714
rowbust Avatar asked Feb 20 '16 04:02

rowbust


People also ask

How do I open Stata files in R?

To open a Stata file in R you can use the read_dta() function from the library called haven. For example, study_df <- read_dta('study_data. dta') will open the Stata file called "study_data.

What package is read DTA in R?

Package to read and write all Stata file formats (version 17 and older) into a R data. frame. The dta file format versions 102 to 119 are supported.


2 Answers

I know this is an old thread but every time I google "read stata 14 with R" I come to this unresolved answer.

Community on SO have answered this: Read Stata 13 file in R

As of today, there is a CRAN package to read stata 13 and 14 using this:

install.packages("readstata13")

library(readstata13)
dat <- read.dta13("myStataFile.dta")

I hope you find this useful.

like image 139
StrayChild01 Avatar answered Sep 27 '22 17:09

StrayChild01


Have a look at Hadley's haven package (CRAN, github). It:

Works with Stata 13 and 14 files (foreign only works up to Stata 12).

Can also write SPSS and Stata files (This is hard to test so if you run into any problems, please let me know).

Once installed you simply:

read_dta("path/to/file")
like image 20
radek Avatar answered Sep 27 '22 16:09

radek