stata - 使用 tabout 命令时结果不一致
问题描述
我想使用社区贡献的命令tabout
来生成一个汇总表。
但是,输出在简单的交叉表中是不一致的。
下面的代码是我正在尝试做的有限示例:
tab demaut revyn if demaut<.5
| Revolution (Y/N)
Polity | NO YES | Total
-----------+----------------------+----------
0 | 341 13 | 354
.05 | 682 91 | 773
.1 | 309 55 | 364
.15 | 1,171 259 | 1,430
.2 | 409 96 | 505
.25 | 149 80 | 229
.3 | 191 32 | 223
.35 | 268 82 | 350
.4 | 172 23 | 195
.45 | 165 75 | 240
-----------+----------------------+----------
Total | 3,857 806 | 4,663
The total observations are 4,663.
但是,如果我使用:
tabout demaut using temp.tex if demaut<.5, replace c(N revyn mean revyn) sum one
表输出写入:temp.tex
Polity N Mean
revyn revyn
0 354.0 0.0
.05 0.0
.1 0.0
.15 0.0
.2 0.0
.25 229.0 0.3
.3 0.0
.35 350.0 0.2
.4 195.0 0.1
.45 0.0
Total 4,663.0 0.2
的所有观察结果demaut = .05,.1,.15...
都缺失,但总观察结果是正确的。
有什么建议么?
解决方案
以下对我有用:
sysuse auto, clear
tab mpg foreign if mpg < 20
Mileage | Car type
(mpg) | Domestic Foreign | Total
-----------+----------------------+----------
12 | 2 0 | 2
14 | 5 1 | 6
15 | 2 0 | 2
16 | 4 0 | 4
17 | 2 2 | 4
18 | 7 2 | 9
19 | 8 0 | 8
-----------+----------------------+----------
Total | 30 5 | 35
tabout mpg foreign using temp.tex if mpg < 20, replace c(count mpg) format(0c) sum
Table output written to: temp.tex
Car type
Mileage (mpg) Domestic Foreign Total
Count mpg Count mpg Count mpg
12 2 0 2
14 5 1 6
15 2 0 2
16 4 0 4
17 2 2 4
18 7 2 9
19 8 0 8
Total 30 5 35
还:
tabout mpg foreign using temp.tex if mpg < 20, replace c(N mpg mean mpg) sum one
Table output written to: temp.tex
N Mean
mpg mpg
Mileage (mpg)
12 2.0 12.0
14 6.0 14.0
15 2.0 15.0
16 4.0 16.0
17 4.0 17.0
18 9.0 18.0
19 8.0 19.0
Total 35.0 16.7
Car type
Domestic 30.0 16.7
Foreign 5.0 16.8
Total 35.0 16.7
推荐阅读
- c - 构建 make 文件 arm 微控制器
- python - 使用 Pandas 的 DateTimeIndex 上的值计数从每个月中选择前 5 个
- laravel - 覆盖 BackpackForLaravel 中的翻译
- unity3d - 从用户操作中检测游戏对象移除
- python - 将张量批次与稀疏矩阵相乘
- c++ - 在 C++ 中读取 bmp 文件
- python-3.x - PyImgui 与 Pyglet 双打键盘输入
- python - 如果元素具有十进制值,python中的max(array)不会返回正确的值
- c# - Xamarin Forms 显示数据网格
- gradle - 如何只在 build.gradle 中执行特定任务?