    # Re: st: mata error - subexp

 From wgould@stata.com (William Gould, Stata) To statalist@hsphsun2.harvard.edu Subject Re: st: mata error - subexp Date Fri, 02 Jun 2006 09:00:28 -0500

```Friederike Sophie Barthel <fsb@ctu.mrc.ac.uk> asks,

> This is an excerpt from a mata program:
>
>       for (i=k; i<=n; i++) {
>               if (c[i,i] > ep) {
>                       cii = sqrt(max(c[i,i],0))
>                       if (i > 1) {
>                               s = [|i,1\k-1|]*y[|1\k-1|]
>                       }
>                       ai = (a[i] - s)/cii
>                       bi = (b[i]-s)/cii
>                       de = normal(bi) - normal(ai)
>                       if (de <= dem ) {
>                               ckk = cii; dem = de; am = ai; bm = bi; im = i;
>                       }
>               }
>       }
>
> When I run it though I get the following error:
>
> nothing found where subexp expected
>
> Does anyone know what this means and where the error may lie?

Here's the output:

: function junk()
> {
>
>         for (i=k; i<=n; i++) {
>                 if (c[i,i] > ep) {
>                         cii = sqrt(max(c[i,i],0))
>                         if (i > 1) {
>                                 s = [|i,1\k-1|]*y[|1\k-1|]
nothing found where subexp expected

So the problem is with the line,

>                                 s = [|i,1\k-1|]*y[|1\k-1|]

Okay, I admit it.  I looked and looked and looked at the line and didn't
see the mistake.  Let me put some spaces in it, just to make it easier to read

s = [| i,1 \ k-1 |] * y[| 1 \ k-1 |]

Do you see the problem yet?  I didn't, but after a while, I saw two problems!
Well, not after a while.  What I did was delete first one part of the
expression, and then another part, until the expression was so simple that,
when the compiler complained, I could not help but spot the mistake.

The first mistake is

s = [| i,1 \ k-1 |] * y[| 1 \ k-1 |]
^
shouldn't something go here?

[| and |] bracket subscripts.  One might write x[|...|].

I suspect the line should read

s = c[| i,1 \ k-1 |] * y[| 1 \ k-1 |]

although perhaps c should be something else.  Anyway, fix that problem, and
the code will compile.  I see a second problem, however,

s = c[| i,1 \ k-1 |] * y[| 1 \ k-1 |]
^^^^^^^^^
looks like a mistake

There are two elements on top, and one on the bottom!  There should be
two on the bottom, yes?  Or maybe one on the top?  Perhaps the line should

s = c[| i-1 \ k-1 |] * y[| 1 \ k-1 |]

or

s = c[| i,1 \ k,1 |] * y[| 1 \ k-1 |]

or
s = c[| i,1 \ k-1,1 |] * y[| 1 \ k-1 |]

or

s = c[| i,1 \ i,k-1 |] * y[| 1 \ k-1 |]

or something else.  Anyway, c[| i,1 \ k-1 |] is certainly a conformability
error, which would have been flagged when Friederike ran the code.

-- Bill
wgould@stata.com
*
*   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/
```