program drop _all use "I:\Web\LearnEconometrics\class\stata\consumpt.dta", clear gen New_t = yq(year,quarter) tsset New_t, quarterly drop if year < 1953 /* Exercise 1.23 */ regress ce yd predict ehat, residual scatter ehat New_t, xtitle(Time) /* Save coefficients and std error of regression for the simulation */ scalar b1 = _b[_cons] scalar b2 = _b[yd] scalar sd = e(rmse) scalar list /* Generate systematic portion */ gen yht = b1 + b2*yd /* Generate normals and ystar */ gen es = sd*invnormal(uniform()) gen ys = yht + es /* Regression for one simulated set and graph 1.24 */ regress ys yd predict ehat1, residual scatter ehat1 New_t, xtitle(Time) /* The program used for the 100 simulations */ program rega gen estar = sd*invnormal(uniform()) gen ystar = yht + estar regress ystar yd drop estar ystar end /* Run the simulations */ /* Plot the results for the slope */ set seed 12121122 simulate , reps(100): rega histogram _b_yd, bin(12) normal