我的问题在于:我收到以下文件:在计算强烈的标准误差时,我应当获得一些价值。
我正试图采用固定效果小组,以群集-暴动标准错误进行回归。 为此,请见rel=“nofollow noreferer”>,Arai(2011年,他在第3页上读到rel=“nofollow noretinger”Stock/ Watson(2006)(在(M/(M-1)*(N-1)/(N-K)
在[https://stackoverflow.com/questions/9260766/robust-standard-errors-in-ggplot2/9264761#9264761>1 ,2上张贴在StackOver和相关问题[
Arai(和第1链接中的答案)使用以下职能守则(I提供以下数据并附加一些评论): 在<代码>gcenter 中,对应偏离(固定效应)。 接着,我继续并正以<代码>回归。 DS_CODE,为我的组别变量(我已点名我的数据)。 并且希望计算 然而,当我想对差异的 <>My data Since my data may be of special structure and I can t figure out the problem, I post the entire thing as a link from Hotmail. The reason is that with other data (taken from Arai (2011)) my problem does not occur. Sorry in advance for the mess but I d be very grateful if you could have a look at it nevertheless.
The file is a 5mb .txt file containing purely data. gcenter <- function(df1,group) {
variables <- paste(
rep("C", ncol(df1)), colnames(df1), sep=".")
copydf <- df1
for (i in 1:ncol(df1)) {
copydf[,i] <- df1[,i] - ave(df1[,i], group,FUN=mean)}
colnames(copydf) <- variables
return(cbind(df1,copydf))}
# 1-way adjusting for clusters
clx <- function(fm, dfcw, cluster){
# R-codes (www.r-project.org) for computing
# clustered-standard errors. Mahmood Arai, Jan 26, 2008.
# The arguments of the function are:
# fitted model, cluster1 and cluster2
# You need to install libraries `sandwich and `lmtest
# reweighting the var-cov matrix for the within model
library(sandwich);library(lmtest)
M <- length(unique(cluster))
N <- length(cluster)
K <- fm$rank
dfc <- (M/(M-1))*((N-1)/(N-K))
uj <- apply(estfun(fm),2, function(x) tapply(x, cluster, sum));
vcovCL <- dfc*sandwich(fm, meat=crossprod(uj)/N)*dfcw
coeftest(fm, vcovCL) }
centerdata <- gcenter(data, data$DS_CODE)
datalm <- lm(C.L1.retE1M ~ C.MCAP_SEC + C.Impact_change + C.Mom + C.BM + C.PD + C.CashGen + C.NITA + C.PE + C.PEdummy + factor(DS_CODE), data=centerdata)
M <- length(unique(data$DS_CODE))
dfcw <- datalm$df / (datalm$df - (M-1))
clx(datalm, dfcw, data$DS_CODE)