## STATA Homework Help on Model Adequacy

• 4th Feb, 2022
• 16:21 PM
*q1a
import delimited "framing3.csv", delimiter("", collapse) clear
stset timecvd, failure(cvd) id(randid)
stsplit, at(failure)
gen cursmoke=cursmoke1
replace cursmoke=cursmoke2 if _t>=time2
replace cursmoke=cursmoke3 if _t>=time3
gen period=1
replace period=2 if _t>=time2
replace period=3 if _t>=time3
stcox i.sex age totchol i.cursmoke##i.period, nolog
contrast i.cursmoke#i.period
stcox i.sex age totchol i.cursmoke, nolog
contrast i.cursmoke#i.period

*q1b
stcox i.sex age totchol i.cursmoke, nolog
estat phtest, detail log
gen lntime=log(_t+1)
stcox i.sex age c.totchol i.cursmoke c.lntime#c.totchol, nolog
* at time 0
lincom totchol,hr
* at time 1
lincom totchol+c.lntime#c.totchol*0.6931,hr
* at time 2
lincom totchol+c.lntime#c.totchol*1.0986,hr
* at time 5
lincom totchol+c.lntime#c.totchol*1.7918,hr
* at time 10
lincom totchol+c.lntime#c.totchol*1.3979,hr
* at time 20
lincom totchol+c.lntime#c.totchol*3.0445,hr

* use multiple record format
import delimited "framing3.csv", clear
gen time1=0
reshape long cursmoke time, i(randid) j(period)
drop if time==.
gen timestart=time
gen timestop=time[_n+1]
replace timestop=timecvd if (timestop==0) | (timestop==.)
replace cvd=0 if timestop drop if timestart>timecvd
replace timestop=timecvd if timestop>timecvd
stset timestop, entry(timestart) failure(cvd) id(randid)

stcox i.sex age totchol i.cursmoke##i.period, nolog
contrast i.cursmoke#i.period

stcox i.sex age totchol cursmoke