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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Order Bar Graph Bars by the Over Variable |

Date |
Fri, 13 Feb 2009 19:05:09 -0000 |

Your syntax wouldn't achieve what you want in Stata, even if it were legal. -over(foreign)- sorts on foreign anyway. Here is one way. sysuse auto, clear local y1 : variable label turn local y2 : variable label mpg stack turn foreign mpg foreign , into(y foreign) clear label def _stack 1 "`y1'" 2 "`y2'" label val _stack _stack label def foreign 0 Domestic 1 Foreign label val foreign foreign graph bar y , over(foreign) over(_stack) ytitle(means) And here is another way: sysuse auto, clear collapse (mean) turn mpg, by(foreign) rename mpg ympg rename turn yturn reshape long y , i(foreign) string graph bar y , over(foreign) over(_j) I am probably missing something easier. Nick n.j.cox@durham.ac.uk L S 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. graph bar (mean) turn mpg, over(foreign, sort(foreign)) However, this produces an error: "variable foreign not found." Do you know of any way to make the graph I want? * * 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/

**References**:**st: Order Bar Graph Bars by the Over Variable***From:*L S <lts40301@gmail.com>

- Prev by Date:
**st: RE: mvencode numlist** - Next by Date:
**Re: st: RE: RE: time trend in a panel with very SHORT time dimension** - Previous by thread:
**Re: st: Order Bar Graph Bars by the Over Variable** - Next by thread:
**st: clustered SE for reg3** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |