Announcement

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

  • Combining in one graph average partial effects (APE) with confidence intervals from linear and quantile regressions using Coefplot

    Dear Stata forum,
    I would like to use coefplot to show in one graph the APE point estimates from my linear regression (constant horizontal line) and quantile regressions including confidence intervals for all APE.
    Basically, I am looking at five quantile APE and one linear regression estimate that is constant across the five quantiles. I want to use coefplot in a way that I have all five quantile APE with associated confidence intervals and replace the
    Code:
    yline(0.011)
    with five repeated linear estimates of the size 0.011 with identical confidence intervals in a graph.
    I hope I make sense and would really appreciate your help.
    Best,
    Nico
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(logrinc wellbeing nonwhite)
    7.542521 30 0
    7.542521 24 0
    7.542521 22 0
    7.542521 31 0
    7.502025 28 0
    7.403252 29 0
    8.121662 15 0
    7.539113 27 0
    7.210631 25 0
    6.942438 14 0
      7.6341 26 0
    7.797384  . 0
    7.094313 25 0
    8.051726  . .
    7.663314  . 0
    7.362408 24 0
    7.203284 16 0
    7.971951 35 0
    8.044318  . .
    7.324188  . 0
    7.296931 21 0
    7.329742  . 0
    7.655503 27 0
    6.972014 26 0
    6.787335  . 0
    3.837201  . 0
     7.25374 30 0
    8.044318  . .
    7.795159 29 0
    5.924093 30 0
    7.021803 26 0
    7.458529 29 0
    7.060616 25 .
      7.1781 22 0
    7.166672 21 0
    6.046361  5 0
    7.296931 30 0
    7.502025 30 0
    7.720029 25 0
    7.061441 30 0
     7.51331  1 0
    7.270761 31 0
    6.723668  . 0
    6.879952  . 0
    7.334941 12 0
    6.388156 23 0
    7.065265 26 0
    6.789718 28 0
    6.179014  . 0
           . 28 0
    7.515503 31 0
    6.844309 26 0
    7.190077 28 0
    7.093958 30 .
    6.931336  1 0
    6.629687 28 0
    6.931336 31 .
    7.020621 27 0
    6.899742 29 0
    7.400417 25 0
    7.634849 20 0
    7.279938 26 0
    7.818018 31 0
    6.821516 28 0
    6.974333 22 0
    6.900592 25 0
    7.017493 28 0
    7.205996  . 0
    7.307733 28 0
    7.386319 27 0
    7.230303 30 0
    7.280488 26 0
    6.639393 31 0
    7.796538 32 .
    7.170705  . 0
    7.634849 25 0
    7.068887 22 0
    6.821858  . 0
    6.508694 22 0
    7.574813 24 0
     6.69715 28 0
    7.629261 31 0
    7.426097 29 0
    7.125466  . 0
    7.406186 29 0
    8.138578 29 0
    7.471175 25 0
    6.882276 31 0
    7.107618  . 0
    7.018179  . 0
    6.983825 26 0
    7.328568 14 0
    7.733629  . .
    7.328334 26 0
    7.640282 26 0
    8.213477 31 0
    7.629825 14 0
    7.462776 27 0
    6.735872 27 0
    7.547617 28 0
    end
    Code:
    global controls c.wellbeing  i.nonwhite 
    global conditions age>=16 & age<=75
    
    rifhdreg logrinc $controls  if $conditions,  cluster(pidp) rif(q(10))
    eststo q10: margins, dydx(wellbeing)  at(wellbeing=(10)) post 
    rifhdreg logrinc $controls  if $conditions,  cluster(pidp) rif(q(25))
    eststo q25: margins, dydx(wellbeing)  at(wellbeing=(25)) post 
    rifhdreg logrinc $controls  if $conditions,  cluster(pidp) rif(q(50))
    eststo q50: margins, dydx(wellbeing)  at(wellbeing=(50)) post 
    rifhdreg logrinc $controls  if $conditions,  cluster(pidp) rif(q(75))
    eststo q75: margins, dydx(wellbeing)  at(wellbeing=(75)) post 
    rifhdreg logrinc $controls  if $conditions,  cluster(pidp) rif(q(90))
    eststo q90: margins, dydx(wellbeing)  at(wellbeing=(90)) post 
    
    rifhdreg logrinc $controls  if $conditions,  cluster(pidp) rif(mean)
    eststo c10: margins, dydx(wellbeing)  at(wellbeing=(10 25 50 75 90)) post   // generates the 0.011 (constant linear APE) 
     
    coefplot (q10, msymbol(T)) (q25, msymbol(S)) (q50, msymbol(D)) (q75, msymbol(O)) (q90, msymbol(Oh)), vertical title("Average Marginal Effect") coeflabels(1._at = "10" 2._at = "25" 3._at = "50"  4._at = "75" 5._at = "90")  ///  
    xtitle(Log Net Real HH Income Quantiles) ytitle(Marginal Effects) yline(0.011) /// 
    graphregion(color(white)) bgcolor(white)
Working...
X