write.Stata: Create .csv and Stata .do file

Description Usage Arguments Examples

View source: R/WriteStataDo.R

Description

This function creates a .csv file and a .do file from a dataframe in R to read into Stata.The data object in R should have variable labels specified in the attribute "variable.labels" and value labels in a list attribute "value labels", with both attributes having the same length as the number of variables in the data frame. As a compatibility check for Stata, any periods (".") in variable names will be replaced with underscores ("_"), all NA values will be replaced with the standard missing value in Stata ("."), and all variables will be cohersed to character to avoid factor conversion issues with Stata.

Usage

1
write.Stata(df, codefile, datafile)

Arguments

df

A dataframe

codefile

The file name of Stata .do file that will be written to read in the csv data and apply the variable and value labels.

datafile

The file name of the .csv Data file that will be created.

Examples

1
2
iris #Create a Stata do file and csv for iris dataset; attr(iris, "variable.labels") = c("Length of Sepal in centimeters", "Width of Sepal in centimeters", "Length of petal in centimeters", "Width of Petal in centimeters", "Species of iris"); attr(iris, "value.labels") = c(rep("", ncol(iris))); write.Stata(iris, codefile="Irisreadin.do", datafile="Irisdata.csv")
DataDictionary()

ajhmohr/datadictionary documentation built on Aug. 23, 2021, 10 a.m.