![]() In other words, macro y will store the number 4, whereas macro x will store 2+2 and the addition will be performed only when the macro is invoked. However, macro list $x will display 2+2, whereas macro list $y will display 4. Consider the following:īoth globals will be evaluated as 4 thus, both dis $x and dis $y will display the number 4. Since compound quotes will not hurt even if no double quotes occur within the macro, it may be best to always use compound quotes the Stata manual suggests to do so whenever the content of the macro exceeds a single word.ģ) In the case of evaluated expressions, it makes a slight difference whether or not you use quotes. (The Stata manual is not particularly helpful here.) "single plus double" quotation marks, as in:īe sure to use the correct single quotation marks: The accent grave, or gravis, at the beginning, and the apostrophe at the end. If the character string stored to the macro does itself contain double quotes (an example will be given below under the heading of "using macros"), the macro must be enclosed in compound quotes, i.e. ![]() But please be sure to note the following: This will never hurt if you are dealing with non-numeric characters. Here, the expression following the equals sign is evaluated, i.e., what is stored to x is not "2 * 5" but rather "10".ġ) The name of a global can be up to (and including) 32 characters long, but it may be as short as a single character.Ģ) You will find many examples where the content of the macro is enclosed in double quotes (such as in global x "this-and-that". Here, "global" is the Stata command to define a global macro, "x" is the name of the global and "this-and-that" is what is stored under the name of x, and will substitute x whenever x is invoked. There are two basic ways to assign content to a global. In Stata, a global macro is something that is stored in memory and can be used anytime during a Stata session by reference to its name (a local macro differs basically inasmuch it can be used only within a circumscribed piece of a program or a do-file). ![]() Local macros work basically the same way as global macros, but there are some important differences which you have to look up should you have to deal with locals. While it is important to know that both global and local macros exist (if only to understand the manual), this section will deal only with globals, as locals most likely are less important for the average user. In the Stata handbook, they are described as "local macros" and "global macros", but in what follows I will often use the abbrevations "global(s)" and "local(s)", as these are the commands used to invoke them also, in programmer's usual parlance a macro is sort of a small subprogram that is used repeatedly, which is not the case here. ![]() However, they can be helpful for the work of 'normal' users as well. ![]() "Global" and "local" are notions (and Stata commands) you will encounter in chapters on "Stata programming".
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |