Announcement

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

  • Vertical line at forefront of histogram

    Hi all, data are below.

    I wish to make a histogram of this variable. I would like to add a vertical line to the x-axis, and bring it at the forefront of the histogram.

    The below code does everything, but does not bring the line at the forefront:

    Code:
    su mcq_exam_gap
    hist mcq_exam_gap, w(1) xti("Differential MCQ Less Final Exam Grade") xline(`r(mean)') freq
    How can I bring the line in front of the bars of the histogram?

    Code:
    clear
    input float mcq_exam_gap
    -10
      0
    -12
    -27
    -15
     -1
    -15
    -15
      9
    -11
      5
      7
     14
    -44
     -2
     14
      3
     12
     -9
      0
      7
     10
     32
    -20
      4
     -3
     -8
     -8
     53
     -1
    -15
      1
     -5
      3
     15
     -5
     23
     -5
     18
     -3
      5
    -14
      0
    -24
    -10
      4
     -8
      0
     -6
     -6
      8
     12
     -9
     -1
     15
    -21
     -3
     19
     12
     13
     -7
      7
     17
    -35
    -28
     15
     -5
     -6
      0
      2
      5
     12
     -2
    -13
      1
     -7
     -4
     -4
      3
     -2
     -2
     -2
    -23
    -15
     -7
     -7
      0
    -13
     -6
     -5
    -13
     -4
     -3
     -2
     -9
    -14
    -35
     -2
     -3
     -7
    end

  • #2
    Code:
    hist mcq_exam_gap, w(1) xti("Differential MCQ Less Final Exam Grade") addplot(scatteri  0 `r(mean)' 8 `r(mean)', recast(line)) freq legend(off)
    With that solution you do need two passes to work out "which value of 8" you need (to recycle an old joke attributed to William Feller).

    For a miniature review in this territory see https://journals.sagepub.com/doi/pdf...6867X241276116 from Stata Journal 24(3) 2024 (that is, the latest issue).

    Comment


    • #3
      Thank you very much Dr. Cox! In my case, it was 100.

      Comment


      • #4
        A line is much easier to see on a quantile plot.

        Code:
        su mcq_exam_gap, meanonly 
        
        local mean = r(mean)
        
        * Stata Journal 
        qplot mcq_exam_gap, yli(`mean') aspect(1) xla(0 0.25 "0.25" 0.5 "0.5" 0.75 "0.75" 1)
        
        quantile mcq_exam_gap, yli(`mean') aspect(1) rlopts(lc(none))

        Comment

        Working...
        X