' ============================================================================================== ' Ergodic Theorem for the Mean ' ' 1.- Generate an ergodic process (AR(1) causal) and a non-ergodic process (Random Walk) yt = my + phi1* yt-1 + eyt and xt = mx + xt-1 + ext ' 2.- Estimate the mean of both processes, for instance by OLS: ' yt = c + et and xt= c + et ' and see where do they converge asymptotically ' 3.- Compute the t-statistics, the DW test and the R2 and save them in the matrices "t", "DW", and "R2", respectively ' 4.- Iterate 1000 times ' 5.- Calculate the rejection frequency of the significance test of mean x=0 and also mean y=0 ' ' Other possible things to do: ' HAC (Newey-West) : equation eq1.ls(cov=hac) yt c or ' equation eq1.ls(cov=hac, bw=neweywest) yt c t ' Regression in forst difference: equation eq1.ls(cov=hac) d(yt) c '============================================================================================== create u 1 1000 rndseed 12345678 ' Generate Data and Statistics scalar rep=1000 vector(rep) meany=0 vector(rep) meanx=0 vector(rep) tmeanx = 0 vector(rep) tmeany = 0 scalar phi1=0.3 scalar my = 0 scalar mx = 0 for !i = 1 to 1000 smpl @first @first series yt = nrnd smpl @first+1 1000 series yt = my + phi1*yt(-1)+ nrnd smpl @first @first series xt = nrnd smpl @first+1 1000 series xt = mx + xt(-1)+ nrnd equation eq1.ls yt c equation eq2.ls xt c smpl @first @last meany(!i)=eq1.@coefs(1) tmeany(!i)=eq1.@tstats(1) meanx(!i)=eq2.@coefs(1) tmeanx(!i)=eq2.@tstats(1) next smpl @first @last ' Rejection frequency Ho: mean (y) = 0 scalar freqmeany=0 for !i = 1 to 1000 if abs(tmeany(!i)) > 1.96 then freqmeany=freqmeany+(1/1000) endif next smpl @first @last ' Rejection frequency Ho: mean (x) = 0 scalar freqmeanx=0 for !i = 1 to 1000 if abs(tmeanx(!i)) > 1.96 then freqmeanx=freqmeanx+(1/1000) endif next