1
votes

I am running a .do-file which includes many models estimated by xtlogit. Even if a model does not converge I would like to document this in the log. As the .do-file takes some hours to run, I normally go away and do something else. Unfortunately, the non-convergence of a model stops the whole .do-file. Therefore, I used capture noisily {} in order to run the whole .do-file. However, this seems to ignore the maximum number of iterations I have specified in each xtlogit command separately depending on the number of variables and the assumed complexity of the model.

I already found a workaround by using set maxiter globally before running the models. But this does not allow for a finer specification of iterations per model (unless I use it a lot).

I could not find any reports about this behaviour of capture. Maybe, there is a better approach to this than my workaround with set maxiter?

Here is an example code which reproduces the error manually by imposing too few iterations:

webuse union, clear
capture noisily {
xtlogit union age grade i.not_smsa south##c.year, fe iter(2)
xtlogit union age grade i.not_smsa south##c.year, iter(3) pa
xtlogit union age grade i.not_smsa south##c.year, fe iter(2)
}

The .do-file stops after the second model with an error message "convergence not achieved" r(430); and does not proceed with the third model as I would suspect because of capture.

3
I can't reproduce this error with this code. iter() works fine here.Roberto Ferrer
I will try to make some reproducible code relying on example datasets.non-numeric_argument
My previous link is broken. Sorry about that. This one works.Roberto Ferrer
@RobertoFerrer: I have added an example. Maybe you can now also reproduce the error?non-numeric_argument

3 Answers

1
votes

My guess is that you are applying capture at the wrong level. You want to capture any error in xtlogit rather than of the whole do-file.

In addition, check out the nostop option of do.

1
votes

This works and respects your individual iters:

webuse union, clear
capture noisily xtlogit union age grade i.not_smsa south##c.year, pa iter(3)
xtlogit union age grade i.not_smsa south##c.year, fe iter(2)
xtlogit union age grade i.not_smsa south##c.year, fe iter(3)

Notice there is a difference in the behavior of xtlogit depending on whether you use the fe or pa option. Failure to converge with the former does not result in the do-file stopping as it does when there is failure to converge with the latter. That is why I only put capture noisily in the first line.

Maybe a more experienced user can comment on this. If not, you can contact Stata-tech support.

Bottom line, as @NickCox already mentioned, you can avoid your specific problem adjusting the location of your capture.

1
votes

I just figured out why this happens because I was running into a similar problem where xtlogit seems to disobey the iterate(#) command. The reason is that it is computing two separate models: the comparison model, and the full model. It applies iterate(#) to the full model and not the comparison model. Because the comparison model gets fitted first, you can see the iterations pass beyond iterate(#). Set maxiter solved it for me thanks to your question!