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

st: RE: setting global in a loop


From   "David Harrison" <[email protected]>
To   <[email protected]>
Subject   st: RE: setting global in a loop
Date   Tue, 15 Feb 2005 12:42:34 -0000

Your problem is exactly what the error message says - code on the same line as the open brace ("{"). Having set the delimiter to ";", all the code up to the next ";" is interpretted as one line. Remove your two -#delimit- statements and the ";" and it should run fine.

David
[email protected]

-----Original Message-----
From: Ada Ma [mailto:[email protected]]
Sent: 15 February 2005 12:34
To: [email protected]
Subject: st: setting global in a loop


Hello Statalist,

I have a problem.  When I run the following program:

#delimit;
foreach i of numlist 3(1)6 {
local j : di char(`i'+96)
global `j'indvars "pid `j'hid";
}
#delimit cr;

I got an error code r(198) with a comment saying:
"program error:  code follows on the same line as open brace"

I am working on the BHPS and I hope that I can draw the same variables out from 
the various waves using globals combined with a loop.  Am I doing anything wrong 
or is global not allowed in a loop?

Many thanks in advance.

Regards,
Ada Ma

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



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