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 (June 2005)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 30 Jun 2005 19:52:43 -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: compute a new variable
Comments:   To: Miller <miller@praxis.ca>
In-Reply-To:   <010801c57d96$dd7dc220$c100a8c0@praxis.ca>
Content-Type:   text/plain; charset="us-ascii"; format=flowed

At 01:12 PM 6/30/2005, Miller wrote:

>I need to compute a new variable based on another variable. I need to >reduce a 10 point scale to 5. So, for example I need to compute: > OLD var NEW var > 9 or 10 5 > 7 or 8 4 > 5 or 6 3

And, at 02:56 PM 6/30/2005:

>Thanks very much for all the help - I used Transform->recode . . >. and then pasted and replicated the syntax for all variables, which >there are too many of ;( .

That's basically the way to do it. I don't know how you did the replication, but RECODE can be very compact. Here's recoding five such variables, but expandable to any number, adapting Jim Marks's RECODE syntax:

* Test data . NEW FILE. INPUT PROGRAM. NUMERIC ROW (N3). NUMERIC A01 TO A05 (F3). VECTOR A#S=A01 TO A05. LOOP #REC = 1 TO 5. . COMPUTE ROW = #REC. - LOOP #A = 1 TO 5. . COMPUTE A#S(#A) = TRUNC(RV.UNIFORM(1,11)). - END LOOP. . END CASE. END LOOP. END FILE. END INPUT PROGRAM.

* RECODE section. RECODE A01 TO A05 (LO thru 2 = 1) (LO thru 4 = 2) (LO thru 6 = 3) (LO thru 8 = 4) (LO thru 10 = 5) INTO B01 TO B05. FORMATS B01 TO B05 (F2). LIST.

List Notes |---------------------|--------------------| |Output Created |30 Jun 05 19:44:30 | |---------------------|--------------------| ROW A01 A02 A03 A04 A05 B01 B02 B03 B04 B05

001 10 3 4 1 8 5 2 2 1 4 002 2 1 2 1 7 1 1 1 1 4 003 7 9 4 5 8 4 5 2 3 4 004 3 8 1 6 7 2 4 1 3 4 005 10 4 6 8 2 5 2 3 4 1

Number of cases read: 5 Number of cases listed: 5


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