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 (February 2012)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 1 Feb 2012 15:32:59 -0800
Reply-To:     Bruce Weaver <bruce.weaver@hotmail.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Bruce Weaver <bruce.weaver@hotmail.com>
Subject:      Re: Interesting bit of code ;-)
In-Reply-To:  <1328137387770-5449105.post@n5.nabble.com>
Content-Type: text/plain; charset=us-ascii

You're right about efficiency. But unless one is working with a HUGE data file, the difference will likely be imperceptible (to the human eye, at least). And in that case, transparency should trump efficiency.

I feel like I'm stealing material from Art Kendall here. ;-)

p.s. - I'd never noticed that one can use PRINT like that on END REPEAT. Thanks for educating me (once again).

David Marso wrote > > OTOH It is less efficient than the VECTOR approach. > N computes rather than 1. > I'm not sure about the RECODE WRT processing efficiency. My point was the > interesting way that RECODE allows multiple vars to be created from one > variable and the ability to subsequently recode these new variables in the > single recode statement. > -- > Remember DO REPEAT cycles through the entire list of stand in 'variables'. > -- > NUMERIC dx1 TO dx4 (F1). > > DO REPEAT dx = dx1 to dx4 / # = 1 to 4 . > - COMPUTE dx = g4 EQ #. > END REPEAT PRINT. > > 18 0 +COMPUTE DX1 = G4 EQ 1 > 19 0 +COMPUTE DX2 = G4 EQ 2 > 20 0 +COMPUTE DX3 = G4 EQ 3 > 21 0 +COMPUTE DX4 = G4 EQ 4 > > LIST. > > Bruce Weaver wrote >> >> I like DO-REPEAT for this task. It's very transparent, I think, and not >> significantly more likely to cause RSI than the other methods you show . >> ;-) >> >> DATA LIST FREE / g4 (F1). >> BEGIN DATA >> 1 2 3 4 >> END DATA. >> >> NUMERIC dx1 TO dx4 (F1). >> DO REPEAT dx = dx1 to dx4 / # = 1 to 4 . >> - COMPUTE dx = g4 EQ #. >> END REPEAT. >> LIST. >> >> >> >> David Marso wrote >>> >>> DUMMY Variables... >>> -------------------- >>> *G4 exists in the data file and has integer values between 1 and 4. >>> **COMMENTS??**. >>> RECODE G4 (1=1) INTO DX1 >>> / G4 (2=1) INTO DX2 >>> / G4 (3=1) INTO DX3 >>> / DX1 DX2 DX3 (MISSING=0). >>> >>> OTOH: The following is more concise with large number of groups ;-) >>> >>> NUMERIC DX1 TO DX4 (F1). >>> RECODE DX1 TO DX4 (ELSE=0). >>> VECTOR DX=DX1 TO DX4. >>> COMPUTE DX(G4)=1. >>> >>> The following IMNSHO is abysmal. >>> DO IF G4=1. >>> + COMPUTE DX1=1. >>> ELSE IF G4=2. >>> + COMPUTE DX2=1. >>> ELSE IF G4=3. >>> + COMPUTE DX3=1. >>> END IF. >>> RECODE DX1 TO DX4 (MISSING=0)(ELSE=COPY). >>> >> >

----- -- Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.

-- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Interesting-bit-of-code-tp5448698p5449148.html Sent from the SPSSX Discussion mailing list archive at Nabble.com.

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD


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