I need to run a regression on a panel data . It has 3 dimensions (Year * Company * Country). For example:
============================================
year | co
This question is much like these:
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.