Statalist The Stata Listserver


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

st: Strange problem with stcox inside a loop


From   "K Jensen" <[email protected]>
To   [email protected]
Subject   st: Strange problem with stcox inside a loop
Date   Sat, 16 Jun 2007 11:45:35 +0100

Hi everyone
I am trying to use some foreach loops to run various stcox models and
to use testparm on them.  I have a problem on the second run on each
loop.  What I'm doing is more complex, but the following code on the
system "cancer" dataset causes the same problem:

sysuse cancer
stset studytime, fail(died)
xi i.drug
local model1 ""_Idrug*""
local model2 ""_Idrug* age""
local models "`model1'" "`model2'"
local options ", nolog"
foreach m in `models' {
 stcox `m' `options'
 foreach var in `m' {
     testparm `var'
 }
}
This works fine for model1, which produces results as expected, but on
model2 it generates the error message:
"option nolog not allowed"

I don't think it's a function of the way I have written the loop, as
an analogous loop with the regress command works perfectly well:
sysuse auto
xi i.rep78
local model1 ""_Irep78*""
local model2 ""_Irep78* weight""
local models "`model1'" "`model2'"
local options ", noheader"
foreach m in `models' {
 regress price `m' `options'
 foreach var in `m' {
     testparm `var'
 }
}

Can anybody explain why this is happening?

Thankyou
Karin
*
*   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