version 10.0 clear capture log close log using c:\data\stata\Figure12-2, replace *--------------------------------------------------------* * I don't quite understand how or when Stata will pause * Typing "set more on, permanently" into the command line * and then running this do file seems to work today *--------------------------------------------------------* * * set sample size and create time variable * set obs 1000 gen timevar = _n *-------------------------------------------------------* * draw random errors *-------------------------------------------------------* *-------------------------------------------------------* * 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 12345 drawnorm e1 e2 e3 e4 e5 e6, n(1000) means(0 0 0 0 0 0) sds(1 1 1 1 1 1) * Stationary AR(1) gen y1 = 0 replace y1 = .7*y1[_n-1]+e1 if _n > 1 * Stationary AR(1) with mean parameter gen y2=0 replace y2 = 1 + .7*y2[_n-1]+e2 if _n > 1 * AR(1) with trend gen y3 = 0 replace y3 = 1 + .01*timevar + .7*y3[_n-1]+e3 if _n > 1 * Random Walk gen y4 = 0 replace y4 = y4[_n-1] + e4 if _n > 1 * Random walk with drift gen y5 = 0 replace y5 = .1 + y5[_n-1] + e5 if _n > 1 * Random walk with trend gen y6 = 0 replace y6 = .1 + .01*timevar + y6[_n-1] + e6 if _n > 1 * Discard first 500 observations as "burn in" period drop if timevar < 501 replace timevar = timevar-500 *------------------------------------------------------* * Comment: these figures will not match text because * different random numbers are used *------------------------------------------------------* twoway (line y1 timevar), ytitle(y1) xtitle(time) title(POE Fig 12.2(a): Stationary AR(1) Process) subtitle(y1(t) = .7*y1(t-1) + n(0,1)) more twoway (line y2 timevar), ytitle(y2) xtitle(time) title(POE Fig 12.2(b): Stationary AR(1) Process) subtitle(y2(t) = 1 + .7*y2(t-1) + n(0,1)) more twoway (line y3 timevar), ytitle(y3) xtitle(time) title(POE Fig 12.2(c): Trending AR(1) Process) subtitle(y3(t) = 1 + .01*t + .7*y2(t-1) + n(0,1)) more twoway (line y4 timevar), ytitle(y4) xtitle(time) title(POE Fig 12.2(d): Random Walk Process) subtitle(y4(t) = y4(t-1) + n(0,1)) more twoway (line y5 timevar), ytitle(y5) xtitle(time) title(POE Fig 12.2(e): Random Walk Process with drift) subtitle(y5(t) = .1 + y5(t-1) + n(0,1)) more twoway (line y6 timevar), ytitle(y6) xtitle(time) title(POE Fig 12.2(f): Random Walk Process with trend) subtitle(y6(t) = .1 + .01*t + y6(t-1) + n(0,1)) log close