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 14:38:42 +0100 (BST)

what about Nick's -tuples- command? See: -ssc desc tuples-

Hope this helps,
Maarten

--- K Jensen <[email protected]> wrote:

> Thanks for replying, Maarten.
> 
> Unfortunately, the solution you posted runs  _Idrug* and age as
> separate models, which wasn't what I intended, and was why I used the
> double quotes as I did.
> 
> The results on the analogous code for regress on the auto dataset
> that
> I posted before do work, and show what I was trying to do.
> 
> With best wishes and thanks
> Karin
> 
> On 16/06/07, Maarten buis wrote:
> > --- 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
> *
> *   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/
> 


-----------------------------------------
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