*! version 1.0.1 14Oct2011 MJC /* History MJC 14Oct2011: version 1.0.1 Help file improved and example dataset changed. MJC 12Oct2011: version 1.0.0 */ program define stjmgraph version 11.2 st_is 2 analysis syntax varlist(min=1 max=1) [if] [in], /// Panel(varname) /// /// [ /// CENSGraphopts(string) /// EVENTGraphopts(string) /// COMBINEopts(string) /// DRAW /// ] tokenize `varlist' marksample touse if "`draw'"=="" { local nodraw "nodraw" } quietly{ sort `panel' _t0 preserve drop if `touse'!=1 tempvar _lagtime _died tempid bys `panel': gen `_lagtime' = _t-_t[_N] if `touse'==1 bys `panel': gen `_died' = 0 if _d[_N]==0 & `touse'==1 bys `panel': replace `_died' = 1 if _d[_N]==1 & `touse'==1 local line_cens keep if `_died'==0 & `touse'==1 egen `tempid' = group(`panel') su `tempid' if `touse'==1, mean local n=r(max) forvalues i=1/`n' { local line_cens "`line_cens' (line `1' `_lagtime' if `tempid'==`i' &`touse'==1, lcol(black) lpat(solid))" } tempname jmg1 jmg2 twoway `line_cens', legend(off) xtitle("Time before censoring") ytitle("Longitudinal response") title("Censored") name(`jmg1') `nodraw' plotregion(margin(zero)) `censgraphopts' restore preserve drop if `touse'!=1 tempvar _lagtime _died tempid bys `panel': gen `_lagtime' = _t-_t[_N] if `touse'==1 bys `panel': gen `_died' = 0 if _d[_N]==0 & `touse'==1 bys `panel': replace `_died' = 1 if _d[_N]==1 & `touse'==1 local line_cens keep if `_died'==1 & `touse'==1 egen `tempid' = group(`panel') if `touse'==1 su `tempid' if `touse'==1, mean local n=r(max) forvalues i=1/`n' { local line_cens "`line_cens' (line `1' `_lagtime' if `tempid'==`i' &`touse'==1, lcol(black) lpat(dash))" } twoway `line_cens', legend(off) xtitle("Time before event") ytitle("Longitudinal response") title("Event") name(`jmg2') `nodraw' plotregion(margin(zero)) `eventgraphopts' graph combine `jmg1' `jmg2', ycommon xcommon `combineopts' restore } end