Dear all, I'm wondering if there is an easy way to generate a .rtf or .xlsx file that include results of -table-.
Code:
sysuse auto.dta table foreign rep78
ssc install estout, replace
sysuse auto.dta table foreign rep78 *USING ESTPOST +TAB + ESTTAB estpost tab foreign rep78 esttab using myfile.rtf, replace cells(b) unstack compress /// nonumbers collab(none) eqlabel(, lhs(`:var lab foreign')) noabbrev /// drop(Total) title(" `:var lab rep78'")
. table foreign rep78 ---------------------------------------- | Repair Record 1978 Car type | 1 2 3 4 5 ----------+----------------------------- Domestic | 2 8 27 9 2 Foreign | 3 9 9 ---------------------------------------- . esttab, cells(b) unstack compress nonumbers drop(Total) /// > collab(none) eqlabel(, lhs(`:var lab foreign')) noabbrev /// > title(" `:var lab rep78'") Repair Record 1978 ---------------------------------------------------------------------- Car type 1 2 3 4 5 Total ---------------------------------------------------------------------- Domestic 2 8 27 9 2 48 Foreign 0 0 3 9 9 21 ---------------------------------------------------------------------- N 69 ----------------------------------------------------------------------
ssc install table1_mc, replace sysuse auto, clear *create an indicator variable to show how a binary variable can be summarised in a moment generate much_headroom = (headroom>3) table1_mc, by(foreign) /// vars(price conts \ displacement contln %5.0f %4.2f \ weight contn %5.0f \ rep78 cate \ much_headroom bine) /// onecol gsdleft(" ×/ ") gsdright(" ") sdleft(" ± ") sdright(" ") nospacelowpercent clear /// saving("example Table 1.xlsx", replace) +--------------------------------------------------------------------------------+ | Domestic Foreign p-value | |--------------------------------------------------------------------------------| | N=52 N=22 | |--------------------------------------------------------------------------------| | Price 4,782.5 (4,184-6,234) 5,759 (4,499-7,140) 0.30 | |--------------------------------------------------------------------------------| | Displacement (cu. in.) 217 ×/ 1.49 109 ×/ 1.24 <0.001 | |--------------------------------------------------------------------------------| | Weight (lbs.) 3317 ± 695 2316 ± 433 <0.001 | |--------------------------------------------------------------------------------| | Repair Record 1978 <0.001 | | 1 2 (4%) 0 (0%) | | 2 8 (17%) 0 (0%) | | 3 27 (56%) 3 (14%) | | 4 9 (19%) 9 (43%) | | 5 2 (4%) 9 (43%) | |--------------------------------------------------------------------------------| | much_headroom 28 (54%) 2 (9%) <0.001 | +--------------------------------------------------------------------------------+ Data are presented as mean ± SD or geometric mean ×/ geometric SD or median (IQR) for continuous measures, and n (%) for categorical measures.
ssc install asdoc sysuse auto.dta asdoc table foreign rep78
Comment