@liuyuxi
2021-07-18T12:11:25.000000Z
字数 4382
阅读 208
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", replacereg ******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) robustest store m_1areg Disw HSR Cash Invt Lev Size ROA Rec Age PGDP SOE i.year,absorb(company_id) robustest store m_2esttab 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,replaceestadd local Year_FE Yes,replaceestadd local Fixed_Effect Yes,replaceestadd local Control No,replaceest 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,replaceestadd local Year_FE Yes,replaceestadd local Fixed_Effect Yes,replaceestadd local Control No,replaceest 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) nototalesttab 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) nototalesttab 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!=_Ntwoway (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)