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" .
标签:return,静态,sum,varlist,scalar,stata,new,写法 From: https://www.cnblogs.com/xkdn/p/17342651.html