-
Notifications
You must be signed in to change notification settings - Fork 116
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
read_dta: import value labels for labeled negative values #367
Comments
We're currently having trouble with saving negative value labels in sjlabelled, which relies on havens functions for reading and writing. But we're not 100% sure whether this is the same problem (see strengejacke/sjlabelled#7). Maybe @hadley has an idea. |
In my example constructing a data set and saving with |
This comment has been minimized.
This comment has been minimized.
library(haven)
x1 <- labelled(-1:3, c(Good = -1, Bad = 3))
tmp <- tempfile()
write_dta(data.frame(x1), tmp, version = 14)
x2 <- read_dta(tmp)$x1
x1
#> <Labelled integer>
#> [1] -1 0 1 2 3
#>
#> Labels:
#> value label
#> -1 Good
#> 3 Bad
x2
#> <Labelled double>
#> [1] -1 0 1 2 3
#>
#> Labels:
#> value label
#> NA(z) Good
#> 3 Bad Created on 2018-06-20 by the reprex package (v0.2.0). |
@evanmiller I think this is a readstat issue — |
A signed/unsigned comparison caused negative values to be tagged as missing. Fixes tidyverse/haven#367
Fix: WizardMac/ReadStat@42c5212 Test: WizardMac/ReadStat@68d7a59 Looks like there was a problem with signed/unsigned comparisons. The fix involved ripping out code, which I am always happy about. |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
Example:
Here the result of
as_factor(df)
contains a rowGood 7
, while the corresponding row ofas_factor(df1)
is-1 7.00
.The produced Stata file is correct:
The text was updated successfully, but these errors were encountered: