Announcement

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

  • set matastrict within ado files

    It's not clear to me why the following program, *saved as an ado file* won't throw an error despite the -mata set matastrict on- (within the ado itself) and the lack of declarations.

    Code:
    program varsum
        version 13
        syntax varname [if] [in]
        marksample touse
        mata: calcsum("`varlist'", "`touse'")
        display as txt " sum = " as res r(sum)
    end
    
    version 13
    mata:
        mata set matastrict on
    
        void calcsum(varname, touse)
        {
        st_view(x, ., varname, touse)
        st_numscalar("r(sum)", colsum(x))
        }
    end
    The program (edited by me: I added the "mata set matastrict on") comes from https://www.stata.com/manuals13/m-1ado.pdf , section "Advice: Use of matastrict".
    Am I missing something?

    Code:
    . program dir
      ado      387  varsum
     mata      248  varsum.calcsum()
          --------
               635

  • #2
    set matastrict on is ignored when the ado-file is automatically loaded. This setting is respected when an ado-file is ran as a do-file, so Andrea can type do varsum.ado and Stata will respond
    Code:
    variable x undeclared
    (0 lines skipped)

    Comment


    • #3
      Dear Rafal, thank you for your kind and swift reply.
      I realise now I misinterpreted the text in the user's guide.

      Comment

      Working...
      X