``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72``` ```This technical note has a few approaches to creating dummy variables from a categorical variable. You can also find it as solution 100000500 on the SPSS AnswerNet at http://www.spss.com/tech/answer/index.cfm . David Matheson SPSS Technical Support Recoding a categorical SPSS variable into indicator (dummy) variables Q. What is the SPSS command to transform a nominal variable of n classification groups into a series of n-1 indicator (or "dummy") variables? A. Unfortunately, there is no single command to do this. There are several short command sequences that can do it and examples are provided below. Of these, the DO REPEAT approach is somewhat more general, or at least easier if the reference category is not the lowest value. * creating indicator variables. * all examples below generate indicators from a nominal variable, called cat, that is present in the active file. * create 4 indicator variables for categories 1 to 4 of a 5-category variable called cat. VECTOR nom(4). LOOP #i = 1 to 4. COMPUTE nom(#i) = (cat = #i). END LOOP. EXECUTE. * alternatively . * create 4 indicator variables for categories 2 to 5 of a 5-category variable called cat. VECTOR ind(4). LOOP #i = 1 to 4. COMPUTE ind(#i) = (cat = #i + 1). END LOOP. EXECUTE. * if you wanted to make the first category the reference category (0 on all indicator vars) with var names reflecting the original category : . NUMERIC dum2 to dum5. VECTOR dumv = dum2 to dum5. LOOP #i = 1 to 4. COMPUTE dumv(#i) = (cat = #i + 1). END LOOP. EXECUTE. * creating similar vars as above but using do repeat command. DO REPEAT iv = indv2 to indv5 / c = 2 to 5 . COMPUTE iv = (cat = c). END REPEAT. EXECUTE. * if reference category were neither first nor last, but 3rd, DO REPEAT seems handier than VECTOR and LOOP. DO REPEAT iv = c3i1 c3i2 c3i4 c3i5 / g = 1 2 4 5 . COMPUTE iv = (cat = g). END REPEAT. EXECUTE. ```
Related pages

...