Statalist The Stata Listserver

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

st: RE: trying local command

From   "Rodrigo Martell" <>
To   <>
Subject   st: RE: trying local command
Date   Mon, 26 Feb 2007 09:58:34 +1100


After you define the macro it can be called by its name, not its content. when you call. For example, you defined local macro truea0 to equal 1, if you want to call it you type in `truea0' not `1'. If you do this Stata tries to look for the contents of a macro called 1, which you haven't defined so it gets all confused. Also, the macro can store strings or pure numbers. Even though the contents of the turea macros will work defined as a string or a number, it's perhaps less confusing to exclude the quotes from the definition. I guess that's a personal choice since it will work both ways so long as you only specify numbers in the strings.

Anyway, here's a revised version of your code. I added in a macro called truea2 to go instead of the third macro you were calling in the -gen- command, which hadn't been defined. The first three lines I added (and commented out) myself to set up a working example.

*set obs 20
*gen x1 = 2
*gen x2 = 3

local truea0=1
local truea1=2
local truea2=3

gen ztreat=`truea0'+`truea1'*x1+`truea2'*x2

I hope this helps.



Rodrigo Martell

Frontier Economics Pty. Ltd.
395 Collins Street
Melbourne VIC 3000

+61 (0)3 9620 4488
+61 (0)3 9613 1518
+61 (0)3 8614 2711
+61 (0)407 909 811 <> 

This e-mail, including any attachments, may contain confidential and privileged information for the sole use of the intended recipient(s). Any review, use, disclosure or distribution by others is strictly prohibited. If you are not the intended recipient (or authorised to receive information for the recipient), please contact the sender by reply e-mail and delete all copies of this message. Thank you.


-----Original Message-----
[]On Behalf Of Michael
Sent: Monday, 26 February 2007 9:47 AM
Subject: st: trying local command

Hello Statalist members,
I'm working on learning the use of the -local- command. I'd like to 
define a few variables, then manipulate them. I'm experiencing some 
roadblocks with defining the terms. For example:

. local truea0="1"
. local truea1="2"
. gen ztreat='1'+'2'*x1+'3'*x2
type mismatch


Michael McCulloch, LAc, MPH
Research Director
Pine Street Foundation
124 Pine St
San Anselmo, CA 94960-2674
Tel:	(415) 407-1357
Fax:	(415) 485-1065
*   For searches and help try:

*   For searches and help try:

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