LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2005)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 21 Sep 2005 17:31:23 -0400
Reply-To:     Richard Ristow <wrristow@mindspring.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Richard Ristow <wrristow@mindspring.com>
Subject:      Re: syntax for creating new var
Comments: To: Kim Jinnett <kjinnett@ibiweb.org>
In-Reply-To:  <MPECLJPOAEIJAOCEBHBJAEPDCDAA.kjinnett@ibiweb.org>
Content-Type: text/plain; charset="us-ascii"; format=flowed

At 02:00 PM 9/21/2005, Kim Jinnett wrote:

>I'm trying to create a set of 8 dummy variables from one variable that >was coded with values 1 to 8. I'm having trouble dealing with the >missing values appropriately. If the original variable "intgtype" has >a missing value, I want the new variable to have a missing value as >well. Where do I insert the missing value statement and what should >it look like? I'm sure there is a much more efficient way to write >the code below as well.

I'd do something like this (untested code)

* You might as well retain the following, since . * you have to declare those variables somehow, . * and they don't have names that can be created . * by a short-form VECTOR statement or a TO list . * on a NUMERIC statement. .

COMPUTE wstdltd=0. COMPUTE awstdltd=0. COMPUTE stdltd=0. COMPUTE astdltd=0. COMPUTE whstdltd=0. COMPUTE awhstltd=0. COMPUTE hstdltd=0. COMPUTE ahstdltd=0.

* Other attributes of the created variables .

FORMATS wstdltd TO ahstdltd (F2). MISSING VALUES wstdltd TO ahstdltd (9). VALUE LABELS wstdltd TO ahstdltd 0 'Not this code' 1 'Is this code' 9 'Source missing'. * (You probably want VAR LABELS, too, but I'll . * let you do those.) .

* Computations: Here we go! .

VECTOR DUMMY = wstdltd TO ahstdltd. LOOP #CODE = 1 TO 8. . DO IF MISSING(intgtype). . COMPUTE DUMMY(#CODE) = 9. . ELSE IF intgtype eq #CODE. . COMPUTE DUMMY(#CODE) = 1. . ELSE COMPUTE DUMMY(#CODE) = 0. . END IF. END LOOP.

I've used a '9' as a user-missing value for the dummies. You can skip this, and make missing ones system-missing, if you like. For that, drop the MISSING VALUES statement, and the label for code 9. Replace . COMPUTE DUMMY(#CODE) = 9. with . COMPUTE DUMMY(#CODE) = $SYSMIS.

Good luck! Richard


Back to: Top of message | Previous page | Main SPSSX-L page