/* Example 6 - Continuous by Continuous Interactions */ clear all set seed 210317 set obs 60 scalar b0 = 1 // reference mean | x1==0, x2==0 scalar b1 = 0.75 // x1 slope when x2==0 scalar b2 = 0.75 // x2 slope when x1==0 scalar b12 = -0.75 // change in slope (curvature) scalar sigma = 0.75 // residual standard deviation generate x1 = runiform(0,5) generate x2 = runiform(0,5) generate mu_y = b0 + b1*x1 + b2*x2 + b12*x1*x2 generate eps = rnormal(0, sigma) generate y = mu_y + eps * Several equivalent ways of writing the model specification regress y c.x1##c.x2 * regress y x1 x2 c.x1#c.x2 * plot 3 slices from predicted surface margins , at(x1=(0(0.1)5) x2=(0 2.5 5)) marginsplot, title("E(y) ~ x1 | x2") recast(line) recastci(rarea) ciopts(color(*.6)) margins , dydx(x1) at(x2=(0/5)) margins , dydx(x1) at(x2=(0(0.2)2))