[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Sort order in graph box, over() by()

From   "Nick Cox" <>
To   <>
Subject   RE: st: Sort order in graph box, over() by()
Date   Tue, 28 Aug 2007 13:36:56 +0100

I think Scott's main idea is right. To solve this, you 
need to create your own grouping variable upstream of 
the graph call.

Here's another way to do it, however, that doesn't
involve resorting to monkeying with extra observations
ad hoc. 

sysuse auto, clear
egen median = median(mpg), by(rep)
egen axis = axis(median rep78), label(rep78) 
graph box mpg, over(axis) by(foreign, b1title(Repair record 1978))

Here you need to have installed -egenmore- from SSC to get -egen, axis()-. 

I have posted on this unofficial -egen- function before, so
here are some related postings: 

If StataCorp would only add one option to -egen, group()- 
none of this would be necessary! 

I have bundled in the example above an extra trick. 
-graph box- won't let you use an -xtitle()- 
in this kind of graph because of -graph-'s dogma
that the axis in question isn't an x-axis. A 
solution is to invoke -b1title()-. 

Those using graphics in Stata <=7 may remember
that graph axis titles came in various flavours, 
being -l-, -r-, -b- or -t- according to whether
they were on the left, right, bottom or top. 
It doesn't seem to be documented, but some of
the associated options still persist in the new
graphics, chiefly to allow Vince Wiggins a few 
extra handles for the very few occasions that he needs them. 


Scott Merryman
> Like this?
> sysuse auto ,clear
> egen median = median(mpg) ,by(rep)
> graph box mpg, over(rep, sort(med)) by(fore) name(gr1,replace)
> set obs 76
> replace fore = 1 in 75/76
> replace rep = 1 in 75
> replace rep = 2 in 76
> replace med = 18 if rep == 2 & fore == 1
> replace med = 20 if rep == 1 & fore == 1
> graph box mpg, over(rep, sort(med)) by(fore) name(gr2,replace)
On 8/27/07, Stefan Kreisel <> wrote:

> > I'll give it another (abbreviated, as suggested in the 
> Statalist FAQ...) try after receiving no response to "Forcing 
> sort order in graph box, over() by()" (see that thread for 
> any details).
> >
> > Is there a way to individually sort the order of boxes in a 
> given subgraph as produced by the by() option in e.g. -graph 
> box yvar, over(xvar, sort(1)) by(anothergroup)-?
> >
> > The problem is that missing categories on a given 
> subgrouping of by() get put on the far right most side of the 
> subgraph; I want them all in the same position in each subgraph.

*   For searches and help try:

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