Book Image

Data Analysis with STATA

Book Image

Data Analysis with STATA

Overview of this book

Table of Contents (16 chapters)
Data Analysis with Stata
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Macros


A Stata macro is not a black box where we can input the text and numbers. You can use this module or box in various commands. One of the best tricks in Stata is to leverage many macro statements or, as they are rightly called, modules or boxes in a single Stata command and optimize the entire code.

First, let's look at local macros. If you are an experienced programmer, you might know the difference between global variables and local variables. This difference remains in Stata as well. Most of the macros in Stata are local macros and are written for specific commands or functions that can be reused for many occasions. For example, take a look at the following command:

local macro_Name table

For example:

local Y 9

In this command or macro, the name of the macro is Y and 9 is the denotation of the table. Another example can be as follows:

display "Y"

On a general note, all the macros are processed by the macro processor. The macro processor properly feeds the macros to Stata. When Stata...