lab session discrete time survival model 2015
TRANSCRIPT
8/17/2019 Lab Session Discrete Time Survival Model 2015
http://slidepdf.com/reader/full/lab-session-discrete-time-survival-model-2015 1/11
Lab SessionDiscrete Time Survival Models
Ch. 11 Singer & Willett
We will use the same dataset and application used in Chapter 11 of Singer and Willett. The dataset containsdata on the grade of first sexual intercourse in a sample of 180 at-risk bos.
.use"C:\geron 701\Fall 2008\data\aldastata\firstsex.dta", clear
. desContains data from C:\geron 701\Fall 2008\data\aldastata\firstsex.dta obs: 180vars: si!e: ,#20 $%%.%& of memor' free()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))variable name t'*e format label variable label)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))idfloat &%.0gtime float &%.0g grade 7)12censor float &%.0g 1+ censored outcome
*t float &%.0g 1+ bo' ex*erienced 1 *arenting transitionbefore 7t- grade, 0+ot-erise
*as float &%.0g /arents level of antisocial be-avior$standardi!ed )score
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))). su
ariable 3bs 4ean 5td. 6ev. 4in 4ax))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) id 180 107.778 #.21 1 21 time 180 10.7 1.272 7 12 censor 180 .# .%#8 0 1 *t 180 . .%12 0 1
*as 180 ).0022#1 .8%#01 )1.7118 2.7811#
We first define a dumm !ariable to indicate cases where the e!ent occurred.
. gen event+0
. re*lace event+1 if censor++0$12 real c-anges made(
. stset time, failure$event(
failure event: event + 0 9 event .obs. time interval: $0, time; exit on or before: failure
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) 180 total obs. 0 exclusions)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) 180 obs. remaining, re*resenting 12 failures in single record<single failure data 1%02 total anal'sis time at ris=, at ris= from t + 0 earliest observed entr' t + 0
1
1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
2
3
8/17/2019 Lab Session Discrete Time Survival Model 2015
http://slidepdf.com/reader/full/lab-session-discrete-time-survival-model-2015 2/11
last observed exit t + 12
. ltable time event, noad>ust surv
?eg. 5td. @nterval Aotal 6eat-s Bost 5urvival rror D%& Conf. @nt.;
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) 7 8 180 1 0 0.%17 0.020 0.8 0.%8% 8 % 1 7 0 0.8778 0.02 0.820# 0.%178 % 10 18 2 0 0.7 0.0#2 0.71 0.801% 10 11 1# 2% 0 0.8## 0.0#7 0.078 0.1 11 12 10 2 0 0. 0.0#70 0.#70% 0.1# 12 1# 80 2 0.#000 0.0#2 0.2#8 0.#78)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
. ltable time event, noad>ust fail
?eg. Cum. 5td. @nterval Aotal 6eat-s Bost Failure rror D%& Conf. @nt.;
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) 7 8 180 1 0 0.08## 0.020 0.011 0.1# 8 % 1 7 0 0.1222 0.02 0.0822 0.17%7 % 10 18 2 0 0.2 0.0#2 0.1%81 0.#2% 10 11 1# 2% 0 0.17 0.0#7 0.#8 0.%22 11 12 10 2 0 0. 0.0#70 0.87 0.2%1 12 1# 80 2 0.7000 0.0#2 0.#22 0.72)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
. ltable time event, noad>ust -a!ard
?eg. Cum. 5td. 5td. @nterval Aotal Failure rror Ea!ard rror D%& Conf. @nt.;
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) 7 8 180 0.08## 0.020 0.08## 0.021 0.0 0.1#0 8 % 1 0.1222 0.02 0.02 0.010 0.0171 0.07%1 % 10 18 0.2 0.0#2 0.11% 0.0#10 0.0%7# 0.218 10 11 1# 0.17 0.0#7 0.21 0.002 0.1% 0.#020 11 12 10 0. 0.0#70 0.2#81 0.07 0.11 0.#01 12 1# 80 0.7000 0.0#2 0.#20 0.0#7 0.212# 0.1#)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
. sts generate s+s, b'$*t(
. sts generate -+-, b'$*t(
. toa' $line s time if *t++1, sort( $line s time if *t++0, sort(
2
4
56
57
58
59
60
61
62
63
6465
66
67
68
69
70
71
72
73
74
75
76
7778
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
5
6
8/17/2019 Lab Session Discrete Time Survival Model 2015
http://slidepdf.com/reader/full/lab-session-discrete-time-survival-model-2015 3/11
. "
. #
. $
. 8
1
S % t & 0 '
( 8 ) 10 11 1"period
S%t&0' S%t&0'
. toa' $line - time if *t++1, sort( $line - time if *t++0, sort(
0
. 1
. "
. *
. #
. +
, e l t a-
% t
'
( 8 ) 10 11 1"period
,elta%t' ,elta%t'
3
7
104105
106
107
108
109
110
111
8
9
8/17/2019 Lab Session Discrete Time Survival Model 2015
http://slidepdf.com/reader/full/lab-session-discrete-time-survival-model-2015 4/11
/n order to estimate a discrete time sur!i!al model we need to con!ert this person dataset %180 cases for bos'to a person-period dataset with each bo ha!ing as man obser!ations as ears elapsed before first sex. Wewill now open the person-period !ersion of the same data set
. use "@:\geron 701\Fall 2008\data\aldastata\firstsex**.dta", clear
. des
Contains data from @:\geron 701\Fall 2008\data\aldastata\firstsex**.dta obs: 822vars: 11si!e: #%, $%%.& of memor' free()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))storage dis*la' valuevariable name t'*e format label variable label)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))id float &%.0g*eriod float &%.0g same as time in ot-er dataset$7)12(event float &%.0g
d7 float &%.0g +1 if *eriod+7, +0 ot-erised8 float &%.0g +1 if *eriod+8, +0 ot-erised% float &%.0g Gd10 float &%.0g Gd11 float &%.0g Gd12 float &%.0g +1 if *eriod+12, +0 ot-erise*t float &%.0g same as ot-er dataset*as float &%.0g same as ot-er dataset))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))). su
ariable 3bs 4ean 5td. 6ev. 4in 4ax))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) id 822 107.#2# #.77% 1 21 *eriod 822 %.07177 1.200 7 12 event 822 .1#287 .#081 0 1 d7 822 .218%781 .1#80 0 1 d8 822 .20072%% .007%0# 0 1))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) d% 822 .1%2211 .#%280# 0 1 d10 822 .1#017 .#%01 0 1 d11 822 .1277#72 .##0002 0 1 d12 822 .0%7#2# .2%78 0 1 *t 822 .7177 .%7022 0 1)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
*as 822 ).08%818 .8187 )1.7118 2.7811#
/t is important to understand the structure of this dataset. ote that there are uneual cases per id becauseeach case now is defined as grade before and including the grade at which the bos in the sample had firstsex. ote that e!ent is 20 for all cases except the last one for each bo who had sex b grade 1". Whene!ent20 the case is censored. Censored means that e!ent as not been obser!ed b the end of the one-eardiscrete time inter!al.
4
10
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
11
12
8/17/2019 Lab Session Discrete Time Survival Model 2015
http://slidepdf.com/reader/full/lab-session-discrete-time-survival-model-2015 5/11
We now use stset again to define the duration and e!ent !ariables. Since we ha!e multiple obser!ations perbo we denote id as the case !ariable. We also use the enter modifier to state that the earliest entr is inperiod $. 3 including it Stata notes below that there are cases that experience the e!ent in grade $.
,efine origin time for risk at end of grade $
. stset *eriod, failure$event( id$id( origin$t (
id: id failure event: event + 0 9 event .obs. time interval: $*eriodDn)1;, *eriod; exit on or before: failure t for anal'sis: $time)origin( origin: time
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) 822 total obs. 0 exclusions)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) 822 obs. remaining, re*resenting 180 sub>ects 12 failures in single failure)*er)sub>ect data 822 total anal'sis time at ris=, at ris= from t + 0 earliest observed entr' t + 0 last observed exit t +
. stdes
failure d: event anal'sis time t: *eriod enter on or after: time id: id
)))))))))))))) *er sub>ect ))))))))))))))
Categor' total mean min median max))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))no. of sub>ects 180no. of records 822 .7 1
$first( entr' time $final( exit time 10.7 7 11 12
sub>ects it- ga* 0time on ga* if ga* 0 . . . .time at ris= 822 .7 1
failures 12 .7 0 1 1
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
Discrete time survival/hazard models
5
13
166
167
168
169
170
171
172173
174175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
14
15
8/17/2019 Lab Session Discrete Time Survival Model 2015
http://slidepdf.com/reader/full/lab-session-discrete-time-survival-model-2015 6/11
We now estimate a discrete time sur!i!al model under a proportional odds assumption. 4nder the proportionalodds assumption we can posit that the logit of the ha5ard rate of first sex is a linear function of time %grade'6parent antisocial beha!ior6 and whether a parental transition occurred b grade $.
Model: logit ht!" #o $ #1 time $#% as $ #' t
The logit of ha5ard rate h%t' between 0 and 1 is eual to the log %h%t'71-h%t''. This is the linear form of thefamiliar binar logit model.
log ht!/1(ht!!" #o $ #1 time $#% as $ #' t
We can rearrange this with algebra to produce a standard logistic model for the ha5ard rate below
ht! " e)#o $ #1 time $#% as $ #' t! /1$ e)#o $ #1 time $#% as $ #' t!!
Model 1: logit o* hazard rate increases linearl+ in time
We specif the !ariable period that ranges from (-1" as a time !ariable. /f there is a constant ha5ard rate forfirst sex its estimated coefficient should not be significantl different from 0. /f the coefficient is positi!e andsignificant6 the ha5ard rate rises as bos enter later school grades. There are multiple obser!ations per bo inthe discrete time dataset and the assumption of independent uncorrelated errors is not plausible. We can addthe option !ce%cluster cluster !ariable'6 where cluster !ariable is the person identifier !ariable in thisapplication. 9bser!ations are clustered within persons as a panel data set. The cluster id option has no effecton the coefficient estimates6 but ad:usts the standard errors for repeat obser!ations.
. logit event *eriod *as *t, or vce$cluster id(
@teration 0: log *seudoli=eli-ood + )#2.1172@teration 1: log *seudoli=eli-ood + )#20.%8%7@teration 2: log *seudoli=eli-ood + )#18.772#@teration #: log *seudoli=eli-ood + )#18.7%
@teration : log *seudoli=eli-ood + )#18.7%
Bogistic regression Humber of obs + 822 Iald c-i2$#( + 7.07 /rob J c-i2 + 0.0000Bog *seudoli=eli-ood + )#18.7% /seudo K2 + 0.0%7
$5td. rr. ad>usted for 180 clusters in id()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) Kobust event 3dds Katio 5td. rr. ! /J! D%& Conf. @nterval;))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) *eriod 1.88 .0%%280% .%1 0.000 1.#71%81 1.72171
*as 1.##78 .102%# 2.% 0.01# 1.02#2 1.%%2 *t 1.%#%2# .%278% 2.80 0.00 1.21%0%8 #.087%1 cons .001871 .0012# )%. 0.000 .0000 .0088))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
The results suggest that the ha5ard rate increases o!er time. The odds of first sex increase b ++; for bos ineach higher school grade. igher le!els of parent antisocial beha!ior increase the odds of first sex occurrence.The odds of first sex are nearl double %9<21.)*' among bos with parental transitions b grade ( controllingfor other !ariables.
6
16
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253254
255
256
257
258
259
260
261
262
263
264
265
266267
268
269
270
271
272
273
274
17
18
8/17/2019 Lab Session Discrete Time Survival Model 2015
http://slidepdf.com/reader/full/lab-session-discrete-time-survival-model-2015 7/11
We are not restricted to a model where the logit of the ha5ard rate increases linearl o!er time. /n place of thetime period !ariable. We can specif a set of categorical dumm !ariables corresponding to the months 8-1"with month ( omitted as the reference group. The coefficients for d8-d1" indicate how the ha5ard rate for firstsex !aries b grade relati!e to grade (.
. logit event d8 d% d10 d11 d12 *as *t, vce$cluster id(
@teration 0: log *seudoli=eli-ood + )#2.1172
@teration 1: log *seudoli=eli-ood + )#18.1%17@teration 2: log *seudoli=eli-ood + )#1.0%%@teration #: log *seudoli=eli-ood + )#1.7#2@teration : log *seudoli=eli-ood + )#1.7#8@teration : log *seudoli=eli-ood + )#1.7#8
Bogistic regression Humber of obs + 822 Iald c-i2$7( + 70.#0 /rob J c-i2 + 0.0000Bog *seudoli=eli-ood + )#1.7#8 /seudo K2 + 0.10
$5td. rr. ad>usted for 180 clusters in id())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
Kobust event Coef. 5td. rr. ! /J! D%& Conf. @nterval;))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) d8 ).%122# .72%7# )1. 0.1# )1.177% .2#71 d% .7#00# .#8% 2.1# 0.0## .0%171% 1.28# d10 1.20007 .#21%1 #.1 0.000 .2%#7# 1.8707 d11 1.#71 .##7 #.88 0.000 .80#28 2.070 d12 1.88### .#88#87 .2 0.000 1.18002 2.8 *as .2%#0 .11%888 2.7 0.01# .01#8# .#1##77 *t .0#01 .2#71% 2.78 0.00 .1%811 1.122% cons )2.8%#2#7 .#0%%8%% )%.## 0.000 )#.0080 )2.288))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
These results suggest that the increase in logit of the ha5ard rate for first sex is not linear. /t is flat or negati!elsloped until grade ) and the ha5ard rate increases !er sharpl in grade 1".
. logit event d8 d% d10 d11 d12 *as *t, vce$cluster id( or
@teration 0: log *seudoli=eli-ood + )#2.1172@teration 1: log *seudoli=eli-ood + )#18.1%17@teration 2: log *seudoli=eli-ood + )#1.0%%@teration #: log *seudoli=eli-ood + )#1.7#2@teration : log *seudoli=eli-ood + )#1.7#8@teration : log *seudoli=eli-ood + )#1.7#8
Bogistic regression Humber of obs + 822 Iald c-i2$7( + 70.#0 /rob J c-i2 + 0.0000Bog *seudoli=eli-ood + )#1.7#8 /seudo K2 + 0.10
$5td. rr. ad>usted for 180 clusters in id()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) Kobust event 3dds Katio 5td. rr. ! /J! D%& Conf. @nterval;
7
19
275
276
277
278
279
280
281
282
283284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
20
21
8/17/2019 Lab Session Discrete Time Survival Model 2015
http://slidepdf.com/reader/full/lab-session-discrete-time-survival-model-2015 8/11
))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) d8 .0081#1 .2#8# )1. 0.1# .1%8### 1.2% d% 2.1022 .7##71 2.1# 0.0## 1.00%8 .1% d10 #.#20#07 1.1#18 #.1 0.000 1.%787 .%#1 d11 #.%7218 1.0#2 #.88 0.000 1.%77#2 7.%2%%7 d12 .717 2.#% .2 0.000 #.212 1#.28#8 *as 1.#% .112 2.7 0.01# 1.0##07 1.70120 *t 1.%#818 .%%812 2.78 0.00 1.21082 #.080
cons .0#% .017172 )%.## 0.000 .0#017#1 .101701))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
We can perform simulations using predicted !alues of the model to show the effect of parental transitions onthe timing of first sex among bos.
We first preser!e the original data.. *reserve
We set pas to 0 so that our predictions pertain to bos with parents with a!erage antisocial beha!ior. We setpt21 first and generate predictions from the abo!e logit model.
re*lace *as+0
re*lace *t+0$# real c-anges made(
4se the post-estimation command predict to get predicted ha5ard rates.
. *redict fsex0$o*tion *r assumedL (
ow replace pt20 so that we can generate predicted ha5ard rates for bos without an parental transitions bgrade (.
. re*lace *t+1
$822 real c-anges made(
. *redict fsex1$o*tion *r assumedL (
. toa' $connected fsex0 *eriod, sort( $connected fsex1 *eriod, sort(
8
22
330
331
332
333
334
335
336
337
338339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
23
24
8/17/2019 Lab Session Discrete Time Survival Model 2015
http://slidepdf.com/reader/full/lab-session-discrete-time-survival-model-2015 9/11
0
. 1
. "
. *
. #
= r % e ! e n t '
( 8 ) 10 11 1"period
=r%e!ent' =r%e!ent'
This graph shows that ha5ard rate of first sex increases with grade le!el and is higher among bos with aparental transition b age (.
/n order to graph the sur!i!al functions b parental transition status we need to compute !alues using >uation10.# Singer and Willett. =**+.
5$t(+ 5$t)1($1)-$t((
/n grade ( the sur!i!al rate is simpl 1- ha5ard rate.
. gen surv1+1)fsex1 if *eriod++7$2 missing values generated(
. gen surv0+1)fsex0 if *eriod++7$2 missing values generated(
/n all other grades we must appl the current grade ha5ard rate to the last period sur!i!al rate. We first makesure that the file is sorted b id and period. We then use the euation 10.# shown abo!e to compute thesur!i!al rate for later grades.
. sort id *eriod. re*lace surv1+surv1Dn)1;M$1)fsex1( if *eriod N+7$2 real c-anges made(
. re*lace surv0+surv0Dn)1;M$1)fsex0( if *eriod N+7$2 real c-anges made(
We can now graph the sur!i!al functions b parental transition status as below
9
25
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
26
27
8/17/2019 Lab Session Discrete Time Survival Model 2015
http://slidepdf.com/reader/full/lab-session-discrete-time-survival-model-2015 10/11
. toa' $connected surv0 *eriod, sort( $connected surv1 *eriod, sort(
. "
. #
. $
. 8
1
( 8 ) 10 11 1"period
sur!0 sur!1
These graphs look !er similar in shape to those produced earlier without a discrete-time sur!i!al model. 3oswith parental transitions ha!e higher ha5ard rates for first sex and lower sur!i!al rates. The higher ha5ard ratessuggest that bos with parental transitions b grade ( ha!e first sex earlier than bos with no parentaltransitions.
/t is common to calculate the ?estimated median lifetime@ as a wa of making the implications of the modelmore concrete b considering differences in the expected elapsed time before the e!ent of interest. Theestimated median lifetime identifies the !alue of time where the !alue of the estimated sur!i!al function is 0.+0%Singer A Willett6 p.**('. 9ne can read this off the table abo!e. /f one tabulates the distribution of !alues for theestimated sur!i!al functions we can approximate those !alues as well. B sur!i!al rate of 0.+0 lies betweengrades 11 and 1" for bos without parental transitions and lies between 10 and 11 for bos with parentaltransitions. This indicates a shorter expected time to first sex among bos with parental transitions.
. tab surv0 surv0 FreO. /ercent Cum. Prade))))))))))))))))))))))))))))))))))))))))))))))) .1%#2 80 %.7# %.7# 12 .72070# 10 12.77 22.1 11 .%777 1# 1.#0 #8.81 10
.82772 18 1%.22 8.0# % .%21%## 1 20.07 78.10 8 .%7111 180 21.%0 100.00 7))))))))))))))))))))))))))))))))))))))))))))))) Aotal 822 100.00. tab surv1
surv1 FreO. /ercent Cum.)))))))))))))))))))))))))))))))))))))))))))))))
10
28
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423424
425
426
427
428
429
430
431
29
30
8/17/2019 Lab Session Discrete Time Survival Model 2015
http://slidepdf.com/reader/full/lab-session-discrete-time-survival-model-2015 11/11
.212# 80 %.7# %.7# .#211 10 12.77 22.1 .1782 1# 1.#0 #8.81 .%%# 18 1%.22 8.0# .8711 1 20.07 78.10 .%0#18 180 21.%0 100.00))))))))))))))))))))))))))))))))))))))))))))))) Aotal 822 100.00
T,- -D
11
31
432
433
434
435
436
437
438
439
440441
442
32
33