Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Stacked histogram - empty bins


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Stacked histogram - empty bins
Date   Thu, 28 Jul 2011 11:20:48 +0100

Evidently your example is Australian, with VIC = Victoria, WA =
Western Australia, ACT = Australian Capital Territory. At a guess,
small numbers with ACT bite hardest here.

But those details don't matter. Whenever small frequencies are being
shown, there is often an advantage in using -dotplot- or -stripplot-
(SSC). (Although not originally intended as such, -stripplot- is now
in broad terms a superset of -dotplot-.)

Alternatively, lay down first a histogram of everything, then a
histogram of WA + VIC, then a histogram of VIC.

But I'd still try -stripplot- first.

This is one command:

twoway histogram admissiondate if inlist(state, "VIC", "WA", "ACT"),
start (`startdate') width(7) freq
||
histogram admissiondate if inlist(state, "VIC", "WA"),
start (`startdate') width(7) freq
||
histogram admissiondate if inlist(state, "VIC"),
start (`startdate') width(7) freq

You will want to fiddle with legend, colours, bar widths, etc. See also

N. J. Cox. 2009.
Stata tip 78: Going gray gracefully: Highlighting subsets and
downplaying substrates
Stata Journal 9(3): 499--503.


On Wed, Jul 27, 2011 at 11:55 PM, Allen Cheng <acscheng@gmail.com> wrote:
> I am trying to make a stacked histogram to show an epidemic in different
> states by epidemiological week. I found Nick Cox's helpful instructions in 2006
> using the undocumented command twoway__histogram_gen
>
> The problem is that some weeks, some states do not have any cases, and this
> makes a mess of trying to line up where rbar starts and ends. Is there any
> way to "force" zeros into the weeks with no cases?
>
> The commands I have tried are
>
> twoway__histogram_gen admissiondate if state=="VIC", gen(freq_vic x_vic)
> start (`startdate') width(7) freq
> twoway__histogram_gen admissiondate if state=="ACT", gen(freq_act x_act)
> start (`startdate') width(7) freq
> twoway__histogram_gen admissiondate if state=="WA", gen(freq_wa x_wa) start
> (`startdate') width(7) freq
> gen freq1=freq_vic+freq_act
> gen freq2=freq_vic+freq_act+freq_wa
> tw (bar freq_vic x_vic if freq1<., ylab(r(0 .))) (rbar freq_vic freq1
> x_act if freq1<.)
> (rbar freq1 freq2 x_wa if freq2<.), xtitle(date) ytitle(number of cases)
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index