Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Strange behavior from conditional logistic - bug?


From   [email protected] (Jeff Pitblado, StataCorp LP)
To   [email protected]
Subject   Re: st: Strange behavior from conditional logistic - bug?
Date   Fri, 26 Oct 2007 17:41:45 -0500

Ricardo Ovaldia <[email protected]> posted a follow-up question and mentioned
that he is using -capture- to prevent his do-file from exiting when -clogit-
exits with an error:

> Thank you Jeff. I assumed that was the case. However,
> should the -e()- results be clear if the regression
> fails?

If the regression failed, then there is something wrong with the model fit.
As a general rule, -e()- is only guaranteed to contain meaningful information
when the model fit completes without error.

The only exception to this is when -ml- fails to converge.  Even if -ml-
failed to converge, it will still post results to -e()- and report the table
of estimation results.  In this case -ml- will also set -e(rc)- to 430.

While -clogit- uses -ml- to perform the model fit, the original error message
that Ricardo posted was the result of a numerical instability resulting in an
error.

> The reason I am concerned is that I wrote a program to
> do a series of -clogit- and produce a table of odds
> ratios and CI. I use -cap clogit- so that when ever
> the model failed it would not stop the run, but would
> output missing values for the OR and CI. However, e(b)
> and e(V) are not missing, and the table looks like all
> models worked.
> 
> I will modify the program to capture the return code,
> but this is something that can easily "bite" even
> experienced users. I see no justification for this
> strange behavior. I assume this also happens with
> other estimators.

Whenever you -capture- the results of a command in Stata, you should also
consult the value of -c(rc)- (the modern synonym for Stata's -_rc- system
variable).

After the -capture-d command, use an -if- statement that branches off to post
results from the successfully fitted model or post a message (or missing
values) for the unsuccessfully fitted model.

Here is a pseudo-example

	tempname b
	local dim = ... // expected dimension of e(b)
	capture clogit ...
	if c(rc) == 0 {
		// code for dealing with the estimation results
		matrix `b' = e(b)
	}
	else {
		// code for handling a failed model fit
		matrix `b' = J(1,`dim',.)
	}

--Jeff
[email protected]
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index