Predictive margins - The marginsplot Command

Updated: Oct 22, 2020

In this post, I will show you how to use marginsplot after running the margins command on a regression. The marginsplot command will draw a graph of predicative margins with 95% confidence interval in Stata. Below is a worked example:

sysuse auto, clear
generate kprice=price/1000
regress  mpg c.kprice##c.kprice i.foreign i.rep78 turn trunk headroom
margins, at(kprice=(3/15))

This generates the following graph:

This is the default predictive margins graph generated by the marginsplot command. We are now going to add some options to the marginsplot command so that it looks the way we want it to. The final graph we create is shown at the top of this tip. The new marginsplot command with the added options is shown below:

marginsplot, recastci(rarea) plotopts(msymbol(none) lcolor(maroon)) ciopts(pstyle(ci)) ytitle(Miles per gallon) xtitle(Price($1000)) title(Predictive margins with 95% confidence interval) xlabel(3(3)15 10.4)

For more useful information, please have a look at the book A Visual Guide to Stata Graphic

155 views0 comments

© 2020 by Survey Design and Analysis Services. 

  • LinkedIn
  • Facebook
  • Twitter
  • YouTube