Thank you, Nick, for pointing this out. I tend not to change scalars
after I have created them (i.e. I just pick a new name for
modifications), so I sometimes forget about the consequences... What
bites me a lot more often is the variable/scalar name ambiguity, as
mentioned in http://www.stata-journal.com/article.html?article=dm0021
.
Eva
2008/8/22 Nick Winter <[email protected]>:
> Note the difference between:
>
> scalar s = 1
> local l s
>
> and
>
> scalar s = 1
> local l = s
>
> in the first case, the string "s" is put in local l. When you display `l',
> Stata replaces `l' with the string "s", which is then evaluated as a scalar.
>
> In the second case, the local l is given the (current) value of the scalar
> s.
>
> Which you want depends on whether you want the value you get when you refer
> to the local to change when the scalar changes. Consider:
>
> . scalar s = 1
>
> . local m1 s
>
> . local m2 = s
>
> . scalar s = 2
>
> . di `m1'
> 2
>
> . di `m2'
> 1
>
>
> --Nick Winter
>
>
>
> Eva Poen wrote:
>>
>> Douglas,
>>
>> like this?
>>
>> scalar s = 1
>> local l s
>>
>> di s
>> di `l'
>>
>> To avoid confusion with variable names, you can write
>>
>> local l scalar(s)
>>
>> Hope this helps,
>> Eva
>>
>>
>> 2008/8/22 Levy, Douglas E., Ph.D. <[email protected]>:
>>>
>>> Hi all,
>>> Is there a way to take a scalar and place its value in a macro?
>>> Thanks,
>>> Doug
>>>
>>> Douglas Levy, PhD
>>> Institute for Health Policy
>>> Massachusetts General Hospital
>>> 50 Staniford Street; Suite 901
>>> Boston, MA 02114
>>> Tel 617.643.3595
>>> Fax 617.724.4738
>>>
>> *
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/statalist/faq
>> * http://www.ats.ucla.edu/stat/stata/
>
> --
> --------------------------------------------------------------
> Nicholas Winter 434.924.6994 t
> Assistant Professor 434.924.3359 f
> Department of Politics [email protected] e
> University of Virginia faculty.virginia.edu/nwinter w
> PO Box 400787, 100 Cabell Hall
> Charlottesville, VA 22904
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/