set.seed(123456) n<-1000 e1<-rnorm(n);e2<-rnorm(n) x<-cumsum(e1);y<-0.6*x+e2 lr.reg<-lm(y$\sim$x) error<-residuals(lr.reg) error.lagged<-error[-c(n-1,n)] dx<-diff(x);dy<-diff(y) diff.dat<-data.frame(embed(cbind(dx,dy),2)) colnames(diff.dat)<-c("dx","dy","dx.1","dy.1") ecm.reg<-lm(dy~error.lagged+dx.1+dy.1,data=diff.dat) summary(ecm.reg) plot(x,type="l");plot(y,type="l");plot(x,y)