Announcement

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

  • Shaded area

    Click image for larger version

Name:	02.png
Views:	1
Size:	174.9 KB
ID:	1694224 Hello,
    I use Stata 15.
    I used twoway to graph marginal effect. the two dashed lines show the confidence limits. I need to create a shaded area between the two dashed lines when x≥2.

    Any help please?
    Many thanks

  • #2
    Code:
    sysuse auto, clear
    set scheme s1mono
    
    // sensible units
    replace weight = weight * 4.535924e-4
    label var weight "weight (1000kg)"
    replace price = price/1000
    label var price "price (1000$)"
    
    // a model
    glm price c.weight##i.foreign , link(log) family(poisson) vce(robust)
    
    // store marginal effects
    tempfile tograph
    margins, dydx(weight) at(weight=(.8(.05)2.2) foreign=(0/1)) saving(`tograph', replace)
    use `tograph', replace
    
    // make the graph
    separate _margin, by(_at2) veryshortlabel
    separate _ci_lb, by(_at2)
    separate _ci_ub, by(_at2)
    
    twoway rarea _ci_lb0 _ci_ub0 _at1 if _at1 > 1.5 , ///
                 astyle(ci)                        || ///
           rarea _ci_lb1 _ci_ub1 _at1 if _at1 > 1.5 , ///
                 astyle(ci)                        || ///
           line _ci_lb0 _ci_lb1 _ci_ub0 _ci_ub1 _at1, ///
                lpattern(dot ..) lcolor(black ..)  || ///
           line _margin0 _margin1 _at1 ,              ///
                lpattern(solid dash) lcolor(black ..) ///
                legend(order(7 8)                     ///
                       pos(4) col(1)                  ///
                       region(lstyle(none)))          ///
                ylab(,angle(0))                       ///
                ytitle(marginal effect of weight)
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      thank you very much for this. i will try it.

      Comment

      Working...
      X