如何向 esttab 添加更多行 summarize summary stat table
How to add more lines to esttab summarize summary stat table
我正在尝试使用 esttab 创建一个 LaTeX table,其中包含使用 summarize 命令的汇总统计信息。如果我一次汇总多个变量,我可以使用如下代码来执行此操作:
sysuse auto, clear
global vars price mpg headroom
eststo clear
eststo: estpost sum $vars, listwise
esttab est*, cells("count mean(fmt(2)) sd") nomtitles nonumber noobs
但是,我不确定如何汇总一行,存储它,汇总另一行,存储它,等等,然后将它们全部合并到同一个 table 中而不创建不必要的列。如果我想通过变量对要总结的观察结果进行个性化限制,我可能想单独总结每个变量。
这里的代码无法满足我的需求。具体来说,它不会将每个变量的汇总统计数据放在同一列下,而是创建新的列,每组列对应一个不同的变量。
eststo clear
gen count = 1
foreach i in $vars {
eststo: estpost sum `i' if `i'>count
replace count = count+1
}
esttab est*, cells("count mean(fmt(2)) sd") nomtitles nonumber noobs
我应该改变什么才能得到我想要的结果?
您可以使用 fragment
和 append
选项逐行制作 tables。您可能想要在没有 fragment
选项的情况下执行一个变量来生成相同的 table header/footer,然后将剩余的行剪切并粘贴到此 table.
你的问题类似于堆叠模型;而不是 "models" 你有摘要。用户编写的命令 estout
不会堆叠模型,因此一种解决方法是创建自己的矩阵并将其提供给 estout
(或 esttab
):
clear
set more off
*----- example data -----
sysuse auto
*----- two-variable example -----
eststo clear
// process price
estpost summarize price
matrix mymat = e(mean), e(count)
// process mpg
estpost summarize mpg if mpg > 15
matrix mymat = mymat \ e(mean), e(count)
// finish formatting matrix
matrix colnames mymat = mean count
matrix rownames mymat = price mpg
matrix list mymat
// tabulate
esttab matrix(mymat), nomtitles
通过额外的工作,您可以自动化这些步骤。
另一个例子见http://repec.org/bocode/e/estout/advanced.html#advanced901。
我正在尝试使用 esttab 创建一个 LaTeX table,其中包含使用 summarize 命令的汇总统计信息。如果我一次汇总多个变量,我可以使用如下代码来执行此操作:
sysuse auto, clear
global vars price mpg headroom
eststo clear
eststo: estpost sum $vars, listwise
esttab est*, cells("count mean(fmt(2)) sd") nomtitles nonumber noobs
但是,我不确定如何汇总一行,存储它,汇总另一行,存储它,等等,然后将它们全部合并到同一个 table 中而不创建不必要的列。如果我想通过变量对要总结的观察结果进行个性化限制,我可能想单独总结每个变量。
这里的代码无法满足我的需求。具体来说,它不会将每个变量的汇总统计数据放在同一列下,而是创建新的列,每组列对应一个不同的变量。
eststo clear
gen count = 1
foreach i in $vars {
eststo: estpost sum `i' if `i'>count
replace count = count+1
}
esttab est*, cells("count mean(fmt(2)) sd") nomtitles nonumber noobs
我应该改变什么才能得到我想要的结果?
您可以使用 fragment
和 append
选项逐行制作 tables。您可能想要在没有 fragment
选项的情况下执行一个变量来生成相同的 table header/footer,然后将剩余的行剪切并粘贴到此 table.
你的问题类似于堆叠模型;而不是 "models" 你有摘要。用户编写的命令 estout
不会堆叠模型,因此一种解决方法是创建自己的矩阵并将其提供给 estout
(或 esttab
):
clear
set more off
*----- example data -----
sysuse auto
*----- two-variable example -----
eststo clear
// process price
estpost summarize price
matrix mymat = e(mean), e(count)
// process mpg
estpost summarize mpg if mpg > 15
matrix mymat = mymat \ e(mean), e(count)
// finish formatting matrix
matrix colnames mymat = mean count
matrix rownames mymat = price mpg
matrix list mymat
// tabulate
esttab matrix(mymat), nomtitles
通过额外的工作,您可以自动化这些步骤。
另一个例子见http://repec.org/bocode/e/estout/advanced.html#advanced901。