Announcement

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

  • Margins and interactions error!

    Dear Statalist Users,

    I am currently working on a regression model in Stata involving interaction terms and am facing challenges with calculating the marginal effects. I would like to understand the change in the effect of the variable represented by var2 on the dependent variable, when interaction terms involving other variables (var1, var2, var3) are added to the regression model. Initially, I run a regression without interaction terms:
    regress dependentvar var1 var2 var3 , vce(cluster f)
    . Subsequently, I introduce interaction terms to assess the derivative or marginal effect of the variable represented by var2 in the presence of these interactions. I think i could not know the real effect of the introduction of var2 in the model without getting the derivative.

    Here is a detailed description of my problem:

    I am running a regression model to examine the relationship between the dependent variable (dependentvar) and several independent variables, including interaction terms. The model is specified as follows:

    regress dependentvar var1 var2 var3 c.var1##c.var2 c.var1##c.var3
    I attempted to calculate the marginal effects for the interaction terms using the margins command with the dydx() option. Here are the code I used:

    margins, dydx(var1 var2 var3 c.var1##c.var2 c.var1##c.var3) atmeans post
    margins, dydx(var1 var2 var3 c.var1##c.var2 c.var1##c.var3) atmeans
    but i alsways get an error! If I use dydx(*) the results are only for the vars not for their interaction terms.

  • #2
    There is no such thing as the marginal effect of an interaction term. Interaction terms change the marginal effects of their "main" variables, but they do not have marginal effects of their own.

    To see why, let's take a simpler case. Suppose we have -regress y i.x1##i.x2-, where x1 and x2 are both dichotomous 0/1 variables. If the "marginal effect" of x1#x2 were to mean anything it would have to be the effect of a unit change in x1*x2 on y. But, a unit change in x1*x2 might represent a change from x1=x2=0 to x1=x2=1, or it could mean a change from x1=1 x2=0 to x1=x2=1, or it could mean a change from x1=0 x2=1 to x1=x2=1. But the corresponding changes in y are different for all three cases unless the marginal effects of x1 and x2 themselves are zero. So in the general case, the effect of a unit change in x1#x2 on y is undefined because it can be many different things. The situation with continuous variables actually allows for an infinite number of possibilities, not just 3.

    Comment


    • #3
      Dear Clyde,

      I appreciate your response. I've introduced an additional variable, let's call it var2, to the regression model. I've subsequently interacted it with other variables. However, upon reviewing the regression results, I wanted to clearly indicate the effect of var2 on the dependent variable (dep-var). To address this, I aim to determine the marginal effect. I plan to calculate (1) the change in y divided by the change in var2 and (2) the change in y divided by the change in var2#var1.

      But it seems that the marginal impact of var2 on y is primarily determined by (1), and there's no necessity to obtain (2). Could you please confirm if my understanding is correct?

      P.S. I'd like to mention one more point: I've come across several papers where researchers conduct a regression analysis, such as probit, and calculate the marginal effects, including those for interaction terms.


      Wishing you a Merry Christmas and thanks again.
      Last edited by Jade Li; 24 Dec 2023, 07:13.

      Comment


      • #4
        I plan to calculate (1) the change in y divided by the change in var2 and (2) the change in y divided by the change in var2#var1.

        But it seems that the marginal impact of var2 on y is primarily determined by (1), and there's no necessity to obtain (2). Could you please confirm if my understanding is correct?
        No, that is incorrect.

        The first thing to clear up is that there is no such thing as the effect of var2 on y in an interaction model. There are many effects of var2 on y: a different one for each value of var1. You can see all of these in a single graph if you run
        Code:
        margins var1, dydx(var2)
        marginsplot
        That code assumes var1 is a discrete variable. If var1 is a continuous variable, then you have to choose a set of representative and interesting values of var1 first. Let me assume for purposes of demonstration that the interesting values of var1 are 0 2 4 6 8 and 10. Then
        Code:
        margins, dydx(var2) at(var1 = (0 2 4 6 8 10))
        marginsplot
        Now, people sometimes get sloppy about the use of language and speak of "the marginal effect" of var2 when the are really talking about the average marginal effect of var2. This average marginal effect is just what it sounds like: it is an average of the marginal effects of var2, weighted by the distribution of var1 in the data. One can get this statistic with:
        Code:
        margins, dydx(var2)
        and this works the same way whether var1 is continuous or discrete. But understand that it is an average of all the different marginal effects of var2. And if var1 is discrete, then it is possible, even likely, that this average marginal effect is not even a possible marginal effect of var2 at any value of var1.

        As for how Stata calculates these marginal effects, whether the ones conditional on a specific value of var1 or the average marginal effect, both the var2 coefficient and the coefficient of var1#var2 play a role in the calculation. The general formula, if var1 is continuous, is
        Code:
        marginal effect of var2 conditional on var1 == V
             = _b[var2] + V*_b[var1#var2]
        (If var1 is discrete then there is a series of terms, one for each level of var1 and with the corresponding interaction coefficient.)

        Either way, both _b[var2] and _b[var1#var2] (or the suite of var1#var2 interaction coefficients for a discrete variable) contribute to it.

        Comment


        • #5
          Thank you Clyde!

          Comment

          Working...
          X