* set mprint=off. DEFINE DumCode ( NomVar !CharEnd ('/') /PreNam !CharEnd ('/') /NumCat !CharEnd ('/') /RefCat !Default(Last) !CMDEnd). DO IF UpCase(!Quote(!RefCat))='FIRST'. + DO IF missing(!NomVar). - compute #NomV = -99999. + ELSE IF !NomVar > 1. - compute #NomV = !NomVar-1. + ELSE IF !NomVar = 1. - compute #NomV = !NumCat. + END IF. ELSE. + recode !NomVar (sysmis,missing=-99999) (else=copy) into #NomV. END IF. VECTOR !PreNam(!NumCat). LOOP #i=1 to (!NumCat). + DO IF #NomV > -99999. - compute !PreNam(#i)=0. + ELSE. - compute !PreNam(#i)=$sysmis. + END IF. END LOOP. IF (#NomV < !NumCat) and (#NomV <> -99999) !PreNam(#NomV)=1. variable labels !ConCat(!PreNam,!NumCat) '(var dropped)'. desc !ConCat(!PreNam,'1') to !ConCat(!PreNam,!NumCat) /statistics sum. print formats !ConCat(!PreNam,'1') to !ConCat(!PreNam,!NumCat) (F2.0). match files /file=* /drop=!ConCat(!PreNam,!NumCat). exe. !EndDefine. /* ----------------------------------------------- */ /* DumCode creates dummy variables (indicator */ /* coding) of a nominal variable. The codes of the */ /* nominal variable must be contiguous from */ /* 1=lowest to highest, i.e. highest category = */ /* number of categories. The dummy variables to be */ /* created may not exist in the working file. */ /* */ /* Syntax of DumCode: */ /* */ /* DUMCODE NOMVAR = name of nominal variable */ /* /PRENAM = prefix of name of dummy- */ /* variables (max. 7 letters, */ /* i.e. prefix+number <= 8 */ /* characters) */ /* /NUMCAT = number of categories of */ /* nominal variables */ /* [/REFCAT = reference category */ /* (default=last) */ /* {FIRST} */ /* {LAST} ]. */ /* */ /* Examples: */ /* */ /* DumCode NomVar = school */ /* /PreNam = D */ /* /NumCat = 6. */ /* */ /* Creates 5 dummy-variables D1 to D5 with: */ /* D1 = 1 if schooltype = 1, else = 0 */ /* D2 = 1 if schooltype = 2, else = 0 */ /* D3 = 1 if schooltype = 3, else = 0 */ /* D4 = 1 if schooltype = 4, else = 0 */ /* D5 = 1 if schooltype = 5, else = 0 */ /* */ /* DumCode NomVar = school */ /* /PreNam = D */ /* /NumCat = 6 */ /* /RefCat = first. */ /* */ /* Creates 5 dummy-variables D1 to D5 with: */ /* D1 = 1 if schooltype = 2, else = 0 */ /* D2 = 1 if schooltype = 3, else = 0 */ /* D3 = 1 if schooltype = 4, else = 0 */ /* D4 = 1 if schooltype = 5, else = 0 */ /* D5 = 1 if schooltype = 6, else = 0 */ /* */ /* To delete the dummy variables from the working */ /* file use: */ /* MATCH FILES */ /* /FILE=* */ /* /DROP d1 to d5. */ /* EXECUTE. */ /* ----------------------------------------------- */.