Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • MATA Error "Nothing found where while expected"

    I am studying from the STATA guide.
    I typed MATA and then copied and entered the following command as shown in the entry for STATA:

    : real matrix id(real scalar n)
    {
    real scalar i
    real matrix res
    res = J(n, n, 0)
    for (i=1; i<=n; i++) {
    res[i,i] = 1
    }
    return(res)
    }
    :
    : I3 = id(3)
    : I3

    Which gives the error: nothing found where 'while' expected
    r(3000);

    Any help is much appreciated.

  • #2
    I am unable to duplicate your experience. I include mata clear as the first command to be sure nothing is left from my previous testing. This was copied and pasted as one into Stata's Command window; it works equally well run from the Do-file Editor window.
    Code:
    . clear all
    
    . mata
    ------------------------------------------------- mata (type end to exit) ----------------------
    : mata clear
    
    : real matrix id(real scalar n)
    > {
    > real scalar i
    > real matrix res
    > res = J(n, n, 0)
    > for (i=1; i<=n; i++) {
    > res[i,i] = 1
    > }
    > return(res)
    > }
    
    : I3 = id(3)
    
    : I3
    [symmetric]
           1   2   3
        +-------------+
      1 |  1          |
      2 |  0   1      |
      3 |  0   0   1  |
        +-------------+
    
    : end
    ------------------------------------------------------------------------------------------------
    
    .

    Comment


    • #3
      William, Thank you very much! This worked like a charm.
      Best,
      Lars.

      Comment

      Working...
      X