Learn R Programming

misty (version 0.6.7)

write.dta: Write Stata DTA File

Description

This function writes a data frame or matrix into a Stata data file.

Usage

write.dta(x, file = "Stata_Data.dta", version = 14, label = NULL,
          str.thres = 2045, adjust.tz = TRUE, check = TRUE)

Arguments

x

a matrix or data frame to be written in Stata, vectors are coerced to a data frame.

file

a character string naming a file with or without file extension '.dta', e.g., "Stata_Data.dta" or "Stata_Data".

version

Stats file version to use. Supports versions 8-15.

label

dataset label to use, or NULL. Defaults to the value stored in the "label" attribute pf data. Must be <= 80 characters.

str.thres

any character vector with a maximum length greater than str.thre bytes wil be stored as a long string strL instead of a standard string str variable if version is greater or equal 13.

adjust.tz

this argument controls how the timezone of date-time values is treated when writing, see 'Details' in the in the write_dta function in the havan package.

check

logical: if TRUE (default), variable attributes specified in the argument var.attr is checked.

Author

Hadley Wickham, Evan Miller and Danny Smith

References

Wickham H, Miller E, Smith D (2023). haven: Import and Export 'SPSS', 'Stata' and 'SAS' Files. R package version 2.5.3. https://CRAN.R-project.org/package=haven

See Also

read.dta, write.sav, write.mplus, write.xlsx

Examples

Run this code
if (FALSE) {

# Example 1: Write data frame 'mtcars' into the State data file 'mtcars.dta'
write.dta(mtcars, "mtcars.dta")
}

Run the code above in your browser using DataLab