Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[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 <kantor.d@att.net>
To   statalist@hsphsun2.harvard.edu
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index