Dear all,

I am working with a panel dataset and am trying to run a non-linear (quadratic) regression using the first difference operator (D.). Specifically, my regressors should be the first difference of the linear and quadratic independent variable. My issue is independent of the specific data used, therefore I just name Y my dependent and X my independent variables. The code would be:

gen X_sqr = X^2

reg d.Y d.X d.X_sqr

However, I need to use the command margins and marginsplot to plot how the marginal effect of X on Y varies at different levels of X. Therefore, I though about the following code:

reg d.Y d.(c.X##c.X)

Unfortunately, the output is not the first difference of the square but it is the square of the first difference. The same as if I typed the following:

reg d.Y d.c.X##d.c.X

I have tried to find a solution but the only relevant page I have found is the following:

https://www.statalist.org/forums/for...ferent-results

Where Clyde Schechter pointed out that this relationship is "not expressible with factor-variable notation". However, since this post is from 2014, I am asking again in case something has changed in the last 8 years. I know the marginal effect can be computed manually, but it is worth checking whether margins could be applicable in this context.

I have read the FAQ and tried to be as precise as possible. Apologies for any mistakes.

Thank you in advance to whoever will read this post.