// Figure 9.1 use "C:\singer willett (2003)\teachers.dta", clear label define censor 0 "Not censored" 1 "Censored" label val censor censor histogram t, by(censor, legend(off) note("")) freq xlabel(1 (1) 12) ylabel(0 (100) 500) /// addlabels discrete xtitle("Years of teaching") name(figure91, replace) // Table 10.1 generate event = !censor qui ltable t event, noadjust saving(lifetable, replace) preserve use lifetable, clear list t0 t1 start deaths lost hazard survival, sep(0) noobs erase lifetable.dta restore // Figure 10.1 stset t, failure(event) sts generate h = h twoway scatter h t, msymbol(i) connect(l) ylabel(0 (.05) .15) xlabel(0 (1) 13) /// sort xtitle("Years in teaching") /// ytitle("Estimated hazard probability") /// name(figure101a, replace) nodraw ltable t event, noadjust notab graph noconf xlabel(0 (1) 13) ylabel(0 (.5) 1) /// yline(.5) xline(7.6) /// xtitle("Years in teaching") /// ytitle("Proportion surviving") /// name(figure101b, replace) nodraw graph combine figure101a figure101b, col(1) name(figure101, replace) ysize(8) // Figure 10.2 use "C:\singer willett (2003)\relapse_days.dta", clear generate weeks = int(days / 7) + 1 generate event = !censor stset weeks, failure(event) sts generate h = h twoway (scatter h weeks, connect(l) msymbol(i)), xlabel(0 (1) 12) ylabel(, format(%6.2f)) /// ytitle("Estimated hazard probability") /// xtitle("Weeks after release") /// name(figure102a1, replace) nodraw ltable weeks event, notable graph noconf ylabel(0 (.25) 1, format(%6.2f)) /// xlabel(0(1)12) yline(0.5) /// ytitle("Estimated survival probability") /// xtitle("Weeks after release") /// name(figure102a2, replace) nodraw graph combine figure102a1 figure102a2, col(2) /// title("{bf:A} Time to cocaine relapse", pos(11)) name(figure102a, replace) nodraw use "C:\singer willett (2003)\firstsex.dta", clear generate event = !censor stset time, failure(event) sts generate h = h twoway (scatter h time, connect(l) msymbol(i) sort), xlabel(6 (1) 12) ylabel(, format(%6.2f)) /// ytitle("Estimated hazard probability") /// xtitle("Grade") /// name(figure102b1, replace) nodraw ltable time event, notable graph noconf ylabel(0 (.25) 1, format(%6.2f)) /// xlabel(6 (1) 12) yline(0.5) /// ytitle("Estimated survival probability") /// xtitle("Grade") /// name(figure102b2, replace) nodraw graph combine figure102b1 figure102b2, col(2) /// title("{bf:B} Age at first intercourse for males", pos(11)) name(figure102b, replace) nodraw use "C:\singer willett (2003)\suicide_orig.dta", clear generate event = !censor stset time, failure(event) sts generate h = h twoway (scatter h time, connect(l) msymbol(i) sort), xlabel(5 (2) 21) ylabel(, format(%6.2f)) /// ytitle("Estimated hazard probability") /// xtitle("Age") /// name(figure102c1, replace) nodraw ltable time event, notable graph noconf ylabel(0 (.25) 1, format(%6.2f)) /// xlabel(5 (2) 21) yline(0.5) /// ytitle("Estimated survival probability") /// xtitle("Age") /// name(figure102c2, replace) nodraw graph combine figure102c1 figure102c2, col(2) /// title("{bf:C} Age at first suicide ideation", pos(11)) name(figure102c, replace) nodraw use "C:\singer willett (2003)\congress_orig.dta", clear generate event = !censor stset time, failure(event) sts generate h = h twoway (scatter h time, connect(l) msymbol(i) sort), xlabel(0 (1) 8) ylabel(0 (.1) .3, format(%6.2f)) /// ytitle("Estimated hazard probability") /// xtitle("Terms in office") /// name(figure102d1, replace) nodraw ltable time event, notable graph noconf ylabel(0 (.25) 1, format(%6.2f)) /// xlabel(0 (1) 8) yline(0.5) /// ytitle("Estimated survival probability") /// xtitle("Terms in office") /// name(figure102d2, replace) nodraw graph combine figure102d1 figure102d2, col(2) /// title("{bf:D} Duration of congressional careers for females", pos(11)) name(figure102d, replace) nodraw graph combine figure102a figure102b figure102c figure102d, row(4) ysize(11) name(figure102, replace) // Table 10.2 use "C:\singer willett (2003)\teachers.dta", clear generate event = !censor qui ltable t event, noadjust saving(lifetable, replace) preserve use lifetable, clear list t0 hazard sehazard survival sesurvival, noobs sep(0) erase lifetable.dta restore // Figure 10.4 use "C:\singer willett (2003)\teachers.dta", clear list id t censor if inlist(id, 20, 126, 129), noobs sep(0) expand t bysort id: generate period = _n // Period identifier bysort id: generate event = !censor & _n == _N // Calculate outcome for // discrete-time analysis list id period event if inlist(id, 20, 126, 129), noobs sepby(id) // Table 10.3 table period, c(sum event n event mean event)
Jul 4, 2017
Chapters 9 and 10 of Singer and Willett's (2003) book on longitudinal data analysis
Labels:
expand,
Histogram,
ltable,
sts generate,
stset,
Survival analysis,
Textbooks



