Description Usage Arguments Examples
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.
1 | write.Stata(df, codefile, datafile)
|
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. |
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()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.