Announcement

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

  • Constant Errors in Marginal effects of interaction terms

    I am trying to calculate marginal effects of interaction terms but keep getting errors. Specifically, I would like to know how the effect of x3 on DV according the changes in the value of x2.


    I used the following commands.


    firthlogit DV x x1 c.x2## i. (x3 x4)


    margins x2 , dydx(x3) atmeans expression (invlogit(predict(xb)))
    factor x2 not found in list of covariates
    r(322);


    .margins c.x2 , dydx(x3) atmeans expression (invlogit(predict(xb)))
    only factor variables and their interactions are allowed
    r(198);


    .margins c.x2 , dydx(i.x3) atmeans expression (invlogit(predict(xb)))
    only factor variables and their interactions are allowed



  • #2
    See this recent thread: https://www.statalist.org/forums/for...deration-model

    Comment


    • #3
      Thank you for the reply. I read the thread and tried the following command.



      firthlogit DV x x1 c.x2## i. (x3 x4)
      margins, dydx(x3) at( x2 =(min max)) atmeans expression (invlogit(predict(xb)))

      (1) I am not sure the command indicates to calculate the effect of x3 on DV according the changes in the value of x2.


      (2) If so, can you tell me how to interpret the following table?
      Click image for larger version

Name:	Interaction table.png
Views:	1
Size:	16.4 KB
ID:	1654227





      (3) Also marginsplot only creates the graph when the value of x3 is 1 but I also would like to know and create a graph when the value of x3 is 0. (X3 is binary variables).
      Attached Files
      Last edited by April Kimm; 14 Mar 2022, 06:39.

      Comment


      • #4
        Originally posted by April Kimm View Post
        https://www.statalist.org/forums/for...deration-model

        (3) Also marginsplot only creates the graph when the value of x3 is 1 but I also would like to know and create a graph when the value of x3 is 0. (X3 is binary variables).

        An indicator can take on two values; 0 or 1. When you add it into the regression, the 0 category is the base - so there are no separate effects for each level of the indicator. If you want to specify the positive category as the base, you can do so in the regression, but all what that means is that the signs of the marginal effects would be reversed.

        Code:
        firthlogit DV x x1 c.x2## ib1.(x3 x4)

        margins, dydx(x3) at( x2 =(min max)) atmeans expression (invlogit(predict(xb)))

        (1) I am not sure the command indicates to calculate the effect of x3 on DV according the changes in the value of x2.


        (2) If so, can you tell me how to interpret the following table?
        Well, you are specifying only 2 values of the continuous variable, i.e., the minimum and the maximum. If you want to compute the effects in-between, you need to partition the range, e.g.,


        Code:
        margins, dydx(x3) at( x2 =(48(8)120)) atmeans expression (invlogit(predict(xb)))
        The average marginal effect for an indicator as Stata states is the discrete change from the base level (so if the base level is 0, it's the change from 0 to 1). Look at Richard Williams's notes for a tutorial: https://www3.nd.edu/~rwilliam/stats/Margins01.pdf

        Comment

        Working...
        X