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

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'

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.


*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index