clear all sysuse auto regress price i.rep78 estimates store orig coefplot , drop(_cons) name(orig) // centered, constant display _b[_cons] + 1/5*_b[2.rep78] + 1/5*_b[3.rep78] + 1/5*_b[4.rep78] + 1/5*_b[5.rep78] contrast g.rep78, nowald post coefplot, name(contrast) estimates store contrast estimates table orig contrast // needs Stata 14.1 regress price i.rep78 forvalues i=1/5 { generate rep`i' = (rep78==`i') if rep78~=. } regress price rep2-rep5 // exactly the same as "orig" coefplot , drop(_cons) name(dummy) estimates store dummy devcon, groups(rep1-rep5) matrix B = r(table) coefplot matrix(B[1,]), ci((B[5,] B[6,])) matrix B = B[1..2,1...] forvalues i=2/5 { replace rep`i' = -1 if rep78==1 } regress price rep2-rep5 estimates store deviation estimates table orig dummy contrast deviation, se stats(r2) matrix list B regress price i.foreign contrast g.foreign generate for1 = foreign==1 generate for0 = foreign==0 regress price for1 devcon, groups(for0 for1) generate fordev = for1 replace fordev = -1 if for1==0 regress price fordev // This example is complicated by the lack of foreign cars // with bad repair records, i.e. empty cells // So we restrict the example to rep78>=3, and set // base levels in contrasts accordingly regress price foreign##rep78 if rep78>=3 est store int1 contrast g.foreign g.rep78 g.foreign#g.rep78, post est store contr1 est tab int1 contr1 forvalues i=1/5 { replace rep`i' = (rep78==`i') if rep78~=. gen rep`i'for1 = (rep78==`i')*(foreign==1) if rep78~=. gen rep`i'for0 = (rep78==`i')*(foreign==0) if rep78~=. } regress price for1 rep4 rep5 rep4for1 rep5for1 if rep78>=3 est table int1 . devcon, groups(for0 for1, rep3 rep4 rep5, /// rep3for0 rep4for0 rep5for0 rep3for1 rep4for1 rep5for1) // gives results, but not correct // hand-coding the contrast: forvalues i=4/5 { replace rep`i' = -1 if rep78==3 } replace for1 = -1 if foreign==0 forvalues i=2/5 { replace rep`i'for1 = rep`i'*for1 } regress price for1 rep4 rep5 rep4for1 rep5for1 if rep78>=3 est tab contr1 .