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.
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.
Comment