' Generates 2 random walks, x and y, without/with drift ' with 2 uncorrelated white noise innovations and ' estimates the relation between the levels: ' level: y = a + b x + eps ' This is repeated !nsim times. (Monte Carlo simulation) ' The distribution of the t-value for variable x and ' the correlation coefficient of x and y are plotted. ' Choose drifts and number of replications ' ALTERNATIVELY: ' Remove the comment sign " ' " and get the corresponding ' distributions for 2 stationary, independent series. ' Compare! !driftx = 0 !drifty = 0 !nsim = 1000 vector(!nsim) vec_corr vector(!nsim) vec_t vector(!nsim) abs_vec_corr vector(!nsim) abs_vec_t series x series y series ux series uy series dy series dx for !i = 1 to !nsim smpl @all x = 0 ux = nrnd y = 0 uy = nrnd smpl 2 @last x = !driftx + x(-1) + ux y = !drifty + y(-1) + uy smpl @all equation level.ls y c x vec_corr(!i) = @cor(x,y) vec_t(!i) = level.@tstats(2) ' smpl @all ' dy = y - y(-1) ' dx = x - x(-1) ' equation diff.ls dy c dx ' vec_corr(!i) = @cor(dx,dy) ' vec_t(!i) = diff.@tstats(2) next vec_corr.distplot vec_t.distplot abs_vec_corr = @abs(vec_corr) abs_vec_t = @abs(vec_t) abs_vec_corr.distplot(cdf) abs_vec_t.distplot(cdf)