带有esttab的频率表

发布于 2025-02-07 19:54:35 字数 2176 浏览 0 评论 0原文

我有兴趣使用Stata输出表命令命令的转置:

sysuse auto, clear

eststo: estpost tab foreign
esttab, cells(b)

这样


--------------------------------------------------
                      
                  Domestic    Foreign     Total 
                        
--------------------------------------------------
Domestic               52.      22.           74
--------------------------------------------------

我可以做类似的事情的输出:

sysuse auto, clear
est clear
tab foreign, gen(newp_`i')
eststo  : estpost tabstat newp_1 newp_2 , stat(sum ) column(variables)
drop newp* 



esttab, cells("newp_1 newp_2") ///
    compress unstack /// 
    nonumbers nodepvars noobs ///
    mtitles("Domestic" "Foreign")

...

------------------------------
            Domestic          
              newp_1    newp_2
------------------------------
sum               52        22
------------------------------

但是当我尝试添加其他变量计数时,我会遇到问题(理想情况下,我想要EST2要垂直附加而不是水平)


sysuse auto, clear
est clear
tab foreign, gen(newp_`i')
eststo  : estpost tabstat newp_1 newp_2 , stat(sum ) column(variables)
drop newp* 

esttab, cells("newp_1 newp_2") ///
    compress unstack /// 
    nonumbers nodepvars noobs ///
    mtitles("Domestic" "Foreign")

g example = (mpg >=22)
tab example, gen(newp_`i')
eststo  : estpost tabstat newp_1 newp_2 , stat(sum ) column(variables)


esttab, cells("newp_1 newp_2") unstack ///
    compress  /// 
    nonumbers nodepvars noobs ///
    mtitles("Domestic" "Foreign")

...
--------------------------------------------------
            Domestic             Foreign          
              newp_1    newp_2    newp_1    newp_2
--------------------------------------------------
sum               52        22        43        31
--------------------------------------------------

我所需的输出是:

---------------------------------                                 
             newp_1    newp_2    
---------------------------------
sum (foreign)   52       22         
sum (price)     43       31
---------------------------------

I'm interested in outputting the transpose of the tabulate command using Stata:

sysuse auto, clear

eststo: estpost tab foreign
esttab, cells(b)

Such that the output would be


--------------------------------------------------
                      
                  Domestic    Foreign     Total 
                        
--------------------------------------------------
Domestic               52.      22.           74
--------------------------------------------------

I can do something similar with the following:

sysuse auto, clear
est clear
tab foreign, gen(newp_`i')
eststo  : estpost tabstat newp_1 newp_2 , stat(sum ) column(variables)
drop newp* 



esttab, cells("newp_1 newp_2") ///
    compress unstack /// 
    nonumbers nodepvars noobs ///
    mtitles("Domestic" "Foreign")

...

------------------------------
            Domestic          
              newp_1    newp_2
------------------------------
sum               52        22
------------------------------

But I run into issues when I try to add counts of other variables (Ideally I'd like est2 to be appended vertically instead of horizontally)


sysuse auto, clear
est clear
tab foreign, gen(newp_`i')
eststo  : estpost tabstat newp_1 newp_2 , stat(sum ) column(variables)
drop newp* 

esttab, cells("newp_1 newp_2") ///
    compress unstack /// 
    nonumbers nodepvars noobs ///
    mtitles("Domestic" "Foreign")

g example = (mpg >=22)
tab example, gen(newp_`i')
eststo  : estpost tabstat newp_1 newp_2 , stat(sum ) column(variables)


esttab, cells("newp_1 newp_2") unstack ///
    compress  /// 
    nonumbers nodepvars noobs ///
    mtitles("Domestic" "Foreign")

...
--------------------------------------------------
            Domestic             Foreign          
              newp_1    newp_2    newp_1    newp_2
--------------------------------------------------
sum               52        22        43        31
--------------------------------------------------

My desired output is:

---------------------------------                                 
             newp_1    newp_2    
---------------------------------
sum (foreign)   52       22         
sum (price)     43       31
---------------------------------

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多情出卖 2025-02-14 19:54:35

以下似乎有效:

sysuse auto, clear
est clear


rename foreign binary1

g binary2 = (mpg >=22)
unab lst : binary*

foreach i in `lst'{ 
    tab `i', gen(test_`v')
    eststo: estpost tabstat test_*,  statistics(sum) columns(statistics)
    drop test_*
}




esttab , ///
    replace cell(sum ) ///
    compress /// 
    nonumbers rename("test_1" "Yes" "test_2" "No") /// 
    mtitles("Binary1" "Binary2")

            
matrix transp = r(coefs)'               
esttab matrix(transp), compress eqlabels(,merge)

The following seems to work:

sysuse auto, clear
est clear


rename foreign binary1

g binary2 = (mpg >=22)
unab lst : binary*

foreach i in `lst'{ 
    tab `i', gen(test_`v')
    eststo: estpost tabstat test_*,  statistics(sum) columns(statistics)
    drop test_*
}




esttab , ///
    replace cell(sum ) ///
    compress /// 
    nonumbers rename("test_1" "Yes" "test_2" "No") /// 
    mtitles("Binary1" "Binary2")

            
matrix transp = r(coefs)'               
esttab matrix(transp), compress eqlabels(,merge)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文