Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: stcox error when run inside a loop

From   Shubhabrata Mukherjee <>
To   stata forum <>
Subject   st: stcox error when run inside a loop
Date   Wed, 28 Dec 2011 10:05:21 -0800 (PST)


I am running stcox in a loop and can't seem to suppress the following error:

For some variables (temp1-temp20) in the varlist, Stata is erroring out because the ML estimation didn't converge for one or more variables. I thought 'capture stcox' takes care of this but it seems when it fails to converge it has nothing to post and that's the reason for the error.

. ** Cox regression for each variable
. foreach var of varlist temp1-temp20 {
          capture stcox `var' `gender age
          post `out' ("`var'") (_b[`var']) (_se[`var'])  ("a") (e(converged)) 
no variables defined
post:  above message corresponds to expression 2, variable beta

Is there a way to print missing values or 'NA'/'NaN' when it fails to convergeso that the code doesn't stop midway?

I used a subset and saw that it's failing to converge for some variables and a normal stcox run for thoses variables gives the following error:

flat region resulting in a missing likelihood

Thanks again,


*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index