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: graph bar, over() with overall mean


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: graph bar, over() with overall mean
Date   Thu, 30 Jan 2014 17:13:42 +0000

Scott showed one good technique.

The same kind of flavour pervades this solution.

Incidentally, I changed the graphics. (It doesn't seem to make much
sense to suppress the legend, and a horizontal dot chart is arguably
cleaner and more effective.)

But the main idea is to use an -expand-ed dataset and calculate totals
from the extra part.

sysuse auto, clear

preserve
local N = _N
expand 2
gen byte new = _n > `N'
replace rep78 = 6 if new
label def rep78 6 "all"
label val rep78 rep78

graph dot (mean) mpg, over(rep78) over(foreign) nofill ///
title("MPG, by Domestic/Foreign  and Repair Record") ytitle("Mean MPG")

restore

Nick
[email protected]

On 30 January 2014 17:04, Scott Merryman <[email protected]> wrote:

> Yes, by creating an additional category:
>
> sysuse auto,clear
> set obs 76
> replace rep = 6 in 75/76
> replace fore = 0 in 75
> replace fore = 1 in 76
> sum mpg if fore == 1 & rep != 6
> replace mpg = r(mean) if fore == 1  & rep == 6
> sum mpg if fore ==0 & rep != 6
> replace mpg = r(mean) if fore == 0  & rep == 6
>
> graph bar (mean) mpg, over(rep78)  over(foreign) asyvars legend(off)
>
*
*   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