I'm doing the following maximum likelihood estimation using mle2 function from bbmle package:
library(bbmle)
llik.probit2<- function(aL,beta, Ks, Kw, Bs, Bw, dta){
Y <- as.matrix(dta$qualified)
sce1 <- as.matrix(dta$eds)
wce1 <- as.matrix(dta$edw)
sce1_obs <- (as.matrix(dta$eds_obs))
wce1_obs <- (as.matrix(dta$edw_obs))
obs <- as.matrix(dta$CombinedObservable1)
c <- as.matrix(dta$const)
phi <- pnorm(ifelse(Y == 0, -1, 1) * (-aL*c + beta*obs + (Bs+Bs*Ks-aL)*sce1 -beta*Ks*sce1_obs + (Bw+Bw*Kw-aL)*wce1 - beta*Kw*wce1_obs), log.p = TRUE)
-sum(phi)
}
starting.pointmle2 <- list(aL=1.4, beta=0.3, Ks=0.5, Kw=0.5, Bs=0.5, Bw=0.5)
result1 <- mle2(llik.probit2, start = starting.pointmle2, data=list(dta=Mydata), skip.hessian=FALSE)
I need to estimate clustered standard errors of this model, clustering on variable c_id. I'm trying to implement the sandwich estimator but cannot retrieve 'meat' part from mle2 output. I have also tried with nlm, and optim (mle2 is basically wrapper for these methods) Any advice how to do it? In general is there any package which provides functions to calculate clustered standard errors for MLE estimation of a general function?
Here is is a small sample of the data file (MyData) in csv format:
const,qualified,eds,edw,eds_obs,edw_obs,CombinedObservable1,c_id
1,0,0,1,0,0,-0.6838316166,1
1,1,0,1,0,0,-0.1433684328,1
1,0,0,1,0,0.0758113685,0.0758113685,1
1,0,1,0,0.2084778637,0,0.2084778637,34
1,0,0,1,0,0,-0.1622519262,34
1,0,0,1,0,0,-0.5061082675,34
1,0,0,1,0,0,-0.6952748613,34
1,0,1,0,0.9883178986,0,0.9883178986,34
1,0,0,1,0,0,-0.5311805315,34
1,0,0,1,0,0,2.7546881325,34
1,1,1,0,-0.2174263974,0,-0.2174263974,34
1,0,0,1,0,0,-0.4397037288,1
1,0,0,1,0,0,-0.3189328097,1
1,0,0,1,0,0,-0.6132276964,12
1,0,0,1,0,0,0.2459941348,12
1,0,0,1,0,0.0589196966,0.0589196966,12