Statalist


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

Re: Re: st: catplot problem


From   n j cox <n.j.cox@durham.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: Re: st: catplot problem
Date   Wed, 07 May 2008 12:19:43 +0100

Anyone trying to follow this thread can find the previous material here:

<http://www.hsph.harvard.edu/cgi-bin/lwgate/STATALIST/archives/statalist.0805/date/article-230.html>

Tunga thinks it a "deficiency" that my -catplot- program, downloadable from SSC, when faced with a subset of observations with categories 1 4 5 6 7 8 9 10 does not notice that elsewhere in the data there are categories 2 3, which he wants to show on a graph. He wants a "better developed" command which does notice that.

In general, Stata graph commands do not do that, even optionally.

To repeat, -catplot- in particular was not designed to work like that, even optionally. Tunga should feel free to write a program that does what he wants, although ensuring that bars of zero height are drawn for categories that don't exist, but might have existed, in the observations being used may prove trickier than he thinks for any approach based on -graph bar-. (That is straightforward if you switch to -graph twoway bar-.)

However, that is all quite unnecessary, as -histogram- (a command, not a function) should prove capable of doing what he wants, or at least I have seen no evidence to the contrary. -histogram- does support categorical variables, with the -discrete- option that Tunga is already aware of (so I still don't understand why he keeps asking this question). If a categorical variable is string, map to numeric first using -encode-. Then show all the gaps you want using -xscale()- and -xlabel()-. That can be automated too:

Simple example:

sysuse auto
levelsof rep78, local(levels)
histogram rep78 if foreign, xla(`levels') discrete freq barw(0.8)

Otherwise put, I do see wanting -catplot- to behave like -histogram- in Tunga's circumstances as perfectly reasonable, but the answer is just to use -histogram-.

If Tunga can identify a specific kind of graph in this territory that it seems neither -catplot- nor -histogram- can produce, then I or others on the list will be happy to try to make suggestions -- or write new code if needed.

Nick
n.j.cox@durham.ac.uk

Tunga Kantarci

Dear Nick,

Thanks for your reply.
I am not sure if I should have called it a bug, but I also don't know what
to call it. For me it is a deficiency.
I would consider catplot to have been better developed if it was able
determine missing values over which the category is defined, i.e. 2 and 3 in
the example.
Because currently it is just not able to match with the values of the
variable of interest over which the categorizations are intended.
Or the histogram function could be developed further to allow
categorizations.


*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index