I am trying to replicate a logit regression from Stata to R. In Stata I use the option "robust" to have the robust standard error (heteroscedasticity-consistent standard error). I am able to replicate the exactly same coefficients from Stata, but I am not able to have the same robust standard error with the package "sandwich".
I have tried some OLS linear regression examples; it seems like the sandwich estimators of R and Stata give me the same robust standard error for OLS. Does anybody know how Stata calculate the sandwich estimator for non-linear regression, in my case the logit regression?
Thank you!
Codes Attached: in R:
library(sandwich)
library(lmtest)
mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")
mydata$rank<-factor(mydata$rank)
myfit<-glm(admit~gre+gpa+rank,data=mydata,family=binomial(link="logit"))
summary(myfit)
coeftest(myfit, vcov = sandwich)
coeftest(myfit, vcov = vcovHC(myfit, "HC0"))
coeftest(myfit, vcov = vcovHC(myfit))
coeftest(myfit, vcov = vcovHC(myfit, "HC3"))
coeftest(myfit, vcov = vcovHC(myfit, "HC1"))
coeftest(myfit, vcov = vcovHC(myfit, "HC2"))
coeftest(myfit, vcov = vcovHC(myfit, "HC"))
coeftest(myfit, vcov = vcovHC(myfit, "const"))
coeftest(myfit, vcov = vcovHC(myfit, "HC4"))
coeftest(myfit, vcov = vcovHC(myfit, "HC4m"))
coeftest(myfit, vcov = vcovHC(myfit, "HC5"))
Stata:
use http://www.ats.ucla.edu/stat/stata/dae/binary.dta, clear
logit admit gre gpa i.rank, robust