syntaxfor choosing the last observation in a case

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

syntaxfor choosing the last observation in a case

Janine-11
Hi everyone,

This question might seem simple, but i'm completely lost. I'm not an
expert, but i'm still learning!!

I've got about 1200 cases in the dataset and each case has different
numbers of visits. For example:

caseno     visit1     v1score    visit2     v2score   visit3     v3score
1           5           1.2        8          3.4       12         3.4
2           2           2.1        5          2.4       --          --
3           4           2.2        --          --       --          --

We don't enter EVERY visit so the ones we do enter just get entered on the
next available place. That's why visit1 might actually be the 5th visit
for that family.  I would like to look at change from the first visit and
the last visit (the actual file goes up to 40 visits).

Is there a command where i can have spss pull out the first visit and the
last visit listed in that row for that particular case?  Or is there a
command to have SPSS pull out the first and last case to create two new
sets of variables that i can compare more easily?

Thanks in advance for any help you can offer.... i'm dying!! And if anyone
needs more info, i'd be more than happy to elaborate.

Take care,
Janine
Reply | Threaded
Open this post in threaded view
|

Re: syntaxfor choosing the last observation in a case

Richard Ristow
At 04:01 PM 5/4/2007, Janine wrote:

>I'm not an expert, but i'm still learning!!

Hey, that's the universal descriptor for as all.

>I've got about 1200 cases in the dataset and each case has different
>numbers of visits. For example:
>
>caseno     visit1     v1score    visit2     v2score   visit3
>v3score
>1           5           1.2        8          3.4       12         3.4
>2           2           2.1        5          2.4       --          --
>3           4           2.2        --          --       --          --
>
>That's why visit1 might actually be the 5th visit for that family.  I
>would like to look at change from the first visit and the last visit
>(the actual file goes up to 40 visits).
>
>Is there a command where i can have spss pull out the first visit and
>the last visit listed in that row for that particular case?  Or is
>there a command to have SPSS pull out the first and last case to
>create two new sets of variables that i can compare more easily?

It can be done, not easily, with VECTOR and LOOP. But I'd 'unroll' to a
'long' data structure, and do it that way. (This seems to be my night
for 'long' data structures.) Unfortunately, you have your data grouped
in logical pairs (both values for visit 1, both for visit 2, ...), and
SPSS doesn't handle those as well as it might. (I've griped about
that.) However, something like this. SPSS 15 draft output (WRR:Not
saved separately):

|-----------------------------|---------------------------|
|Output Created               |05-MAY-2007 02:55:52       |
|-----------------------------|---------------------------|
caseno visit1 v1score visit2 v2score visit3 v3score

     1     5      1.2     8      3.4    12      3.4
     2     2      2.1     5      2.4     .       .
     3     4      2.2     .       .      .       .

Number of cases read:  3    Number of cases listed:  3


VARSTOCASES  /MAKE Visit# FROM visit1 visit2 visit3
  /MAKE Score FROM v1score v2score v3score
  /INDEX = VisitPos "Position of visit in original record"(3)
  /KEEP =  caseno
  /NULL = DROP
  /COUNT = N_Visits "Visits on record for this case" .


Variables to Cases
|----------------------------|---------------------------|
|Output Created              |05-MAY-2007 02:55:53       |
|----------------------------|---------------------------|
Generated Variables
|--------|---------------|
|Name    |Label          |
|--------|---------------|
|N_Visits|Visits on      |
|        |record for this|
|        |case           |
|--------|---------------|
|VisitPos|Position of    |
|        |visit in       |
|        |original record|
|--------|---------------|
|Visit#  |<none>         |
|--------|---------------|
|Score   |<none>         |
|--------|---------------|

Processing Statistics
|-------------|-|
|Variables In |7|
|-------------|-|
|Variables Out|5|
|-------------|-|


.  /**/  LIST /*-*/.

List
|-----------------------------|---------------------------|
|Output Created               |05-MAY-2007 02:55:53       |
|-----------------------------|---------------------------|
caseno N_Visits VisitPos Visit# Score

     1       3        1      5     1.2
     1       3        2      8     3.4
     1       3        3     12     3.4
     2       2        1      2     2.1
     2       2        2      5     2.4
     3       1        1      4     2.2

Number of cases read:  6    Number of cases listed:  6


SORT CASES BY caseno Visit#.
NUMERIC   VisitOrd (F2).
VAR LABEL VisitOrd 'Position of visits in sequence of recorded visits'.
VAL LABEL VisitOrd
           1 'Earliest visit'
           2 'In between'
           3 'Latest visit'.
ADD FILES
     /FILE=*
     /BY  caseno
     /FIRST=FrstVist
     /LAST =LtstVist.

DO IF   FrstVist.
.  COMPUTE VisitOrd = 1.
ELSE IF LtstVist.
.  COMPUTE VisitOrd = 3.
ELSE.
.  COMPUTE VisitOrd = 2.
END IF.
LIST.

List
|-----------------------------|---------------------------|
|Output Created               |05-MAY-2007 02:55:54       |
|-----------------------------|---------------------------|
caseno N_Visits VisitPos Visit# Score VisitOrd FrstVist LtstVist

     1       3        1      5     1.2     1        1        0
     1       3        2      8     3.4     2        0        0
     1       3        3     12     3.4     3        0        1
     2       2        1      2     2.1     1        1        0
     2       2        2      5     2.4     3        0        1
     3       1        1      4     2.2     1        1        1

Number of cases read:  6    Number of cases listed:  6

===================
APPENDIX: Test data
===================
(Gives the desired result, but with lots of error messages)

DATA LIST FREE SKIP=1/
    caseno (F3)
    visit1     v1score
    visit2     v2score
    visit3     v3score (3(F2,F4.1)).
BEGIN DATA
caseno     visit1     v1score    visit2     v2score   visit3
v3score
1           5           1.2        8          3.4       12         3.4
2           2           2.1        5          2.4       --          --
3           4           2.2        --          --       --          --
END DATA.
.  /**/  LIST /*-*/.