Bookmark and Share

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

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

st: Re: Stacked histogram - empty bins

From   Allen Cheng <>
Subject   st: Re: Stacked histogram - empty bins
Date   Sun, 31 Jul 2011 10:52:07 +1000

Thanks for everyone for your replies. Yes, these are Australian data.

"stripplot" (with the "stack" option) worked quite well and is clearer
than a conventional histogram, with the added bonus of the "separate"
option. To force the bins to start from a set date, I manually
assigned then into bins. If you reduce the h and use square markers,
it looks like a histogram.

gen dategroup=(floor((admissiondate-`startdate')/7)*7)+`startdate'
stripplot dategroup, over(state) stack width(7) h(.6) ms(S S S)
xlabel(`startdate'(14)`currdate',format (%d) ang(45))

I note that in stripplot without the stack option the x axis is
automatically labelled in date format, but if you use the stack
option, you have to specify the date format.

Thanks again
Allen Cheng

On Thu, Jul 28, 2011 at 8:55 AM, Allen Cheng <> 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)
> Thanks
> Allen Cheng

Allen Cheng
Associate Professor in Infectious Diseases Epidemiology
Department of Epidemiology and Preventive Medicine
Monash University

Infectious Diseases Physician
Alfred Hospital

Honorary Principal Research Fellow
Menzies School of Health Research
*   For searches and help try:

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