Qualtrics wide to long export file conversion

While helping out with the implementation of a slightly tangled Qualtrics survey, I needed to develop some workarounds that might be of use to others – so I thought I’d share them with you here! The experimental design of this particular survey consisted of 3×6 conditions/factors, where each condition made use of a specific image. To make this work, I started out by adding some hidden questions with additional Javascript code which randomly assigned answers – where the answer(s) were used to represent different factors.These “factor answers” could then be build upon to retrieve the correct image in each and every condition. One example of such a question made use of the following hidden text entry question form:

With the following JS:

Another question made use of the default Qualtrics feature that enables it to pick one answer at random:

Again with some JS that automatically checks that one answer:

I was then able to retrieve the images through Qualtrics’ “piped text” functionality:

<img src="https://www.webserver.org/t/${lm://Field/1}/${q://QID1019/ChoiceTextEntryValue/1}.png" />

For this particular experiment, I additionally chose to make use of Qualtrics “Loop and Merge” feature, enabling me to make Qualtrics pick one of distinct permutation {1, 1, 2, 2, 3, 3} = 90 combinations following a previously randomly assigned answer:

We ran the survey, collected our data, and all seemed well. When we wanted to analyse the data we did run into one problem though: the resulting data file were extremely “wide”, as Qualtrics “Loop and Merge” functionality insists on adding one column for each “random loop option” x “question within the loop”. These additional columns not only result in unwieldy files, but it also breaks Qualtrics’ regular data export option. Luckily, we were still able to export our results by opting for Qualtrics “legacy” data format. Now we just needed to convert the impossibly wide files to a “long” format. Here, the following simple Python script was able to help out (feel free to adapt it to your needs!):

Feel free to adapt the script in case you ever need to convert a wide Qualtrics data file yourself!

Leave a Reply