# [R] Time Series DGPs

Pfaff, Bernhard Bernhard.Pfaff at drkw.com
Thu Sep 25 16:10:38 CEST 2003

```>   I was wondering if anyone had some sample time series dgp
> code.  I am
> particularly interested in examples of autoregressive processes and
> error correction model DGPs.  I have attached a more specific example
> of what I mean.  I have tried myself but would hoping someone
> more elegant code that would help me extend my own code.
>
Hello Luke,

your setting does not qualify exactly as an ECM (both series have to be of
the same integration order, i.e. I(1) *and* there exists a linear
combination between them, which is I(0) -- see for instance Engle/Grangers'
seminal paper).

However, you can set up a sample ECM by generating an I(1) series, construct
a linear combination to produce a second one, run a regression and save the
residuals and finally enter these lagged by one period into your ECM.
Incidentally, avoid inclusion of contemporaneous differenced Xs due to
simultaneity-bias. Something, as follows should work:

# function for producing lags
tslag <- function(x, d=1)
{
n <- length(x)
c(rep(NA,d),x)[1:n]
}
# generate a RW
x1 <- rnorm(100)
x <- cumsum(x1)
# generate artifically another I(1)-variable that is linearly dependent
y <- 0.8*x + rnorm(100)
# run ci-regression and save error (lagged one period)
ci.lm <- summary(lm(y~x))
error <- tslag(ci.lm\$residuals)
# estimate ECM
y.diff <- y - tslag(y)
x.diff.l1 <- tslag(x-tslag(x))
ecm.lm <- summary(lm(y.diff~x.diff.l1+error))

HTH,
Bernhard

----------------------------------------------------------------------
If you have received this e-mail in error or wish to read our e-mail
disclaimer statement and monitoring policy, please refer to
http://www.drkw.com/disc/email/ or contact the sender.

```