Mata course: Ado-file programming

Basic outline

program ...
syntax varlist [if] [in] ...
marksample touse
....
mata: myfunction("`varlist'", "`touse'")
...
end

mata:
void myfunction(string scalar varnames, string scalar touse)
{
real matrix	x
...

...
st_view(x, ., tokens(varnames), touse)
...
}
end

This was the outline we used in .

Improved outline

program ...
syntax varlist [if] [in] ...
marksample touse
....
mata: myfunction("varlist", "`touse'")
...
end

mata:
void myfunction(string scalar varmac, string scalar touse)
{
real matrix	x
string scalar	varnames
...

...
varnames = st_global(varmac)
st_view(x, ., tokens(varnames), touse)
...
}
end

We can shorten myfunction:

void myfunction(string scalar varmac, string scalar touse)
{
real matrix	x
...

...
st_view(x, ., tokens(st_global(varmac)), touse)
...
}

That is,

If a macro is long

do not pass "`macro'"

pass "macro"

and then take st_global() of it.

Another example

See
.

Top