fixed effects in R: plm vs lm + factor()

前端 未结 1 811
臣服心动
臣服心动 2021-01-03 08:51

I\'m trying to run a fixed effects regression model in R. I want to control for heterogeneity in variables C and D (neither are a time variable).

I tried the follow

相关标签:
1条回答
  • 2021-01-03 09:13

    That error is saying you have repeated id-time pairs formed by variables C and D.

    Let's say you have a third variable F which jointly with C keep individuals distinct from other one (or your first dimension, whatever it is). Then with dplyr you can create a unique indice, say id :

    data.frame$id <- data.frame %>% group_indices(C, F) 
    

    The the index argument in plm becomes index = c(id, D).

    The lm + factor() is a solution just in case you have distinct observations. If this is not the case, it will not properly weights the result within each id, that is, the fixed effect is not properly identified.

    0 讨论(0)
提交回复
热议问题