Computing Ordered Variable

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

Computing Ordered Variable

Jean Hanson
Hello Listserve,
I have a file with multiple records per client. The clients have visits on different dates and some clients might have only one visit while others may have six visits. I would like to create a variable that reflects the ordering of the date variable. For example, visit1 would be the first/earliest visit for a client, visit2 for the second time a client was seen. etc. Does anyone have syntax that would help me with this? Thank you.

Jean Hanson
Reply | Threaded
Open this post in threaded view
|

Re: Computing Ordered Variable

Edward Boadi
Hi Jean,

I hope this works for you :

**First sort records by ClientID and  date of visit (VisitDate) .

SORT CASES BY ClientID,VisitDate (A).

**epis_num = 1  is the first visit .

compute epis_num = 1.
EXECUTE.

IF (ClientID= lag(ClientID)) epis_num = 1+lag(epis_num) .
EXECUTE .


Regards.
Edward.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of
Jean Hanson
Sent: Thursday, November 02, 2006 11:57 AM
To: [hidden email]
Subject: Computing Ordered Variable


Hello Listserve,
I have a file with multiple records per client. The clients have visits on different dates and some clients might have only one visit while others may have six visits. I would like to create a variable that reflects the ordering of the date variable. For example, visit1 would be the first/earliest visit for a client, visit2 for the second time a client was seen. etc. Does anyone have syntax that would help me with this? Thank you.

Jean Hanson
Reply | Threaded
Open this post in threaded view
|

Re: Computing Ordered Variable

Bauer, Craig
In reply to this post by Jean Hanson
Hi Jean

This should do what you want.


sort cases by id date.
compute order=1.
if (lag(id)=id) order=lag(order)+1.


Craig

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Jean Hanson
Sent: Thursday, November 02, 2006 11:57 AM
To: [hidden email]
Subject: Computing Ordered Variable

Hello Listserve,
I have a file with multiple records per client. The clients have visits
on different dates and some clients might have only one visit while
others may have six visits. I would like to create a variable that
reflects the ordering of the date variable. For example, visit1 would be
the first/earliest visit for a client, visit2 for the second time a
client was seen. etc. Does anyone have syntax that would help me with
this? Thank you.

Jean Hanson