Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Two-way table


From   Friedrich Huebler <[email protected]>
To   [email protected]
Subject   st: Two-way table
Date   Fri, 1 Aug 2003 08:27:01 -0700 (PDT)

I would like to make a two-way table that lists the number of
observations per row in the last column and the row percentages in
the remaining columns. For example, with the auto data we can make
this table:

. tab rep78 foreign, row

    Repair |
    Record |       Car type
      1978 |  Domestic    Foreign |     Total
-----------+----------------------+----------
         1 |         2          0 |         2 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         2 |         8          0 |         8 
           |    100.00       0.00 |    100.00 
-----------+----------------------+----------
         3 |        27          3 |        30 
           |     90.00      10.00 |    100.00 
-----------+----------------------+----------
         4 |         9          9 |        18 
           |     50.00      50.00 |    100.00 
-----------+----------------------+----------
         5 |         2          9 |        11 
           |     18.18      81.82 |    100.00 
-----------+----------------------+----------
     Total |        48         21 |        69 
           |     69.57      30.43 |    100.00 

Instead, I would like this table:

    Repair |
    Record |       Car type
      1978 |  Domestic    Foreign |     Total
-----------+----------------------+----------
         1 |    100.00       0.00 |         2 
         2 |    100.00       0.00 |         8 
         3 |     90.00      10.00 |        30 
         4 |     50.00      50.00 |        18 
         5 |     18.18      81.82 |        11 
-----------+----------------------+----------
     Total |     69.57      30.43 |        69 

The closest I could come to this table is with the following
commands:

. gen domestic = 100*(foreign==0)
. replace foreign = 100*foreign
. bysort rep78: egen counter = count(rep78)
. format domestic foreign %6.2f
. format counter %2.0f
. tabstat domestic foreign counter, by(rep78) format

   rep78 |  domestic   foreign   counter
---------+------------------------------
       1 |    100.00      0.00         2
       2 |    100.00      0.00         8
       3 |     90.00     10.00        30
       4 |     50.00     50.00        18
       5 |     18.18     81.82        11
---------+------------------------------
   Total |     69.57     30.43        20

The cell in the lower right corner should contain the total number of
observations, that is 69 instead of 20. How can this be done?

Friedrich Huebler

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index