2
$\begingroup$

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?

$\endgroup$

1 Answer 1

1
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ could you please clarify what "dfirst" imply ? $\endgroup$
    – Bob
    Oct 21, 2022 at 11:17
  • $\begingroup$ please see the documentation for the PLM package - it is very helpful: cran.r-project.org/web/packages/plm/plm.pdf. What "dfirst" does is to represent as the fixed effects in terms of deviations from the first value of the index ("dfirst") as opposed to to in terms of deviations from the overall mean ("dmean") or relative to the default reference in your factor (index) which happens when you select (type = "level"). $\endgroup$ Feb 18, 2023 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.