Bookmark and Share

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: SOLVED - Re: st: Why won't my -local- work?


From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: SOLVED - Re: st: Why won't my -local- work?
Date   Sun, 24 Feb 2013 22:01:31 -0500

At 07:31 PM 2/22/2013, Brandon Olszewski  wrote:
That was it! Thanks, Phil.
I was running all out of the same .do window, but in a piecemeal
fashion. I didn't realize you have to run the whole block (including
macro assignment, cleaning, and reg, for instance) in one shot. When I
do that, it works.
Thanks!

It's been a couple of days since this was posted, but I want to add a comment.

You don't necessarily need to have everything in one "block". You just need to have all local references in the same scope as their assignments. Every program or do-file has its own distinct scope, as does the "command" window. But you can also pass names into programs or do-files via parameters or options. (Options only apply to programs.) Thus...

program def myprog
syntax, macname(string)

... references to `macname'
end

local mymacro "abc"
myprog, macname(`mymacro')

Inside myprog, the references to macname will be evaluated as "abc". But note that the reference therein is to macname, not mymacro. The scope of mymacro does not extend inside myprog. The fact that its assignment came after the definition of myprogram is irrelevant. Had the assignment
of mymacro come first, its scope would still not extend inside myprogram.

HTH
--David

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index