1

I have the folllowing codes:

y<-my.data$GDP
tt<-my.data$period
dataset<-data.frame(y,tt)
gnp.lm <- dynlm(formula = y ~ L(d(y), 1:10) + 1 + L(y) + tt, data = dataset)

Both my.data$period and my.data$GDP are one-dimensional arrays with the same lengths.

However, I got the following error message:

error in fix.by(by.x x) 'by' must match numbers of columns.

Could someone help me with this problem?

Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
  • 1
    hard to do anything without a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Just cosmetic, but you should be able to use `dynlm(GDP ~ L(d(GDP), 1:10) + 1 + L(GDP) + period, data = my.data)` (i.e. no need to create a new data frame) – Ben Bolker Dec 29 '13 at 16:50
  • Two comments from trying to reproduce: (1) I think if you want 10 separate lags you need to specify them separately (i.e. `L(.,1)`+L(.,2)+L(.,3)+...`) -- even though the documentation claims you can use a vector-valued lag; (2) I'm not sure you can use `L(d(y))`; I get an error when I try it. – Ben Bolker Dec 29 '13 at 16:56

1 Answers1

0

Without giving a reproducible example, the following reason could be the answer:

obs <- 1000
y <- rnorm(1000)
tt <- 1:obs

dataset <- data.frame(y, tt)
dyn_lm <- dynlm(y~L(y,1:5)+ tt)

Here, the error occurs due to the problem of the unknown class of y. But if you specifiy the class of y and tt to be of ts, it perfectly works.

y.ts <- ts(y)
tt.ts<-ts(tt)

dyn_lm_ts <- dynlm(y.ts~L(y.ts,1:5)+ tt.ts)
Stefan
  • 1
  • 1