我正试图准备一个表,将显示几个变量的双向频率表。逻辑是,每个变量将由相同的二进制指示符制表。
我想使用estout
社区贡献的命令族将输出发送到tex
文件。但是,每个交叉表出现在新列中。
考虑以下可复制的玩具示例:
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
----------------------------------------------------------------
是否有一种方法来"对齐"输出,以便只有两个Domestic
和Foreign
列?
如果要输出到一个tex文件,一种解决方案是使用esttab
的append
选项。在你的例子中,应该是这样的:
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
我相信可能还有一个更优雅的解决方案,但这通常很容易实现。当append
运行时,您可能必须指定一堆选项来删除各种列标头(我相信estout
的默认假设您不想要大多数这些标头,因此可能值得研究estout
而不是esttab
)。
生成所需的输出需要将结果叠加在一起。
首先定义程序append_tabs
,这是appendmodels
的快速修改版本,Ben 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
--------------------------------------
使用esttab
命令中的tex
选项来查看LaTeX输出