stata 输出结果到doc文件

转自网络

https://gitee.com/arlionn/reg2docx/blob/master/reg2docx-Wu.md

 

clear all

set more off

putdocx begin //新建 Word 文档

putdocx paragraph, halign(center) //段落居中

*-定义字体、大小等基本设置

putdocx text ("附:文中待插入表格"), ///

font("华为楷体",16,black) bold linebreak

*-保存名为 My_Table.docx 的 Word 文档

putdocx save "My_Table.docx", replace

sysuse "auto.dta", clear

*-Table 1

sum2docx price-length using "My_Table.docx", append ///

obs mean(%9.2f) sd min(%9.0g) median(%9.0g) max(%9.0g) ///

title("表 1: 描述性统计")

*-Note: 选项 append 的作用是将这张新表追加到 "My_Table.docx" 尾部, 下同.

*-Table 2

putdocx begin

putdocx pagebreak

putdocx save "My_Table.docx", append

corr2docx price-length using "My_Table.docx", append ///

star(* 0.05) fmt(%4.2f) ///

title("表 2:相关系数矩阵")

*-Table 3

putdocx begin

putdocx pagebreak

putdocx save "My_Table.docx", append

t2docx price-length using "My_Table.docx", append ///

by(foreign) title("表 3:组间均值差异 t 检验")

*-Table 4

putdocx begin

putdocx pagebreak

putdocx save "My_Table.docx", append

reg price mpg weight length

est store m1

reg price mpg weight length foreign

est store m2

probit foreign price weight length

est store m3

reg2docx m1 m2 m3 using "My_Table.docx", append ///

r2(%9.3f) ar2(%9.2f) b(%9.3f) t(%7.2f) ///

title("表4: 回归结果")

shellout "My_Table.docx" //大功告成!打开生成的 Word 文档

你可能感兴趣的:(stata 输出结果到doc文件)