Dataset: https://gofile.io/?c=SL3Jow
Code:
use ens_dur.dta
/*Descriptive Statistics */
des
sum
tab smoker
tab physical_act
tab bmi
tab health_q
tab d_compl_init
tab d_compl_quit
/* Drop observations for Ceuta and Melilla */
drop if ccaa>=18
/* Create binary dummies */
gen native=0
replace native=1 if Spanish==1
gen female=0
replace female=1 if sex==2
gen chrill=0
replace chrill=1 if chronic==1
/* Setting the duration and the censoring variables */
stset dur_quit, failure(d_compl_quit)
/* Empirical hazard */
sts graph, hazard
/* Estimation of continuous time duration models */
/* Basic models */
streg, dist(exponential) nohr
streg, dist(weibull) nohr
streg, dist(loglogistic)
streg, dist(lognormal)
streg, dist(ggamma)
streg, dist(gompertz)
stcox, estimate
/* Complete model */
streg c.age##c.age female native i.ccaa i.size_mun i.marital_st /*
*/ i.health_q chrill i.bmi i.physical_act, dist(exponential) nohr
streg c.age##c.age female native i.ccaa i.size_mun i.marital_st /*
*/ i.health_q chrill i.bmi i.physical_act, dist(weibull) nohr
streg c.age##c.age female native i.ccaa i.size_mun i.marital_st /*
*/ i.health_q chrill i.bmi i.physical_act, dist(loglogistic)
streg c.age##c.age female native i.ccaa i.size_mun i.marital_st /*
*/ i.health_q chrill i.bmi i.physical_act, dist(lognormal)
streg c.age##c.age female native i.ccaa i.size_mun i.marital_st /*
*/ i.health_q chrill i.bmi i.physical_act, dist(ggamma)
streg c.age##c.age female native i.ccaa i.size_mun i.marital_st /*
*/ i.health_q chrill i.bmi i.physical_act, dist(gompertz) nohr
stcox c.age##c.age female native i.ccaa i.size_mun i.marital_st /*
*/ i.health_q chrill i.bmi i.physical_act, nohr
estat phtest
0 Response to Duration model, cox or whatever?
Post a Comment