Learn R Programming

foreign (version 0.4-8)

read.dta: Read Stata binary files

Description

Reads a file in Stata version 5-7 binary format into a dataframe.

Usage

read.dta(file, convert.dates=TRUE,tz="GMT",convert.factors=TRUE)

Arguments

file
a filename as a character string.
convert.dates
Convert Stata dates to POSIXct class?
tz
timezone for date conversion
convert.factors
Use Stata value labels to create factors? (version 6.0 or later)

Value

  • a data frame

Details

The variables in the Stata data set become the columns of the data frame. Missing values are correctly handled. The data label, variable labels, and timestamp are stored as attributes of the data frame. Nothing is done with variable characteristics.

Optionally, Stata dates (%d formats) are converted to R's POSIXct class and variables with Stata value labels are converted to factors. In any case the value label and format information is stored as attributes on the returned data frame.

References

Stata Users Manual (versions 5 & 6) and Programming manual (version 7) describe the format of the files

See Also

write.dta, attributes DateTimeClasses factor

Examples

Run this code
data(swiss)
write.dta(swiss,swissfile<-tempfile())
read.dta(swissfile)

Run the code above in your browser using DataLab