您好我想使用 table 命令创建一个三向表。但是,我想要百分比而不是频率。
table var mcdstr year ///
if inlist(year,1900,1930) & inlist(mcdstr,"BRONX","BROOKLYN","MANHATTAN","QUEENS","RICHMOND")
据我所知, table 命令没有内置频率功能。因此,我使用了具有内置百分比命令的 tabout 命令。我用了这个命令
tabout lit mcdstr year if ///
inlist(year,1910,1930) & inlist(mcdstr,"BRONX","BROOKLYN","MANHATTAN","QUEENS","RICHMOND") using table1.text, ///
cells(freq col cum) format(0 1) clab(No. Col_% Cum_%)
但是,此命令不会创建三向表。我想知道是否可以使用 table 命令计算百分比,或者使用 tabout 创建一个三向表。
答案 0 :(得分:2)
最简单的方法是使用社区贡献的命令tab3way
:
ssc install tab3way
使用Stata的auto
玩具数据集的示例可以在下面找到:
sysuse auto, clear
tab3way headroom rep78 foreign
Table entries are cell frequencies
Missing categories ignored
------------------------------------------------------------------------
| Car type and Repair Record 1978
Headroom | --------- Domestic --------- ---------- Foreign ---------
(in.) | 1 2 3 4 5 1 2 3 4 5
----------+-------------------------------------------------------------
1 | 1 1 1
2 | 1 3 8 2 2 6 5
3 | 1 13 3 1 2 4
4 | 3 6 5
5 | 1
------------------------------------------------------------------------
要添加百分比:
tab3way headroom rep78 foreign, cellpct
Table entries are cell frequencies and cell percentages
Missing categories ignored
----------------------------------------------------------------------------------
| Car type and Repair Record 1978
Headroom | ------------ Domestic ----------- ------------ Foreign ------------
(in.) | 1 2 3 4 5 1 2 3 4 5
----------+-----------------------------------------------------------------------
1 | 1 1 1
| 1.45 1.45 1.45
|
2 | 1 3 8 2 2 6 5
| 1.45 4.35 11.59 2.90 2.90 8.70 7.25
|
3 | 1 13 3 1 2 4
| 1.45 18.84 4.35 1.45 2.90 5.80
|
4 | 3 6 5
| 4.35 8.70 7.25
|
5 | 1
| 1.45
----------------------------------------------------------------------------------
对于没有频率的百分比:
tab3way headroom rep78 foreign, cellpct nofreq
Table entries are cell percentages
Missing categories ignored
----------------------------------------------------------------------------------
| Car type and Repair Record 1978
Headroom | ------------ Domestic ----------- ------------ Foreign ------------
(in.) | 1 2 3 4 5 1 2 3 4 5
----------+-----------------------------------------------------------------------
1 | 1.45 1.45 1.45
2 | 1.45 4.35 11.59 2.90 2.90 8.70 7.25
3 | 1.45 18.84 4.35 1.45 2.90 5.80
4 | 4.35 8.70 7.25
5 | 1.45
----------------------------------------------------------------------------------
键入help tab3way
将提供有关语法和选项的完整详细信息。