Coefficient of variation when using esttab

61 views Asked by At

I am tabulating in Stata the weighted frequency of three variables (EVR_CIGS, P12M_CIGS, CUR_CIGS), and I am using the estout package to have my weighted results in Excel.

I need to print the coefficient of variation cv along with cell, lb, ub, and obs when I run esttab, but the column for cv stays empty. I know it is not one of the saved vectors, so I wonder if there is a workaround.

This is what I tried:


svyset [pweight=ES04WGT], brr(ES04WGT1 - ES04WGT100) vce(brr) mse fay(.3)
    

eststo clear
foreach var in EVR_CIGS P12M_CIGS CUR_CIGS {
    estpost svy, sub(if inrange(AGE,16,17)): tab `var', ci obs percent cv format(%9.1fc) stubwidth(25)  
    eststo
}

esttab using "${nugget}Table1_09122023.csv", replace cv cell("cell cv lb ub obs")  varwidth(20) wide plain page nostar unstack varlabels(`e(labels)') mtitle("EVR_CIGS" "P12M_CIGS" "CUR_CIGS") 

This is what I get:

enter image description here

1

There are 1 answers

0
Kathryn Roman Banda On

I really like the 'asdoc' wrapper. You'll have to install it and do some minor coding, but it includes the coefficient of variation as needed. You can read about it here:

https://www.statalist.org/forums/forum/general-stata-discussion/general/1435798-asdoc-an-easy-way-of-creating-publication-quality-tables-from-stata-commands

Or just do: ssc install asdoc, update