read.dta {foreign}R Documentation

Read Stata binary files

Description

Reads a file in Stata version 5-7 or 7/SE 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)

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.

Value

a data frame

Author(s)

Thomas Lumley

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

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

[Package Contents]