how can calculate heteroskedastic consistent covariance matrix (hccm) univariate regression (i.e., ols regression 1 regressor , no intercept)?
back story: have fixed effect panel regression, 1 regressor. can either least squares dummy variable (lsdv) approach
lm.ser.yr <- lm(realwage ~ placebo.ser + factor(incyear) + 0, data = cps)
or can demean lhs @ year level , regress
cps <- ddply(cps, .(incyear), transform, realwage.dm.yr = realwage - mean(realwage)) lm.ser.yr <- lm(realwage.dm.yr ~ placebo.ser + 0, data = cps)
but there problems both.
with lsdv approach , enough dummies
lm
object gets huge (1 gb each). because of largeqr
matrix have keep passvcovhc()
calculate hccm, stops on "can't allocate vector of size" errors (or lot of paging).with demeaned within estimator works great, can't calculate hccm because neither
vcovhc()
orhccm()
have handle no intercept univariatelm
object (i.e., spitsna
, best can tell because without intercept , dummy variables, residuals farther 0 mean).
is there solution short of aggressively managing memory and/or moving cloud?
vcovhc()
plm
package seems handle lm()
models without intercepts fine:
library(plm) df <- data.frame('a'=rnorm(1000), 'b'=rnorm(1000)) mod <- lm(a ~ b -1, df) vcovhc(mod)
edit: here's code calculate them manually.
library(matrix) e2 = mod$residuals ^ 2 x = model.matrix(mod) n = nrow(x) bread = solve(crossprod(x)) <- matrix(data=0, ncol=n, nrow=n, sparse=true) diag(i) <- e2 salami <- t(x) %*% %*% x v = bread %*% salami %*% bread
Comments
Post a Comment