cd "/Users/dave/UCSF/Projects/Teaching/Teaching 12/Lecture 8" use "lecture class.dta", clear mkspline agesp = age, cubic nknots(5) mkspline agedonsp = age_don, cubic nknots(5) mkspline yearsp = year, cubic nknots(5) logistic txtype prevtx prevtx##c.yearsp* prevtx##c.agesp* prevtx##c.agedonsp* i.hla predict prop xtile group=prop, nq(5) tab group txtype /* Overlap */ kdensity prop if txtype==1, generate(dens1 x1) nograph kdensity prop if txtype==0, generate(dens0 x0) nograph twoway (line x0 dens0, sort) (line x1 dens1, sort), yscale(off) xtitle(Probability of Cadaveric Kidney) scheme(s1color) legend(order(1 "Living" 2 "Cadaveric")) table txtype group, c(mean prevtx) format(%9.2f) /* Quintile */ cc death txtype, by(group) logistic death i.txtype i.group tabulate death txtype if group==1 tabulate death txtype if group==5 /* Likelihood Ratio Test for Interaction */ logistic death txtype##i.group est store A logistic death txtype i.group lrtest A /* Linear in Propensity */ logistic death i.txtype prop /* Splines */ mkspline prop_sp = prop, cubic nknots(3) logistic death txtype prop_sp* /* Quintile */ logistic death i.txtype i.group margins txtype . margins, dydx(txtype) /* RR based on Quintile */ logistic death i.txtype i.group margins txtype, post nlcom (logRR: log(_b[1.txtype]) - log(_b[0.txtype])) /* (log) RR based on Quintile */ logistic death i.txtype i.group margins txtype, post nlcom (logRR: log(_b[1.txtype]) - log(_b[0.txtype])) /* (log) OR based on Quintile */ logistic death i.txtype i.group margins txtype, post nlcom (OR: log(_b[1.txtype])+log(1-_b[0.txtype])-log(_b[0.txtype])-log(1-_b[1.txtype]) ) /* Regression */ logistic death i.txtype prevtx year age age_don i.hla logistic death i.txtype prevtx prevtx##c.yearsp* prevtx##c.agesp* prevtx##c.agedonsp* i.hla /* (log) OR based on Logistic Regression for Death */ margins txtype, post nlcom (OR: log(_b[1.txtype])+log(1-_b[0.txtype])-log(_b[0.txtype])-log(1-_b[1.txtype]) ) /* 20 Strata */ xtile group3=prop, nq(20) logit death txtype, i.group3