Skip to content
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

Dates in labelled_spss #742

Open
greenhorn82 opened this issue Nov 22, 2023 · 3 comments
Open

Dates in labelled_spss #742

greenhorn82 opened this issue Nov 22, 2023 · 3 comments
Labels
bug an unexpected problem or unintended behavior documentation

Comments

@greenhorn82
Copy link

Hi,

when using labelled_spss with date columns it converts all columns to numeric and exports them incorrectly. Without adding a label write_sav can correctly export dates.

Robert

# Haven Bug-report 
rm(list = ls())
library(haven)

data_example <- data.frame(example_date1 = lubridate::ymd(20101215))
data_example$example_date2 <- labelled_spss(data_example$example_date1,
                                            label = "testlabel")
haven::write_sav(data_example, "example.sav")

@dusadrian
Copy link

I would like to second this issue.
Date/Time variables can also have missing values, as well as value labels (for those missing values, for instance).
It would be great to export .sav files for more than just character and numeric variables.

@gorcha gorcha added bug an unexpected problem or unintended behavior feature a feature request or enhancement and removed bug an unexpected problem or unintended behavior feature a feature request or enhancement labels Jan 31, 2024
@gorcha
Copy link
Member

gorcha commented Jan 31, 2024

Hi @greenhorn82,

The labelled() and labelled_spss() functions don't currently support date variables, and running these functions without specifiny a set of value labels still runs them through the rest of the preparation/validation code which forces a conversion to numeric. Will make a note to update the documentation/checks to make this clearer.

Adding a variable label only requires the addition of a "label" attribute - I'd recommend checking out the labelled package, which has a set of helper functions to make this easier where creating a full labelled vector is not required. For e.g.:

library(haven)
library(labelled)

data_example <- data.frame(example_date1 = lubridate::ymd(20101215))
var_label(data_example$example_date1) <- "testlabel"
write_sav(data_example, "example.sav")

@dusadrian
Copy link

We know these function don't currently support date variables. I would just be great to add this functionality, especially since a software like Stata does support value labels for date variables.

This makes conversion from Stata incomplete, and exporting to SPSS likewise.

Library declared does support value labels for date/time variables (in R) but since haven is responsible with the import / export, that would be a greatly appreciated feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior documentation
Projects
None yet
Development

No branches or pull requests

3 participants