# st: RE: maximum of a list of values

 From "Nick Cox" To Subject st: RE: maximum of a list of values Date Tue, 28 Jun 2005 20:36:10 +0100

```Alas, this is just fantasy syntax.

You imply that it is legal, but
not giving you what you want, whereas
it is illegal.

When you write something like this
in mathematics, you rely on a human
reader being smart enough to work
out what should replace those dots.

Stata requires you to be explicit
might indeed tempt people to think that
there should be a syntax to cover
it, but suppose that only

x1 x2 x3 x4 x5 x7 x8

exist: should Stata interpret

max(x1[1,1],...,x8[1,1])

as the maximum over those
that exist, or should it squawk
that x6 doesn't exist? Also,
how smart should Stata be about

max(x1[1,1],...,x8[7,7])

in such a situation?

Once a list gets long, it is better
to think in terms of a loop, as in

scalar max = x1[1,1]
forval i = 2/8 {
scalar max = max(scalar(max), x`i'[1,1])
}

That is not much shorter than

scalar max = max(x1[1,1], x2[1,1], x3[1,1], x4[1,1], x5[1,1], x6[1,1], x7[1,1], x8[1,1])

but once you have 80 or 800 items, the loop
really scores.

Nick
n.j.cox@durham.ac.uk

NEYMOTIN, FLORENCE

> also, one more question:
>
> If I want to get the maximum of the first entry of a bunch of
> entries, then is there a way to do
> this in shorthand? i.e. suppose I want the maximum of
> x1[1,1], x2[1,1], x3[1,1], x4[1,1], x5[1,1],
> x6[1,1], x7[1,1] x8[1,1], then I thought it was possible to
> write:  max(x1[1,1],...,x8[1,1]) but
> this isn't giving me all of the values in between.

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