@liuyuxi
2021-07-18T12:11:25.000000Z
字数 4382
阅读 41
stata
基本上,描述性统计的输出跟在sum xxxxxxx, detail
之后;回归结果输出跟在reg xxxxxxx
之后。
outreg2
描述性统计
特点:1.支持变量排序;2.可在窗口中呈现结果。3.
回归结果输出
在回归结果输出中,主要的选项有append
,title
,ctitle
,keep
,addtext
,replace
等等,其他可用的选项则还包括nocons
,dec(4)
,adjr2
等。另外,outreg2
也可与由est store
保存的估计结果合用,需要使用中括号如outreg2 [m1 m2 m3 m4] using 表3B.xml,
reg ******
outreg2 using xxx.doc,word replace title(outreg2_Table: regression result) ctitle(OLS-1) keep(x1 x2 x3) addtext(City FE,YES,Year FE,YES,City timetrend,YES)
reg ******
outreg2 using xxx.doc,word replace append ctitle(OLS-2) keep(x1 x2 x3) addtext(City FE,YES,Year FE,YES,City timetrend,YES)
..........
最简单版本:
reg ******
outreg2 using "xxx.doc", replace
reg ******
outreg2 using "xxx.doc", append
esttab
描述性统计
回归结果输出
(1) esttab
输出到 Word 的表格形式最符合一般文献报告表格的格式。
(2)最常用的选项应属star()
,b()
,t()
,se()
,r2()
,scalar()
,nogaps
,compress
,mtitles
,title
,indicate()
等。其中,indicate("race=race_num*")
选项,以及可设置每个统计量的小数点位数是其特色。
*引自饶品贵等《高铁开通与供应商分布决策》,《中国工业经济》2019年。
areg Dis HSR Cash Invt Lev Size ROA Rec Age PGDP SOE i.year,absorb(company_id) robust
est store m_1
areg Disw HSR Cash Invt Lev Size ROA Rec Age PGDP SOE i.year,absorb(company_id) robust
est store m_2
esttab m_1 m_2 using baseline.rtf, replace ///
b(%9.4f) star(* 0.1 ** 0.05 *** 0.01) t(%9.4f) ///
scalar(F N r2_a) nogaps ///
mtitle()
*连享会“四个输出命令对比”一文中的code:
esttab m1 m2 m3 using Myfile.rtf, ///
replace star( * 0.10 ** 0.05 *** 0.01 ) nogaps compress ///
order(married) drop(occupation) b(%20.3f) se(%7.2f) ///
r2(%9.3f) ar2 aic bic obslast scalars(F) ///
indicate("race=race_num*") mtitles("OLS-1" "OLS-2" "OLS-3") ///
title(esttab_Table: regression result)
(3)asdoc
,outreg2
中的addtext()
选项在esttab
中可用estadd()
代替。
reghdfe fdi c.D if treatdate ==2017|treatdate ==2015|treatdate ==2013 , absorb(id year) vce(r)
estadd local Cluster Yes,replace
estadd local Year_FE Yes,replace
estadd local Fixed_Effect Yes,replace
estadd local Control No,replace
est sto m1
...........
reghdfe fdi c.D if treatdate ==2019|treatdate ==2018|treatdate ==2017|treatdate ==2015|treatdate ==2013 , absorb(id year) vce(r)
estadd local Cluster Yes,replace
estadd local Year_FE Yes,replace
estadd local Fixed_Effect Yes,replace
estadd local Control No,replace
est sto m3
...........
esttab m1 m2 m3 m4 using result030906.rtf, star(* 0.1 ** 0.05 *** 0.01) b(%6.3f) t(%6.3f) compress nogap ///
stats(Year_FE Fixed_Effect Cluster Control N r2_a aic bic , fmt(%3s %3s %3s %12.0f %9.3f)) ///
varwidth(20) title('Regression Result') mtitles("treat13to17" "treat13to18" "treat13to19" "treat13to20")
sum2docx
与reg2docx
特色:可以把四张表同时输出到同一张表上,参见“连享会”文章。
- 描述性统计
*连享会《用…2docx来进行四大表输出》的code:
sum2docx price-foreign using ///
1.docx, append obs ///
mean(%9.2f) sd min(%9.0g)///
median(%9.0g) max(%9.0g) ///
title("表 1: 描述性统计")
esttab
类似,但特色在于支持中文。
*连享会“四个输出命令对比”一文中的code:
reg2docx m1 m2 m3 using Myfile.docx, replace indicate("race=race_num*") ///
b(%9.2f) se(%7.2f) scalars(r2(%9.3f) r2_a(%9.2f) N) ///
drop(occupation) order(married) ///
title(reg2docx_Table: regression result) ///
mtitles("OLS-1" "OLS-2" "OLS-3")
asdoc
asdoc sum
选择变量
asdoc sum price mpg rep78,save(summary.doc) title(###)
选择统计量
asdoc sum, stat(N mean sd tstat p1 p99) fs(7) dec(2)
分组输出
asdoc sum, stat(N mean sd tstat p1 p99) by(foreign)
-或
bysort foreign: asdoc sum, stat(N mean sd tstat p1 p99)
加文字描述
asdoc, text(A car is a wheeled motor vehicle used for transportation) append fs(10)
asdoc reg price mpg rep78, nest replace ///对第一个回归
asdoc reg price mpg rep78 headroom, nest append ///针对以后的回归
需要在一张表上显示多个回归结果就依次进行 nest append。
横向放置回归表格,需要使用 asdoc 中的 wide 选项。
asdoc reg price mpg rep78, replace wide
想把被解释变量为 trunk 的回归结果追加于上表,输入如下命令:
asdoc reg trunk mpg rep78, wide
回归命令后加 t(below) 表示在系数的下方显示对应的 t 值,t(side)表示在旁边显示t值。
estpost tabstat
,esttab
。
//Preliminary observation
/*2014-2017 air quality comparision*/
qui:estpost tabstat aaqi aso2 apm10 apm25 aco ano2 ao3,by(year) col(stat) nototal
esttab using table2-1-1.rtf, cell(mean) unstack label noobs nogap nonumber title("table2-1")
qui:estpost tabstat maqi mso2 mpm10 mpm25 mco mno2 mo3,by(year) col(stat) nototal
esttab using table2-1-2.rtf, cell(mean) unstack label noobs nogap nonumber title("table2-2")
bys year dd: egen complex=mean(county_soph)
bys year dd: drop if _n!=_N
twoway (connect complex year if dd==1,lp(solid) lc(black) mc(black)) ///
(connect complex year if dd==0,lp(dash) lc(black) mc(black)), ///
ytitle("技术复杂度") xtitle("年份") legend(label(1 "实验组") label(2 "对照组"))
logout
命令来输出。
logout, save(表1) word dec(4) replace: tabstat lngdp lnpgdp fdi exp popden industry non_agri sav welfare minor fin govspend near agro_t match ///
lnis1 lnis2 lnloan lninv student citylive rurallive lnincome, stat( mean sd min max n) c(s) f(%9.4f)