Announcement

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

  • mata matuse is finicky

    If I write

    Code:
    mata
    mata drop G0*
    mata matuse "$indir/G0.mmat"
    end
    it runs just fine. But as soon as there's an if block...

    Code:
    mata
    if (1){
    mata drop G0*
    mata matuse "$indir/G0.mmat"
    }
    ;
    end
    all hell breaks loose, as conveyed by two expressive messages for the same error:

    invalid expression
    r(3000);
    and ... wait for it ...

    expression invalid
    r(3000);
    I applaud the developers for going to the trouble of documenting this outcome in two different ways, but would prefer something a little more informative.

    Anyway, is there a way to use matuse inside an if block? The documentation suggests that I switch from matuse/matsave to fopen/fclose when inside a program. However, this is not a program... and I am not a computer scientist or package builder.

    My last post in this other thread is related: http://www.statalist.org/forums/foru...00#post1054000
    Last edited by Frank Erickson; 13 Mar 2015, 15:10. Reason: if blocks that end just before "end" break, but that's not my problem here. so: semicolon

  • #2
    From the help m3_intro entry:
    The mata command, however, is different. When what you type is prefixed by the word mata, think
    of yourself as standing outside of Mata and giving an instruction that affects the Mata environment
    and the way Mata works. For instance, typing

    : mata clear

    says that Mata is to be cleared. Typing

    : mata set matastrict on

    says that Mata is to require that programs explicitly declare their arguments and their working variables;
    see [M-2] declarations.

    Remarks and examples
    The mata command cannot be used inside functions. It would make no sense to code
    function foo(...)
    {
    ...
    mata query
    ...
    }
    because mata query is something that can be typed only at the Mata colon prompt:
    : mata query
    (output omitted )

    See [M-1] how.

    Comment


    • #3
      Ah, thanks Scott! That explains it.

      As far as solving my problem goes, I ended up copying my condition to a macro and then using Stata's if block

      Code:
      mata: st_local("mycond",strofreal(mycond))
      if `mycond' mata: mata matuse "$indir/myfile.mmat"
      This strikes me as terribly clunky, so if anyone has a better idea, I'd appreciate it.

      Comment

      Working...
      X