Good day,
I'm trying to export a labeled dataset to SPSS and Stata. When I open the data in SPSS, the labels export correctly, however, the underlying values are recoded. For example, 0 is recoded to 1. I've tried exporting the data with haven::write_dta()
and foreign::write.dta()
The result that I expect is
0 = "Never [0]"
1 = "Monthly or less [1]",
2 = "2 to 4 times a month [2]",
3 = "2 to 3 times a week [3]",
4 = "4 or more times a week [4]"
However, these are the values and labels I'm getting in SPSS for SPSS and Stata datasets.
1 = "Never [0]"
2 = "Monthly or less [1]",
3 = "2 to 4 times a month [2]",
4 = "2 to 3 times a week [3]",
5 = "4 or more times a week [4]"
Here is the R code I've used:
library(Hmisc)
audit$a_audit_1_1 = factor(audit$a_audit_1_1, levels = c(0, 1, 2, 3, 4))
levels(audit$a_audit_1_1) = c(
"Never [0]",
"Monthly or less [1]",
"2 to 4 times a month `[2]",
"2 to 3 times a week [3]",
"4 or more times a week [4]")
label(audit$a_audit_1_1)="How often do you..."
library(haven)
write_dta(audit, "audit.dta")
According to this introduction to variable labels and expss:
The usual way to connect numeric data to labels in R is in factor variables. However, factors miss important features which the value labels provide. Factors only allow for integers to be mapped to a text label, these integers have to be a count starting at 1 and every value need to be labelled. Also, we can’t calculate means or other numeric statistics on factors.
Is there a way to keep the original codes?
Thank you very much for your help.
André
Please note, I've also posted this question on the following forums: