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

# RE: st: mata error - subexp

 From "Friederike Sophie Barthel" To Subject RE: st: mata error - subexp Date Fri, 2 Jun 2006 15:17:52 +0100

```Thank you!

-------------------------------------------------------------
Friederike Maria-Sophie Barthel
Medical Statistician

MRC Clinical Trials Unit
222 Euston Road
London
NW1 2DA

Tel: 020 7670 4828
Mob: 07939 144610

www.fm-sbarthel.de

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of William Gould,
Stata
Sent: 02 June 2006 15:00
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: mata error - subexp

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
read,

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/

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

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