FAQ/dummy - CBU statistics Wiki

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment
Flind the wroneg tetters tin eaech wrord

location: FAQ / dummy

SPSS does not automatically create dummy variables using the linear regression procedure. Dummy variables are indicator 0-1 used in regressions (see here for how to interpret these) for representing categorical variables with 3 or more levels. The macro below will produce these prior to entry in a linear regression. Remember to make sure there are no empty categories.

The data (race which is a categorical variable with 3 levels) is read in from a file on the C disk called GSS1991.sav but the name of this file can be changed. The data file is assumed to be on the C: disk.

Open data file before running e.g using get file='C:GSS1991.sav'.

[ CUT AND PASTE THE BELOW SYNTAX INTO A SPSS SYNTAX WINDOW. THE TWO ARGUMENTS ARE THE NAME OF THE CATEGORICAL VARIABLE AND THE NAME OF THE DATA FILE. THE DUMMY VARIABLES ARE ADDED ON TO THE END OF THE DATA SPREADSHEET].

define !d1 (!POS !TOKENS(1)
               /!POS !CMDEND).
matrix.
get x /var=!1.
compute n=mmax(x)-1.
save {n} /outfile='C:temp.sav' /vars=n.
end matrix. 
get file='C:temp.sav'. 
WRITE  ouTFILE 'C:temp.sps' /"DEFINE !nbcases()"n"!ENDDEFINE.".
exe.
!d2 !1 !2.
!enddefine.

define !d2 (!POS !TOKENS(1)
               /!POS !CMDEND).
GET FILE=!QUOTE(!CONCAT('C:', !UPCASE(!2))  ).
INCLUDE FILE='C:temp.sps'.

VECTOR !concat(!1,d) (!nbcases,F3).
LOOP #I=1 TO !nbcases.
   COMPUTE !concat(!1,d)(#I)=0.
END LOOP.
LOOP #I=1 TO !nbcases.
DO IF !1 eq #i.
   COMPUTE !concat(!1,d)(#I)=1.
END IF.
END LOOP.
exe.
!enddefine.

!d1 race gss1991.sav.