You are the best. Between this version and the one you did for Matthew Wallace in the related post, I think I might have my perfect version of Table 1 demographics.
-
Login or Register
- Log in with
clear all sysuse auto drop if rep78==1 | rep78==2 set table_style table table (rep78) (foreign), statistic(p50 mpg) statistic(p25 mpg) statistic(p75 mpg) levelsof rep78, local(levels) foreach l of local levels { quietly: collect r(p), tag(rep78[`l']): ranksum mpg if rep78==`l', by(foreign) } quietly: collect r(p), tag(rep78[.m]): ranksum mpg, by(foreign) collect style cell result[p25 p50 p75], nformat("%4.1f") collect composite define iqr = p25 p75 , delimiter("-") trim collect style cell result[iqr], sformat("[%s]") collect composite define median_iqr = p50 iqr , delimiter(" ") trim collect stars p .1 "*" .01 "**" .001 "***" collect style header result[stars], level(hide) collect composite define p_stars = p stars collect layout (rep78) (foreign[.m 0 1]#result[median_iqr] result[p_stars]) collect style header foreign, title(hide) collect style header result[median_iqr], level(hide) collect label levels result p "PValue", modify collect style row stack, nobinder spacer collect style cell border_block, border(right, pattern(nil)) collect label levels result median_iqr "Median [IQR]", modify collect notes "Median [IQR]" collect notes "* p<0.05 ** p<0.01 *** p<0.001" collect style notes, font(Garamond, size(7) italic) collect style cell result[p], nformat(%5.3f) collect style cell result[p_stars], halign(left) collect style cell, font(Garamond) collect preview collect style save style-multimedian, replace set table_style style-multimedian table (rep78) (foreign), statistic(p50 mpg) statistic(p25 mpg) statistic(p75 mpg) // style(style-multimedian, override) //set table_style style-multimedian collect preview
------------------------------------------------------------------------------------- Total Domestic Foreign PValue ------------------------------------------------------------------------------------- Repair record 1978 3 19.0 [17.0-21.0] 19.0 [16.0-21.0] 23.0 [21.0-26.0] 0.040 * 4 22.5 [18.0-25.0] 18.0 [15.0-21.0] 25.0 [23.0-25.0] 0.005 ** 5 30.0 [18.0-35.0] 32.0 [30.0-34.0] 25.0 [18.0-35.0] 0.635 Total 20.0 [18.0-25.0] 19.0 [16.0-21.0] 25.0 [21.0-28.0] 0.004 ** ------------------------------------------------------------------------------------- Median [IQR] * p<0.05 ** p<0.01 *** p<0.001
----------------------------------------------- Domestic Foreign Total ----------------------------------------------- Repair record 1978 3 50th percentile 19.0 23.0 19.0 25th percentile 16.0 21.0 17.0 75th percentile 21.0 26.0 21.0 4 50th percentile 18.0 25.0 22.5 25th percentile 15.0 23.0 18.0 75th percentile 21.0 25.0 25.0 5 50th percentile 32.0 25.0 30.0 25th percentile 30.0 18.0 18.0 75th percentile 34.0 35.0 35.0 Total 50th percentile 19.0 25.0 20.0 25th percentile 16.0 21.0 18.0 75th percentile 21.0 28.0 25.0 ----------------------------------------------- Median [IQR] * p<0.05 ** p<0.01 *** p<0.001
collect style use style-multimedian, override layout
Comment