Kindly help me include by as an option in the following ado file. How may I add a % sign after the value of coefficient of variation please?
Output:
Code:
capture drop cvs program define cvs, rclass byable(recall) version 13.2 syntax varlist(numeric) [if] [in] display display as text " Variable N mean sd cv" display as text " -----------------------------------------------" marksample touse foreach var of local varlist { if "`if'" ~= "" | "`in'" ~= "" { quietly keep `if' `in' } quietly summarize `var' if `touse', detail local mn = r(mean) local s = r(sd) local n = r(N) local cv = round(`s'/`mn'*100, .1) display as result %20s "`var'" %9.0f `n' %10.2f `mn' %10.2f `s' %10.2f `cv' } end
Code:
. sysuse auto (1978 Automobile Data) . cvs price-rep78 Variable N mean sd cv ----------------------------------------------- price 69 6146.04 2912.44 47.40 mpg 69 21.29 5.87 27.60 rep78 69 3.41 0.99 29.10 . bysort foreign: cvs price-rep78 ------------------------------------------------------------- -> foreign = Domestic Variable N mean sd cv ----------------------------------------------- price 48 6179.25 3188.97 51.60 mpg 48 19.54 4.75 24.30 rep78 48 3.02 0.84 27.70 ------------------------------------------------------------- -> foreign = Foreign Variable N mean sd cv ----------------------------------------------- price 21 6070.14 2220.98 36.60 mpg 21 25.29 6.31 25.00 rep78 21 4.29 0.72 16.70
Comment