clear capture log close log using hetero.txt, text replace di "heteroskedasticity.txt: Stata simulation example for heteroskedasticity" version 7 * Example of heteroskedastic error * Y = a + bX + u, where a = 10, b = 2, u ~ N(0,X^2), X ~ N(3,1) * The number of samples is determined by "set obs n" command below drop _all set seed 11111 set obs 200 gen x = 3 + invnorm(uniform()) gen u = x*invnorm(uniform()) gen y = 10 + 2*x + u regress y x regress y x, robust predict yhat, xb predict e, residuals twoway (scatter y x, ms(0)) (line yhat x, sort) (scatter e x) cap log close