Advertisement
Guest User

Untitled

a guest
Feb 24th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. mymodel <- (lm(Y ~ X1 + X2 + I(X1*X2), data = mydata));
  2.  
  3. clusteredSE <- function(fm, dfcw, cluster)
  4. {
  5. library(sandwich)
  6. library(lmtest)
  7. library(zoo)
  8. M <- length(unique(cluster))
  9. N <- length(cluster)
  10. dfc <- (M / (M - 1)) * ((N - 1) / (N - fm$rank))
  11. u <- apply(estfun(fm), 2, function(x) tapply(x, cluster, sum))
  12. vcovCL <- dfc * sandwich(fm, meat = crossprod(u) / N) * dfcw
  13. coeftest(fm, vcovCL)
  14. }
  15.  
  16. clusteredSE(mymodel, 1, mydata$countries)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement