Recode onto the next case

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Recode onto the next case

Alison America
I have syntax that says:

RECODE EVENT (100=1) (ELSE=0) INTO EVENT2.
VARIABLE LABELS  EVENT2 'EVENT2'.
EXECUTE.

I want this command to happen, but the recoded variable should appear on
the next case, not the case on which the origninal EVENT code happened.

In the data set, there are 2 cases per person and I want the "1" in EVENT2
to appear in the person's second case.

Any ideas?

Thanks, alison

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
Reply | Threaded
Open this post in threaded view
|

Re: Recode onto the next case

John McConnell-2
Alison

The wonderful LAG function allows you to perform transformations across
cases.

So ...

IF LAG(EVENT) = 100 EVENT2=1.
IF LAG(EVENT) = 0 EVENT2=0.

... (untested) should do the job

HTH

John

John McConnell
analytical people
500 Chiswick High Road
London
W4 5RG, United Kingdom
Mobile:            +44 (0)7711 786600
Office:              +44 (0)845 680 1871
Skype:              Johnmac65
Web:                www.analytical-people.com

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Alison America
Sent: 02 July 2009 13:35
To: [hidden email]
Subject: Recode onto the next case

I have syntax that says:

RECODE EVENT (100=1) (ELSE=0) INTO EVENT2.
VARIABLE LABELS  EVENT2 'EVENT2'.
EXECUTE.

I want this command to happen, but the recoded variable should appear on
the next case, not the case on which the origninal EVENT code happened.

In the data set, there are 2 cases per person and I want the "1" in
EVENT2
to appear in the person's second case.

Any ideas?

Thanks, alison

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
Reply | Threaded
Open this post in threaded view
|

Re: Recode onto the next case

Bruce Weaver
Administrator
John McConnell-2 wrote
Alison

The wonderful LAG function allows you to perform transformations across
cases.

So ...

IF LAG(EVENT) = 100 EVENT2=1.
IF LAG(EVENT) = 0 EVENT2=0.

... (untested) should do the job

HTH

John
John, I agree with the use of LAG, but I think your syntax needs a bit of tweaking.  Remember that there are two records per ID, and Alison only wants to compute EVENT2 on record 2 for each person.  Assuming the cases are already sorted appropriately, this should work:

if ( ID EQ lag(ID) ) event2 = ( lag(event) EQ 100 ).
exe.

--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).