Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • histogram - xline and normal density plot

    I wish to draw a histogram with a normal density plot and a line indicating the mean value. I am using Stata 18

    I have used the following code (to obtain the mean value) and try to draw the normal density plot (dlwg6 is the continuous variable of interest)
    summ dlwg6
    local a= r(mean)
    hist dlwg6, normal gap(5) xline(`a')

    however with the above command I get the plot without the xline
    But if I omit the normal density option I get the histogram with the xline at the mean value - it seems I can have one but not both!


  • #2
    I can't see your dlwg6 so let's discuss a reproducible example -- and on the way cut out the middle macro.

    Code:
    sysuse auto, clear 
    summ mpg 
    hist mpg, normal gap(5) xline(`r(mean)')
    I have two guesses at what's biting you. I will hold one guess and try the simpler guess first. Your added line may be obscured by the tallest histogram bar. It's supposed to be a feature of Stata's added lines that they aren't placed on top of any data element. (Ways of getting the opposite will be discussed in a Stata Journal Tipunder development.)

    Click image for larger version

Name:	histo_line.png
Views:	1
Size:	47.6 KB
ID:	1736385

    Comment


    • #3
      Thanks Nick
      It worked perfectly - I think it may have been cutting out the middle macro that sorted it - the line was not hidden by the tallest bar

      Comment

      Working...
      X