I believe the following example using the autos dataset demonstrates a complete example of code and technique that can be adapted to meet your needs in a straightforward fashion. Note also that if the separate matrices are not needed for other purposes, you can replace references to mtx_`var' and mtx_`var'_long with mtx and mtx_long.
Code:
sysuse auto, clear drop if missing(rep78) putexcel set "~/Downloads/tables.xlsx", sheet("Descriptives") modify local row 1 foreach var of varlist foreign rep78 { estpost tabulate `var' matrix freq = e(b) matrix pct = e(pct) matrix mtx_`var' = freq \ pct matrix mtx_`var'_long = mtx_`var'' matrix colnames mtx_`var'_long = "N" "Percent" matrix list mtx_`var'_long putexcel A`row' = matrix(mtx_`var'_long), names putexcel A`row' = "`var'" local row = `row' + rowsof(mtx_`var'_long) + 2 } putexcel close
Comment