Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: is it possible to use local macros to define global macros?
From
Gabi Huiber <[email protected]>
To
[email protected]
Subject
Re: st: is it possible to use local macros to define global macros?
Date
Sun, 27 Jun 2010 01:01:27 -0400
Yes. The quick fix to this problem is to use the curly bracked syntax
${myglobal} instead of $myglobal:
global g1 foo
global g2 bar
forvalues i=1/2 {
di "$g`i'" // not what you want
di "${g`i'}" // this is what you want
}
But I'd only do this if my code was already written with these
global/local combos and I didn't feel like changing it. I'm not sure
that I'd go with this design if I had to start from scratch.
Gabi
On Sun, Jun 27, 2010 at 12:39 AM, Benjamin Villena Roldan
<[email protected]> wrote:
>
> Hi Statalist,
> I'm trying to use several lists of variable names that I want to use in various do files, so in my master do file I define
>
> global covar1 x1 x2 x3
> global covar2 x4 x5 x6
> ...
> global covar10 x28 x29 x30
>
> Then, I want to run regressions in a forvalue loop to use the defined global macros
>
> forv a=1/10{
> reg y $covar`a'
> }
>
> But this approach does not work because the dereferencing operator $ does not include the local macro "a" into the global name.
>
> Is there any way I can do this without having to redefine my global macros as local macros in all my do files?
>
> Thanks
>
> Benjamin
>
>
>
> _________________________________________________________________
>
>
> *
> * 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/
--
Gabi Huiber
(919) 636-9366
enoriver.net
*
* 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/