Statalist The Stata Listserver


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

st: RE: Easy question: How to get 0 to show up?


From   "Ben Jann" <[email protected]>
To   <[email protected]>
Subject   st: RE: Easy question: How to get 0 to show up?
Date   Fri, 23 Jun 2006 13:17:28 +0200

You could also use -mrtab- (-ssc d mrtab-). For example:

    . sysuse auto, clear
    (1978 Automobile Data)

    . mrtab foreign, r(0 1 2 3) poly

                |             Percent of     Percent
                |  Frequency   responses    of cases
    ------------+-----------------------------------
     0 Domestic |         52       70.27       70.27
     1  Foreign |         22       29.73       29.73
     2        2 |          0        0.00        0.00
     3        3 |          0        0.00        0.00
    ------------+-----------------------------------
          Total |         74      100.00      100.00

    Valid cases:         74
    Missing cases:        0

Or simply:

    . mrtab foreign, r(0/3) poly

                |             Percent of     Percent
                |  Frequency   responses    of cases
    ------------+-----------------------------------
     0 Domestic |         52       70.27       70.27
     1  Foreign |         22       29.73       29.73
     2        2 |          0        0.00        0.00
     3        3 |          0        0.00        0.00
    ------------+-----------------------------------
          Total |         74      100.00      100.00

    Valid cases:         74
    Missing cases:        0

Now comes the cool part:

    . lab def origin 2 "Martian" 3 "Venusian", add

    . mrtab foreign, r(0/3) poly

                |             Percent of     Percent
                |  Frequency   responses    of cases
    ------------+-----------------------------------
     0 Domestic |         52       70.27       70.27
     1  Foreign |         22       29.73       29.73
     2  Martian |          0        0.00        0.00
     3 Venusian |          0        0.00        0.00
    ------------+-----------------------------------
          Total |         74      100.00      100.00

    Valid cases:         74
    Missing cases:        0

ben

> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Nick Cox
> Sent: Friday, June 23, 2006 11:07 AM
> To: [email protected]
> Subject: st: RE: Easy question: How to get 0 to show up?
> 
> I can't speak for STATA. Curiously enough,
> the same question arises in Stata.
> 
> The key question is how you expect Stata to
> know that "Green" was also a possible category.
> 
> I guess that there are some languages in which
> the fact that "Green" was
> defined as a possible value by way of a specification
> of possible values would be enough.
> 
> Stata doesn't work that way, however. Even if
> you define a set of value labels, Stata doesn't
> automatically tabulate those which are not
> represented in the data, or the subset of the
> data you specify. If these data are string,
> then why should Stata know that "Green" was
> a possible answer any more than (say) "Aardvark"?
> 
> So you need a work-around in which you yourself spell
> out the possible values. The only ones I know
> are -tabcount- from SSC and the earlier -tabcond-
> from SSC. Note that had you used
> 
> . findit zeros
> 
> or
> 
> . findit zero
> 
> you would have found out about -tabcount- for
> yourself (together, naturally, with lots of
> other stuff).
> 
> . findit tabulate zero
> 
> would have zeroed in further on what you need.
> 
> Here are a few simple examples of how -tabcount-
> works:
> 
> . tabcount foreign, v(0 1 2 3 4)
> 
> ----------------------
>  Car type |      Freq.
> ----------+-----------
>  Domestic |         52
>   Foreign |         22
>         2 |
>         3 |
>         4 |
> ----------------------
> 
> . tabcount foreign, v(0 1 2 3 4) zero
> 
> ----------------------
>  Car type |      Freq.
> ----------+-----------
>  Domestic |         52
>   Foreign |         22
>         2 |          0
>         3 |          0
>         4 |          0
> ----------------------
> 
> . decode foreign, gen(FOREIGN)
> 
> . tabcount FOREIGN , v("Domestic" "Foreign" "Martian" "Venusian") zero
> 
> ----------------------
>  Car type |      Freq.
> ----------+-----------
>  Domestic |         52
>   Foreign |         22
>   Martian |          0
>  Venusian |          0
> ----------------------
> 
> Missings are not shown by default. I guess the reason
> you have a puzzle about missing is that you think string
> "." means missing. With strings in Stata only the empty string
> "" means missing. If you have strings "." that you
> regard as missing you should just exclude those if desired
> by
> 
> ... if COLOR != "."
> 
> or replace them with empty strings.
> 
> There was a more discursive account in the Stata Journal
> 
> SJ-3-4  pr0011  . . . . . . . .  Speaking Stata: Problems with tables,
> Part II
>         Q4/03   SJ 3(4):420--439
>         reviews three user-written commands (tabcount, makematrix,
>         and groups) as different approaches to tabulation problems
> 
> Nick
> [email protected]
> 
> buddyb
> 
> > I'm running STATA 8.
> >
> > If I had a multiple choice question, like, what is
> > your favorite color with red, yellow, black, green as
> > the given choices,and asked 7 people and got the
> > following results....
> >
> > Red     1
> > Yellow  2
> > Black   3
> > Green   0
> >          . (missing)
> >
> > When I do a Table COLOR (this is my vname),
> > I get:
> >
> > Red    1
> > Yellow 2
> > Black  3
> >
> > The Green does not show up and I would like it too. I
> > want to repress the missing.  How do I do this?
> 
> 
> *
> *   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/

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