我正在编写代码,以便使用tabstat, by()和esttab导出Latex中的汇总统计表。
这里有一个复制我的数据结构的玩具示例:
cls
clear all
set more off
use auto, clear
// Create two groups to be used in the -by()- option
gen rep2="First dataset" if rep78>=3
replace rep2="Second dataset" if rep78<3
// Recode "price" as completely missing in the first group
replace price=. if rep2=="First dataset"
// Table
eststo: estpost tabstat weight price mpg trunk, ///
column(statistics) statistics(count mean median sd) by(rep2) nototal
local sum_statistics "count(label(Observations)) mean(label(Mean) fmt(2)) p50(label(Median)) sd(label(Standard deviation) fmt(2))"
esttab using "table1.tex", replace type ///
title("Summary Statistics") ///
cells("`sum_statistics'") ///
noobs nonum booktabs输出将汇总统计信息显示到两个子表中,每个子表分别用于每个数据集(由rep2定义)。这两个数据集不一定有相同的变量:第一个数据集中完全缺少price。
我想完全省略“第一数据集”的price汇总统计数据行(将其留给“第二数据集”)。这是因为由于“第一个数据集”缺少变量price,所以它的所有汇总统计信息都缺少值。这相当于在“观察”在特定的分组中等于0的情况下省略了整个汇总统计信息行。
我查看了tabstat的文档,但不太确定如何继续。我必须使用drop()选项estout吗?
非常感谢,S
发布于 2015-09-21 12:53:40
如前所述,您可以使用drop()选项:
clear all
set more off
sysuse auto, clear
// Create two groups to be used in the -by()- option
gen rep2="First" if rep78>=3
replace rep2="Second" if rep78<3
// Recode "price" as completely missing in the first group
replace price=. if rep2=="First dataset"
// Table
eststo: estpost tabstat weight price mpg trunk, ///
column(statistics) statistics(count mean median sd) by(rep2) nototal
local sum_statistics "count(label(Observations)) mean(label(Mean) fmt(2)) p50(label(Median)) sd(label(Standard deviation) fmt(2))"
esttab, replace type ///
title("Summary Statistics") ///
cells("`sum_statistics'") ///
noobs nonum booktabs drop(First:price)这涉及到使用全名,而不仅仅是变量名。
注意,我在分组变量的值中取出了空格。在调用esttab时,这似乎很麻烦,但我留给您来探讨。
https://stackoverflow.com/questions/32691890
复制相似问题