Date: Wed, 1 Feb 2012 15:32:59 -0800
Reply-To: Bruce Weaver <firstname.lastname@example.org>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Bruce Weaver <email@example.com>
Subject: Re: Interesting bit of code ;-)
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
> 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.
>> David Marso wrote
>>> DUMMY Variables...
>>> *G4 exists in the data file and has integer values between 1 and 4.
>>> 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).
"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
For a list of commands to manage subscriptions, send the command