Introduction
Surveys often contain questions where people are asked to choose one option first, then another item, and then a third item, etc (e.g., brand preferences).
Within Q, there are a number of different ways of analyzing such data:
- By setting the question as a Pick One - Multi question, it is possible to see the number of people to choose each item as first, second, third, etc.
- By setting a question as a Pick Any - Compact question, Q will count up the proportion of people who chose each item at least once, automatically removing any duplicates.
- If the data is stored in a format where there is one variable per item, and the data indicates what order it was chosen (i.e., its ranking), there are further methods (see How to Analyze Ranking Data).
Sometimes it is useful to display this data as a Pick One - Multi question, but to also remove duplicates, so that the numbers add up to the numbers in a Pick Any - Compact question. This process is described below:
Requirements
A Q project with Pick One - Multi and/or Pick 'Any - Compact questions.
Method - R
- On the Variables and Questions tab, right click and select Insert Variable(s) > R Variable.
-
Paste in the following code - modified for your need:
#EDIT the Rank name below to your Pick One-Multi Label in backticks
df = `Rank`
#apply the duplicated function on each row (1 below)
#transform the results to match the shape of the data
#set duplicated responses to NA (missing)
df[t(apply(df,1,duplicated))]=NA
#return final variable set
df - Press play to run the code.
- Give it a sensible Question Name.
- Click Add R Variable.
- Change Question Type > Pick One-Multi.
Method - JavaScript
To remove duplicates, you need to create a new JavaScript variable for each and replace their code with new logic :
- Select the question in the Variables and Questions tab.
- Right-click and select Copy and Paste Question(s) > Linked (this will create a new JavaScript variable for each in the question).
- Right-click on the second variable, and select Edit Variable, and in the Expression box replace its contents with if (v1_L == v2) 999; else v2, where v1 and v2 are the Variable Names of the original two variables in the question, and v1_L will be the Variable Name of the first variable in the linked question that was created in the previous step. Press OK.
- Right-click on the third variable, select Edit Variable, and in the Expression box replace its contents with if (v1_L == v3 || v2_L == v3) 999; else v3.
- Repeat the above process, modifying the Expression as required if there are any additional variables.
Note that the 999 is necessary as if instead it is set as a missing value, the numbers on the table will not add up to the numbers from a Pick Any - Compact question, due to the percentages in the new question having different base sizes for each variable.
NEXT
How to Handle Duplicate Cases in Survey Data
How To Delete Duplicate Cases in a .sav
How to De-duplicate Raw Data Using R
How to Identify Duplicates in Q Using Code