Announcement

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

  • reghdfe makes Mata forget Mata functions

    Hi, I am a beginner with Mata and also have not written Stata programs (.ado files).

    Inside a larger loop I run reghdfe after which I do some evaluations in Mata. I learned this can be only a one-liner (otherwise the loop breaks at Mata's "end") so I need to define a Mata function called by the one-liner. So far so good. My problem is that once reghdfe has run, the previously defined Mata function is forgot. Here is a MWE:

    Code:
    cls
    clear all
    adopath + // path to reghdfe.ado goes here
    
    mata
        real matrix mtest()     { 
            return(runiform(3,4))
        }
    end
    
    mata: st_matrix("rt1",mtest()) // works
    mat li rt1
    
    sysuse auto
    qui reghdfe price foreign mpg, absorb(i.rep78) // reghdfe makes mata forget the function mtest()
    
    mata: st_matrix("rt2",mtest()) // error <istmt>:  3499  mtest() not found
    mat li rt2
    Somehow (I guess) I have to declare this function mtest() permanently by other means (not just in the .do file) but as I have never written any of these .ado programs or whatever kind of wrapper is needed here, I got stuck. Any idea?

    Peter

  • #2
    I think reghdfe may do something clever where on the fly it compiles a version of the Mata code that is optimized for your estimation problem. This might include a "mata clear" command.
    You could also post on the issues page at Github: https://github.com/sergiocorreia/reghdfe/issues.
    Sergio Correia

    Comment


    • #3
      Thank you David. I think I have to cope with reghdfe as it is. Finally I found a solution. While calling the mata function from a program...end wrapper (still defined inside the .do file) did not help, outsourcing the mata stuff and the wrapper to an ado file does help. This file seems to be unaffected by reghdfe's deletions (or it is re-defined each time I call it; luckily that's not critical to my application)

      Comment

      Working...
      X