Hello,

I'm struggling with an unexpected interference between the two packages dplyr and plm, or to be more concrete with the "lag(x, ...)" function of both packages.

If dplyr is in the namespace the plm function uses no longer the appropriate lag()-function which accounts for the panel structure.

The following code demonstrates the unexpected behaviour:

## starting from a new R-Session (plm and dplyr unloaded) ##

  ## generate dataset
  set.seed(4711)
  df <- data.frame(
          i = rep(1:10, each = 4),
          t = rep(1:4, times = 10),
          y = rnorm(40),
          x = rnorm(40)
  )
  ## manually generated laged variable
  df$lagx <- c(NA, df$x[-40])
  df$lagx[df$t == 1] <- NA


require(plm)
summary(plm(y~lagx, data = df, index = c("i", "t")))
summary(plm(y~lag(x, 1), data = df, index = c("i", "t")))
# > this result is expected

require(dplyr)
summary(plm(y~lagx, data = df, index = c("i", "t")))
summary(plm(y~lag(x, 1), data = df, index = c("i", "t")))
# > this result is unexpected

Is there a way to force R to use the "correct" lag-function? (or at the devel-level to harmonise both functions)

Thank you very much in advance for your answer

Yours
Constantin

--
^
|                X
|               /eiser, Dr. Constantin (weis...@hhu.de)
|              /Chair of Statistics and Econometrics
|             / Heinrich Heine-University of Düsseldorf
| *    /\    /  Universitätsstraße 1, 40225 Düsseldorf, Germany
|  \  /  \  /   Oeconomicum (Building 24.31), Room 01.22
|   \/    \/    Tel: 0049 211 81-15307
+----------------------------------------------------------->

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to