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

SPSS fails to read value labels for ordered factors #285

Closed
gitrman opened this Issue Apr 24, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@gitrman
Copy link

gitrman commented Apr 24, 2017

SPSS is unable to read value labels for ordered factors -- whereas unordered factors are fine.

A minimal example:

x <- c("a", "b", "c")

df <- data.frame(
  v1 = factor(x),
  v2 = factor(x, ordered = TRUE)
)

library(haven)
write_sav(df, "df.sav")

Here is a screenshot of the SPSS Data View tab after I open the file in SPSS:

data_view

v1 and v2 should look identical - however for v2 the numeric values rather than the factor labels are displayed.

On the SPSS Variable View tab, for the unordered factor v1, SPSS correctly displays the measure type as Nominal and the value labels are listed correctly in the Values column. Whereas for the ordered factor v2, SPSS displays the correct measure type (Ordinal), but the value labels have been erroneously set to "None".

variable_view

I am using the development version of Haven from github (haven_1.0.0.9000), Windows 10, and SPSS 22. I have also experienced this error on machines running Windows 7 and earlier versions of Haven.

@jeroen

This comment has been minimized.

Copy link
Contributor

jeroen commented May 24, 2017

I ran into the same problem when trying to roundtrip the diamonds dataset:

> tmp <- tempfile()
> haven::write_sav(ggplot2::diamonds, tmp)
> diamonds <- haven::read_sav(tmp)
> head(diamonds)
# A tibble: 6 × 10
  carat   cut color clarity depth table price     x     y     z
  <dbl> <dbl> <dbl>   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1  0.23     5     2       2  61.5    55   326  3.95  3.98  2.43
2  0.21     4     2       3  59.8    61   326  3.89  3.84  2.31
3  0.23     2     2       5  56.9    65   327  4.05  4.07  2.31
4  0.29     4     6       4  62.4    58   334  4.20  4.23  2.63
5  0.31     2     7       2  63.3    58   335  4.34  4.35  2.75
6  0.24     3     7       6  62.8    57   336  3.94  3.96  2.48

This same problem appears for write_sav, write_sas and write_dta.

@hadley hadley closed this in f210dc9 May 25, 2017

@lock lock bot locked and limited conversation to collaborators Jun 26, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.