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

 From Lars Korsholm To statalist@hsphsun2.harvard.edu Subject Re: st: How do I do -local macroname = var1 if var2==value- Date Mon, 19 Apr 2004 16:38:34 +0200 (MEST)

```On Fri, 16 Apr 2004, Renzo Comolli wrote:

> Dear Statalist
>
> 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]

I guess that in macroname you want the value of var1 (which is unique)
when var2==value.

the best way I know is
sum var1 if var2==value, meanonly
local macroname=`r(mean)'

chers
lars

>
>
> Any suggestion would be appreciated.
>
> Best Regards,
> Renzo Comolli
>
>
> *
> *   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/
>

..............................................
: Lars Korsholm Ph.D.,                       :
:  Department of Statistics                  :
:  University of Southern Denmark            :
:  Sdr. Boulevard 23A, 2.                    :
:  DK-5000 Odense C                          :
: Phone +45 6550 3608 (or 3868)              :
: Mobil +45 3033 3617                        :
: Fax   +45 6595 7766                        :
: Mail  korsholm@stat.sdu.dk                 :
: Web   http://www.biostat.sdu.dk/~korsholm  :
:............................................:

*
*   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/
```