I am trying to find the correct way to graph an interaction effect between two continuous variables in Stata. My regression, the code is

nestreg: regress y (c1 c2) (x1 x2) (x1_x_x2)

with y the outcome variable, c1 and 2 controls, x1 and 2 the independent variables, and x1_x_x2 a multiplicative variable obtained by 'generate x1_x_x2 = x1*x2'. All coefficients are statistically significant, as are the two R2-change values.

Next, I created a new variable called x2_groups, sorted the data by x2 values, and then divided the variable into low (1), medium (2), and high (3) groups.

To graph the interaction, I used the following code:

twoway (lft y x1 if x2_groups==1) (lft y x1 if x2_groups==2) (lft y x1 if x2_groups==3), ytitle(y) xtitle(x1) legend(label(x2 low) label(x2 medium) label(x2 high))

Which produces the attached graph.

However, I was cautioned that this was not the correct way to do this, and I have been searching for the proper graphing method. Should I use the predicted value of y from the model, i.e., by placing

predict pr_y

after the model and substituting this new pr_y value for y in the graph?

I appreciate any help that can be offered about this. Please ask any questions and I can clarify if I have not been clear.

Thank you.