Hey, all:
Here's some code we wrote to try to calculate the robust standard errors
for a logit regression of the binary "winner" on the dataset X, consisting
of 18 independent variables and a column of ones. It produces a sensible
19x19 variance-covariance matrix, but the square root of the diagonal
elements of V are much larger than the authors'. Any thoughts on this
code would be much appreciated.
Thanks,
Ryan & Nirmala
reg <- glm(winner ~ racebl + racehi + raceas + inchi + incmed + edhs +
edcol + edba + agec1 + agec4 + sex + margin + regla + regbay + regsc +
libcon+ pdem + poth, data = zol, family = binomial(logit))
X <- zol[,c(3,4,5,24,23,11,12,13,6,9,25,26,14,16,15,1,19,21)]
X <- as.matrix(cbind(c(1),na.omit(X)))
a <- matrix(NA,nrow(X),1)
for(i in 1:nrow(X)){
u.sq <- (reg$residuals[i])^2
x.pr.x <- t(X[i,])%*%X[i,]
a[i] <- u.sq*(x.pr.x)
}
V <- solve(t(X)%*%X)%*%(sum(a)*solve(t(X)%*%X))
--
------------------------------------------
Ryan T. Moore ~ Government & Social Policy
Ph.D. Candidate ~ Harvard University
Show replies by date