如何用R计算面板靴子标准错误?

时间:2015-06-11 12:44:51

标签: r

我最近从STATA改为R,并且不知何故努力寻找相应的命令。我想使用plm库从固定效果模型中获取面板靴片标准错误,如here所述,对于STATA用户:

  1. 我的问题一般涉及方法(引导是适当的库还是库(meboot) )

  2. 如何使用boot解决该特定错误:

  3. 首先获得一些面板数据:

    library(plm)
    data(EmplUK) # from plm library
    
    test<-function(data, i) coef(plm(wage~emp+sector,data = data[i,],
                                          index=c("firm","year"),model="within"))
    

    第二

    library(boot)
    boot<-boot(EmplUK, test, R = 100)
    
    > boot<-boot(EmplUK, test, R = 100)
      duplicate couples (time-id)
      Error in pdim.default(index[[1]], index[[2]]) : 
      Called from: top level 
      Browse[1]> 
    

1 个答案:

答案 0 :(得分:2)

出于某种原因,boot会将索引(此处为原始)传递给plm,并带有重复值。您应该删除所有重复的值并断言索引唯一,然后再将其传递给plm

test <- function(data,original) {
   coef(plm(wage~emp+sector,data = data[unique(original),],
       index=c("firm","year"),model="within"))
}


boot(EmplUK, test, R = 100)

## ORDINARY NONPARAMETRIC BOOTSTRAP
## Call:
## boot(data = EmplUK, statistic = test, R = 100)
## Bootstrap Statistics :
##       original      bias    std. error
## t1* -0.1198127 -0.01255009  0.05269375