首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如果缺少值,则从-tabstat- by子组省略汇总统计信息。

如果缺少值,则从-tabstat- by子组省略汇总统计信息。
EN

Stack Overflow用户
提问于 2015-09-21 09:38:37
回答 1查看 2.7K关注 0票数 2

我正在编写代码,以便使用tabstat, by()esttab导出Latex中的汇总统计表。

这里有一个复制我的数据结构的玩具示例:

代码语言:javascript
运行
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-21 12:53:40

如前所述,您可以使用drop()选项:

代码语言:javascript
运行
复制
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时,这似乎很麻烦,但我留给您来探讨。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32691890

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档