Epidemiology & Technology

Stata customised tables of Regression results

Stata added collect and enable suite of commands. I am discovering them now having migrated to Stata 18 from Stata 15.

Useful Links

splitsample, generate(train, replace) split(0.80 0.20) show
tab train tt, row

global y "tt"
global x "age i.sex c.ucvaLogmar i.prevSurg c.trichisisDur i.trichisisDurCat c.medial c.middle c.lateral c.totalTrichiatic i.totalTrichiaticCat  i.fpcConj i.fpcEn i.fpcCO i.herberts i.pannusHt i.trichisisLL "
set seed 2342
 
************** Run models on training dataset 
tab train
count 
*** Logistic Regression, 
qui logit $y $x   if train ==1 , baselevels
est store logistic
etable, ///
	showstars showstarsnote ///
	cstat(_r_b, nformat(%4.2f)) ///
	cstat(_r_ci, cidelimiter(,) nformat(%6.2f)) ///
	mstat(N) ///
	mstat(r2_p, nformat(%5.4f) label("Pseudo R2")) ///
	mstat(aic) ///
	mstat(bic) ///
	mstat(ll) ///
	column(estimates) // export(logistic.docx, replace)
Code language: Stata (stata)

Sample Output for etable

using Collect suite

global y "tt"
global x "age i.sex c.ucvaLogmar i.prevSurg c.trichisisDur  c.medial c.middle c.lateral i.fpcConj i.fpcEn i.fpcCO i.herberts i.pannusHt i.trichisisLL "

logit $y $x   if train ==1 , baselevels cformat(%5.3f) pformat(%5.3f) vsquish
est store logisticreg

collect clear
collect create myModels, replace
collect _r_b _r_ci , name(myModels) tag(model[(1)])   : logit $y $x   if train ==1 , baselevels
collect layout (colname#result) (model[(1)]), name(myModels)

* coefficient names are stored in dimension -colname-
*collect dims
*collect levelsof colname
*collect levelsof result

* target cell styles to the results of interest
collect style cell result[_r_b _r_ci], nformat(%4.2f)
collect style cell result[_r_ci], cidelimiter(",") sformat("(%s)")

* turn off factor variables binder so that the row headers can stack
* their levels
collect style row stack , nobinder 

* show result's label in header
collect style header result, title(label)
* center repeated column headers
collect style column, dups(center)

* change the label for the collected odds ratios
*collect label levels result _r_b "OR", modify
* specify the coefficients and results to report in the table
* collect layout (colname[age i.sex c.ucvaLogmar i.prevSurg c.trichisisDur i.trichisisDurCat c.medial c.middle c.lateral c.totalTrichiatic i.totalTrichiaticCat  i.fpcConj i.fpcEn i.fpcCO i.herberts i.pannusHt i.trichisisLL ]) (result[_r_b _r_ci])

collect layout (colname)(result[_r_b _r_ci ]) (model[(1)]), name(myModels)

Code language: PHP (php)

SAMPLE OUTPUT for Collect

Related Posts