log using uncv.log, text /* construction of artificial dataset */ sysuse auto, clear keep mpg weight gen id = _n rename mpg x1 rename weight x2 replace x2 = x2/100 label var x1 label var x2 * the equation for group 1 will be y = x1 - x2, se(u) = 15 tempfile base one qui save `base' set seed 1245 gen y = x1 - x2 - 15*invnormal(uniform()) gen group = 1 qui save `one' * the equation for group 2 will be y = x1 + x2, se(u) = 7 use `base', clear gen y = x1 + x2 + 7*invnormal(uniform()) gen group = 2 append using `one' sort group id drop id * next, the groups will made slightly unbalanced drop in -3/l * BEGINNING OF DEMONSTRATION regress y x1 x2 if group==1 /* [1] */ regress y x1 x2 if group==2 /* [2] */ gen g2 = (group==2) gen g2x1 = g2*x1 gen g2x2 = g2*x2 regress y x1 x2 g2 g2x1 g2x2 /* [3] */ predict r, resid sum r if group==1 gen w = r(Var)*(r(N)-1)/(r(N)-3) if group==1 sum r if group==2 replace w = r(Var)*(r(N)-1)/(r(N)-3) if group==2 reg y x1 x2 g2 g2x1 g2x2 [aw=1/w] /* [4] */ test g2x1 g2x2 g2 quietly regress y x1 x2 g2 g2x1 g2x2 /* [3] */ test g2x1 g2x2 g2 xtgls y x1 x2 g2 g2x1 g2x2, panel(het) i(group) /* [5] */ log close exit