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

st: RE: While loop and input command


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: While loop and input command
Date   Mon, 21 Oct 2002 13:58:15 +0100

[email protected]
> 
> I am having a problem running a do file that contains a 
> while loop.  Within
> the while loop, I have the following input commands:
> 
> input str16 agegroup
> 	""
> 	"age0"
> 	"ages1to4"
> 	"ages5to9"
> 	"ages10to14"
> 	"ages15to19"
> 	"ages20to24"
> 	"ages25to29"
> 	"ages30to34"
> 	"ages35to39"
> 	"ages40to44"
> 	"ages45to49"
> 	"ages50to54"
> 	"ages55to59"
> 	"ages60to64"
> 	"ages65to69"
> 	"ages70to74"
> 	"ages75to79"
> 	"ages80to84"
> 	"ages85plus"
> 	"total"
> end  
> 
> When I run the do-file I get the r(1) break message 
> immediately after this
> command.  However, when I remove the above command the 
> do-file runs fine.
> Has anybody encountered similar problems, and is there any 
> way of getting
> round this.

I've not experienced this, but I have not tried 
to enter a variable in this way. 

gen str1 agegroup = "" 
qui replace agegroup = "age0" in 2
qui replace agegroup = "total" in 21
* fill out the ... 
local args "1to4 ... 85plus" 
tokenize `args' 
qui forval i = 1 / 19 { 
	local j = `i' + 2
	replace agegroup = "ages``i''" in `j' 
} 

Nick 
[email protected] 
*
*   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