# Set the sample size and save it in n nulldata 100 scalar n = $nobs # generate n observations on x series z = 5*uniform() # 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 = 1 # regression slope scalar sigma = 10 # measurement error in y scalar sigx = .1 # amount of measurement error in x scalar gam = 1 # instrument strength scalar rho = .0 # correlation between error scalar n = $nobs # start the loop, indicating the desired number of samples. loop 400 --progressive --quiet series u = normal(0,sigma) # generate sample of x and y series x=gam*z+rho*u+normal(0,sigx) series y = slope*x + u # run the ols regression ols y const x # save the estimated coefficients genr b2 = $coeff(x) genr s2 = $stderr(x) # run the tsls regression tsls y const x; const z genr biv2 = $coeff(x) genr siv2 = $stderr(x) # store the results in a dataset for future analysis is desired store arcoeff.gdt b2 biv2 s2 siv2 print b2 biv2 s2 siv2 endloop