{smcl} {bf:Mata course: Ado-file programming} {hline} {title:Basic outline} {hline} {cmd}program ... syntax varlist [if] [in] ... marksample touse .... mata: myfunction("`varlist'", "`touse'") ... end mata: void myfunction(string scalar varnames, string scalar touse) {c -(} real matrix x ... ... st_view(x, ., tokens(varnames), touse) ... {c )-} end{txt} {hline} {p 4 4 2} This was the outline we used in {bf:{view varsum.ado}}. {title:Improved outline} {hline} {cmd}program ... syntax varlist [if] [in] ... marksample touse .... mata: myfunction("varlist", "`touse'") ... end mata: void myfunction(string scalar varmac, string scalar touse) {c -(} real matrix x string scalar varnames ... ... varnames = st_global(varmac) st_view(x, ., tokens(varnames), touse) ... {c )-} end{txt} {hline} {p 4 4 2} We can shorten {cmd:myfunction}: {cmd}void myfunction(string scalar varmac, string scalar touse) {c -(} real matrix x ... ... st_view(x, ., tokens(st_global(varmac)), touse) ... {c )-}{txt} {p 4 4 2} That is, {p 8 8 2} If a macro is long {p 12 12 2} do not pass {cmd:"`macro'"} {p 12 12 2} pass {cmd:"macro"} {p 8 8 2} and then take {cmd:st_global()} of it. {title:Another example} {p 4 4 2} See {bf:{view hsearch.ado}}. {hline} {bf:{view talk.smcl:Top}}