⇤ ← Revision 1 as of 2007-03-06 12:26:44
Size: 1045
Comment:
|
Size: 1144
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
SPSS does not automatically create dummy variables using the linear regression procedure. Dummy variables are indicator 0-1 used in regressions 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. | |
Line 2: | Line 3: |
* Improved version of dummy variable example which doesn't need the number of levels of a categorical variables to be specified | |
Line 4: | Line 4: |
* Example of reading in a dummy variable without having to specify its maximum value * * features: matrix, nested macro, use of include to read in macro script * * reading in from a specified file |
* reading in from a specified file called GSS1991.sav |
Line 10: | Line 6: |
Open data file before running e.g using |
SPSS does not automatically create dummy variables using the linear regression procedure. Dummy variables are indicator 0-1 used in regressions 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.
* * reading in from a specified file called GSS1991.sav
Open data file before running e.g using get file='C:GSS1991.sav'.
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.