简体   繁体   中英

r plm time and individual fixed effects - "twoways" vs. factor(index) time

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 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?

This is a statistical question and not a programming question.

Degrees of freedom vary between the two model estimations and these are part of the calculation of eg the R squared.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM