0

I am trying to use the effects package to extract predicted values for a PLM Model. Unfortunately, as soon as I include a factor variable, the effects package breaks down with the error message

Error in Summary.factor(c(2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 
‘range’ not meaningful for factors

Has anyone found a way to work around this problem?

Here is a minimum working example that replicates the issue

data("Produc", package = "plm")

Produc$dummy1<-(rbinom(nrow(Produc), 1 , 0.4)) #Generate Random Dummy
Produc$dummy2<-as.factor(Produc$dummy1)


mod1 <- plm(gsp ~ pcap * dummy1,data = Produc, index = c("state","year"), model="fd")
mod2 <- plm(gsp ~ pcap * dummy2,data = Produc, index = c("state","year"), model="fd")

Effect(c("pcap","dummy1"),mod1) #This works 
Effect(c("pcap","dummy2"),mod2) #This does not

This might be related to this question, but the error is different.

Community
  • 1
  • 1
CGN
  • 687
  • 1
  • 6
  • 12
  • Maybe, the `effects` package cannot cope with `plm`-objects? As a workaround, you can always "simulate" the panel models with `lm()`. Either transform the data yourself or use `pmodel.response()` and `plm:::model.matrix()` (the latter does not seem to be exported, thus `plm:::`) to get the transformed data on which you can run `lm()`. – Helix123 Oct 26 '15 at 17:35
  • On the other hand: The warning makes sense: if `dummy2` is a factor, it can only be specific values, in this case 0 and 1. Thus, it does not make sense to calculate effects for other value than 0 and 1.Try `allEffects(mod2)` is that what you want? – Helix123 Oct 26 '15 at 17:55

0 Answers0