Stata 我怎么能';对齐';esttab中有多个双向表格?
我正在准备一个表格,它将显示几个变量的双向频率表。逻辑是,每个变量将由相同的二进制指示符制成表格 我想使用社区提供的命令系列将输出发送到Stata 我怎么能';对齐';esttab中有多个双向表格?,stata,Stata,我正在准备一个表格,它将显示几个变量的双向频率表。逻辑是,每个变量将由相同的二进制指示符制成表格 我想使用社区提供的命令系列将输出发送到tex文件。但是,每个交叉列表都显示在新列中 考虑以下可复制的玩具示例: sysuse auto eststo clear eststo: estpost tab headroom foreign, notot eststo: estpost tab trunk foreign, notot esttab, c(b) unstack wide collab
tex
文件。但是,每个交叉列表都显示在新列中
考虑以下可复制的玩具示例:
sysuse auto
eststo clear
eststo: estpost tab headroom foreign, notot
eststo: estpost tab trunk foreign, notot
esttab, c(b) unstack wide collabels(N)
有没有一种方法可以“对齐”输出,这样就只有两个
国内
和国外
列?如果要输出到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
ing时,您可能需要指定一组选项来删除各种列标题(我认为estout
的默认设置假定您不需要大多数标题,因此可能值得研究estout
而不是esttab
).生成所需输出需要将结果堆叠在一起
首先定义程序append_tabs
,这是Ben Jann的堆叠模型程序appendmodels
的快速修改版本:
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
最后,请参见结果:
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输出
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
--------------------------------------