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

Re: st: Macro from scalar

From   Nick Winter <>
Subject   Re: st: Macro from scalar
Date   Fri, 22 Aug 2008 15:07:13 -0400

Note the difference between:

scalar s = 1
local l s


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'

. di `m2'

--Nick Winter

Eva Poen wrote:


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,

2008/8/22 Levy, Douglas E., Ph.D. <>:
Hi all,
Is there a way to take a scalar and place its value in a macro?

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:
Nicholas Winter                                 434.924.6994 t
Assistant Professor                             434.924.3359 f
Department of Politics         e
University of Virginia w
PO Box 400787, 100 Cabell Hall
Charlottesville, VA 22904

*   For searches and help try:

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