[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: AW: creating and calling local macros in do-files

From   Jeph Herrin <>
Subject   Re: st: AW: creating and calling local macros in do-files
Date   Tue, 04 Aug 2009 16:04:39 -0400

If for some reason it is critical to have macros that persist
across do-files, use -global-s instead of -local-s.

As an alternative, I sometimes define macros (locals or globals)
inside a single -do- file, and then -include- that file at the
top of my other -do-files. This is often useful if I want to
run a number of different analyses with the same sets of variables
broken into subsets - then to make changes to my various lists
of variables I only have to edit one file.


S Aneeqa Aqeel wrote:
Thank you, that certainly helped clarify what I was doing incorrectly (trying to break up a do-file and run it piecemeal).



Quoting Martin Weiss <>:


First of all, from your description it is not necessarily the case that you
need -local-s at all. If you do, a do-file counts as one session, and all
-local-s are lost upon its termination.

I would suggest you post example data and what you want to achieve, and the
-local- thing will be rendered redundant...


-----Ursprüngliche Nachricht-----
[] Im Auftrag von S Aneeqa Aqeel
Gesendet: Dienstag, 4. August 2009 18:10
Betreff: st: creating and calling local macros in do-files

I am using STATA10 on a Windows 64-bit system.
I have looked up past FAQs on macros as well as the STATA user guide,
etc.  I have also tried my code on a different computer, but get the
same result. So I'm posting my question to the Statalist and would be
grateful for any light you can shed on this matter.

I am using panel data and creating quarterly dummies for each year
I then create local macros, one for each year, collecting the
quarterly dummies by year.

I am finding that STATA does not create more than one local macro if I
try to create several inside a do-file.  Consequently, when  the
do-file then tries to execute a regression, based on the local macros
created, the regression output shows no results at all for the
variables inside the macros which I am calling in the regression.

If I create each macro in the command window, one by one, and then run
the regression by typing it out in the command window, I get results
for each of the variables included.

Similarly, if I try to see what variables are included in the macro
(by using "summarize"), it doesn't work if the macro was one of
several created in the do-file, but will work if I created it directly
from the command window.

Can you tell me why a macro might not run from inside the do-file? Is
there an upper limit to the number of local macros one can create and
call at any time?

I can provide log files and my code if it would help.

Many thanks and regards,


*   For searches and help try:

*   For searches and help try:

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index