Fixed Effects plm package R - multiple observations per year/id

前端 未结 1 1138
误落风尘
误落风尘 2020-12-21 05:30

I\'m working on a state and year fixed effects regression, which has 3 observations per state/year combo based on the race for that row (white, black, other) - See link belo

相关标签:
1条回答
  • 2020-12-21 06:03

    The plm function needs just one pair of id/time. For each id you supplied you have more than one year.

    If each st_name and race pairs form an "individual" (or whatever the name you give to this dimension of the panel), then you could do:

    library(dplyr)
    
    my.data$id <- group_indices(my.data, st_name, race)    
    #which would be the same as my.data <- my.data %>% mutate(id = group_indices(st_name, race)), if this function supported mutate. 
    
    plm.reg <- plm(drugcrime_ar ~ decrim_dummy + median_income + factor(race),
               data = my.data, index=c("id","year"), model = "within",
               effect = "twoways")
    

    See, however, that in this situation you are not using a kind of nested panel structure as @Helix123 suggested. You are only redefining the first dimension of the panel.

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