Currently, when I export the results of my Qualtrics survey, the output file contains one row per unique survey taken (which in this context corresponds to one row per person). Each question in the survey appears as a new column on that row.
However, to do the statistical analysis I need in R or Pandas, I need a dataframe with one row per observation. In other words, a file where each response to each question is on a separate row, with the participant ID, question number, etc recorded in separate rows.
Visually:
Current Qualtrix export
SubjectID | Condition | Q1 | Q2 | ...
14 | A | Yes | No | ...
26 | B | No | No | ...
What I need:
SubjectID | Condition | Q.Number | Q.Response
14 | A | 1 | Yes
14 | A | 2 | No
26 | B | 1 | No
26 | B | 2 | No
Does anyone know how to export data in this format or any automated tools to assist that process?
You'll have to convert this wide data to the long format on your own.
I think dplyr in R has a function called gather, which could help with this. However, you won't find any pre existing solutions.
Hi alioudosdiallo !
This code below should work! I've added in some data cleaning as well, which you can ignore if you'd like! This code works when the data is exactly as you laid out.
library(dplyr)
library(tidyr)
qual_pivot <- function(qualtrics){
q <-
#Once Run you can select a file
read.csv(file.choose())
qual_c <-
qual %>%
# Remove Annoying Two Rows
filter(Finished == "TRUE") %>%
# Remove 'Unneeded' Columns
select(!StartDate:Duration..in.seconds.) %>%
select(!Finished:UserLanguage) %>%
# flag empty condition rows
mutate_all(na_if,"")
# Subset Conditions A
qual_a <-
qual_c %>%
# Get Only A Conditions
filter(Condition == "A") %>%
# Remove Duplicates
select(!Q1.1:Q2.1)
# Subset Conditions B
qual_b <-
qual_c %>%
# Get Only B Conditions
filter(Condition == "B") %>%
# Remove Duplicates
select(!Q1:Q2) %>%
# Rename Columns
dplyr::rename(Q1 = Q1.1,
Q2 = Q2.1)
# Combine and Pivot
qual_full <-
# Combine
bind_rows(qual_a,qual_b) %>%
# Combine the Questions
# Changes Values to Q.Response
# Change Question number to Q.Number
pivot_longer(cols = starts_with("Q"),
values_to = "Q.Response",
names_to = "Q.Number")
}
# Make sure to assign to something! Ex. data <- qual_pivot()
qual_pivot()
Starting with this:
The data will look like this:
Hope this helps!
Wow, excellent! Thank you DavidBrocker! This helps a lot!
https://community.qualtrics.com/XMcommunity/discussion/comment/45669#Comment_45669You're welcome! If this ends up working out for you, could you mark this as the answer?
This is a late response, but as an FYI for others, if you use R, the packages qualtRics and excluder are extremely useful to deal with some of the data cleaning steps, as well as recoding or not recoding answers.
qualtRics is definitely the way to go. You can pretty easily remove the labels in rows 2 and 3 above. Heck, you download your survey and run t-tests, logistical regressions, etc., in the same script if you wanted.
I made a video about this on YouTube since I didn’t see any others. It’s mostly catered to noobs, so I didn’t go into a lot of detail (I may in future videos if the video does well). I mostly cover how to get the key info from the Qualtrics API and how to put it into R so you can export it. A link to my code is provided in the video description.
Python has a good module that connects to the Qualtrics API too.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.