Solved – r plm time and individual fixed effects – “twoways” vs. factor(index) time

panel dataplmrregression

I have an unbalanced panel with weekly data and want to do a panel regression with both, individual and time fixed effects.

Following the code in https://www.princeton.edu/~otorres/Panel101R.pdf my code looks like this:

tfe <- plm(y ~ x1 + x2 + factor(index), data, model = "within", index = c("id", "index"))

where index is 1 for the first week, 2 for the second and so on and id is the identifier for each individual in the data set.

From my understanding this code should create the same results as:

tfe <- plm(y ~ x1 + x2, data, effect = "twoways", model = "within", index = c("id", "index"))

is that correct? (see https://stackoverflow.com/questions/28359491/r-plm-time-fixed-effect-model for example)

However, while my coefficients are identical, the time fixed effects and especially the R² are not.

Can someone help me in understanding the difference between my two regressions?

Best Answer

From what I understand about the plm package, those two approaches should be identical.

However, the fixed effects produced from this explicit specification are shown to be "reference dependent" [i.e. relative to the default reference in your factor(index)]

    tfe <- plm(y ~ x1 + x2 + factor(index), data, model = "within", index = c("id", "index"))

In contrast, fixef() returns the fixed effects in levels (by default). For you to get the same fixed effect estimates, by specifying the following:

    fixef(object = tfe, effect = "individual", type = "dfirst")

The equivalent for the individual level fixed effects would be:

    fixef(object = tfe, effect = "time", type = "dfirst")

Computing R-Squared
Also, please see this post for computing R^2 and Adjusted R^2 manually for the full model (i.e. including both the fixed and specified effects): http://karthur.org/2016/fixed-effects-panel-models-in-r.html

Related Question