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

st: Re: value of var in local macro


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: Re: value of var in local macro
Date   Sun, 18 Apr 2004 20:40:16 -0400

On Apr 18, 2004, at 2:33 AM, Renzo wrote:

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.

. forv i=1/7 {
  2. local cty = var1[`i']
  3. local gdp`cty' = var2[`i']
  4. }

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/



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