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

st: while loop problem

Subject   st: while loop problem
Date   Fri, 11 Oct 2002 10:17:47 +0100

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"

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

	outsheet using $ha, replace

	winexec "C:\program files\microsoft office\office\excel.exe" $ha.out


*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index