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: local variable defined outside a do file
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: local variable defined outside a do file
Date
Mon, 4 Jul 2011 14:26:35 +0100
First, let's be clear that there is no term "local variable" in Stata.
What you are referring to is called a local macro. See also, for
example,
http://www.stata.com/statalist/archive/2008-08/msg01258.html
In terms of your main question, you should pass the value of a local
macro to your do-file as an argument; otherwise it follows from the
definition of a local macro that the contents of that macro are quite
invisible outside the program in which it is defined.
foreach x in a b c d {
do dummy.do `x'
save, replace
}
If you do this the value of `x' is accessible within dummy.do as `1'.
What you need to read is any account of using do files with arguments.
What should be fixed in the memory is that "local" means what it says:
local macros as such are only visible locally.
Nick
On Mon, Jul 4, 2011 at 2:13 PM, Mayank Mishra <[email protected]> wrote:
> This is regarding a problem related to a local variable defined
> outside a do file. Following is the code:
>
> foreach x in a b c d {
> do dummy.do
> save, replace
> }
>
> The dummy file uses the local variable x in its calculations and as
> you can see it is defined outside the do file. The Stata gives an
> error on this.
> So, please tell me what can be done in this case.
*
* 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/