The mata matsave help file
warns
With that in mind can anyone explain the behavior of mata matsave in the following contexts. I'm particularly interested in why there's no error in the first and second cases but an error in the third case.
Results:
Code:
help mata_matsave
These commands are for interactive use; they are not for use inside programs.
Code:
mata
z=J(10,10,1)
mata matsave ztestmat1 z, replace
end
mata
k=1
if (k==1) {
z=J(10,10,1)
}
stata("mata: mata matsave ztestmat2 z, replace")
end
mata
k=1
if (k==1) {
z=J(10,10,1)
}
mata matsave ztestmat3 z, replace
end
Code:
. mata
------------------------------------------------- mata (type end to exit) ---------------------------
: z=J(10,10,1)
: mata matsave ztestmat1 z, replace
(saving z[10,10])
file ztestmat1.mmat saved
: end
-----------------------------------------------------------------------------------------------------
.
. mata
------------------------------------------------- mata (type end to exit) ---------------------------
: k=1
: if (k==1) {
> z=J(10,10,1)
> }
> stata("mata: mata matsave ztestmat2 z, replace")
(saving z[10,10])
file ztestmat2.mmat saved
: end
-----------------------------------------------------------------------------------------------------
.
. mata
------------------------------------------------- mata (type end to exit) ---------------------------
: k=1
: if (k==1) {
> z=J(10,10,1)
> }
> mata matsave ztestmat3 z, replace
invalid expression
r(3000);
: end
-----------------------------------------------------------------------------------------------------
.
.
end of do-file

Comment