When I do the two ways model in the plm
package, my understanding is that it should have fixed effects for group and time, but when I manually look at the fixed effects it only produces fixed effects for the group variable. For example, using the canned data in the plm package:
> data("Produc", package = "plm")
> zz <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp,
data = Produc, index = c("state","year"),model='pooling')
> qq <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp,
data = Produc, index = c("state","year"),model='within',effects='twoways')
> length(fixef(zz))
Error in fixef.plm(zz) : fixef is relevant only for within models
> length(fixef(qq))
[1] 48
> length(unique(Produc$state))+length(unique(Produc$year))
[1] 65
My expectation is that the last two lines should be equal, i.e. that there should be year and state fixed effects. Why are they different?
This is explained in the help for fixef
, use ?fixef
to view it:
For a two-ways model, fixef
's default behaviour is to output the group ("individual") fixed effects. If you want the time fixed effects, use fixef(your_model, effect = "time")
.
Picking up your example, take heed you do not estimate a two-way fixed effects model as the argument is called effect
rather than effects
(with a s). So use:
qq <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp,
data = Produc, index = c("state","year"), model ="within", effect = "twoways")
length(fixef(qq)) # 48
length(fixef(qq, effect = "time")) # 17
You can check with summary(qq)
which model you estimated as the first line of its output will tell you the model: "Twoways effects Random Effect Model" in this case.