如何使用esttab为N和R平方显示不同的小数位?

问题描述

我使用esttab生成回归表。请参见下面的示例代码。

eststo clear
eststo: reghdfe y x1,absorb(year state) cluster(year state)
        estadd local FE       "Yes"
        estadd local Controls "No"
eststo: reghdfe y x1 x2 x3,absorb(year state) cluster(year state)
        estadd local FE       "Yes"
        estadd local Controls "Yes"
esttab,star(* 0.10 ** 0.05 *** 0.01) b(3) t(2) r2 replace label drop(_cons)   stats(FE Conrols N r2,fmt(%9.0fc) labels("Fixed Effects" "Controls" "Obserations" "R-Squared"))          

因为我的数据集很大,所以我使用fmt(%9.0fc)将逗号添加到我的观测值中。但是,此选项将我的R平方四舍五入为0。如何为观察值使用整数(带逗号),对R平方使用小数点后三位?

还可以显示调整后的R平方吗?用户手册建议stats禁用ar2,但我很难找到解决方法。

解决方法

esttabBen Jannestout的一部分,有关安装和更多信息,请参见online documentation

这是使用esttab的默认格式的最小工作示例。

eststo clear        
sysuse auto

eststo: quietly regress price weight mpg
eststo: quietly regress price weight mpg foreign

esttab,star(* 0.10 ** 0.05 *** 0.01) ///
    b(3) t(2) ar2 

请注意,ar2调用了调整后的R ^ 2。但是,如果您要使用stats()选项来设置obs的格式,那么语法更改将是:

esttab,star(* 0.10 ** 0.05 *** 0.01) ///
    b(3) t(2) ///
    stats(N r2_a)

要应用格式,请为每个统计信息添加一个字词,如果您提供的字数少于统计信息,则esttab将最后一个字词应用于其余统计信息。这就是为什么您的R ^ 2四舍五入为零的原因。请尝试以下操作:

esttab,star(* 0.10 ** 0.05 *** 0.01) ///
    b(3) t(2) ///
    stats(N r2_a,fmt(%9.0fc %9.2fc)

因此,我将按如下所示编辑您的esttab行:

esttab,star(* 0.10 ** 0.05 *** 0.01) ///
    b(3) t(2) /// no 'ar2' here
    label /// note you only need 'replace' if you are generating a file
    nocons /// 'reghdfe' has an option to 'drop(_cons)'   
    stats(FE Controls N r2_a,/// 'Controls' not 'Conrols'
    fmt(%9.0fc %9.0fc %9.0fc %9.2fc) /// it seems you need place holders for the string stats
    labels("Fixed Effects" "Controls" "Obserations" "R-Squared"))          

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...