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

st: Re: How do I do -local macroname = var1 if var2==value

From   "Naheed Mirza" <[email protected]>
To   <[email protected]>
Subject   st: Re: How do I do -local macroname = var1 if var2==value
Date   Sat, 17 Apr 2004 16:56:11 +0200

Renzo Comolli

I would like to do the following thing 

. local macroname = var1 if var2==value 

This is not legal syntax though. I looked on [U] and [P] 
to see if there were any extended macro function to help me 
but I did not find any. I know for a fact that value referred 
to in the if-condition is going always to be unique. I tried 
the following work around but for some reason (that I don't 
understand) it does not work either (it returns a missing even 
if I know for a fact that it should return a number) 

. tempvar var1 
. gen `var1'=var1 if var2==value 
. local macroname = `var1'[1] 

>>> This should work: 

if var2[1] == value local macroname "var1" 

But note that the test must be of a single value. 
Stata can't cope with a variable-full of trues or

*   For searches and help try:

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