Herve--
I'm guessing the easiest way to tackle this is in Mata. However, like
Joseph, I would jump first to a -preserve- and -collapse- method. One
drawback of -collapse- is that it fails noisily if you have string
variables, which -su- does not. That said, if you only care about
means, which are undefined for string variables, we can just strip any
errant string variables out of the varlist. Try this out (and try out
the options):
prog susort, rclass
syntax [varlist] [fw aw iw pw] [, Reverse Stat(str) *]
if "`reverse'"!="" local reverse="-"
if "`stat'"=="" local stat="mean"
foreach v of local varlist {
cap conf numeric v `v'
if _rc!=0 {
local nvars: list varlist - v
}
}
preserve
qui {
collapse (`stat') `nvars' [`weight'`exp'], fast
xpose, clear
tempname var
gen `var'=""
local i=1
foreach v of local nvars {
replace `var'="`v'" in `i'
local i=`i'+1
}
gsort `reverse' v1
forv i=1/`=_N' {
local list `list' `=`var'[`i']'
}
}
return local v "`list'"
if "`weight'"=="pweight" local weight="aw"
restore
su `list' [`weight'`exp'], `options'
end
sysuse auto, clear
susort
susort, r
susort [aw=for], stat(max)
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/