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

 From Nick Winter To statalist@hsphsun2.harvard.edu Subject Re: st: Re: saving memory local vs usual variable Date Fri, 03 Oct 2008 14:39:10 -0400

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.

-Nick Winter

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 ?

Thank you,
Ashim.

On Fri, Oct 3, 2008 at 9:29 PM, Martin Weiss <martin.weiss1@gmx.de> wrote:
```
```As we said this morning:

su age,mean
loc lj=r(max)

HTH
Martin _______________________
----- Original Message ----- From: "Ashim Kapoor" <ashimkapoor@gmail.com>
To: <statalist@hsphsun2.harvard.edu>
Sent: Friday, October 03, 2008 5:54 PM
Subject: st: saving memory local vs usual variable

```
```Hello everyone,

I have a question. Suppose I have a variable say - > age. Now I can do
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) and
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:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

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

```
```*
*   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/
```
```--
--------------------------------------------------------------
Nicholas Winter                                 434.924.6994 t
Assistant Professor                             434.924.3359 f
Department of Politics                  nwinter@virginia.edu e
University of Virginia          faculty.virginia.edu/nwinter w
PO Box 400787, 100 Cabell Hall
Charlottesville, VA 22904

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