creating new variable with last valid case

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

creating new variable with last valid case

Jordan Kennedy
Good morning:

I have a longitudinal data set with a maximum of 16 time-points, and 16 variables representing these time-points. What I want to do is create a variable that represents the last valid (i.e., non-missing) case value. This will obviously vary by participant. Is there an automated way to do this?

Thank you for any help that you can provide!

Jordan

===================== 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: creating new variable with last valid case

Jon Peck
Use AGGREGATE with the Last function breaking on the time point and adding this, perhaps with an ID variable, too, to the active dataset.

On Sun, Oct 25, 2020 at 11:00 AM Scott Roesch <[hidden email]> wrote:
Good morning:

I have a longitudinal data set with a maximum of 16 time-points, and 16 variables representing these time-points. What I want to do is create a variable that represents the last valid (i.e., non-missing) case value. This will obviously vary by participant. Is there an automated way to do this?

Thank you for any help that you can provide!

Jordan

===================== 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


--
Jon K Peck
[hidden email]

===================== 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: creating new variable with last valid case

Art Kendall
In reply to this post by Jordan Kennedy
See if this is what you want.
if not please add a variable or two at the end for what you want.

data list list /id (f2) MyVar01 to MyVar16 (16f1).
begin data
    01 1 1 1 1 0 1 1 1 0 2 2 2 1 1 0 1
    02 3 0 3 4 1 1 1 1 1 1 1 1 1 1 0 0
    03 2 2 2 2 3 3 3 3 1 1 1 1 0 0 0 0
    04 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
end data.
* remove missing status.
Missing values MyVar01 to MyVar16().
numeric Total16 (f3)Position.Last (f2) Value.Last (f1).
compute Total16 = sum(MyVar01 to MyVar16).
compute Position.Last = 0.
compute Value.Last = 0.
do if Total16 ne 0.
    do repeat MyVar = MyVar01 to MyVar16 /Position = 1 to 16.
        Do If MyVar ne 0.
            compute Position.Last = Position.
            compute Value.Last = MyVar.
        end if.
    END REPEAT.
End if.
List.
Missing values MyVar01 to MyVar16 Total16 Position.Last Value.Last (0).
* be sure to do VARIABLE LABELS .






-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: creating new variable with last valid case

Rich Ulrich
That is the brute-force method.

How about --
CasesToVars to create 16 numbered records;
Select if not Missing;
Aggregate to get Last (for the value and the period#).

--
Rich Ulrich

From: SPSSX(r) Discussion <[hidden email]> on behalf of Art Kendall <[hidden email]>
Sent: Sunday, October 25, 2020 1:27 PM
To: [hidden email] <[hidden email]>
Subject: Re: creating new variable with last valid case
 
See if this is what you want.
if not please add a variable or two at the end for what you want.

data list list /id (f2) MyVar01 to MyVar16 (16f1).
begin data
    01 1 1 1 1 0 1 1 1 0 2 2 2 1 1 0 1
    02 3 0 3 4 1 1 1 1 1 1 1 1 1 1 0 0
    03 2 2 2 2 3 3 3 3 1 1 1 1 0 0 0 0
    04 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
end data.
* remove missing status.
Missing values MyVar01 to MyVar16().
numeric Total16 (f3)Position.Last (f2) Value.Last (f1).
compute Total16 = sum(MyVar01 to MyVar16).
compute Position.Last = 0.
compute Value.Last = 0.
do if Total16 ne 0.
    do repeat MyVar = MyVar01 to MyVar16 /Position = 1 to 16.
        Do If MyVar ne 0.
            compute Position.Last = Position.
            compute Value.Last = MyVar.
        end if.
    END REPEAT.
End if.
List.
Missing values MyVar01 to MyVar16 Total16 Position.Last Value.Last (0).
* be sure to do VARIABLE LABELS .






-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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: creating new variable with last valid case

David Marso-2
In reply to this post by Jordan Kennedy
Why not use VECTOR and LOOP backwards.
BREAK when you locate non missing.

=====================
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