I imported a .dta (Stata file format) into R, but it looks like the variable labels did not get imported along with the variable names.
- Using
foreign::read.dta, I triedlabels(df), but that only gives me the variable names; andstr(df$var)is also is not telling me label. - Using a function from the
havenpackage,attributes(df$var)gives me levels and class, but not variable label.
Am I missing something here?
To see variable labels in R, it depends on how the Stata file is imported. Just using the
foreignpackage (commandread.dta) does not import variable labels.Use the
havenpackage to import the Stata file (read_dtacommand). Using theattributescommand viahavenpackage (@parfait) will give you format, class, and levels, in addition to variable label. However, if you only want to see the variable labels, then use thevar_labcommand from theexpsspackage.