--- K Jensen <[email protected]> wrote:
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"
The problem has to do with the way you use double quotes. It's use
is explained in -help quotes-. An example that works is shown
below:
*------------- begin example ---------------
sysuse cancer, clear
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'
}
}
*-------------- end example ----------------
Hope this helps,
Maarten
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