Announcement

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

  • Plotting marginal effect after xtivreg with binary endogenous regressor

    Hi,

    I need some advice on how to plot the marginal effects from manual interaction. I am aware that margins and factor variables are the basic solutions, but I couldn't get the results even after using the expression option.

    My data is a panel (company year), and the main variable of interest is the interaction between binary variable x1 and continuous variable x2.
    As the binary variable x1 is likely endogenous, I follow Procedure 21.1 in Wooldridge and use 4 variables z1, z2, z3, and z4 to construct the instrument functional form in the first stage using probit, and then use the fitted probabilities as instruments in the second stage using xtivreg.

    ***First stage
    [probit x1 z1 z2 z3 z4 $controls i.year, cluster(company)]
    [predict vhat, pr]

    Because xtivreg does not allow factor variables as DV, I have to manually create the interaction term
    ***Second stage
    [gen interaction = x1*x2]
    [gen Vinteraction = vhat*x2]
    [xtivreg y (x1 interaction = vhat Vinteraction) $controls i.year, fe vce(cluster company)]
    [margins, dydx(interaction) expression(_b[x2] + _b[interaction]*x1) ]

    I have also explored ivreghdfe to reintroduce the factor variables so that I can use margins but my code didn't work (it doesn't give the same results as xtivreg)
    [ivreghdfe y (i.x1 i.x1#c.x2 = vhat c.vhat#c.x2) x2 $controls i.year, absorb(company)]

    I hope the coding alone will be enough to illustrate my problem. Thanks.

  • #2
    Originally posted by Irene Margaret View Post
    margins, dydx(interaction)
    Even if you were using factor variables, this is invalid. You can independently change the constituent variables of the interaction term, but not the interaction itself. To get the expression

    _b[x2] + _b[interaction]*x1
    you are taking the derivative with respect to what?

    Comment


    • #3
      Hi Andrew,
      If I use factor variable, it indeed should be something like margins, dydx(x2) at (x1=(0 1)
      But because xtivreg does not accept factor variables as DV (the x1#x2) I couldn't do the above.

      As for
      the _b[x2] + _b[interaction]*x1, the derivate is taken with respect to x1.
      But now I see that _b[x2] will be zero in this case. Any idea on how to fix the expression?

      Comment


      • #4
        Just want to inform that I (pragmatically) solved the issue with ivreghdfe.
        Seems like my previous code didn't work because x1 is time-invariant. So x1 should be removed (which maybe good as I end up with overidentified model).

        So
        Code:
        xtivreg y (interaction = vhat Vinteraction) $controls i.year, fe vce(cluster company)
        will produce the same coefficient estimates (minus constant) as
        Code:
        ivreghdfe y (i.x1#c.x2 = vhat c.vhat#c.x2) x2 $controls i.year, absorb(company) cluster(company)
        margins then work as usual (although constant still needs to be included when calculating the linear prediction)

        Comment


        • #5
          If your endogenous variable is time-invariant, you cannot include it in a fixed effects model. So I would not know what to make of your analysis on face value.

          Comment


          • #6
            Hi Andrew,
            The main interest is in the interaction between x1 and x2. So even though the endogenous binary variable x1 is ommitted, its interaction with x2 in a fixed effect model is still meaningful.
            I do compare the results with random effects model so the main effect of x1 can be observed.

            Comment

            Working...
            X