** Program ass3w07q5.do for Stata version 8 ** STATA Program by A. Colin Cameron ********** SETUP clear capture log close log using ass3w07q5.txt, text replace set more off version 9.0 set scheme s1mono /* Graphics scheme */ ********** OVERVIEW OF ASS3W07Q5.DO * This program does Monte Carlo study for OLS estimator with bivariate regression * where y is redrawn each time while x is fixed. * - No data need to be read in * - Sample size N is defined in the global numobs * - Number of simulation replications in defined in the global numsims ********** MONTE CARLO OVERVIEW * The data generating process is * - y = b1 + b2*x2 + u * - where b1 = 10 and b2 = 5 * - where regressor x = 1, 2, 3, ..., N where N is sanmple size * - and where u is N[0, 2^2] * The simulation is done using stata command simulate ********** INITIAL SIMULATION SET UP set seed 10101 /* set seed so get same results in future */ global numobs "5" /* sample size N */ global numsims "1000" /* number of simulations */ ****** PROGRAM TO BE SIMULATED * The program is rclass, so results returned by program are put into r( ) * Here we return b2 and se2 and t2 * The program has no arguments (makes program simpler). * It returns three values: * - the slope coeff * - the slope standard error * - and the slope t-statistic for H0: b2 = 5 (its true value) * labelled b2, se2, t2 program simols, rclass version 9.0 /* No arguments to define in this example */ /* Generate the data used in this example */ drop _all set obs $numobs gen x = _n // x is a time trend gen y = 10 + 5*x + 2*invnorm(uniform()) // error is N[0,2^2] /* Do the analysis for this example */ regress y x return scalar b2 =_b[x] return scalar se2 = _se[x] return scalar t2 = (_b[x]-5)/_se[x] end ****** RUN PROGRAM ONCE TO CHECK simols sum y x sum ****** RUN THE SIMULATION simulate "simols" b2=r(b2) se2=r(se2) t2=r(t2), reps($numsims) ****** SUMMARIZE SIMULATION RESULTS summarize summarize, detail kdensity b2, normal graph export b2density.wmf, replace kdensity se2, normal graph export se2density.wmf, replace kdensity t2, normal graph export t2density.wmf, replace ********** CLOSE OUTPUT log close