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

# Re: st: RE: question on graphing a bar

 From Nick Cox To statalist@hsphsun2.harvard.edu Subject Re: st: RE: question on graphing a bar Date Sat, 19 May 2012 07:18:07 +0100

```It's all in the help for -graph bar-, which you are expected to read.
-over(whatever, gap(*4))- makes the gaps between bars 4 times bigger.
Therefore the bars will be smaller.

Nick

On Sat, May 19, 2012 at 5:47 AM, Jian Zhang <jian32@gmail.com> wrote:

> Nick, now the bars look too big. Is there a way to reduce the width of the bars?

> On Fri, May 18, 2012 at 10:47 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
>> The problem is trivial then. You just need to produce a dataset that is of the form exemplified in my first post. With three means, and nothing else explained, you could create that interactively.
>>
>> Also it is easy enough to automate that:
>>
>> gen means = .
>> gen label = ""
>> su non, meanonly
>> replace label = "non" in 1
>> replace means = r(mean) in 1
>> su self, meanonly
>> replace label = "self" in 2
>> replace means = r(mean) in 2
>> su wage, meanonly
>> replace  label = "wage" in 3
>> replace means = r(mean) in 3
>>
>> gen twothree = _n > 1
>>
>> graph bar (asis) means in 1/3 , over(label) over(twothree) asyvars stack
>>
>> Nick
>> n.j.cox@durham.ac.uk
>>
>> Jian Zhang
>>
>> Each bar represents the mean of the variable in the sample.
>>
>> On Fri, May 18, 2012 at 10:35 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
>>
>>> If you don't ask the real question, you may not get the real answer.
>>>
>>> This still isn't clear to me: How is each variable going to produce one and only one bar?
>>>
>>> Nick
>>> n.j.cox@durham.ac.uk
>>>
>>> Jian Zhang
>>>
>>> Nick, it works. but what  i have is a data set of three variables, say
>>> non-earned income, wage_income and self-employment income. what i
>>> wanted is a bar chart where there is one bar for non-earned income,
>>> then one bar for wage_income and one bar for self-employment income
>>> but the two later bars were stacked. Note that all the observations
>>> have values for the three variables. So it is not possible to use the
>>> option of over.  Is there a way to graph a bar like this with the
>>> data?
>>>
>>> On Fri, May 18, 2012 at 10:05 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
>>>> Consider
>>>>
>>>> clear
>>>> set obs 3
>>>> gen cat = _n
>>>> gen twothree = _n > 1
>>>> gen y = runiform()
>>>> graph bar (asis) y , over(cat) over(twothree) asyvars stack
>>>>
>>>> Nick
>>>> n.j.cox@durham.ac.uk
>>>>
>>>> Jian Zhang
>>>>
>>>> I was trying to graph a vertical bar chart where there are three bars.
>>>> but i wanted the second and third bars stacked. Does anyone know how
>>>> to do this? thanks!

*
*   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/
```