Learn R Programming

haven (version 0.2.0)

read_dta: Read and write Stata DTA files.

Description

Currently haven can read and write logical, integer, numeric, character and factors. See labelled for how labelled variables in Stata are handled in R.

Usage

read_dta(path)
read_stata(path)
write_dta(data, path)

Arguments

path
Path to data. When reading data, if the path is a URL, the file will be first downloaded to a temporary location before reading.
data
Data frame to write.

Value

A data frame with additional "tbl_df" and "tbl" classes, which improve printing if dplyr is loaded.Variable labels are stored in the "label" attribute of each variable. It is not printed on the console, but the RStudio viewer will show it.

Examples

Run this code
tmp <- tempfile(fileext = ".dta")
write_dta(mtcars, tmp)
read_dta(tmp)
read_stata(tmp)

Run the code above in your browser using DataLab