If you are downloading this SHAZAM code for use on your own computer, select "File", then "Save As...", and save on your own diskette (a:) or your own hard drive (c:\) using the same filename e143sh21.sha.
IMPORTANT: you must then use an editor (like TED) to delete all of the HTML code from the top and the bottom of the file, leaving only the SHAZAM code. The line which reads "* SHAZAM code (e143sh21.sha) downloaded from UCLA Econ 143 (CAMERON) WebSite" should be the first line of your edited program file. Save the edited program as omitvar.sha
* SHAZAM code downloaded from UCLA Econ 143 (CAMERON) WebSite: * HTML file called e143sh21.htm, and should have * been downloaded as omitvar.sha * PROGRAM TO EXPLORE "OMITTED VARIABLES BIAS" sample 1 100 dim core 2 2 dim b1 98 b2 98 b3 98 dim b1omit 98 b2omit 98 dim t1 98 t2 98 t3 98 dim t1omit 98 t2omit 98 dim corr_x_z 98 * set default values for characteristics of the data * sige=standard deviation of the regression error term, e * mux=central tendency of the x variable * muz=central tendency of the z variable * sigx=scale of the x variable * sigz=scale of the z variable * b1true= "true" intercept in the model * b2true= "true" slope on the x-variable (always in model) * b3true= "true" slope on the z-variable (sometimes erroneously omitted) sige:3 mux:3 muz:5 sigx:3 sigz:2 b1true:1 b2true:2 b3true:3 *===================== start of makedata procedure ===================== proc makedata do #=2,98 sample 1 100 * draw some random normal regression errors with given standard deviation genr error=nor([sige]) * let correlation between x and z vary almost between -1 and +1 gen1 corxz=(#-50)/50 * save each value of the correlation as it is being considered * we will need it for the plots at the end matrix corr_x_z(#)=corxz * this next batch of commands "creates" data for the x and z * explanatory variables such that they have the specified * degree of negative or positive correlation (advanced econometrics) matrix core(1,1)=1 matrix core(1,2)=corxz matrix core(2,1)=corxz matrix core(2,2)=1 print core matrix ccf=chol(core) matrix cf=ccf genr ux=nor(1) genr uz=nor(1) matrix u=ux|uz matrix e=u*cf' matrix mex=e(0,1) matrix mez=e(0,2) genr ex=mex genr ez=mez genr x=0 genr z=0 genr x=[mux]+[sigx]*ex genr z=[muz]+[sigz]*ez * now we "create" some data on the dependent variable y that has a * "known" relationship to the current x and z variables with their * specified level of correlation. genr y=[b1true] + [b2true]*x + [b3true]*z + error * once we have these data on y, x, and z, we can run regressions with * and without the z variable on the right-hand-side. Objective: see * what happens to the intercept and the slope on x when z is omitted, * for different levels of correlation between z and the included * variable x. ols y x z / coef=bhat tratio=trat * remember that SHAZAM lists the intercept coefficient last matrix b1(#)=bhat:3 matrix b2(#)=bhat:1 matrix b3(#)=bhat:2 matrix t1(#)=trat:3 matrix t2(#)=trat:1 matrix t3(#)=trat:2 * remember that SHAZAM lists the intercept coefficient last ols y x / coef=bomit tratio=tomit matrix b1omit(#)=bomit:2 matrix b2omit(#)=bomit:1 matrix t1omit(#)=tomit:2 matrix t2omit(#)=tomit:1 endo procend *======================end of makedata procedure====================== * NOW RUN THE PROCEDURE (using default settings): exec makedata * For a given set of conditions, you have estimated regression parameters * for different degrees of correlation between the included and excluded * variables. For these default conditions, try some plots. b*hat is the * parameter estimate under the correct model and b*omit is the (biased) * parameter when a relevant variable is omitted. * * YOU WILL NEED TO USE THE FOLLOWING SET OF COMMANDS: * sample 2 98 * plot b2 b2omit corr_x_z / gnu * plot b1 b1omit corr_x_z / gnu * * plot t2 t3 t2omit corr_x_z / gnu * After this, you can change the default settings to see how the results * for omitted variables bias differ as conditions vary.
| COURSE OUTLINE | LECTURE OUTLINES | PROBLEM SETS | PROBLEM SOLUTIONS | COMPUTER LABS |
| SHAZAM EXAMPLES | DATA SETS | ONLINE QUIZZES | GRAPHICS | HANDOUTS |