Statalist The Stata Listserver

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

st: RE: boxredo?

From   "Nick Cox" <>
To   <>
Subject   st: RE: boxredo?
Date   Thu, 9 Nov 2006 22:51:00 -0000

Another approach is to write your own script. 

This code is based on a do file posted about a week
ago in response to another question about 
alternative recipes for box plots. 

// another box plot: one box p10 to p90 
//                   other box mean +/- smidgen                         
// two arguments: y byvar  
// examples: do anotherbox mpg rep78 
//           ru anotherbox mpg rep78  
// NJC 9 Nov 2006 

args y byvar  
if "`byvar'" == "" error 198 
local Y `"`: variable label `y''"' 
if `"`Y'"' == "" local Y "`y'" 

tempvar mean p10 p90 mean1 mean2 

su `y', meanonly 
local smidgen = 0.002 * (r(max) - r(min))

qui statsby "su `y', detail" `mean'=r(mean) `p10'=r(p10) `p90'=r(p90) ///
	, by(`byvar')

qui gen `mean1' = `mean' + `smidgen' 
qui gen `mean2' = `mean' - `smidgen' 

twoway ///
rbar `p10' `p90' `byvar', bcolor(none) barw(0.2) ||    ///
rbar `mean1' `mean2' `byvar', bcolor(red) barw(0.2)   ///
legend(off) ytitle(`"`Y'"') yla(, ang(h)) ///
note("red bars: mean; empty bars: 10%, 90% percentiles")


Incidentally, note that the mean may lie beyond the 
10% or 90% points, so a program depending on the 
contrary may fall over, surprised though you might be
if that happened to you. That is, only one data point 
need be larger (or smaller) than the mean.  


Caleb Southworth
> I would like to make boxplots where middle = mean, hinges = 10th/90th
> pctile. I note this has come up several times before and Michael
> Blasnik had a program called boxredo.ado, but I don't seem to find
> that on SSC. Perhaps it was renamed or incorporated elsewhere? Thanks!
> Original post here:

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index