stata 程序写法 静态运行写法 help return
program mysum, rclass syntax varname return local varname `varlist' tempvar new quietly { count if !missing(`varlist') return scalar N = r(N) gen double `new' = sum(`varlist') return scalar sum = `new'[_N] return scalar mean = return(sum)/return(N) } end
. clear . webuse auto,clear (1978 automobile data) . mysum mpg . ret list scalars: r(mean) = 21.2972972972973 r(sum) = 1576 r(N) = 74 macros: r(varname) : "mpg" .