write.dta package:foreign R Documentation _W_r_i_t_e _F_i_l_e_s _i_n _S_t_a_t_a _B_i_n_a_r_y _F_o_r_m_a_t _D_e_s_c_r_i_p_t_i_o_n: Writes the data frame to file in the Stata binary format. Does not write array variables unless they can be 'drop'-ed to a vector. _U_s_a_g_e: write.dta(dataframe, file, version = 7L, convert.dates = TRUE, tz = "GMT", convert.factors = c("labels", "string", "numeric", "codes")) _A_r_g_u_m_e_n_t_s: dataframe: a data frame. file: character string giving filename. version: integer: Stata version: 6, 7, 8 and 10 are supported, and 9 is mapped to 8. convert.dates: Convert 'Date' and 'POSIXt' objects to Stata dates? tz: timezone for date conversion convert.factors: how to handle factors _D_e_t_a_i_l_s: The major differences between file formats in Stata versions is that version 7.0 and later allow 32-character variable names (5 and 6 were restricted to 8-character name). The 'abbreviate' function is used to trim long variables to the permitted length. A warning is given if this is needed and it 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. Unless deselected, R date and date-time objects ('POSIXt' classes) are converted into the Stata format. For date-time objects this may lose information - Stata dates are in days since 1960-1-1. 'POSIXct' objects can be written without conversion but will not be understood as dates by Stata; 'POSIXlt' objects cannot be written without conversion. There are four options for handling factors. The default is to use Stata 'value labels' for the factor levels. With 'convert.factors="string"', the factor levels are written as strings. With 'convert.factors="numeric"' the numeric values of the levels are written, or 'NA' if they cannot be coerced to numeric. Finally, 'convert.factors="codes"' writes the underlying integer codes of the factors. This last used to be the only available method and is provided largely for backwards compatibility. For Stata 8 or later use the default 'version=7' - the only advantage of Stata 8 format is that it can represent multiple different missing value types, and R doesn't have them. Stata 10 allows longer format lists, but R does not make use of them. Note that the Stata formats are documented to be use ASCII strings - R does not enforce this, but use of non-ASCII character strings will not be portable as the encoding is not recorded. Stata uses some large numerical values to represent missing values. This function does not currently check, and hence integers greater than '2147483620' and doubles greater than '8.988e+307' may be misinterpreted by Stata. _V_a_l_u_e: 'NULL' _A_u_t_h_o_r(_s): Thomas Lumley _R_e_f_e_r_e_n_c_e_s: Stata 6.0 Users Manual, Stata 7.0 Programming manual, Stata 8.0, 9.0 online help describe the file formats. _S_e_e _A_l_s_o: 'read.dta', 'attributes', 'DateTimeClasses', 'abbreviate' _E_x_a_m_p_l_e_s: write.dta(swiss, swissfile <- tempfile()) read.dta(swissfile)