UCLA Academic Technology Services HomeServicesClassesContactJobs

SPSS Code Fragment
Making dummy variables in SPSS

Making dummy variables in SPSS via syntax. Say race has three values, 1 2 and 3, and you want to make three dummies, race1 race2 and race3.  Note that this does not work for string variables (but you can first convert the string variable to numeric and then use this procedure).

DATA LIST FREE / race.
BEGIN DATA.
1
2
3
.
-9
END DATA.
MISSING VALUES RACE(-9).

* make dummies, method 1 .
COMPUTE race1=(race=1).
COMPUTE race2=(race=2).
COMPUTE race3=(race=3).
crosstab /tables = race by race1 
         /tables = race by race2 
         /tables = race by race3.

* make dummies, method 2 .
DO REPEAT A=race1 race2 race3 /B=1 2 3.
COMPUTE A=(race=B).
END REPEAT.
crosstab /tables = race by race1 
         /tables = race by race2 
         /tables = race by race3.

How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.