I have three questions. My first question is about the order of the summary statistics that appear in the cells of my continuous variables. Here's my code:
And here's the resulting table:
I've deliberately enclosed the ranges in brackets [] rather than parentheses () and highlighted them so they can more easily be spotted. For "age of mother", the range is the last statistic displayed in each cell while for "weight at last menstrual period" it's the first statistic displayed. What determines the order? In my continuous options, rangei appears at the end of the statistic suboption, so the order isn't determined by the order each statistic is listed here.
I've come up with a work around, but would still like to know how to control the order in which each summary statistic is displayed.
In my work around, I've placed the range in a separate row. To do this I've generated a copy of each continuous variable. My second question: Is there a more efficient way to do this?
My third question is about adding a blank row between each variable. I know I can do this for the factor/categorical variables using this code:
Is it possible to add a blank row after each continuous variable using collect? I've been able to do it via putdocx so it's OK if not.
Kind regards,
Suzanna
Code:
*Reading in the low birthweight dataset available on the Stata Press website.
use https://www.stata-press.com/data/r18/lbw,clear
*Defining and attaching value labels.
label define noyes 0 No 1 Yes
label values low ht noyes
*Clearing any collections that may be in Stata's memory.
collect clear
*Creating descriptive table.
dtable age lwt i.race i.ht, by(low, nototals) ///
sample(, statistic(frequency) place(seplabels)) ///
sformat("n=%s" frequency) ///
define(rangei = min max, delimiter("-")) sformat("[%s]" rangei) ///
define(iqi = q1 q3, delimiter(",")) sformat("(%s)" iqi) ///
continuous(age, statistic(mean sd rangei)) ///
continuous(lwt, statistic(median iqi rangei)) ///
nformat(%2.0f fvpercent mean median sd iqi rangei) nformat(%3.1f sd) ///
title(Table 1: Mother's demographic and clinical characteristics) ///
titlestyles(font(Calibri, size(14) bold))
Code:
Table 1: Mother's demographic and clinical characteristics
-----------------------------------------------------------------------------
Birthweight<2500g
No Yes
n=130 n=59
-----------------------------------------------------------------------------
Age of mother 24 (5.6) [14-45] 22 (4.5) [14-34]
Weight at last menstrual period [85-250] 124 (113,147) [80-200] 120 (103,130)
Race
White 73 (56%) 23 (39%)
Black 15 (12%) 11 (19%)
Other 42 (32%) 25 (42%)
Has history of hypertension
No 125 (96%) 52 (88%)
Yes 5 (4%) 7 (12%)
-----------------------------------------------------------------------------
I've come up with a work around, but would still like to know how to control the order in which each summary statistic is displayed.
In my work around, I've placed the range in a separate row. To do this I've generated a copy of each continuous variable. My second question: Is there a more efficient way to do this?
Code:
*Creating a copy of the continuous variables included in the table. This creates
*a separte row to display the range.
foreach var of varlist age lwt {
gen `var'2=`var'
label var `var'2 "(Range)"
}
*Creating descriptive table.
dtable age age2 lwt lwt2 i.race i.ht, by(low, nototals) ///
sample(, statistic(frequency) place(seplabels)) ///
sformat("n=%s" frequency) ///
define(rangei = min max, delimiter("-")) sformat("(%s)" rangei) ///
define(iqi = q1 q3, delimiter(",")) sformat("(%s)" iqi) ///
continuous(age, statistic(mean sd)) ///
continuous(lwt, statistic(median iqi)) ///
continuous(age2 lwt2, statistic(rangei)) ///
nformat(%2.0f fvpercent mean median sd iqi rangei) nformat(%3.1f sd) ///
title(Table 1: Mother's demographic and clinical characteristics) ///
titlestyles(font(Calibri, size(14) bold))
Table 1: Mother's demographic and clinical characteristics
-----------------------------------------------------------
Birthweight<2500g
No Yes
n=130 n=59
-----------------------------------------------------------
Age of mother 24 (5.6) 22 (4.5)
(Range) (14-45) (14-34)
Weight at last menstrual period 124 (113,147) 120 (103,130)
(Range) (85-250) (80-200)
Race
White 73 (56%) 23 (39%)
Black 15 (12%) 11 (19%)
Other 42 (32%) 25 (42%)
Has history of hypertension
No 125 (96%) 52 (88%)
Yes 5 (4%) 7 (12%)
-----------------------------------------------------------
Code:
collect style row stack, spacer
Kind regards,
Suzanna
Comment