Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: question regarding macro assignment


From   Phil Schumm <[email protected]>
To   [email protected]
Subject   st: question regarding macro assignment
Date   Thu, 2 Dec 2004 11:43:09 -0600

I'm sorry to return to the well again so soon, but I suspect that this question (and its answer) might be of interest to others out there. One of the first things one learns when working with macros is the difference between

local macname = "mystring"

and

local macname "mystring"

In the first case, "mystring" is evaluated as a string expression before macro assignment occurs, and thus only the first 80 characters of mystring (244 for Stata/SE) are assigned to macname. In the second case, "mystring" is not evaluated as a string expression prior to assignment, and thus up to 67,784 characters (even more for Stata/SE) may be assigned to macname.

There is another difference, however, which is a bit easier to forget -- namely, the first form drops leading spaces while the second does not. Witness:


. loc foo = " a "

. di "|`foo'|"
|a |


while, in the second case,


. loc foo " a "

. di "|`foo'|"
| a |


Part of the reason I tend to forget this is the fact that the statement:


gen y = " a "


does exactly what you'd expect it to (i.e., it creates a variable named y in which each observation contains " a ").

Can someone explain why leading spaces are dropped when using the first form of macro assignment?


-- Phil
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




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