Closed khanhhtt closed 2 years ago
Hi @khanhhtt, the correct class for labelled vectors in haven is haven_labelled
. Some other packages (e.g. expss, Hmisc) have a labelled
class. The haven class was originally called labelled
, but this was changed to haven_labelled
in version 2.0.0 to avoid conflicts with other packages.
It looks like the sample code above is coming from expss - expss uses a different class to store value and variable labels so it doesn't play nicely with haven. The correct way to create a labelled vectors in haven is to use the labelled()
function. For easier manipulation of attributes the labelled package provides helper functions (for e.g. val_labels()
, var_labels()
) similar to the functions from expss used in your example above that are built to work with haven.
Hi team, I have read the information on another thread (#21) that the function "write_sav" will work for factors or labelled class. But when I tested on the data with labelled class, the datafile output is missing value label. When I change the class to _havenlabelled, the the value label is written successfully on the output file.
Please see below my test. I also enclose the output files for your reference. Thank you in advance for looking into this.
TEST.zip