Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: input statement inside a while loop


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: input statement inside a while loop
Date   Thu, 8 Jul 2010 17:00:17 +0000

<>

My guess is that in simplifying the snippet you gave us, we've lost some information about why you couldn't just separate these two processes (  that is, (1)creating the 100 observation dataset with random "x" and (2) inputing a dataset with a variable "lines") into different loops -- they don't seem to inform one another in any way. 

I'm not sure why the input - end causes a loop to break (might have something to do with input being an interactive command ?), but could you replace it with -gen- and -replace- commands ?  e.g., 
******
local i 1
	while `i'<=10 {
		clear
		set obs 100
		gen x=uniform()
		sum x
	clear
	set obs 2
	g lines = "rec" in 1
	replace lines = "dat" in 2
                 save temp`i', replace
		local i=`i'+1
	}
******

~ Eric

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754

On Jul 8, 2010, at 11:44 AM, Ricardo Ovaldia wrote:

> I am trying to create a data set inside a -while- loop but it keeps failing. I think that the -end- confuses Stata. 
> Here is a simplified version:
> -----------------------------
> local i 1
> 	while `i'<=10 {
> 		clear
> 		set obs 100
> 		gen x=uniform()
> 		sum x
> 		clear
> 		input str5 lines1
> 			"rec"
> 			"dat"
> 		end
>                  save temp`i', replace
> 		local i=`i'+1
> 	}
> -------------------------------------
> 
> 
> output:
> . local i 1
> 
> .         while `i'<=10 {
>  2.                 clear
>  3.                 set obs 100
>  4.                 gen x=uniform()
>  5.                 sum x
>  6.                 clear
>  7.                 input str5 lines1
>  8.                         "rec"
>  9.                         "dat"
> 10.                 end
> --Break--
> r(1);
> 
> end of do-file
> 
> 
> 
> If I take out the -input- command it works. Any ideas?
> 
> Thank you,
> Ricardo
> 
> Ricardo Ovaldia, MS
> Statistician 
> Oklahoma City, OK



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index