0
$\begingroup$

I'm running the pgrangertest package from plm, and getting the following error:

Error in waldtest.lm(fm, 2, ...) : 
  there are aliased coefficients in the model

What's odd is that my formula is just y ~ x - i.e. just one variables, so it doesn't seem possible for anything to be linearly dependent on anything else. Why might I be getting this error and how can I fix it?

I tried adding a new variable rising which is unique for every individual and time (equal to unit_index * n_periods + period), and setting the formula y ~ rising. I also tried setting rising as the outcome variable. I'm still getting the same error so it seems it has little to do with the variables themselves and more with the shape of the data...

EDIT: Here is reproducible code:

library(haven)
library(data.table)
library(dplyr)
library(zoo)
library(plm)

df <- data.frame(id=c(1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2),
                  timeid=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9),
                  x=c(0.003, 0.04, 0.00683, 0.0, 0.0, 0.0, 0.0, 0.00012, 0.31, 0.003, 0.04, 0.00683, 0.0, 0.0,  0.0, 0.0, 0.0, 0.1), 
                  y=c(0.03, 1.04, 0.05683, 0.1, 0.5, 0.0, 0.0, 0.12, 0.041, 0.003, 0.04, 0.00683, 0.0, 0.0,  0.0, 0.0, 0.0, 0.0))
panel_df <- pdata.frame(as.data.frame(df), index=c("id", "timeid"))

pgrangertest(y ~ x, data = panel_df, order=1, 
             test="Ztilde")
$\endgroup$
6
  • $\begingroup$ can you make a reproducible example (or make your data + code available) see stackoverflow.com/questions/5963269/…? $\endgroup$
    – Helix123
    Feb 24, 2021 at 18:36
  • $\begingroup$ Maybe the coefficient becomes non-estimable due to the lagging involved in the test procedure? $\endgroup$
    – Helix123
    Feb 24, 2021 at 19:46
  • $\begingroup$ Just added a reproducible example, sorry that it wasn't in the original answer. Can you explain the impact lagging would have? The Granger test already enforces a restriction that the length of the data for each individual is at least 3 times the lag length plus five... but maybe that doesn't help here? $\endgroup$ Feb 25, 2021 at 6:03
  • $\begingroup$ The normal Granger test errors for the 2nd individual lmtest::grangertest(y ~ x, data = df[10:18, ], order=1). Also, your data looks a little suspicious with all the 0-valued rows. $\endgroup$
    – Helix123
    Feb 25, 2021 at 20:17
  • $\begingroup$ What do you mean by 0-valued rows? This isn't my actual data, but it's similar - a lot of x- and y-values are 0 for some individuals at some times, but there are no individuals for which x=0 or y=0 for the entire measurement period. $\endgroup$ Feb 25, 2021 at 20:24

1 Answer 1

1
$\begingroup$

I figured out that if one of x or y don't "move" (i.e. the value is the same through the entire series) it gvies this error. I fixed it by just dropping units that have this property and the model works fine.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.