-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
write_sav() fails to set missing values #596
Comments
HI @dusadrian, This appears to be an issue in readstat - it supports writing missing values for doubles, but not for integers. In the mean time, as a work around you can convert to numeric before making it a labelled vector: library(haven)
library(tibble)
test <- tibble(A = labelled_spss(as.numeric(1:10), c(Good = 1, Bad = 8, DK = 9, NR = 10), na_values = c(9, 10)))
test$A
#> <labelled_spss<double>[10]>
#> [1] 1 2 3 4 5 6 7 8 9 10
#> Missing values: 9, 10
#>
#> Labels:
#> value label
#> 1 Good
#> 8 Bad
#> 9 DK
#> 10 NR
write_sav(test, "test.sav")
testback <- read_sav("test.sav", user_na = TRUE)
testback$A
#> <labelled_spss<double>[10]>
#> [1] 1 2 3 4 5 6 7 8 9 10
#> Missing values: 9, 10
#>
#> Labels:
#> value label
#> 1 Good
#> 8 Bad
#> 9 DK
#> 10 NR Created on 2021-08-04 by the reprex package (v2.0.0) |
Thanks @gorcha, that is a good workaround in the meantime. And hopefully, it will be solved in ReadStat soon. |
Hi @dusadrian - sorry, to clarify I think this issue should stay open in haven. This change will still need to be made in haven, it just needs to be implemented in readstat first 🙂 |
Oh, I see. Alright then, I am reopening it to make sure it will be solved at some point. |
Information about missing values is lost, roundtrip reprex below
The text was updated successfully, but these errors were encountered: