0

我正在尝试准备一个表格,该表格将显示几个变量的双向频率表。逻辑是每个变量都将由相同的二进制指标制成表格。

我想使用社区提供tex的命令系列将输出发送到文件。但是,每个交叉表都会出现在新列中。estout

考虑以下可重现的玩具示例:

sysuse auto
eststo clear 

eststo: estpost tab headroom foreign, notot
eststo: estpost tab trunk foreign, notot

esttab, c(b) unstack wide collabels(N)

----------------------------------------------------------------
                      (1)                       (2)             

                 Domestic      Foreign     Domestic      Foreign
                        N            N            N            N
----------------------------------------------------------------
1_missing_5             3            1                          
2                      10            3                          
2_missing_5             4           10                          
3                       7            6                          
3_missing_5            13            2                          
4                      10            0                          
4_missing_5             4            0                          
5                       1            0            0            1
6                                                 0            1
7                                                 3            0
8                                                 2            3
9                                                 3            1
10                                                3            2
11                                                4            4
12                                                1            2
13                                                4            0
14                                                1            3
15                                                2            3
16                                               10            2
17                                                8            0
18                                                1            0
20                                                6            0
21                                                2            0
22                                                1            0
23                                                1            0
----------------------------------------------------------------
N                      74                        74             
----------------------------------------------------------------

有没有办法“对齐”输出,以便只有两DomesticForeign

4

2 回答 2

1

If you're outputting to a tex file, one solution would be to use the append option of esttab. So in your case it would be something like:

sysuse auto
eststo clear 
estpost tab headroom foreign, notot
eststo tab1
estpost tab trunk foreign, notot
eststo tab2
esttab tab1 using outputfile.tex, c(b) unstack wide collabels(N) replace
esttab tab2 using outputfile.tex, c(b) unstack wide collabels(N) append

I believe there may be a more elegant solution as well, but this is generally pretty easy to implement. When appending, you'll likely have to specify a bunch of options to remove the various column headers (I believe estout's default assumes you don't want most of those headers, so it may be worth looking into estout instead of esttab).

于 2013-12-15T21:36:46.827 回答
1

产生所需的输出需要您将结果堆叠在一起。

首先定义程序append_tabs,这是appendmodelsBen Jann 的堆叠模型程序的快速修改版本:

program append_tabs, eclass
    version 8
    syntax namelist
    tempname b tmp
    local i 0
    foreach name of local namelist {
        qui est restore `name'
        foreach x in Domestic Foreign {
            local ++i
            mat `tmp'`i' = e(b)
            mat li `tmp'`i'
            mat `tmp'`i' = `tmp'`i'[1,"`x':"]
            local cons = colnumb(`tmp'`i',"_cons")
            if `cons'<. & `cons'>1 {
                mat `tmp'`i' = `tmp'`i'[1,1..`cons'-1]
            }
            mat li `tmp'`i'
            mat `b'`i' = `tmp'`i''
            mat li `b'`i'    
        }
    }
    mat `b'D = `b'1 \ `b'3
    mat `b'F = `b'2 \ `b'4
    mat A = `b'D , `b'F
    ereturn matrix results = A
    eret local cmd "append_tabs"
end

接下来运行您的表格并使用以下命令堆叠它们的结果append_tabs

sysuse auto, clear
estimates store clear

estpost tabulate headroom foreign, notot
estimates store one 

estpost tabulate trunk foreign, notot
estimates store two

append_tabs one two

最后,看看结果:

esttab e(results), nonumber mlabels(none) eqlabels(none) collabels("Domestic" "Foreign")

--------------------------------------
                 Domestic      Foreign
--------------------------------------
1_missing_5             3            1
2                      10            3
2_missing_5             4           10
3                       7            6
3_missing_5            13            2
4                      10            0
4_missing_5             4            0
5                       1            0
5                       0            1
6                       0            1
7                       3            0
8                       2            3
9                       3            1
10                      3            2
11                      4            4
12                      1            2
13                      4            0
14                      1            3
15                      2            3
16                     10            2
17                      8            0
18                      1            0
20                      6            0
21                      2            0
22                      1            0
23                      1            0
--------------------------------------

使用命令中的tex选项esttab查看 LaTeX 输出。

于 2019-07-13T23:13:16.770 回答