使用tabout命令时结果不一致

时间:2019-05-15 13:46:45

标签: stata

我想使用社区贡献的命令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...的所有观察值均缺失,但总观察值正确。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

以下对我有用:

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