# Set the sample size and save it in n set hc_version 3 nulldata 1000 scalar n = $nobs # set a seed if you want to get same results each time you run this set seed 3213799 # Set the values of the parameters scalar slope = 10 scalar sigma = 1 scalar rho_xz = .9 scalar gam = .4 # generate n observations on x and a correlated variable z series x = 10*uniform() series z = rho_xz*x + normal(0,sigma) # initialize variables u and y series u = normal() series y = normal() # start the loop, indicating the desired number of samples. loop 400 --progressive --quiet # generate variances that depend on z genr sig = exp(gam*z) # generate normal errors series u = sig*normal() # generate sample of y series y = slope*x + u # run the regression with usual error ols y const x # save the estimated coefficients genr b2 = $coeff(x) genr se2 = $stderr(x) # run OLS regression with HC std errors ols y const x --robust genr se2r = $stderr(x) endloop