You can use if with tabstat to get the results you want.
sysuse auto, clear
by for: tabstat mpg
tabstat mpg if for == 0, save
matrix a = r(StatTotal)
putexcel A1=(a) ...
tabstat mpg if for == 1, save
matrix a = r(StatTotal) ...
putexcel A4=(a)
You can use if with tabstat to get the results you want.
sysuse auto, clear
by for: tabstat mpg
tabstat mpg if for == 0, save
matrix a = r(StatTotal)
putexcel A1=(a) ...
tabstat mpg if for == 1, save
matrix a = r(StatTotal) ...
putexcel A4=(a)