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

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

From   "Nick Cox" <>
To   <>
Subject   RE: st: Re: saving memory local vs usual variable
Date   Fri, 3 Oct 2008 19:50:46 +0100

I think that's good advice for saving the mode(s) somehow. 

For reporting modes, see also -modes- from SJ. 

Also, -egen-'s -nummode()- option is for selecting from tied modes, not
for selecting secondary or other modes. 

Thus, if values 1, 2, 3 occur equally frequently, so that all are
candidates for mode, -nummode(2)- will select 2. But if only one mode
exists, -nummode(2)- does not select the next most common value. 


Nick Winter

Somewhere along the way there was a question about how to retrieve the 
mode, "second mode," "third mode" and so on.  (I, too, am not sure if 
that is standard usage...)

The easiest way I see to get there is:

. sysuse auto
. tab rep78, matcell(cell) matrow(row) sort

The -sort- option tells Stata to sort the tabulation by frequency 
(highest to lowest).  The -matrow(row)- option puts the values of rep78 
in a matrix called 'row', and the -matcell(cell)- puts the actual 
frequencies in a matrix called 'cell.'

So the modal value is

. di row[1,1]

The "second modal" value is

. di row[2,1]

and so on.

Ashim Kapoor wrote:

> Yes I see that. Quite clever. BUT what if it is something which is NOT
> generated by a summary statistic . Like say the 2nd mode  ( assuming a
> variable has 2 modes). Can I directly store it into a local variable ?
> On Fri, Oct 3, 2008 at 9:29 PM, Martin Weiss <>

>> As we said this morning:
>> su age,mean
>> loc lj=r(max)

> ----- Original Message ----- From: "Ashim Kapoor"

>>> I have a question. Suppose I have a variable say - > age. Now I can
>>> egen j=max(age). Then I will have the max value of age in ONE
>>> VARIABLE! Horrible waste of memory. I try to do local lj=max(age)
>>> that does not work. How can I conserve memory ? Is there something
>>> basic which I have missed ?
>>> Thank you,
>>> Ashim.
>>> PS : I do understand that I can do egen j = max (age ) and then say
>>> local lj=j[1] and then -do drop j - but is there a better way ?

*   For searches and help try:

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