【问题标题】:Add column with number of observations to esttab summary statistics table将包含观察数的列添加到 esttab 汇总统计表
【发布时间】:2014-12-15 02:07:31
【问题描述】:

我想使用 SSC 上的 estout 包中的 esttab 制作一个汇总统计表。我可以把表格做得很好,但我想添加一个列来计算每个变量的非缺失观测值的数量。也就是说,有些变量可能不完整,我希望读者能清楚这一点。

在下面的示例中,我删除了 price 的前五个观察值,因此我希望该行中有 69。但我的代码不包括特定行的观察计数,只包括页脚中的观察总数。

sysuse auto, clear
estpost summarize, detail
replace price = . in 1/5
local screen ///
    cells("N mean sd min p50 max") ///
    nonumber label 
esttab, `screen'

这会产生一个空的 N 列,我希望在 69 处拥有它,然后是所有 74s。

【问题讨论】:

    标签: stata


    【解决方案1】:

    是这样吗:

    clear all
    set more off
    
    *----- exmple data -----
    
    sysuse auto, clear
    keep price mpg rep78 headroom
    
    replace price = . in 1/5
    
    *----- what you want -----
    
    estpost summarize, detail
    
    local screen cells("count mean sd") nonumber label noobs
    
    esttab, `screen'
    

    ?

    它只使用countesttabestout 的包装器,help 是后者文档的包装器,它将采用“来自 e(myel) 的结果”,您可以从 estpost summarize, detail 获得。

    另一种选择是:

    tabstat _all, statistics(count mean sd) columns(statistics)
    

    还有一个,只是它允许显示变量标签:

    fsum _all, stat(n mean sd) uselabel
    

    fsum 来自 SSC。

    【讨论】:

    • TL;DR:使用count 而不是N。 :) 奇怪,因为其他地方 esttab 使用来自 summarizereturn list 的宏名称。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 2023-01-25
    • 1970-01-01
    相关资源
    最近更新 更多