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

Re: st: foreach and globals and {.}


From   "Michael Blasnik" <michael.blasnik@verizon.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: foreach and globals and {.}
Date   Mon, 11 Apr 2005 07:47:10 -0400

woops, I forgot about that requirement. You can also put the global into a local before using it (which may be helpful in other situations):

local outyear ${out_`year'}
foreach x in `outyear' {
...

Michael Blasnik

----- Original Message ----- From: "David Harrison" <david.harrison@icnarc.org>
To: <statalist@hsphsun2.harvard.edu>
Sent: Monday, April 11, 2005 7:34 AM
Subject: RE: st: foreach and globals and {.}



Braces are also necessary when the global name contains a local macro...

. local loc a

. global ga hello world

. di "$ga"
hello world

. di "$g`loc'"
a

. di "${g`loc'}"
hello world

This was the case in the posted query... as I said in my previous response (which doesn't seem to have arrived yet more than an hour since I sent it) the -foreach x of global g- construct solves the problem.

D

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