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 |
Maria Ana Vitorino <vitorino@wharton.upenn.edu> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: RE: local variables and running do files |

Date |
Fri, 28 Oct 2011 14:40:26 -0400 |

I am using Stata 11. But in any case what if I want to run some regressions, for example: reg y x1 x2 x3 is equiv to --regtest.do local x "x1 x2 x3" reg y `x' ----

Thanks, Ana On Oct 28, 2011, at 2:30 PM, Nick Cox wrote:

The term "local variable" is to be avoided, as explained at http://www.stata.com/statalist/archive/2008-08/msg01258.htmlWhat you are seeing is a defining feature of a local macro: it isvisible only locally, i.e. within the locale in which it is defined,i.e. not visible outside the interactive session, program, do fileor do file editor contents within which it is defined.You need to pass the contents of your local macro to the do-file asan argument. If you write e.g.------------ mydo.do su `1' ------------ And then go mydo "var1 var2"then the do file uses the argument you feed to it. Arguments areseparated by spaces and bound by " ". This is all explained in thechapter(s) on do-files in [U], which is part of your Stata, aswithout declaring otherwise it is assumed that you are using Stata 12.Nick n.j.cox@durham.ac.uk Maria Ana Vitorino I would like to run a do file in batches (i.e. a few lines at a time) but it seems that then the local variables that I defined in the beginning do not carry over ... Any solution for this? Here is some output for a simple example so that you can better understand what is my issue. Thanks!! Ana. do "/var/folders/Xn/Xnl4Mq-lGR4-mNII1zm-Wk+++TI/-Tmp-//SD17268.000000". sum Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- var1 | 24 12.5 7.071068 1 24 var2 | 24 36.5 7.071068 25 48 var3 | 24 61.5 7.071068 50 73 . local var "var1 var2" . end of do-file. do "/var/folders/Xn/Xnl4Mq-lGR4-mNII1zm-Wk+++TI/-Tmp-//SD17268.000000". sum `var' Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- var1 | 24 12.5 7.071068 1 24 var2 | 24 36.5 7.071068 25 48 var3 | 24 61.5 7.071068 50 73 * * 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/

* * 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/

**Follow-Ups**:**Re: st: RE: local variables and running do files***From:*Nick Cox <njcoxstata@gmail.com>

**References**:**st: local variables and running do files***From:*Maria Ana Vitorino <vitorino@wharton.upenn.edu>

**st: RE: local variables and running do files***From:*Nick Cox <n.j.cox@durham.ac.uk>

- Prev by Date:
**Re: st: local variables and running do files** - Next by Date:
**Re: st: local variables and running do files** - Previous by thread:
**st: RE: local variables and running do files** - Next by thread:
**Re: st: RE: local variables and running do files** - Index(es):