spssforum.com

by SPSS users, for SPSS users
SPSSVideoTutor.com
It is currently Sun May 26, 2013 7:37 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Fri May 04, 2012 11:00 am 
Offline

Joined: Fri May 04, 2012 10:42 am
Posts: 4
Hi,
I'm struggling with my data... :?
I have a file with multiple records for certain persons. If a person (person A) has scored 1 for a certain variable (event) the records hereafter, which are sorted by date, should also score 1.
How do I do that?
AnnieLin


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
PostPosted: Fri May 04, 2012 1:25 pm 
Offline

Joined: Thu Apr 05, 2012 5:58 pm
Posts: 463
This may do:

Quote:
* Sort case by ID and admission date .
SORT CASES BY PATCOD(A) admission(A).

* Make a new variable .
COMPUTE eventrecoded = event001 .

* Recode into a chain of 1 if event has already occurred .
IF patcod = lag(patcod) and lag(event001) = 1 eventrecoded = 1 .
EXECUTE .


Top
 Profile  
 
PostPosted: Fri May 04, 2012 4:04 pm 
Offline

Joined: Fri May 04, 2012 10:42 am
Posts: 4
thanks for that :) , but it didn't really work. It gives a "1" in the record where event001=1 and the next one.
It should be in all the next lines with the same PATCOD (not necessarily where Event001=1)
I'm not familiar with the command LAG(variable), I should educate myself...Is there a clear explanation available for this on the net?
What I've done in the mean time is very complex and prone to mistakes (see below) . Can you see an obvious mistake?

*restructurate.
SORT CASES BY PATCOD Birthdate .
CASESTOVARS
/ID=PATCOD Birthdate
/GROUPBY=VARIABLE.

*than computed a new variabel
COMPUTE PREV0adm1=0.
compute prev1adm2=EVENT001.1.
COMPUTE PREV2adm3=EVENT001.1 + EVENT001.2.
COMPUTE PREV3adm4=EVENT001.1 + EVENT001.2 +EVENT001.3.
etc

*than restructurated it back
VARSTOCASES
/MAKE PREVV FROM PREV0adm1 prev1adm2 PREV2adm3 PREV3adm4
/INDEX=Index1(4)
/KEEP=PATCOD
/NULL=DROP
/COUNT=casenr.

RECODE PREVV (0=0) (1 thru Highest=1) INTO Pr_event.
EXECUTE.


Top
 Profile  
 
PostPosted: Fri May 04, 2012 8:09 pm 
Offline

Joined: Thu Apr 05, 2012 5:58 pm
Posts: 463
Oh, sorry. I made a mistake. Try this one:

Quote:
* Sort case by ID and admission date .
SORT CASES BY PATCOD(A) admission(A).

* Make a new variable .
COMPUTE eventrecoded = event001 .
EXECUTE .

* Recode into a chain of 1 if event has already occurred .
IF patcod = lag(patcod) and lag(eventrecoded) = 1 eventrecoded = lag(eventrecoded) .
EXECUTE .


LAG is a function to borrow the data in the previous row.

See this syntax:
IF patcod = lag(patcod) and lag(eventrecoded) = 1 eventrecoded = lag(eventrecoded) .

Literally, it means if patcod on any row k is equal to patcod on row (k-1) AND the eventrecoded in the previous row is 1, then recode the eventrecoded in row k as 1.


Top
 Profile  
 
PostPosted: Sun May 06, 2012 5:45 pm 
Offline

Joined: Fri May 04, 2012 10:42 am
Posts: 4
Thanks, I understand better now. It still didn't do exactly what I wanted, but I rewrote the syntax to the one below and now it seems to do the trick.
In the previous one, also alle events without a previous event were scored 1, which they shouldn't.
Thanks for your help!

* Make a new variable .
COMPUTE eventrecoded = 0 .
EXECUTE .

* Recode into a chain of 1 if event has already occurred .
IF patcod = lag(patcod) and lag(event001) = 1 eventrecoded = 1.
EXECUTE .
IF patcod = lag(patcod) and lag(eventrecoded) = 1 eventrecoded = 1.
EXECUTE .


Top
 Profile  
 
PostPosted: Mon May 07, 2012 7:00 pm 
Offline

Joined: Thu Apr 05, 2012 5:58 pm
Posts: 463
That's probably because I didn't understand the request correctly. I am glad that the problem was rectified.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group