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

Enable numeric responses with value labels from fetch_survey() #363

Open
JDenn0514 opened this issue Feb 13, 2025 · 1 comment
Open

Enable numeric responses with value labels from fetch_survey() #363

JDenn0514 opened this issue Feb 13, 2025 · 1 comment

Comments

@JDenn0514
Copy link

JDenn0514 commented Feb 13, 2025

I recently discovered this package and think it's awesome. However, there is one significant downside to using this compared to downloading the data directly from Qualtrics.

I tend to download my data via the SPSS option so that each variable has both the label and labels attributes. This makes it easy to convert numeric variables to factors via the labels attribute but also to calculate means with the numeric vector.

I have tried almost all of the arguments in fetch_survey() trying to get this but none of them add the labels attribute to the variables. Having the option of downloading the data where each variable has value labels (labels attribute) would be incredibly valuable.

While I'm not at all familiar with the API, I would assume that there I some way of accessing the data from Qualtrics in the SPSS style instead of csv.

Nevertheless, this how I'd like the data set up with value labels:

ideal_df <- data.frame(
  a = c(3, 4, 4, 4, 1, 2, 3, 1) %>% 
    structure(
      label = "Variable A as numeric with value labels",
      labels = c("Strongly agree" = 1, "Somewhat agree" = 2, "Somewhat disagree" = 3, "Strongly disagree" = 4)
    ),
  b = c(1, 1, 2, 2, 1, 3, 3, 4) %>% 
    structure(
      label = "Variable B as numeric with value labels",
      labels = c("Strongly agree" = 1, "Somewhat agree" = 2, "Somewhat disagree" = 3, "Strongly disagree" = 4)
    )
)

Now here are the kinds of data sets you get from fetch_survey()

# a data set that you get when the `label` argument is FALSE
label_TRUE <- data.frame(
  a = c("Somewhat disagree", "Strongly disagree", "Strongly disagree", "Strongly disagree", "Strongly agree", "Somewhat agree", "Somewhat disagree", "Strongly agree") %>% 
    structure(label = "Variable A as a character vector"),
  b = c("Strongly agree", "Strongly agree", "Somewhat agree", "Somewhat agree", "Strongly agree", "Somewhat disagree", "Somewhat disagree", "Strongly disagree") %>% 
    structure(label = "Variable b as a character vector")
)

# a data set that you get when the `label` argument is FALSE
label_FALSE <- data.frame(
  a = c(3, 4, 4, 4, 1, 2, 3, 1) %>% 
    structure(
      label = "Variable A as numeric without value label",
    ),
  b = c(1, 1, 2, 2, 1, 3, 3, 4) %>% 
    structure(
      label = "Variable B as numeric without value label",
    )
)
@nathanj3
Copy link

This should be possible. The Qualtrics API specifies that if useLabels is FALSE, which is the default, one can specify includeLabelColumns = TRUE to "export two columns: one that uses recode values and one that uses labels."

It would probably change the way the data is cleaned after the export, because you'd manually have to say that every column marked IsLabelColumn should be turned into labels for the corresponding non-labelled column, and it might make the download take a bit longer because there would be up to twice as many columns. But it should work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants