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: Program error: code follows on same line as open brace


From   Ronnie Babigumira <rb.glists@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Program error: code follows on same line as open brace
Date   Thu, 13 Sep 2012 01:00:22 +0200

Daniel
Your first loop looks fine to me and the code below for me (Stata 12, Mac OS)

****
clear
set obs 10
foreach wave of numlist 1/8 {
            gen r`wave'Name = `wave'
}
*****

What version of Stata are you using, and, are you using Stata's own do-file editor or an external text editor. If you are, could the problem be that the external text editor is not recognizing the carriage return

Could you also add one carriage return after the loop closing brace }. "In Stata, commands are not executed unless they are "entered" by a carriage return. Hence, a different solution is to add just one carriage return at the end of the master file (instead of two)" (http://www.stata.com/statalist/archive/2009-07/msg00224.html)

One last potential source of error: Have you set a delimiter somewhere before you start the loop (http://www.stata.com/statalist/archive/2005-02/msg00434.html). "One other thing to be aware of using the semicolon as the delimiter,is to remember to put one after the curly braces" http://www.stata.com/statalist/archive/2003-09/msg00309.html 

-- 
010100100110111101101110011011100110100101100101




On Wednesday, September 12, 2012 at 11:26 PM, Daniel Almar de Sneijder wrote:

> Hello statalist,
> 
> When I attempt:
> 
> foreach wave of numlist 1/8 {
> gen r`wave'Name = r`wave'Caregiving
> }
> 
> I receive the error:
> Program error: code follows on same line as open brace
> 
> The first wave gots created, i.e. r1Name. But as soon as it starts
> with wave 2 the message appears.
> Does anybody knows why this is happening? And how to fix it?
> 
> I have tried
> foreach wave of numlist 1/8 { *
> gen r`wave'Semin = r`wave'Caregiving
> } *
> *
> 
> without succes
> and also
> 
> foreach wave of numlist 1/8 { *
> 
> gen r`wave'Semin = r`wave'Caregiving
> 
> } *
> *
> 
> THANKS,
> daniel
> *
> * 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/



*
*   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