Announcement

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

  • Superimposing graphs

    Hi everyone,

    I am relatively new to using Stata for graphs and I want to superimpose a normal distribution over a histogram (see below). I am not sure what the code should be for the graphs. Thank you for any advice!

    Click image for larger version

Name:	Screen Shot 2018-08-19 at 8.05.48 PM.png
Views:	1
Size:	63.4 KB
ID:	1458816


  • #2
    See help histogram. One of the options is -normal-, allowing for the overlay of a normal density curve.
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Hi Carole,

      Thank you for the quick and helpful response! I looked up help histogram and only managed to graph this (see below). Is there any way to move the curve to the centre similar to Post #1? Thank you!

      Code:
      histogram zhawho_cutoff, normal

      Click image for larger version

Name:	Screen Shot 2018-08-19 at 8.25.03 PM.png
Views:	1
Size:	70.6 KB
ID:	1458824

      Comment


      • #4
        Originally posted by Mangji Zo View Post
        Hi Carole,

        Thank you for the quick and helpful response! I looked up help histogram and only managed to graph this (see below). Is there any way to move the curve to the centre similar to Post #1? Thank you!

        Code:
        histogram zhawho_cutoff, normal

        [ATTACH=CONFIG]n1458824[/ATTACH]
        you may try this code:

        Code:
         hist zhawho_cutoff, addplot(function y=normden(x,0,1),range(-5 5))
        2B or not 2B, that's a question!

        Comment


        • #5
          A slightly more general approach described by Liu Qiang is to bulid your graph with each plot element, one at a time. Using -||- allows you to add a new graphic element. As described above, you may plot general functions, one of which is the Normal density as provided by Stata.

          Here's a working example:
          Code:
          sysuse bpwide
          graph twoway hist bp_before || (function y = normalden(x, 120, 20), range(50 200) lw(medthick) lcol(black) ) ///
             , legend(label(1 "Blood Pressure (mm Hg)") label(2 "N(120, 20) density"))

          Comment


          • #6
            Thank you so much for the codes and the advice!

            Comment

            Working...
            X