Announcement

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

  • Density Graph with threshold

    Dears,

    I would like to create a stata graph as the one below
    Click image for larger version

Name:	density.jpg
Views:	1
Size:	20.3 KB
ID:	1374356

    The first step that is the density line is ok ( I only have 1 court), but I don't know how I could create the two "grey areas" on the same gr. I created two additional variable severe and stunted but I don't know how to get such a graph. Could you please give me some hints?
    Thanks

    Federica

  • #2
    Code:
    sysuse nlsw88, clear
    twoway scatteri 0 0 .15 0 .15  5 0  5,      ///
                    recast(area) color(gs10) || /// first shaded area
           scatteri 0 5 .15 5 .15 10 0 10,      ///
                    recast(area) color(gs8)  || /// second shaded area
           scatteri .15 2.5 (12) "very poor"    ///
                    .15 7.5 (12) "poor",        /// labels on top
                     msymbol(i)              || ///
           kdensity wage, lstyle(p1)            /// density graph
                    legend(off)                 ///
                    yscale(range(0 .155))
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Hello Maarten, nice to see your comment. (You helped me a lot during my dissertation work.)

      How could the above graph be altered to achieve Federica's posted example of a two-sample comparison of kdensity, where each of two values of var_x has its own line within the same graph?

      Below is code of how I'd like the -at()- option to work in comparing wage at age==34 | age==44, but obviously it doesn't.
      Code:
             kdensity wage, at(age==34 | age==44) lstyle(p1)            /// density graph
                 legend(off)                 ///
                 yscale(range(0 .155))
      And this code does work but combines the two levels of age into the same kdensity plot line of wage.
      Code:
      kdensity wage if age==34 | age==44, lstyle(p1)            /// density graph
                 legend(off)                 ///
                 yscale(range(0 .155))

      Comment


      • #4
        Michael McCulloch You can use the twoway graph with the if qualifier once for age 34 and once for 44, something like:
        Code:
        use http://www.stata-press.com/data/r13/lifeexp, clear
        twoway kdensity lexp if region==1|| kdensity lexp if region==2

        Comment


        • #5
          Brilliant, Oded, that produces precisely what I intended. Many thanks.

          Comment

          Working...
          X