spssforum.com

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

 All times are UTC

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: count values for matched, sorted recordsPosted: Fri May 04, 2012 11:00 am

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

 Post subject: Re: count values for matched, sorted recordsPosted: Fri May 04, 2012 1:25 pm

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

Quote:
* Sort case by ID and admission date .

* 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

 Post subject: Re: count values for matched, sorted recordsPosted: Fri May 04, 2012 4:04 pm

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
etc

*than restructurated it back
VARSTOCASES
/INDEX=Index1(4)
/KEEP=PATCOD
/NULL=DROP
/COUNT=casenr.

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

Top

 Post subject: Re: count values for matched, sorted recordsPosted: Fri May 04, 2012 8:09 pm

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 .

* 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

 Post subject: Re: count values for matched, sorted recordsPosted: Sun May 06, 2012 5:45 pm

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.

* 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

 Post subject: Re: count values for matched, sorted recordsPosted: Mon May 07, 2012 7:00 pm

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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 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 forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ SPSS    General    Data input    Output    SPSS for beginners    Enhancing data    Modifying SPSS output    Coding SPSS syntax SPSS the software    Errors    Where is .. in SPSS Statistics    Statistics for beginners    Heavy statistics SPSS Jobs    SPSS Jobs SPSS Forum    Read this first    General feedback or questions about this forum    Library