首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >表中的子组和

问表中的子组和
EN

Stack Overflow用户
提问于 2018-09-13 17:51:55
回答 1查看 516关注 0票数 0

下面是我尝试过的Stata代码:

代码语言:javascript
复制
eststo clear
sysuse auto, clear
eststo Dom: estpost sum rep78 mpg turn trunk weight length if foreign==0
eststo For: estpost sum rep78 mpg turn trunk weight length if foreign==1
esttab Dom For, cells("mean(fmt(2))" "sd") ///
    nonumber nodepvars noobs se collabels(none) mlabels(, lhs("Var") title)

以下也是产出:

代码语言:javascript
复制
--------------------------------------
Var                   Dom          For
--------------------------------------
rep78                3.02         4.29
                     0.84         0.72
mpg                 19.83        24.77
                     4.74         6.61
turn                41.44        35.41
                     3.97         1.50
trunk               14.75        11.41
                     4.31         3.22
weight            3317.12      2315.91
                   695.36       433.00
length             196.13       168.55
                    20.05        13.68
--------------------------------------

这样做的目的是使用summarize计算多个变量的均值和标准差。这是根据一个条件单独进行的(一次用于外国观测,一次用于非外国观测)。

结果,均值和标准差,然后显示在esttab。我最终希望在LaTeX中获得这个结果,但为了简单起见,这个示例展示了Stata中的结果。

我有两个问题:

  1. 如何在括号中显示标准偏差?
  2. 是否有可能在变量之间包含任何线来分隔这两个不同的组?

我有这样的想法:

代码语言:javascript
复制
--------------------------------------
Var                   Dom          For
--------------------------------------
Variable Group 1:
--------------------------------------
rep78                3.02         4.29
                    (0.84)       (0.72)
mpg                 19.83        24.77
                    (4.74)       (6.61)
turn                41.44        35.41
                    (3.97)       (1.50)
--------------------------------------
Variable Group 2:
--------------------------------------
trunk               14.75        11.41
                   (4.31)       (3.22)
weight            3317.12      2315.91
                 (695.36)      (433.00)
length             196.13       168.55
                  (20.05)       (13.68)
--------------------------------------

如果可能的话,我想使用eststo等。我希望它尽可能自动化,但我愿意将矩阵从Stata导出到LaTeX,或者使用片段(如果需要的话)。如果这是不可能的,我也愿意考虑其他解决办法。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-13 18:00:00

关于第一个问题,您需要在par内的sd中指定选项cells()

代码语言:javascript
复制
sysuse auto, clear

eststo clear

eststo Dom: estpost sum rep78 mpg turn trunk weight length if foreign==0
eststo For: estpost sum rep78 mpg turn trunk weight length if foreign==1
esttab Dom For, cells("mean(fmt(2))" "sd(par)") ///
    nonumber nodepvars noobs se collabels(none) mlabels(, lhs("Var") title)

关于第二个问题,你可以这样做:

代码语言:javascript
复制
eststo clear

eststo Dom: estpost sum rep78 mpg turn if foreign==0
eststo For: estpost sum rep78 mpg turn if foreign==1
esttab Dom For using output.txt, cells("mean(fmt(2))" "sd(par)") ///
    nonumber nodepvars noobs collabels(none) mlabels(, lhs("Vars") title) ///
    posthead("@hline" "Variable Group 1:" "@hline" ) postfoot(" ") replace

eststo clear

eststo Dom: estpost sum trunk weight length if foreign==0
eststo For: estpost sum trunk weight length if foreign==1
esttab Dom For using output.txt, cells("mean(fmt(2))" "sd(par)") ///
    nonumber nodepvars noobs collabels(none) mlabels(none)  ///
    prehead("@hline" "Variable Group 2:") append

这将产生所需的输出:

代码语言:javascript
复制
type output.txt

--------------------------------------
Vars                  Dom          For
--------------------------------------
Variable Group 1:
--------------------------------------
rep78                3.02         4.29
                   (0.84)       (0.72)
mpg                 19.83        24.77
                   (4.74)       (6.61)
turn                41.44        35.41
                   (3.97)       (1.50)

--------------------------------------
Variable Group 2:
--------------------------------------
trunk               14.75        11.41
                   (4.31)       (3.22)
weight            3317.12      2315.91
                 (695.36)     (433.00)
length             196.13       168.55
                  (20.05)      (13.68)
--------------------------------------
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52319249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档