Bookmark and Share

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


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

Re: st: Sort graphic by a non-graphed variable


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: Sort graphic by a non-graphed variable
Date   Wed, 28 Aug 2013 09:08:10 +0200

On Wed, Aug 28, 2013 at 7:41 AM,  <[email protected]> wrote:
> I'm using version 8
> Consider the following...
>
> sysuse auto, clear
> keep if _n < 6
> keep make price weight
> list
> graph hbar (asis) price , over(make)
>
> Here the order of the hbars is sorted by make.
> However, I'd like to have the hbars sorted by weight (a third variable
> that I don't wish to graph).

You can do that by creating a new variable that contains an integer
for each value of make but these integers are increasing according to
the sort order of weight and has value labels according to make. This
is what the -axis()- egen-function is for. This is part of the
-egenmore- package that you can download by typing in Stata -ssc
install egenmore-. Below is an example. There are more examples in the
help file, which you can read by typing in Stata -help egenmore-.

Hope this helps,
Maarten

*------------------ begin example ------------------
sysuse auto, clear
keep if _n < 6
keep make price weight
egen Make = axis(weight make), label(make)
list, nolabel
graph hbar (asis) price , over(Make)
*------------------- end example -------------------
* (For more on examples I sent to the Statalist see:
* http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten


---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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