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: st: RE: local macro

From   Ekaterina Hertog <>
To   "" <>
Subject   Re: st: RE: local macro
Date   Tue, 27 Apr 2010 20:15:00 +0200

Dear Nick,
Thank you for advice and for taking time to explain to me how my description of a problem fell short of a clear statement of a problem. I will definitely keep that in mind next time I have a question,
sincerely yours,

You give further questions, but little further information, except that
you are not writing any programs.
But you are using do files and also, I guess, interacting with Stata
through the command window. The explanation that local macros defined in
a do file are not visible to the main interactive session, and vice
versa, remains my best guess on what your problem is.
If you want to avoid globals, fine, and I support that, but you must
repeat the definition of a local in each place. (There are other,
programmers', solutions, but frankly I think they would just confuse
What is unclear? I know it is difficult, but you have to imagine
yourself decoding the problem from this description and this description
alone. A completely clear description would mean, ideally, that someone
else could run the code you give and reproduce your problem exactly.
Your report falls a long way short of that goal. Stripping the code down
to the minimum that produces the problem often helps. Reproducing the
problem with complete code that others can see is even better.

1. Precisely where you defined what remains unclear.
2. You seem unclear and confused yourself: "Stata does not seem to
recognise my local macro." That is not a description of a concrete
problem. What happened, precisely? 3. Extraneous detail doesn't help. Nick
Ekaterina Hertog

thank you very much for the clarification. Sorry, what would be the crucial details I have not mentioned and that could make my problem clearer to the Stata community? I am just trying to avoid using global macros as I am afraid that at some point I will forget I have defined one already and it will lead to confusion. I only want to use my local macro within one do-file, I am not using -programs- as defined by Stata. I would like not to have to run the whole of it each time as it takes a lot of time. I would like to be able

to run the section of the file which sets up the data and defines the local macro and then some regressions using that macro, but not all as specified in the do-file. Is that possible?

Nick Cox wrote:

This isn't very clear to me, as you give lots of details but not all
crucial ones! But the mention of a do file suggests that you are defining a local macro and one place and trying to use it in another. -local- means precisely that. Local macros are local to one of 1. an interactive session 2. a -program- defined as such
3. a do file
4. a do file editor window, whether saved as a file or not
and are not visible outside any such context. It may well be that globals will serve your purpose better.

Ekaterina Hertog

I was wondering if you could help me clarify something about local macros. I use Stata 11. I have a log do file with probably 100 regressions. I am essentially testing 2 models the 2nd one being an extension of the first in a sense that I use all the variables that proved important in the first model and add some new ones. To make editing easier once I finalised the first model I created a local
which is a list of variables used in the first model and used it when running out the regressions of the second model. It works fine if I
my whole do file continuously. However, when I want to run just a few
e.g. the line with a local macro and some regressions a few paragraphs

down which use the macro in question
Stata does not seem to recognise my local macro.
Here is a sample of my commands:
local streglist prsexratio2039 citotalgen osaka age agesq height
income smoker withfam university goodhealth face3 sightprobl strongintnumb intsexratio streg `streglist' nodes desartokyo desosaka mindesinc if age<=40, dist(gamma) nolog
I just wanted to confirm is it possible to use a local macro the way I

was trying to and in that case what am I doing wrong? Or is it impossible and I should set a global macro instead?

*   For searches and help try:

Ekaterina Hertog (née Korobtseva)
Career Development Fellow
Department of Sociology and Nissan Institute of Japanese Studies
University of Oxford

27 Winchester Road
United Kingdom

*   For searches and help try:

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