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

st: Re: More on passing one value inside a variable to a local macro


From   "Naheed Mirza" <mirza@newmail.dk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: More on passing one value inside a variable to a local macro
Date   Sun, 18 Apr 2004 00:36:06 +0200

Renzo Comolli

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.

>>> 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:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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