[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: twoway bar
Nick Cox <email@example.com>
Re: st: twoway bar
Wed, 28 Mar 2012 13:58:50 +0100
In the case of the code below
graph bar (mean) trunk turn, over(foreign)
is a more direct approach. But you still need -twoway- to plot your
means and confidence intervals.
Also, if in your code -group- is the x variable, then -by(group)- is
usually better omitted.
On Wed, Mar 28, 2012 at 1:49 PM, Nick Cox <firstname.lastname@example.org> wrote:
> In each of your graph calls, you specify that -group- defines the x
> axis variable; inevitably -twoway- does exactly what you ask for and
> plots bars etc. on top of each other.
> You may be expecting default behaviour like that of -graph bar-, but
> -twoway bar- does not behave in the same way,
> One way round this is to use an offset. The following gives an example
> sysuse auto, clear
> egen mean_turn = mean(turn), by(foreign)
> egen mean_trunk = mean(trunk), by(foreign)
> label var mean_turn "Mean of Turn circle, ft"
> label var mean_trunk "Mean of Trunk space, cu. ft"
> gen foreign1 = foreign - 0.1
> gen foreign2 = foreign + 0.1
> twoway bar mean_turn foreign1 , barw(0.18) ///
> || bar mean_trunk foreign2, barw(0.18) xtitle("`: var label foreign'")
> base(0) xla(0 "Domestic" 1 "Foreign")
> See also
> SJ-7-1 gr0026 . . . . Stata tip 42: The overlay problem: Offset for clarity
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . J. Cui
> Q1/07 SJ 7(1):141--142 (no commands)
> tip for graphing several quantities on a continuous axis
> which is accessible to all at
> On Wed, Mar 28, 2012 at 1:29 PM, ofran almossawi
> <email@example.com> wrote:
>> I have done a two way bar plot but stata keeps stacking the bars and the sd
>> lines on top of each other instead of laying all four columns side by side.
>> I have compared the pain scores of two groups of patients post caesarean
>> section, before and after taking their pain medications. The sm group take
>> their own pain killers, and the nsm group are given the painkillers by the
>> This is the code that I used:
>> twoway (bar meanpain group) (rcap upper_pain lower_pain group) (bar
>> meanmed group) (rcap upper_med lower_med group), by(group)
>> i'm not sure where i'm going wrong with this.
* For searches and help try: