Loops and LAG

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

Loops and LAG

G.Hammond
Hello,

Have a problem with a piece of data manipulation which i'm hoping to get
some feedback on. Here is the data as currently formatted. Start and end
dates represent days.

ID   Start    END VALUE
1    1        15  4
1    16       31  6
1    32       47  7
2    3        15  2
2    16       23  5
2    24       30  7
3    1        17  3
3    18       29  6
3    30       37  9

Eventually for each individual, i would like to have a daily value
corresponding to the ones above for each day. So, for person 2, there
would be:

ID Day.3 Day.4 Day.5 ... Day.15 Day.16 Day.17...Day.24 Day.25
1   2     2     2         2      5      5        7      7

I have flipped the data into long format using the start value as an
index, but the value is only available for that day. Any idea how to
create a loop which would use the value in the variable name (the 16 in
DAY.16 for example) to imput the value for the given range of days?

Hopefully that makes some sense!

Any and all comments welcome.

Regards,

Geoff

=====================
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: Loops and LAG

Maguin, Eugene
Geoff,


>>Have a problem with a piece of data manipulation which i'm hoping to get
some feedback on. Here is the data as currently formatted. Start and end
dates represent days.

ID   Start    END VALUE
1    1        15  4
1    16       31  6
1    32       47  7
2    3        15  2
2    16       23  5
2    24       30  7
3    1        17  3
3    18       29  6
3    30       37  9

Eventually for each individual, i would like to have a daily value
corresponding to the ones above for each day. So, for person 2, there
would be:

ID Day.3 Day.4 Day.5 ... Day.15 Day.16 Day.17...Day.24 Day.25
1   2     2     2         2      5      5        7      7


Warning: Untested.
I think I'd go at it this way. Do a frequencies on start and end to get the
range of day values. In your sample data that would be 1 to 47. Then:

Vector day(47).
Loop #i=start to end.
+  compute day(#i)=value.
End loop.
Execute.

Aggregate outfile=*/break=id/
   day1 to day47=first(day1 to day47).
Execute.


Gene Maguin

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