I just upgraded to Stata 18 and am trying to create my Table 1. I have successfully exported the table to Excel, but the mean and sd are in the same Excel column, and the n and % are in the same Excel column. I need the mean/N in one column and the sd/% in one column (see screenshot of what I want below). I haven't found a way to do this using Dtable, but I am sure there must be a way. Does anyone know how to do this?
I pasted the code I am using and a sample of my dataset below. I also attached a screenshot from Excel showing the format I am trying to achieve.
This is an example of the column format I would like to achieve for the mean/sd and n/%.

Thanks in advance,
Mark
I pasted the code I am using and a sample of my dataset below. I also attached a screenshot from Excel showing the format I am trying to achieve.
Code:
dtable c.age i.gender i.education, by(amphetamines_past30m, nototals tests) sample(, statistics(freq) place(seplabels)) sformat("(N=%s)" frequency) note(Total sample: N = 344) nformat(%7.2f mean sd) title(Table 1. Demographics) export(table1.xlsx, replace)
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int participant_ID byte(age gender education) float amphetamines_past30m 180 52 2 3 0 38 67 2 4 0 266 63 1 4 1 184 55 2 2 0 32 65 1 1 0 190 52 2 1 1 244 68 2 3 0 303 55 1 2 0 211 62 2 1 0 196 60 1 2 0 174 46 2 4 0 51 57 2 3 0 52 35 2 2 0 309 36 1 2 1 127 53 1 3 0 59 60 2 3 0 94 60 2 3 0 274 58 1 4 0 246 43 2 2 1 67 65 2 1 1 6 59 2 2 0 187 60 1 1 1 258 73 2 3 0 42 59 2 2 0 96 59 1 1 0 69 67 2 2 0 end
This is an example of the column format I would like to achieve for the mean/sd and n/%.
Thanks in advance,
Mark
Comment