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

Re: st: foreach and globals and {.}

From   "Hans J. Baumgartner" <>
Subject   Re: st: foreach and globals and {.}
Date   Mon, 11 Apr 2005 14:00:13 +0200

Thanks Michael,

I guess that’s a feasible workaround.

To all the other postings: I need the braces, since otherwise Stata thinks the global is $out_ , which it does not find to be defined, since the global reads $out_`year’, i.e. ${out_`year’}.

It would be nice if either the loops or the macros or better both would allow for different braces, i.e. “(“, “[“.

Best wishes

Michael Blasnik schrieb:

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" <>
To: <>
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'"

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


*   For searches and help try:

Hans J. Baumgartner DIW Berlin
German Institute for Economic Research
Dept. Public Economics
Königin-Luise-Str. 5; 14195 Berlin; Germany
Tel.: +49/30/89789-307
Fax.: +49/30/89789-114

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index