I am trying to export my data table from R Studio to the dta format. I use write_dta function from haven library in R and get the following error:
A provided string value was longer than the available storage size of the specified column.
I am quite new to R and Stata and don't understand what it means and what should I do about it.
It sounds like you have a piece of long text in your data.frame. The
write_dtahas known issues handling long strings (https://github.com/tidyverse/haven/issues/437). You can trim the strings in your data.frame like this:And then try
write_dta(df). The max length of 128 characters should be safe, but newer versions of Stata can handle a lot more.