mara
February 14, 2019, 11:47am
2
It seems you also posted this as an issue in the haven repo:
opened 06:22PM - 13 Feb 19 UTC
closed 01:54PM - 14 Feb 19 UTC
Good day,
I'm trying to export a labeled data set to SPSS and Stata using th… e Haven package. When I open the data in SPSS, the labels export correctly, however, the underlying values are recoded. For example, 0 is recoded to 1.
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")
```
Is there a way to for Haven to keep the original codes?
Thank you very much for your help.
André
This is fine, but we ask that you please link to the thread so others can follow it/we avoid duplication of effort if you get an answer over there. See our FAQ re. cross-posting below.
Thanks
Posting the same question both here and on other sites
Posting the same question to multiple forums at the same time is often considered impolite. We don't completely ban such cross-posting, but we ask you to think hard before you do it and to follow some rules.
Cross-post sparingly
Rather than post the same thing here and elsewhere from the get-go, post in one place at a time. Let enough time go by (think days, not hours) before you take your question somewhere else. Sometimes people at another site may suggest you post here if your question doesn't fit within the scope of the other site.
Always link to your other posts, and update everywhere with any solution…
1 Like