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]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

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 <mayankm16@gmail.com> 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/

**References**:**st: local variable defined outside a do file***From:*Mayank Mishra <mayankm16@gmail.com>

- Prev by Date:
**st: local variable defined outside a do file** - Next by Date:
**RE: st: RE: Using macros and batch running.** - Previous by thread:
**st: local variable defined outside a do file** - Index(es):