Announcement

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

  • Plotting the results from the margins command

    Hi everyone

    I have an analysis kind of like this:

    Code:
    webuse nlswork, clear
    xtset idcode
    
    xtreg ln_w ttl_exp, re
    qui margins, at(ttl_exp=(0(5)30))
    qui marginsplot, recastci(rarea) recast(line) title(Random effects w/out controls) name(one, replace)
    
    xtreg ln_w ttl_exp grade age c.age#c.age 2.race not_smsa south, re
    qui margins, at(ttl_exp=(0(5)30))
    qui marginsplot, recastci(rarea) recast(line) title(Random effects w/ controls) name(two, replace)
    
    xtreg ln_w ttl_exp, fe
    qui margins, at(ttl_exp=(0(5)30))
    qui marginsplot, recastci(rarea) recast(line) title(Fixed effects w/out controls) name(three, replace)
    
    xtreg ln_w ttl_exp grade age c.age#c.age 2.race not_smsa south, fe
    qui margins, at(ttl_exp=(0(5)30))
    qui marginsplot, recastci(rarea) recast(line) title(Fixed effects w/controls) name(four, replace)
    I.e. I have a set of models that differ in one way or another and I am using margins to illustrate the slope of treatment across models.

    I can plot those slopes like this:

    Code:
    graph combine one two three four, col(2) ycommon
    and this looks like this:

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	85.2 KB
ID:	1678745


    But I don't like the small-multiples aspect of the figure. Is there a simple way I can plot the lines and the confidence intervals overlaid in the same figure?

    In case this verbal description of my desired figure wasn't clear I am also providing a simulation I did in MS Paint:

    Click image for larger version

Name:	one.jpg
Views:	1
Size:	117.4 KB
ID:	1678746
    Thanks for your consideration
    KS

  • #2
    Code:
    ssc install combomarginsplot
    help combomarginsplot
    This may help: https://www.statalist.org/forums/for...ne-marginsplot

    Comment


    • #3
      Amazing, thank you!

      Click image for larger version

Name:	Graph.png
Views:	1
Size:	81.4 KB
ID:	1678762


      Code:
      webuse nlswork, clear
      xtset idcode
      
      tempfile one two three four
      
      xtreg ln_w ttl_exp, re
      qui margins, at(ttl_exp=(0(5)30)) saving(`one', replace)
      
      xtreg ln_w ttl_exp grade age c.age#c.age 2.race not_smsa south, re
      qui margins, at(ttl_exp=(0(5)30)) saving(`two', replace)
      
      xtreg ln_w ttl_exp, fe
      qui margins, at(ttl_exp=(0(5)30)) saving(`three', replace)
      
      xtreg ln_w ttl_exp grade age c.age#c.age 2.race not_smsa south, fe
      qui margins, at(ttl_exp=(0(5)30)) saving(`four', replace)
      
      combomarginsplot `one' `two' `three' `four', labels("RE" "RE w/ controls" "FE" "FE w/ controls")

      Comment

      Working...
      X