Hi everyone,
I am trying to create a report with putdocx. I have managed to put percentages in a table, but in the same table, I want to put values of an interquartile range and median.
Anyone that can help?
Thanks in advance.

This is the code i have used:

putdocx begin

putdocx paragraph, halign(left)

putdocx text ("Table 3.1. Demographics (by country)"), font(calibri)

**produce table
putdocx table tbl3=(10,7), layout(autofitcontent) border(top) border(bottom) border(start) border(insideV) border(end)
**
putdocx table tbl3(1,1)=("Characteristic"), halign(left) bold colspan(1) border(bottom) border(right)
putdocx table tbl3(2,1)=("Age"), halign(left) colspan(1) rowspan(2) border(bottom) border(right)
putdocx table tbl3(4,1)=("Gender"), halign(left) colspan(1) rowspan(3) border(bottom) border(right)
putdocx table tbl3(7,1)=("Race"), halign(left) colspan(1) rowspan(4) border(bottom) border(right)

putdocx table tbl3(2,2)=("Median"), halign(left) colspan(1) border(bottom) border(right)
putdocx table tbl3(3,2)=("IQR"), halign(left) colspan(1) border(bottom) border(right)
putdocx table tbl3(4,2)=("Male"), halign(left) colspan(1) border(bottom) border(right)
putdocx table tbl3(5,2)=("Female"), halign(left) colspan(1) border(bottom) border(right)
putdocx table tbl3(6,2)=("Other"), halign(left) colspan(1) border(bottom) border(right)
putdocx table tbl3(7,2)=("White"), halign(left) colspan(1) border(bottom) border(right)
putdocx table tbl3(8,2)=("Black or African American"), halign(left) colspan(1) border(bottom) border(right)
putdocx table tbl3(9,2)=("Asian"), halign(left) colspan(1) border(bottom) border(right)
putdocx table tbl3(10,2)=("Unknown"), halign(left) colspan(1) border(bottom) border(right)

putdocx table tbl3(1,2)=(""), halign(center) bold colspan(1) border(bottom)
putdocx table tbl3(1,3)=("Russia"), halign(center) bold colspan(1) border(bottom)
putdocx table tbl3(1,4)=("China"), halign(center) bold colspan(1) border(bottom)
putdocx table tbl3(1,5)=("USA"), halign(center) bold colspan(1) border(bottom)
putdocx table tbl3(1,6)=("Australia"), halign(center) bold colspan(1) border(bottom)
putdocx table tbl3(1,7)=("Overall"), halign(center) bold colspan(1) border(bottom)



local site2 site2

local col=2 //this created two columns that carry the first data


forvalues site2=1/4{

local Tcol=`col'+`site2'
{
**Age
????This is the command that i have failed to get

**Gender
count if gender==1 & site2==`site2' //male
local s=r(N)
count if gender==0 & site2==`site2' //female
local t=r(N)
count if gender==3 & site2==`site2' //other
local v=r(N)
**Race
count if race_white==1 & site2==`site2' //white, Unchecked
local w=r(N)

count if race_black==1 & site2==`site2' //black, Unchecked
local x=r(N)

count if race_asian==1 & site2==`site2' //asian, Unchecked
local y=r(N)

count if race_unknown==1 & site2==`site2' //unknown, Unchecked
local z=r(N)


count if site2==`site2'
local normal=r(N)

local perc=100*(`s'/`normal')
local perc: di %3.0f `perc'
local perc1=100*(`t'/`normal')
local perc1: di %3.0f `perc1'
local perc2=100*(`v'/`normal')
local perc2: di %3.0f `perc2'

local perc3=100*(`w'/`normal')
local perc3: di %3.0f `perc3'
local perc4=100*(`x'/`normal')
local perc4: di %3.0f `perc4'
local perc5=100*(`y'/`normal')
local perc5: di %3.0f `perc5'
local perc6=100*(`z'/`normal')
local perc6: di %3.0f `perc6'




putdocx table tbl3(4,`Tcol')=("`s'(`perc'%)"), halign(center)
putdocx table tbl3(5,`Tcol')=("`t'(`perc1'%)"), halign(center)
putdocx table tbl3(6,`Tcol')=("`v'(`perc2'%)"), halign(center)
putdocx table tbl3(7,`Tcol')=("`w'(`perc3'%)"), halign(center)
putdocx table tbl3(8,`Tcol')=("`x'(`perc4'%)"), halign(center)
putdocx table tbl3(9,`Tcol')=("`y'(`perc5'%)"), halign(center)
putdocx table tbl3(10,`Tcol')=("`z'(`perc6'%)"), halign(center)

}

}


count if gender==1
local s=r(N)
count if gender==0
local t=r(N)
count if gender==3
local v=r(N)
count if race_white==1
local w=r(N)
count if race_black==1
local x=r(N)
count if race_asian==1
local y=r(N)
count if race_unknown==1
local z=r(N)

count
local normal=r(N)

local perc=100*(`s'/`normal')
local perc: di %3.0f `perc'
local perc1=100*(`t'/`normal')
local perc1: di %3.0f `perc1'
local perc2=100*(`v'/`normal')
local perc2: di %3.0f `perc2'
local perc3=100*(`w'/`normal')
local perc3: di %3.0f `perc3'
local perc4=100*(`x'/`normal')
local perc4: di %3.0f `perc4'
local perc5=100*(`y'/`normal')
local perc5: di %3.0f `perc5'
local perc6=100*(`z'/`normal')
local perc6: di %3.0f `perc6'



putdocx table tbl3(4,7)=("`s'(`perc'%)"), halign(center)
putdocx table tbl3(5,7)=("`t'(`perc1'%)"), halign(center)
putdocx table tbl3(6,7)=("`v'(`perc2'%)"), halign(center)
putdocx table tbl3(7,7)=("`w'(`perc3'%)"), halign(center)
putdocx table tbl3(8,7)=("`x'(`perc4'%)"), halign(center)
putdocx table tbl3(9,7)=("`y'(`perc5'%)"), halign(center)
putdocx table tbl3(10,7)=("`z'(`perc6'%)"), halign(center)

AND THIS IS THE OUTPUT
Characteristic Russia China USA Australia Overall
Age Median
IQR
Gender Male 0( 0%) 0( 0%) 1(100%) 1(100%) 2( 40%)
Female 1(100%) 2(100%) 0( 0%) 0( 0%) 3( 60%)
Other 0( 0%) 0( 0%) 0( 0%) 0( 0%) 0( 0%)
Race White 0( 0%) 0( 0%) 0( 0%) 0( 0%) 0( 0%)
Black or African American 1(100%) 1( 50%) 0( 0%) 1(100%) 3( 60%)
Asian 0( 0%) 0( 0%) 0( 0%) 0( 0%) 0( 0%)
Unknown 0( 0%) 0( 0%) 0( 0%) 0( 0%) 0( 0%)