Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: stcox error when run inside a loop


From   brendan.halpin@ul.ie (Brendan Halpin)
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: stcox error when run inside a loop
Date   Tue, 03 Jan 2012 16:28:19 +0000

On Wed, Dec 28 2011, Shubhabrata Mukherjee wrote:

> Hello,
>
> 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)) 
>   }
>

Try something like this: 

foreach var of varlist temp1-temp20 {
capture stcox `var' `gender age
if !_rc {
  post `out' ("`var'") (_b[`var']) (_se[`var']) ("a") (e(converged)) 
}
else {
  post `out' ("`var'") (.) (.) ("a") (e(converged)) 
}

Brendan
-- 
Brendan Halpin,   Department of Sociology,   University of Limerick,   Ireland
Tel: w +353-61-213147  f +353-61-202569  h +353-61-338562;  Room F1-009 x 3147
mailto:brendan.halpin@ul.ie    ULSociology on Facebook: http://on.fb.me/fjIK9t
http://teaching.sociology.ul.ie/bhalpin/wordpress         twitter:@ULSociology

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index