How to run regressions on multidimensional panel data in R

后端 未结 4 874
暗喜
暗喜 2021-02-04 22:11

I need to run a regression on a panel data . It has 3 dimensions (Year * Company * Country). For example:

============================================
 year | co         


        
4条回答
  •  南方客
    南方客 (楼主)
    2021-02-04 22:16

    This question is much like these:

    • fixed effects in R: plm vs lm + factor()
    • Fixed Effects plm package R - multiple observations per year/id

    You may not want to create a new dummy, then with dplyr package you can use the group_indices function. Although it do not support mutate, the following approach is straightforward:

    fakedata$id <- fakedata %>% group_indices(comp, count)
    

    The id variable will be your first panel dimension. So, you need to set the plm index argument to index = c("id", "year").

    For alternatives you can take a look at this question: R create ID within a group.

提交回复
热议问题