I would probably construct this using -statsby-, for example (pretend that rep78 is country and foreign is sex):
Here's an alternative method which is probably a little faster:Code:sysuse auto, clear set more off tempfile results // temporary file to store cumulative results foreach var of varlist price mpg headroom weight length turn displacement gear_ratio { preserve statsby, by(rep78) clear: ttest `var', by(foreign) gen variable="`var'" capture append using `results' save `results', replace restore } use `results', clear order variable // just to make it easier to read output
You can then calculate the t-statistic etc yourself.Code:sysuse auto, clear set more off tempfile results // temporary file to store cumulative results foreach var of varlist price mpg headroom weight length turn displacement gear_ratio { preserve collapse (mean) mean=`var' (sd) sd=`var' (count) n=`var', by(rep78 foreign) reshape wide mean sd n, i(rep78) j(foreign) gen variable="`var'" capture append using `results' save `results', replace restore } use `results', clear order variable // just to make it easier to read output





Reply With Quote
