Statalist The Stata Listserver


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

Re: st: Strange problem with stcox inside a loop


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Strange problem with stcox inside a loop
Date   Sat, 16 Jun 2007 12:12:30 +0100 (BST)

--- 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 ---------------- 
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      ___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/ 
*
*   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