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 15:35:50 +0100

The problem with tables is analogous to that of 
graphs. Almost everyone comes to Stata with 
"all I want is a simple table" and expects that 
there will be a quick answer available. Experience
shows with tables, as with graphs, that if you put 
together the expectations of all the users with 
all their desired "simple" tables that you need some 
very complicated commands to be able to meet all 
their needs -- and a few desires will still slip
through. 

Now, in your case: You want Stata to be smart about 
observations that in principle might exist, but happen
not to exist in the data. That is, a variable might have
a value 1, but you don't have such a value in practice, 
and you want Stata to show that there might be 1s, but 
there aren't, so please show a frequency of 0. This 
is, and is not, simple. It is, and is not, an ordinary 
problem. In part, it is programmable
by users and efforts exist under that heading, 
such as -tabcount-. 

I have to tell you that I wrote 
-tabcount- probably for two reasons. One, fun. Two, 
some people kept asking for something like this, so
whether it could be done was a challenge. To do 
more with -tabcount-, I need more than that. I 
need Three, much more time. Four, wanting to use
it myself a lot (not true, in fact). 

Naturally, there are plenty of other programmers 
out there, but they must speak for themselves. 

In essence tabulation in Stata is a bit of a mess 
but then what is the alternative? One enormous command 
with numerous bells and whistles and 
with a manual entry 150 pages long that will do 
all these special things too? Or that StataCorp provide
a powerful low-level language so that other people 
can then write the kinds of middle-level tools that 
some users occasionally need? The first does actually
appeal to some people, but the second is StataCorp's
apparent strategy. 

In short, it is one thing to say that tabulation 
should be easier. It is quite another thing to be 
clear about exactly how that is to be made possible. 

To recall the graph analogy: Before Stata 8, Stata
graphics came in for a lot of flak because it was
seen as increasingly limited compared with the 
alternatives. When StataCorp came back with a much 
more powerful new graphics, there were lots of 
grumbles that it was much more complicated! But 
then what did people expect would be the solution? 
A language in which you spoke to Stata and said
"Stata, draw a sensible graph of these data?" 

Nick 
[email protected] 

Giovanni Vecchi
 
> Chris and Nick, thanks for your suggestions. As you both say, the
> problem with tabcount is that it does not allow row and column totals.
> 
> I'm always puzzled when I find Stata unable to offer easy answers to
> easy questions (as the one raised in my posting). Faced with the
> failure to produce a simple two-way table, I ask myself: is it me or
> is it Stata? And my answers start looping ... "it's me", "it's Stata",
> "it's me", "it's Stata",... time goes by, frustration/irritation start
> off, etc...
> 
> A quick reaction to Nick's suggestion. In my opinion, there is an
> issue on the opportunity cost of pursuing a Mata-based strategy.  My
> guess is that it is high for most Stata users.
> 
> My point: ordinary two-way tables should be within the reach of
> Mata-almost-illiterate users. Needless to say, I am an outstanding
> member of this club. 
> 
> A bottom line: hope StataCorp is sympathetic to my argument... :)

[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