Statalist


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

Re: st: Order Bar Graph Bars by the Over Variable


From   Ulrich Kohler <[email protected]>
To   [email protected]
Subject   Re: st: Order Bar Graph Bars by the Over Variable
Date   Fri, 13 Feb 2009 19:52:39 +0100

L S schrieb:
> Hello,
> 
> I am trying to create a simple bar graph in STATA.  Suppose I am using
> the sysuse auto dataset.
> 
> Q:  I would like to have it so that my graph compares the variables
> turn and mpg across the dummy variable foreign.  That is, on the left side
> of the graph, it should compare turn across foreign and domestic cars, and
> on the right side it should compare mpg across foreign and domestic cars.
> Right now I am typing:
> 
> sysuse auto, clear
> bar graph (mean) turn mpg, over(foreign)
> 
> The problem with this is that this displays the mean of turn and mpg for
> domestic cars on the left hand side, and then the mean of turn and mpg for
> foreign cars on the right hand side.  Visually, this setup makes the reader
> compare turn and mpg for domestic cars, and compare turn and mpg for
> foreign cars,
> instead of the comparison I want.  What I want to essentially do is to
> sort the 4 bars by foreign.

Here is a solution with reshape:

--------------------------------------
sysuse auto, clear
ren turn var1
ren mpg var2
reshape long var, i(make) j(typ)
lab val typ typ
lab def typ 1 "turn" 2 "mpg"
graph bar var, over(foreign) over(typ)
----------------------------------------

Uli




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