version 10.0 capture log close set more off clear log using c:\data\stata\ch10-simulation, replace text *-------------------------------------------- * Chapter 10 page 273 introduces the use of * simulated data. The data used in the book * and recorded in the file ch10.dat was * generated by another software package. * Each software has its unique random number * generators, so the numbers generated here * will not match those in the text, but the * process is the same, and the examples * instructive *-------------------------------------------- *-------------------------------------------- * The following command sets the seed number * for the random number generator. By inluding * a seed, the stream of random numbers generated * and the results will be the same each time * this do-file is executed. If you omit the set seed * command then the results will change each time the * do file is run, as the seed is generated automatically * by Stata *-------------------------------------------- set seed 1234567 * create correlation matrix of (x2 e z1 z2 and z3) matrix C = (1,.6,.5,.3,.5 \.6,1,0,0,.3\.5,0,1,0,0\.3,0,0,1,0\.5,.3,0,0,1) matrix list C *-------------------------------------------- * First for sample size 1000 *-------------------------------------------- * draw sample of size 1000 drawnorm x2 e z1 z2 z3, n(1000) corr(C) * check correlations correlate x2 e z1 z2 z3 * generate regression data gen ey = 1 + 1*x2 gen y = ey + e * OLS regression reg y x2 * 2sls -- compare to p. 280 ivregress 2sls y (x2=z1) ivregress 2sls y (x2=z2) ivregress 2sls y (x2=z3) * 2sls -- compare to equation (10.27) ivregress 2sls y (x2 = z1 z2) estat firststage estat overid * 2sls -- Test surplus moment ivregress 2sls y (x2 = z1 z2 z3) estat firststage estat overid *-------------------------------------------- * repeat for sample size 100 *-------------------------------------------- clear * create correlation matrix of x2 e z1 z2 and z3 matrix C = (1,.6,.5,.3,.5 \.6,1,0,0,.3\.5,0,1,0,0\.3,0,0,1,0\.5,.3,0,0,1) matrix list C * draw sample of size 100 drawnorm x2 e z1 z2 z3, n(100) corr(C) * check correlations correlate x2 e z1 z2 z3 * generate regression data gen ey = 1 + 1*x2 gen y = ey + e * OLS regression reg y x2 * 2sls -- compare to p. 280 ivregress 2sls y (x2=z1) ivregress 2sls y (x2=z2) ivregress 2sls y (x2=z3) * 2sls -- compare to equation (10.27) ivregress 2sls y (x2 = z1 z2) estat firststage estat overid * 2sls -- Test surplus moment ivregress 2sls y (x2 = z1 z2 z3) estat firststage estat overid log close