Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Re: saving memory local vs usual variable


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Re: saving memory local vs usual variable
Date   Fri, 3 Oct 2008 19:33:40 +0100

Agreed (modulo the elegance). 

Nick
[email protected] 

Martin Weiss

Not what I want, but what Ashim initally complained about. My idea was
to 
have this done with only temps, but your code is obviously much more 
elegant. It is also easy to see how one could generalize this and throw
it 
into a -program- if Ashim absolutely wants this capability...

"Nick Cox" <[email protected]>

> If that's what you want.
>
> Martin Weiss
>
> loc absmax=max(`max', r(max))
>
> at the end of your code to get this into a -local- then?
>
> Nick Cox
>
>> Not the main point, perhaps, but there is a much more direct way to
do
>> this.
>>
>> sysuse auto, clear
>> su price, meanonly
>> local max = r(max)
>> su trunk, meanonly
>> di max(`max', r(max))
>
> Martin Weiss
>>
>> Well, -egen- does not take more than one variable because usually
that
>> is
>> what users want: either the -max- of a variable or the max across
>> columns,
>> which -egen- also supports with the -rowmax- option. If you want the
>> maximum
>> of two vars for whatever reason:
>>
>> sysuse auto, clear
>>
>> tempvar prmax trmax overallmax
>>
>> egen `prmax'=max(price)
>> egen `trmax'=max(trunk)
>> egen `overallmax'=rowmax(`prmax' `trmax')
>> su `overallmax',mean
>> loc max=r(max)
>>
>> di in red `max'
>>
>> Ashim Kapoor
>>
>>> On 2nd thought.
>>>
>>> egen j=max(x) DOES NOT take more than one variable.
>>>
>>> It is gen which can do the max of 2 or more variables.
>>>
>>> So since egen returns a variable with ONE constant value, it would
>>> seem that it should be allowed to be stored in a scalar / local
> macro.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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