Dear Kit,
I don't believe I am confusing the two -if- (although maybe I am, but I
don't think so).
I want the local macro to take the value of var1 for the same row for which
var2 takes a specific value, say 5 or "Texas". I know a priori that var2
will take that value only once, so macroname will end up containing only one
number coming from var1.
Example, my need is to find a way to do something like passing the GDP of
Texas to a local macro. Inside var1 I have all GDPs for each state and
inside var2 I have the name of all states. Something like this
. local macroname = var1 if var2=="Texas"
where I know a priori that Texas will appear only once in var2.
If I knew a priori that Texas where in the, say, 22nd observation, then I
would just write
. local macroname = var1[22]
and be done with it. But in the ado I am programming "Texas" can appear at
any place. Sorting would not help.
While writing for you what I meant with my work-around I understood why it
does not work. I am not sure that explaining my mistake would help. I think
it would just generate more confusion, so I omit it.
Thanks,
Renzo
----------------------------------------------------------------------------
----
*From Kit Baum <[email protected]>
To [email protected]
Subject st: Re: if vs if
Date Sat, 17 Apr 2004 11:30:43 -0400
----------------------------------------------------------------------------
----
On Apr 17, 2004, at 2:33 AM, Renzo wrote:
>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.
You are confusing the 'if' that may appear as a component of many Stata
commands, e.g. summarize income if sex==1, and the programmer's 'if'.
Furthermore, since each observation of var2 may take on a different value,
what does it mean to generate one macro with value equalling the first
observation of var1 in this context? Do you mean if any observation of var2
takes on 'value'? Or if all observations of var2 are equal to 'value'?
Your workaround looks only at the first observation of var2. Is that what
you really mean? Please clarify.
Kit
*
* 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/