I am doing a survival analysis and need to identify what spell a family is in and how long the spell is at each point in time. Eventually i want to left censor the data so that a family who started in the first period is excluded. i want to only use the first spell for a family (with the exception of families that started in period 1, then i want to use their second spell if they have one) I tried using tsset and tsspell, but it was ignoring the breaks in periods.
Can you help me with the syntax for this?
I want to end up with a dataset like this (here is an example of family #7 which has several breaks in periods so they will have several spells and the first spell will be left-censored because we don't know the true duration of their spell because they started in period 1 :
here is a sample of my data:
Can you help me with the syntax for this?
I want to end up with a dataset like this (here is an example of family #7 which has several breaks in periods so they will have several spells and the first spell will be left-censored because we don't know the true duration of their spell because they started in period 1 :
FamilyID | period | spell | duration | leftcen |
7 | 1 | 1 | 1 | 1 |
7 | 2 | 1 | 2 | 1 |
7 | 3 | 1 | 3 | 1 |
7 | 5 | 2 | 1 | 0 |
7 | 6 | 2 | 2 | 0 |
7 | 7 | 2 | 3 | 0 |
7 | 8 | 2 | 4 | 0 |
7 | 9 | 2 | 5 | 0 |
7 | 10 | 2 | 6 | 0 |
7 | 11 | 2 | 7 | 0 |
7 | 12 | 2 | 8 | 0 |
7 | 13 | 2 | 9 | 0 |
7 | 15 | 3 | 1 | 0 |
7 | 16 | 3 | 2 | 0 |
7 | 17 | 3 | 3 | 0 |
7 | 18 | 3 | 4 | 0 |
7 | 21 | 4 | 1 | 0 |
7 | 22 | 4 | 2 | 0 |
7 | 23 | 4 | 3 | 0 |
7 | 24 | 4 | 4 | 0 |
here is a sample of my data:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long FamilyID float period 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 3 1 3 2 3 3 3 4 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 5 3 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 7 1 7 2 7 3 7 4 7 5 7 6 7 7 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 21 7 22 7 23 7 24 8 1 8 2 8 3 8 18 8 19 8 20 8 21 8 22 8 23 8 24 9 17 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 11 1 end label values AdultID_num AdultID_num label def AdultID_num 1 "AA000L1R", modify label def AdultID_num 2 "AA001G1U", modify label def AdultID_num 3 "AA001G1X", modify label def AdultID_num 4 "AA03597B", modify label def AdultID_num 5 "AA07853F", modify label def AdultID_num 6 "AA09875B", modify label def AdultID_num 7 "AA100W3R", modify label def AdultID_num 8 "AA11244G", modify label def AdultID_num 9 "AA11632F", modify label def AdultID_num 10 "AA12853B", modify label def AdultID_num 11 "AA15963E", modify
Comment