Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Two by two stacked bars


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Two by two stacked bars
Date   Thu, 26 May 2005 00:09:49 +0100

There may well be an easier way, but this does
work and is tunable: 

gen old_new = old + new 

gen oldpop_newpop = oldpop + newpop 

gen year2 = year - 0.2

gen year3 = year + 0.2

twoway bar oldpop year2, barw(0.4) || 
	 rbar oldpop oldpop_newpop year2, barw(0.4) || 
	 bar old year3, barw(0.4) || 
       rbar old old_new year3, barw(0.4) 
       legend(order(1 "oldpop" 2 "newpop" 3 "old" 4 "new")) 

To quote a forthcoming article in the Stata Journal: 
"as is common with Stata's
graphics, whatever is difficult with -graph dot-, -graph bar- or
-graph hbar- is often straightforward with {\tt graph twoway},
modulo some persistence". 

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

Margo Schlanger
 
> I want to create a single bar graph presenting the means of four
> variables for each of four years, stacked 2x2.
> 
> My five variables are:  old new oldpop newpop year.  I can easily get
> two different stacked graphs:
> 
> graph bar (mean) old new  over(year) stack 
> graph bar (mean) oldpop newpop over(year) stack 
> 
> What I want to do, though, is have these all appear on one graph, with
> old and new stacked in one color, and oldpop and newpop stacked in
> another color, with those stacked bars grouped by year.  I can get
> something close by creating an "old+new" variable and an 
> "oldpop+newpop"
> variable, and then graphing those by year.  But I want the information
> from the stacks, too, and all I've been able to do, so far, 
> is put them
> in different colors and then combine them with grc1leg or graph
> combine.

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