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:
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
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
Peter

Comment