[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: Re: More on passing one value inside a variable to a local macro
To add to this: what if the variable var2 is string?
-summarize- will not help in this case.
One possibility is
gen long `order' = _n
su `order' if var2 == "value", meanonly
local macroname = var1[`r(min)']
That is, the observation number you need is returned in r(min),
and then used to identify the value of -var1-.
Another possibility is
gen byte `true' = var2 == "`value'"
local macroname = var1[_N]
From: Naheed Mirza [mailto:email@example.com]
Sent: 18. april 2004 00:36
Subject: Re: More on passing one value inside a variable to a local
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
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.
>>> One way of doing this
su var1 if var2 == <value>
local macroname "`r(min)'"
If, as you say, the value is unique, then -summarize- will
return the same value as, say, r(min) or r(max).
An assumption here is that -var1- is not string.
* For searches and help try: