Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: while loop problem


From   Alfonso Miranda <ecrgw@csv.warwick.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: while loop problem
Date   Fri, 11 Oct 2002 10:36:03 +0100 (BST)

you should not use $ when you mean to create a local macro, or use local
when you mean to create a global macro.

Alfonso.






On Fri, 11 Oct 2002 Chris.Fergusson@sth.nhs.uk wrote:

> Hello statalisters,
>
> I had a do file set up to calculate the age-specific rates for cancer in
> specified health authorities.  However this program became slow and
> laborious as I could only do this for one health authority at a time.
> Through website renevation, the person that mainly uses this do file is
> running the do file for the same ten health authorities every time.  I would
> like to reduce running time by having an option to state that you would like
> to look at all ten health authorities, but still have the option that you
> may only want to look at a number less than ten.  The syntax below runs
> through the while loop one, giving results for the first health authority
> "barnsley". However, when it comes to the second run, it keeps $ha as
> barnsley, even though my counter q increases in value.  Any suggestions, my
> guess is a simple syntax error.
>
> I have included the syntax below,
>
> Christopher D Fergusson
>
>
>
> display "How many Health Authorities would you like to look at"
> _request(total)
>
> local q=1
>
> while `q'<$total {
>
> 	if $total<10 {
> 	display "Which health authority (lowercase) would you like to look
> at?" _request(ha)
> 	}
>
> 	else if `q'==1 {
> 	local $ha "barnsley"
> 	}
> 	else if `q'==2 {
> 	local $ha "doncaster"
> 	}
> 	else if `q'==3 {
> 	local $ha "leicester"
> 	}
> 	else if `q'==4 {
> 	local $ha "lincs"
> 	}
> 	else if `q'==5 {
> 	local $ha "n derbys"
> 	}
> 	else if `q'==6 {
> 	local $ha "n notts"
> 	}
> 	else if `q'==7 {
> 	local $ha "nottingham"
> 	}
> 	else if `q'==8 {
> 	local $ha "rotherham"
> 	}
> 	else if `q'==9 {
> 	local $ha "s derbys"
> 	}
> 	else {
> 	local $ha "sheffield"
> 	}
>
> 	local q=`q'+1
>
> ......................................main bulk of
> program...................................
>
> 	outsheet using $ha, replace
>
> 	winexec "C:\program files\microsoft office\office\excel.exe" $ha.out
>
> 	clear
> }
>
>
>
> *
> *   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/
>

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index