/* Regress 3 - Categorical Variables */ clear all set seed 210314 set obs 60 scalar b0 = 1 // group 1 mean scalar b1 = 0.5 // group 2 mean - group 1 mean scalar b2 = 0.6 // group 3 mean - group 1 mean scalar sigma = 0.75 // residual standard deviation generate x = runiformint(1,3) sort x // for graphing * In order to generate data, we need indicators generate x1 = (x==1) generate x2 = (x==2) generate x3 = (x==3) generate mu_y = b0 + b1*x2 + b2*x3 generate eps = rnormal(0, sigma) generate y = mu_y + eps graph twoway (scatter y x) (scatter mu_y x, mcolor(red)) /// (pcarrowi 1 1.5 `=b0+b1' 1.5) (pcarrowi 1 2.5 `=b0+b2' 2.5), /// title(Data Generating Process) /// yline(1 `=b0+b1' `=b0+b2') /// legend(label(2 "true E(y)") label(3 "b1") label(4 "b2")) /// name(datagenbinary) regress y i.x regress y ib2.x anova y x // useful syntax when you have more variables regress * regress y i.x // back to the original parameterization test 2.x = 3.x contrast x, asobs pwcompare x, asobs mcompare(tukey) group