Announcement

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

  • Temporary names and Mata matrix operations

    Does anyone know why the space after the row-join operator and before the tempname matrix matters in the following?

    Code:
    tempname tn
    mata m=J(1,3,2)
    mata `tn'=m
    mata m \ m
    mata m\m
    mata `tn' \ `tn'
    mata `tn'\(`tn')
    mata `tn'\`tn'
    Code:
    . tempname tn
    
    . mata m=J(1,3,2)
    
    . mata `tn'=m
    
    . mata m \ m
           1   2   3
        +-------------+
      1 |  2   2   2  |
      2 |  2   2   2  |
        +-------------+
    
    . mata m\m
           1   2   3
        +-------------+
      1 |  2   2   2  |
      2 |  2   2   2  |
        +-------------+
    
    . mata `tn' \ `tn'
           1   2   3
        +-------------+
      1 |  2   2   2  |
      2 |  2   2   2  |
        +-------------+
    
    . mata `tn'\(`tn')
           1   2   3
        +-------------+
      1 |  2   2   2  |
      2 |  2   2   2  |
        +-------------+
    
    . mata `tn'\`tn'
    invalid expression
    r(3000);
    
    end of do-file
    
    r(3000);

  • #2
    I think that it's a Stata error and not of Mata origin. I can't find it now, but I remember reading somewhere that the reverse solidus is an escape character for the ` character in local macros. See below for illustration.

    .ÿlocalÿbÿTextÿhere

    .ÿdisplayÿinÿsmclÿasÿtextÿ"`b'"
    Textÿhere

    .ÿdisplayÿinÿsmclÿasÿtextÿ"\`b'"
    `b'

    .ÿtempnameÿM

    .ÿmatrixÿdefineÿ`M'ÿ=ÿJ(1,ÿ3,ÿ2)

    .ÿmatrixÿdefineÿ`M'ÿ=ÿ`M'ÿ\ÿ`M'

    .ÿmatrixÿlistÿ`M'

    __000001[2,3]
    ÿÿÿÿc1ÿÿc2ÿÿc3
    r1ÿÿÿ2ÿÿÿ2ÿÿÿ2
    r1ÿÿÿ2ÿÿÿ2ÿÿÿ2

    .ÿmatrixÿdefineÿ`M'ÿ=ÿJ(1,ÿ3,ÿ2)

    .ÿmatrixÿdefineÿ`M'ÿ=ÿ`M'\`M'
    __000001`Mÿnotÿfound
    r(111);

    .

    Comment


    • #3
      Originally posted by Joseph Coveney View Post
      I can't find it now, but I remember reading somewhere that the reverse solidus is an escape character for the ` character in local macros.
      The issue is discussed in Cox (2008).


      Cox, N. J. 2008. Stata tip 65: Beware the backstabbing backslash, The Stata Journal, 8(3), pp. 446--447.

      Comment


      • #4
        Thanks Joseph and Daniel.

        Comment

        Working...
        X