I have a very big data set with a survival structure that I want to compress/collapse. Right now the data look like this:
ID | t0 | t1 | y | x1 | x2 |
1 | 0 | 1 | 0 | 0 | 0 |
1 | 1 | 2 | 0 | 0 | 0 |
1 | 2 | 3 | 0 | 3 | 1 |
1 | 3 | 4 | 0 | 2 | 1 |
1 | 4 | 5 | 0 | 2 | 1 |
1 | 5 | 6 | 1 | 2 | 0 |
1 | 6 | 7 | 0 | 1 | 0 |
1 | 7 | 8 | 0 | 2 | 1 |
1 | 8 | 9 | 1 | 2 | 1 |
What I want to do is to collapse spells of t0 t1 where none of the time-varying variables (including y) vary for a period.
In other words, I want to transform the data above to look like this:
ID | t0 | t1 | y | x1 | x2 |
1 | 0 | 2 | 0 | 0 | 0 |
1 | 2 | 3 | 0 | 3 | 1 |
1 | 3 | 5 | 0 | 2 | 1 |
1 | 5 | 6 | 1 | 2 | 0 |
1 | 6 | 7 | 0 | 1 | 0 |
1 | 7 | 8 | 0 | 2 | 1 |
1 | 8 | 9 | 1 | 2 | 1 |
Example code:
Code:
input str1 id t0 t1 y x1 x2 1 0 1 0 0 0 1 1 2 0 0 0 1 2 3 0 3 1 1 3 4 0 2 1 1 4 5 0 2 1 1 5 6 1 2 0 1 6 7 0 1 0 1 7 8 0 2 1 1 8 9 1 2 1 end
0 Response to Collapsing survival data
Post a Comment