2

I'm trying to combine a set of "select-all-that-apply" variables into one variable from a dataset downloaded from Qualtrics.

As it stands, Qualtrics creates a variable for each possible choice, assigning a "1" if a respondent selected it and a "." for missing if a respondent didn't select it.

In this particular instance (racial categories), I just duplicated each variable, assigned a unique number to each variable for a "selected," (e.g., white selected value of 1 converted to 100), and then added all the duplicated variables together into a new variable. This gave each case a unique number that may or may not have represented multiple racial categories.

So the new labels for a respondent who checked multiple answer choices looked something like "White AND Asian," instead of a "1" in each of those individual variables, for example.

I was thinking, though, that there's probably an easier way to do this?

EDIT: Syntax included below.

Recode into race variable with unique value for each selection

RECODE w1srace_1 (1=1) (ELSE=Copy) INTO r2w1srace_1.
VARIABLE LABELS  r2w1srace_2 'recoded to higher values'.
EXECUTE.

RECODE w1srace_2 (1=5) (ELSE=Copy) INTO r2w1srace_2.
VARIABLE LABELS  r2w1srace_2 'recoded to higher values'.
EXECUTE.

RECODE w1srace_3 (1=10) (ELSE=Copy) INTO r2w1srace_3.
VARIABLE LABELS  r2w1srace_3 'recoded to higher values'.
EXECUTE.

RECODE w1srace_4 (1=20) (ELSE=Copy) INTO r2w1srace_4.
VARIABLE LABELS  r2w1srace_4 'recoded to higher values'.
EXECUTE.

RECODE w1srace_5 (1=50) (ELSE=Copy) INTO r2w1srace_5.
VARIABLE LABELS  r2w1srace_5 'recoded to higher values'.
EXECUTE.

RECODE w1srace_6 (1=100) (ELSE=Copy) INTO r2w1srace_6.
VARIABLE LABELS  r2w1srace_6 'recoded to higher values'.
EXECUTE.

RECODE w1srace_7 (1=200) (ELSE=Copy) INTO r2w1srace_7.
VARIABLE LABELS  r2w1srace_7 'recoded to higher values'.
EXECUTE.

RECODE w1srace_8 (1=500) (ELSE=Copy) INTO r2w1srace_8.
VARIABLE LABELS  r2w1srace_8 'recoded to higher values'.
EXECUTE.

**Create new combined race variable**

COMPUTE r3w1srace=sum(r2w1srace_1,r2w1srace_2,r2w1srace_3,r2w1srace_4,r2w1srace_5,r2w1srace_6,r2w1srace_7,r2w1srace_8).
EXECUTE.
eli-k
  • 10,898
  • 11
  • 40
  • 44
  • Please add your present syntax to the question so we can better understand what you've already done and where we can suggest improvements. – eli-k Jul 16 '18 at 05:42
  • I just included the syntax--thanks for your response! Looks like we did something similar. – Eric Williamson Jul 16 '18 at 13:12
  • Right. The advantage of my suggested syntax (apart from using only one line of course) is that you can interpret the result visually, being a combination of zeros and ones corresponding to the original eight variables – eli-k Jul 16 '18 at 13:19

2 Answers2

1

First run this to create some sample data to play with:

data list list/dog cat mouse frog bird (5f1).
begin data
1 0 0 1 0
0 1 0 1 0
0 0 0 1 1
0 1 0 0 0
1 1 1 1 1 
1 0 1 0 1
0 0 0 0 0
end data.

A simple way to combine all the categories into one number:

compute mult_categoryN = 10000*dog + 1000*cat +100*mouse +10*frog + bird.

To create a text variable that will have a unique name for every combination of categories you can go this way:

string mult_categoryT (a50).
compute #=0.
do repeat vr=dog cat mouse frog bird/ct="dog" "cat" "mouse" "frog" "bird".
    do if vr=1.
        if #=0 mult_categoryT=ct.
        if #>0 mult_categoryT=concat(rtrim(mult_categoryT), " and ", ct).
        compute #=#+1.
    end if.
end repeat.
exe.
eli-k
  • 10,898
  • 11
  • 40
  • 44
  • Thanks for this--if I wanted, can I make this a numeric (nominal) variable? Also, what does "ct" indicate here? – Eric Williamson Jul 16 '18 at 13:19
  • The first option I gave (`mult_categoryN`) is for a nominal numeric variable. Re ct - it is an element in the loop: `vr` represents the variable names, `ct` represents the actual category names (in your case they should be "white", "asian" etc'). – eli-k Jul 16 '18 at 13:29
0

It is probably too late now, but the easy way would have been to create an embedded variable in the Qualtrics survey flow and assigned it the value of the question’s selected choices. It would have given you a comma separated list of the text choices.

Something to keep in mind for future surveys.

T. Gibbons
  • 4,919
  • 2
  • 15
  • 32