SAVE2RDA - Stata module to export data to R

SAVE2RDA - export Stata datasets to R

by Sergiy Radyakin

This program exports data from Stata to R by saving it into an R-workspace. An R-workspace file can be opened directly in the R statistical package. To the extent possible, attributes of the dataset are saved as well: variable and value labels, and variable types.

If you need to transfer data to SPSS, another freely available Stata command savespss may be useful: it produces SPSS binary file directly.

Features

save2rda attempts to preserve all features that are present in the data, including labels and missing values. The following is the list of supported features:

  • variable labels
  • value labels
  • missing values (extended missing values are converted to the system missing value)
  • variable types (numeric or string only)

The following is the list of not supported features:

  • variable formats
  • dataset timestamp
  • dataset sort order
  • variable characteristics (expansion fields)
  • dataset characteristics (expansion fields)

Installation

This is a beta! Be careful!

Stata 14.0 is required. To install, execute the following Stata command while connected to the internet, then follow instructions:

  net from http://www.radyakin.org/transfer/save2rda/beta

After the installation is completed, close Stata and start a new Stata session.

Usage

  save2rda using "filename.rdata", name("mydata")
  save2rda using "filename.rdata", name("mydata") replace
  save2rda using "filename.rdata" if x>0 & y<100, name("mydata") replace
  save2rda using "filename.rdata" in 1/100, name("mydata") replace

Note that the name option defines the name of the data object. R programs will utilize this name to get access to the data this object contains. In most cases name corresponds to the file name (for example auto for auto.rdata), but it doesn't have to.

If option replace is specified the save2rda is permitted to replace the specified file.

save2rda does not imply file extension and requires quotes around the file name exactly as shown.

Mata version is available:

  mata rda_save("filename.rdata","name")

Author

save2rda was written by Sergiy Radyakin.


The program is supported via StataList.