Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

RE: st: RE: input statement inside a while loop


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: input statement inside a while loop
Date   Thu, 8 Jul 2010 18:12:17 +0100

Good. But the problem you outline is no problem: as long as you -save- appropriate results you can -use- them later. (Same applies to other ways of saving and reading.) 
Also, you could store them in macros, matrices, characteristics, etc. 

Nick 
n.j.cox@durham.ac.uk 

Ricardo Ovaldia, MS 

Thank you Nick. Your first option is just what I needed. The second option will not work for me because the data in the new data set will contain output generated earlier in the loop.


--- On Thu, 7/8/10, Nick Cox <n.j.cox@durham.ac.uk> wrote:

> This has I think arisen recently but
> I am not going to try to search the
> archives for "end". 
> 
> I guess you're right: -end- in a do-file or programming
> context is just
> hopelessly ambiguous. 
> 
> If this example is close to the problem, then 
> 
> set obs 2 
> gen lines1 = cond(_n == 1, "rec", "dat") 
> 
> is a way of avoiding 
> 
>         input str5 lines1
>            
> "rec"
>            
> "dat"
>         end
> 
> Another way is just to store that data in a separate
> dataset and read it
> in each time. 
> 
> Ricardo Ovaldia, MS 
> 
> 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?

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