Hi all

I would like to know if there is a more efficient way of getting subtotals and totals when creating tables. I have created a frequency table using contract for three variables (remoteness, Gender, Age group) and I would like to get a subtotal (remoteness gender) and a total (remoteness). I have done this by creating a table using contract then appended the subtotal and total tables created using collapse (code below). I have also attached an example table of the output.

Thanks heaps in advance.

Code:
contract RemoteRegion Gender Age_GP, nomiss

tempfile temp1
save `temp1'

collapse (sum) _freq, by(RemoteRegion Gender)
tempfile temp2
save `temp2'

collapse (sum) _freq, by (RemoteRegion)
tempfile temp3
save `temp3'

use `temp1'
append using `temp2'
append using `temp3'