Read Stata 13 File in R

Read Stata 13 file in R

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.

Reading Stata 14 file in R

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.

Problems when importing factor variables from Stata using readstata13 package

It seems the problem is that the package readstata13 recreates factor values in R, without keeping the order of those in Stata.

The "solution" was to not import levels from Stata. This can be achieved using the convert.factors = FALSE option. Although not an optimal solution, it works for me because I do not need factor levels in the first place. I raised an issue in the package's website to see potential solutions.

How to load subset of dta/Stata file with R

I haven't tested it myself, but the latest version of the readstata13 package seems to allow for subsetting on both columns and rows:

read.dta13(file, convert.factors = TRUE, 
generate.factors = FALSE, encoding = "UTF-8",
fromEncoding = NULL, convert.underscore = FALSE,
missing.type = FALSE, convert.dates = TRUE,
replace.strl = TRUE, add.rownames = FALSE,
nonint.factors = FALSE, select.rows = NULL,
select.cols = NULL, strlexport = FALSE,
strlpath = ".")

How to treat encoding when reading .dta-files into R from Stata-files prior to version 14?

The correct encoding to read files generated by Stata prior to version 14 on Macs is "macroman"

df <- read.dta13('example.stata13.dta', fromEncoding="macroman")

On my Mac, both .dta-files in stata13 and stata12 formats (saved by saveold in Stata 13) imported nicely like this.

Supposedly, the manual of read_stata13, correctly assumes "CP1252" on other platforms. To me, "macroman", however, did the trick, (also for the .csv-files that Stata 13 generated with export delimited).



Related Topics



Leave a reply



Submit