Announcement

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

  • Comparing linear regression models

    Hi, I'm not sure where I am going wrong with this code... I'm trying to compare two linear regression models using anova. Specifically, I'm trying to see if adding an interaction term improves the model. However, Stata keeps returning variable m1 not found. How can I fix this? For example, the code I'm using is:

    regress outcome v1 v2 v3
    est store m1

    regress outcome v1 v2##v3
    est store m2

    anova m1 m2

    Thank you for your help in advance.

  • #2
    Before getting to the comparison of models, notice that v2 and v3 are treated as continuous in your first model, but as categorical in your second model. You must use the c. prefix in your second model. I.e., change v2##v3 to c.v2##c.v3.

    Regarding the model comparison, have you considered using -nestreg-? The last table in its output will include an F-test comparing the two models. Here is a simple example.

    Code:
    clear *
    sysuse auto
    nestreg: regress weight (length mpg price) (c.mpg#c.price)
    And here is the relevant bit of output:

    Code:
      +-------------------------------------------------------------+
      |       |          Block  Residual                     Change |
      | Block |       F     df        df   Pr > F       R2    in R2 |
      |-------+-----------------------------------------------------|
      |     1 |  265.22      3        70   0.0000   0.9191          |
      |     2 |    1.61      1        69   0.2086   0.9210   0.0018 |
      +-------------------------------------------------------------+
    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 18.5 (Windows)

    Comment


    • #3
      You can also do a likelihood ratio test with -lrtest-. The problem here is that Stata expects m1 and m2 to be variables, like v1 or v2. m1 and m2 are stored model estimates, not variables, so the line fails.

      You can pass R model estimates to anova() like this (actually turns out to be an alias of anova.lm()), but the syntax doesn't translate to Stata.

      Comment

      Working...
      X