Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: a question about loop and local marco name


From   "David Harrison" <david.harrison@icnarc.org>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: a question about loop and local marco name
Date   Fri, 27 Jan 2006 08:45:51 -0000

The distinction is between assignment and evaluation. If all you want to
do is assign something to a macro, you do not need the = sign and are
often better off without it. The = sign forces Stata to evaluate what it
is given before assigning it to the macro. The most simple example is as
follows:

. local a 2+2

. local b = 2+2

. di "`a'"
2+2

. di "`b'"
4

The first line assigned 2+2 to the local macro a - hereafter it contains
the string "2+2". The second line evaluated 2+2 and assigned the result
to macro b.

The reason why one of your examples worked the same both with and
without the = is that there was nothing to evaluate, so evaluating the
expression did not change the result.

With strings, Stata can assign a long string to a macro, but cannot
evaluate a long string - hence the problems you encountered.

Hope this helps

David

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Jian Zhang
Sent: 26 January 2006 21:29
To: Richard Williams; statalist@hsphsun2.harvard.edu;
statalist@hsphsun2.harvard.edu
Subject: Re: st: a question about loop and local marco name

Thanks, Richard! Your explanation is really helpful! also, your guess is
right that I am using Intercooled and Small Stata, which explains why
the local marco command with equal sign does not work since my list has
more 
than 80 characters.

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

*
*   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–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index