1

How can I create a three-way table in Stata but with percentages rather than frequencies?

For example:

table var mcdstr year if inlist(year,1900,1930) &  ///
                          inlist(mcdstr,"BRONX","BROOKLYN","MANHATTAN","QUEENS","RICHMOND")

To my understanding the table command does not have a built in frequency function.

As an alternative, I used the community-contributed command 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_%) 

However the aforementioned syntax does not create a three-way table.

Rodrigo
  • 69
  • 5
  • 14

1 Answers1

1

The simplest way to do this is to use the community-contributed command tab3way:

ssc install tab3way

An example using Stata's auto toy dataset can be found below:

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                                                  
------------------------------------------------------------------------

To add percentages:

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                                                          
----------------------------------------------------------------------------------

For percentages without frequencies:

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                                                          
----------------------------------------------------------------------------------

Typing help tab3way will provide full details on syntax and options.