Hi,
I'm using Stata 14.1, and in particular the "optimise" mata routine.
I'm writing some stata and mata code to perform permutation-based inference with inverse probability weights to correct for attrition. I'm generating these weights by performing simple maximum likelihood estimation of a logit model on R samples with randomly permuted treatment assignment vectors. This code is embedded in a mata function which is then called by an external stata routine.
My code is currently similar to the following:
My problem is that, in my empirical application, the optimiser fails in certain instances, for two main errors:
"convergence not achieved"
"Hessian is not negative semidefinite"
This is expected given the small sample size (around 250 observations, with lower numbers due to attrition).
I'm fine with the optimisation failing for some permutations, but I have two questions:
1) How can I manage these errors and avoid the whole stata routine that wraps my function to stop?
2) How can I keep track of how many of the permutations failed to optimise?
Thanks so much for your help!
Giacomo
I'm using Stata 14.1, and in particular the "optimise" mata routine.
I'm writing some stata and mata code to perform permutation-based inference with inverse probability weights to correct for attrition. I'm generating these weights by performing simple maximum likelihood estimation of a logit model on R samples with randomly permuted treatment assignment vectors. This code is embedded in a mata function which is then called by an external stata routine.
My code is currently similar to the following:
Code:
for (r=1; r<=R; r++) { /* permutation loop */ /* computing OLS starting values (X are covariates, A is outcome) */ data = A,X XpXi = quadcross(X, X) XpXi = invsym(XpXi) binit = XpXi*quadcross(X, A) /* Optimisation ------------------------------- */ S=optimize_init() optimize_init_evaluator(S,&logitf()) optimize_init_evaluatortype(S,"v0") optimize_init_argument(S,1,data) optimize_init_params(S,binit') optimize(S) /* get coefficients */ beta=optimize_result_params(S)' /* compute linear index */ linind = X * beta /* ... more stuff with the estimated coefficients */ } /* permutation loop */
"convergence not achieved"
"Hessian is not negative semidefinite"
This is expected given the small sample size (around 250 observations, with lower numbers due to attrition).
I'm fine with the optimisation failing for some permutations, but I have two questions:
1) How can I manage these errors and avoid the whole stata routine that wraps my function to stop?
2) How can I keep track of how many of the permutations failed to optimise?
Thanks so much for your help!
Giacomo
Comment