Skip to content

Variable character length limit for Stata not respected by write_dta #485

@JackLandry

Description

@JackLandry

Stata has a variable length limit of 32 characters. However, you can export data with variable names over 32 characters from R using write_dta. The result will successfully read into Stata, but you can't perform any operations on the variable or even rename it to something shorter. It's virtually inoperable. Therefore, I think a good addition to haven would be to give an error when exporting dataframes that include variable names with more than 32 characters, or at least a warning to shorten the variable names. Quick example below, including the Stata code that causes errors.

library(haven)
test <- data.frame("a_variable_name_with_too_many_characters" = 1)
write_dta(test, "test.dta")

##Stata code below 
use "test.dta", clear
tab a_variable_name_with_too_many_characters
ren a_variable_name_with_too_many_characters shorter_varname

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions