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

# RE: st: RE: Graphing Histograms and Overlaying A Vertical Line

 From "Cohen, Elan" To "statalist@hsphsun2.harvard.edu" Subject RE: st: RE: Graphing Histograms and Overlaying A Vertical Line Date Fri, 24 May 2013 17:48:58 +0000

```I see now.  From http://www.stata-journal.com/sjpdf.html?articlenum=gr0014, the following should work:

sysuse auto
twoway__histogram_gen mpg, percent gen(h x)
su h, meanonly
loc max = 1.1*r(max)
qui su mpg, d
loc mean = r(mean)
loc med = r(p50)
tw hist mpg, percent || function y=`mean', hor ra(0 `max') || function y=`med', hor ra(0 `max')

HTH,

- Elan

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Erika Kociolek
Sent: Friday, May 24, 2013 11:24
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: RE: Graphing Histograms and Overlaying A Vertical Line

When I run your code, the two lines appear behind the histogram. I'd
like for them to be in front of the histogram. In other posts, folks
have suggested using function to achieve this, but I don't know how to
ensure that the range of "function" aligns with that of the histogram
and in a way that can change dynamically if the histogram range should
shift dramatically.

Best,
Erika

On Fri, May 24, 2013 at 8:00 AM, Cohen, Elan <cohened@upmc.edu> wrote:
> Erika,
>
> The following works fine for me:
>
> sysuse auto
> su mpg, d
> hist mpg, percent xline(`r(mean)' `r(p50)')
>
> - Elan
>
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Erika Kociolek
> Sent: Friday, May 24, 2013 10:22
> To: statalist@hsphsun2.harvard.edu
> Subject: st: Graphing Histograms and Overlaying A Vertical Line
>
> I am attempting to graph a histogram, overlaying vertical lines
> showing the mean and median. I know that the xline option won't get me
> what I want, so I went the twoway route. What I'm trying to figure out
> is how to get the range for "function" to match what's used for twoway
> histogram.
>
> summarize height
> twoway histogram height, percent || function y=`r(mean)', range(? ?)
>
> Any thoughts?
>
> Thanks!
> Erika
> *
> *   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/
>
>
> *
> *   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/
*
*   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/

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