Announcement

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

  • Graphing a logistic regression model with a quadratic term

    I have a quadratic regression model that includes a quadratic term. I know that the command

    twoway qfit yvar xvar
    will plot a model with a quadratic term in it, but upon closer inspection this is for linear models, not logistic ones. What is the appropriate way of plotting this relationship? Appreciate your guidance in this.

  • #2
    Like this:
    Code:
    sysuse auto, clear
    logistic foreign c.mpg##c.mpg // AND OTHER TERMS IF YOU LIKE
    margins, at(mpg = (15(5)40))
    marginsplot
    Note: for this to work you absolutely must use factor variable notation to include the quadratic. If you try -gen mpgsq = mpg*mpg- and -logistic foreign mpg mpgsq-, then -margins- and -marginsplot- will give you gibberish. If you are not yet familiar with factor variable notation do read -help fvvarlist- and the corresponding manual section: this is one of Stata's most useful features and every regular Stata user should learn it.

    Also note that -marginsplot- accepts most of the options available with -graph twoway-, so you can customize the appearance of the graph to your taste.
    Last edited by Clyde Schechter; 23 Sep 2016, 21:15. Reason: Fix typo in code

    Comment


    • #3
      Clyde, thanks so much, that was very clear.

      Comment

      Working...
      X