Colleagues: If I execute the following code in a new Stata session I encounter no difficulties
However, my Mata session has been open and performing other tasks and now I'm receiving this r(3000) error message when executing the same code:
While I'm encountering this error in this particular instance it also seems to happen rarely but every so often in function definitions. If I change the declaration to real matrix rv,chg,j the code runs fine. I generally don't declare loop/index variables in my declarations and in most cases that's not problematic.
Does anyone have insights into why this r(3000) error might be arising? I can certainly do a work-around, but mostly I'm curious why such an error would arise at all.
Thanks for any insights you might be able to share.
Code:
capture mata mata drop reindex() mata function reindex(v,updown) { real matrix rv,chg rv=sort(v,1) chg=1 while (chg>0) { chg=0 for (j=1;j<=(rows(v)-1);j++) { if (rv[j]==rv[j+1]) { chg=chg+1 rv[j]=rv[j]+updown } } } return(rv) } end
Code:
. do "/var/folders/d5/6w9t_lzx3plbpmk6zpyz93dm0000gp/T//SD09710.000000" . capture mata mata drop reindex() . . mata ------------------------------------------------- mata (type end to exit) ------------------------------------- : : function reindex(v,updown) { > real matrix rv,chg > > rv=sort(v,1) > chg=1 > while (chg>0) { > chg=0 > for (j=1;j<=(rows(v)-1);j++) { > if (rv[j]==rv[j+1]) { > chg=chg+1 > rv[j]=rv[j]+updown > } > } > } > return(rv) > } variable j undeclared r(3000); : : end --------------------------------------------------------------------------------------------------------------- . end of do-file
Does anyone have insights into why this r(3000) error might be arising? I can certainly do a work-around, but mostly I'm curious why such an error would arise at all.
Thanks for any insights you might be able to share.
Comment