Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: an ordinary two-way table


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: an ordinary two-way table
Date   Fri, 11 May 2007 11:28:04 +0100

Chris and Giovanni refer to -tabcount- from SSC. -tabcount- has 
modest generality for what it tries to do, but that
does not include marginal totals. The best I can 
suggest in this particular case is that you save the 
matrix of counts and then do other things with it. 
The best strategy would be Mata-based. 

Nick 
[email protected] 

[email protected]
 
> sysuse auto, clear
> drop if rep78==1
> tabcount rep78 foreign, v1(1/5) v2(0/1) zero
> 
> This produced the following for me:
> 
>  tabcount rep78 foreign, v1(1/5) v2(0/1) zero
> 
> ------------------------------
> Repair    |
> Record    |      Car type
> 1978      | Domestic   Foreign
> ----------+-------------------
>         1 |        0         0
>         2 |        8         0
>         3 |       27         3
>         4 |        9         9
>         5 |        2         9
> ------------------------------
> 
> But now I see that the resulting table does not contain a column for
> totals, so not exactly what you want.  You had probably 
> gotten this far
> already . . . .
> 
> > I'd like to produce a simple two-way table... but have failed to do
> > so. To illustrate:
> >
> > sysuse auto, clear
> > replace rep78=. if rep78==1
> >
> > The table that I've been dreaming of during the last hour 
> or so (sic!)
> > is the following:
> >
> >
> >     Repair |
> >     Record |       Car type
> >       1978 |  Domestic    Foreign |     Total
> > -----------+----------------------+----------
> >          1 |         0          0 |         0
> >          2 |         8          0 |         8
> >          3 |        27          3 |        30
> >          4 |         9          9 |        18
> >          5 |         2          9 |        11
> > -----------+----------------------+----------
> >      Total |        46         21 |        67
> >
> >
> > Please note the first row with all zeros...
> >
> > I've tried with tabcount, tab2way, tabdisp, etc. ... but did not
> > manage to obtain *exactly* the above table.

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