Hi all,
I have a regression model with two variables that have quadratic terms for each and includes an interaction term between them. I am trying to create something similar to the following figure which shows the marginal effect of X1 on Y as X1 changes:

where I can observe the nonlinearity of X1 across its own range and also look at how it changes with different values of X2, the variable it is interacted with (hence the curve shifting for different values of X2). I am hoping to be able to create something like this using Margins plot. I have the following MWE below and have attached the excel file I use as well.
This code generates the following regression output:

And the two margins plot, in order of X1 over X2 and X1 over X1 are
My main questions are:
I have a regression model with two variables that have quadratic terms for each and includes an interaction term between them. I am trying to create something similar to the following figure which shows the marginal effect of X1 on Y as X1 changes:
where I can observe the nonlinearity of X1 across its own range and also look at how it changes with different values of X2, the variable it is interacted with (hence the curve shifting for different values of X2). I am hoping to be able to create something like this using Margins plot. I have the following MWE below and have attached the excel file I use as well.
Code:
// Data! import excel "~\SE Question ME.xlsx", sheet("SE Question ME") firstrow clear egen countryid=group(Country) foreach v in Y { //log a set of variables gen l`v' = log(`v') } xtset countryid Year // Regression Analysis xtreg lY c.X1##c.X2 c.X1#c.X1 c.X2#c.X2, fe margins, dydx(X1) at(X2=(350(25)550)) level(90) marginsplot, yline(0) margins, dydx(X1) at(X1=(0(2)30)) level(90) marginsplot, yline(0)
And the two margins plot, in order of X1 over X2 and X1 over X1 are
My main questions are:
- Why does the second -marginsplot- not show any non-linearity even though the regression output clearly shows diminishing returns/a negative quadratic term?
- How would I be able to combine these two plots in a way that is similar to the first figure?
Comment