I have a dataset where I want to group countries on a broader level then per country. Still, the country is the id variable in my dataset. Example:
library(plm)
Data <- data.frame(iris)
Data$time <- c(rep(1951:2000,3))
Data$mygroup <- c(rep("a",100),rep("b",50))
test <- plm(Sepal.Length ~ Sepal.Width + Petal.Length,data=Data, model="within", index=c("time","Species"))
summary(test)
Can I tell plm
somehow, that I want the within transformation to happen over mygroup
rather than species
? If I use mygroup as the index, I run into trouble with duplicate years per id which I'm guessing bothers plm
when trying to calculate individual specific constants etc.
test2 <- plm(Sepal.Length ~ Sepal.Width + Petal.Length,data=Data, model="within", index=c("time","mygroup"))
I could simply build dummies based on mygroup
and include them but the within transformation should be more efficient and also seems more elegant. I don't see an option for this in the plm
help file though. Any help would be appreciated!