*! version 1.1 (14Nov02) pbe
program define histbox
  version 7.0
  syntax varlist(max=1) [if] [in] [fweight] [, Mean by(string) * ]
  if `"`by'"' != "" {
    window manage forward results
    display as err "by option not allowed"
    exit 198
  }
  tokenize `varlist'
  gph open
  capture graph `1' `if' `in' [`weight' `exp'], hist bbox(600,0,23063,32000,850,390,0) `options'
  if _rc>0 {
    window manage forward results
    display as help "r(198)"
    exit
  }
  local ay = r(ay)
  local by = r(by)
  local ax = r(ax)
  local bx = r(bx)
  local r1 = 50
  local r2 = 600
  local rc = (`r2'-`r1')/2+`r1'
  quietly summarize `1' `if' `in' [`weight' `exp'], detail
  local q1 = r(p25)
  local q2 = r(p50)
  local q3 = r(p75)
  local qm = r(mean)
  local ql = r(min)
  local qu = r(max)
  local cl = `ax'*`ql'+`bx'
  local c1 = `ax'*`q1'+`bx'
  local c2 = `ax'*`q2'+`bx'
  local c3 = `ax'*`q3'+`bx'
  local cu = `ax'*`qu'+`bx'
  local cm = `ax'*`qm'+`bx'
  gph pen 2
  gph line  `r1' `c1' `r1' `c3'
  gph line  `r2' `c1' `r2' `c3'
  gph line  `r1' `cl' `r2' `cl'
  gph line  `r1' `c1' `r2' `c1'
  gph line  `r1' `c2' `r2' `c2'
  gph line  `r1' `c3' `r2' `c3'
  gph line  `r1' `cu' `r2' `cu'
  gph line  `rc' `cl' `rc' `c1'
  gph line  `rc' `c3' `rc' `cu'
  if "`mean'"~="" {
    gph pen 3
    gph point  `rc' `cm' 0 6
  }
  gph close
  window manage forward graph
end