Rev 91 | Rev 4680 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{write.dta}\alias{write.dta}\title{Write Files in Stata Binary Format}\usage{write.dta(dataframe, file, version = 6,convert.dates = TRUE, tz = "GMT",convert.factors = c("labels", "string", "numeric", "codes"))}\arguments{\item{dataframe}{a data frame.}\item{file}{character string giving filename.}\item{version}{Stata version: 6 and 7 are supported.}\item{convert.dates}{Convert \code{POSIXt} objects to Stata dates?}\item{tz}{timezone for date conversion}\item{convert.factors}{how to handle factors}}\description{Writes the data frame to file in the Stata version 6.0 or 7.0 binaryformat. Does not write matrix variables.}\details{The major differences between Stata versions is that 7.0 allows 32-charactervariable names. The \code{abbreviate} function is used to trim longvariables to the permitted length. A warning is given if this is needed andit is an error for the abbreviated names not to be unique.The columns in the data frame become variables in the Stata data set.Missing values are correctly handled. Optionally, R date/time objects(\code{POSIXt} classes) are converted into the Stata format. This losesinformation -- Stata dates are in days since 1960-1-1. \code{POSIXct}objects can be written without conversion but will not be understood asdates by Stata; \code{POSIXlt} objects cannot be written withoutconversion.There are four options for handling factors. The default is to useStata \code{value labels} for the factor levels.With \code{convert.factors="string"}, the factor levels are written asstrings. With \code{convert.factors="numeric"} the numeric valuesof the levels are written, or \code{NA} if they cannot be coerced tonumeric. Finally, \code{convert.factors="codes"} writes the underlyinginteger codes of the factors. This last used to be the only availablemethod and is provided largely for backwards compatibility.For Stata 8.0 use \code{version=7} -- the only advantage of Stata 8.0format is that it can represent multiple different missing valuetypes, and R doesn't have them.}\value{\code{NULL}}\references{Stata 6.0 Users Manual, Stata 7.0 Programming manual, Stata 8.0 onlinehelp describe the file formats.}\author{Thomas Lumley}\seealso{\code{\link{read.dta}},\code{\link{attributes}},\code{\link{DateTimeClasses}},\code{\link{abbreviate}}}\examples{write.dta(swiss, swissfile <- tempfile())read.dta(swissfile)}\keyword{file}