Statalist


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

RE: st: Bar graph ordered by values of yvar


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Bar graph ordered by values of yvar
Date   Fri, 14 Mar 2008 16:39:34 -0000

Two further thoughts: 

Doing individual graphs and then combining works pretty nicely: 

sysuse nlsw88, clear

foreach v in hours wage tenure { 
	graph hbar `v', over(collgrad) saving(`v') 
} 

graph combine "hours" "wage" "tenure", col(1) imargin(zero) 

You could insist on -xcommon- if you really wanted. 

It's not your question, but in almost all circumstances just plotting
the means throws a lot of information away! 

Nick 
[email protected] 

David Radwin


Thank you for the explanation. I was afraid that might be the case.

At 11:53 PM +0000 3/13/08, Nick Cox wrote:

>I've devoted some time to trying to automate the kind of
>manipulations needed here without being clear whether the emphasis
>should
>on changing the data structure or doing the graphics. (Short answer:
You
>
>need some of both.)
>
>Absent a simple solution that I know of:
>
>I'd -collapse- the data -- just as -graph bar- does, temporarily --
>and then fool around in the editor to produce a dataset that was
>amenable to
>-textbarplot- fron SSC.
>
>That may not be practical for your real example, especially if you want
>to do this repeatedly or for a rather larger dataset.

David Radwin

>Thank you for the suggestion. This graph is adequate, but I would
>like greater control over the spacing between bars as is typically
>done using the bargap or gap options. The reason would be to
>emphasize the comparison between college grads and non-college grads.
>
>Is there a way to make the gaps between bars 2 and 3 and between bars
>4 and 5 larger than the gaps between bars 1 and 2, bars 3 and 4, and
>bars 5 and 6?

At 7:09 PM -0400 3/13/08, Friedrich Huebler wrote:

>>Here is one solution.
>>
>>. sysuse nlsw88, clear
>>. foreach var of varlist hours wage tenure {
>>      sum `var' if collgrad == 0
>>      gen ncg`var' = r(mean)
>>      sum `var' if collgrad == 1
>>      gen cg`var' = r(mean)
>>    }
>>. keep in 1
>>. graph hbar ncghours - cgtenure, ascategory

On Thu, Mar 13, 2008 at 6:34 PM, David Radwin <[email protected]>

>>>    I have a question analogous to one I asked last year that was
>>>    graciously answered by Nick Cox
>>>    (http://www.stata.com/statalist/archive/2007-08/msg00934.html).
>>>
>>>    Rather than pose the question outright, I will illustrate with a
>>>    example comparing college graduates with non-college graduates:
>>>
>>>    . sysuse nlsw88, clear
>>>    . graph hbar (mean) hours wage tenure, over(collgrad) showyvars
>>>
>>>    give you a graph with the bars in the order, from top to bottom,
>of:
>>>
>>>    1. mean hours for non-college grads
>>>    2. mean wage for non-college grads
>>>    3. mean tenure for non-college grads
>>>    4. mean hours for college grads
>>>    5. mean wage for college grads
>>>    6. mean tenure for college grads
>>>
>>>    But what I actually want is
>>>
>>>    1. mean hours for non-college grads
>>>    2. mean hours for college grads
>>>    3. mean wage for non-college grads
>>>    4. mean wage for college grads
>>>    5. mean tenure for non-college grads
>>>    6. mean tenure for college grads
>>>
>>>    Is there a option, user-written program, or set of commands that
>>>    would produce this graph?

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