Stata added collect and enable suite of commands. I am discovering them now having migrated to Stata 18 from Stata 15.
Useful Links
- https://blog.stata.com/2021/09/02/customizable-tables-in-stata-17-part-6-tables-for-multiple-regression-models/
- https://www.stata.com/support/faqs/reporting/export-regression-results-table-formats/
- https://www.statalist.org/forums/forum/general-stata-discussion/general/1742631-use-of-collect-to-customize-a-table
- https://www.statalist.org/forums/forum/general-stata-discussion/general/1726941-collect-layout-with-regression-coefficients-for-continuous-independent-variables
- https://www.stata.com/features/overview/tables-of-estimation-results/
- https://www.stata.com/stata-news/news38-1/etable/
- https://www.stata.com/meeting/italy22/slides/Italy22_Pitblado.pdf
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
![](https://www.epidemiology.tech/wp-content/uploads/2024/06/image-5.png)
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
![](https://www.epidemiology.tech/wp-content/uploads/2024/06/image-4.png)