
The quote after the x is the right single quote. It is found in the upper left corner of the keyboard, under the tilde ( ~). The quote before the x is the left single quote. To use a macro, you put its name in a command, surrounded by a particular set of quotation marks: This creates a local macro called x and puts the character ' 1' in it (not the value 1 as in "one unit to the right of zero on the number line"). If not, just trust us that local macros are the right ones to use. If you're familiar with global and local variables from other languages, Stata's local macros are local in the same way. (The real trick is getting a single command to run multiple times with a different bit of text in the box each time-we'll get there). You then use what's in the box in subsequent commands. MacrosĪ Stata macro is a box you put text in.

Typing the commands in the examples yourself will help you notice and retain all the details, and prepare you to write your own code. This article is best read at the computer with Stata running. If you've done a lot of Stata programming already and are looking to expand your "bag of tricks" check out Stata Programming Tools. The primary intended audience is Stata users with no other programming experience. To benefit from this article you'll need a solid understanding of basic Stata syntax, such as you can get from our Stata for Researchers series. This article will focus on those programming tools that, in our experience, anyone who uses Stata heavily will eventually want to learn. Stata has all the tools required to write very sophisticated programs, but knowing just a few of them allows you to make everyday do files shorter and more efficient. If not, someday you will-so you might as well keep reading anyway.

Ever needed to do the same thing to ten different variables and wished that you didn't have to write it out ten times? If so, then this article is for you.
