*Tutorial 5 *Learning Mata by example *Mata help *--------------Start Example 1 ----------------* help mata //main mata help file from which you can access other help files help m5_intro //main help file for m5 *--------------End Example------------------* *mata function *--------------Start Example 2 ----------------* clear mata mata real scalar add1(a, b) //declared type { return(a+b) } add1(1,2) b=J(10,1,2) c=b*add1(1,2) c end *--------------End Example------------------* *mata function *--------------Start Example 3 ----------------* clear mata mata function add1(a, b) //state function the same result as above { return(a+b) } add1(1,2) b=J(10,1,2) c=b*add1(1,2) c end *--------------End Example------------------* *Mata functions *--------------Start Example 4 ----------------* clear mata version 10 mata : void add(real a, real b) { c=a+b st_numscalar("result",c) st_numscalar("a",a) st_numscalar("b",b) } end mata: add(3,4) di "this result of " a "+" b " ="result *--------------End Example------------------* help m1_intro *--------------Start Example 5 ----------------* clear mata version 10 mata: //start of mata function string matrix fill(string matrix a1) { b1="this"\"is" a1=a1\b1 a1 return(a1) } end mata:b="this"\"is" mata: a=fill(b) // mata: a *--------------End Example------------------* **require 10 observations to be fill in with the sequence 1 2 3 *--------------Start Example 6 ----------------* mata a=(1\2\3) a z=10/rows(a) for (i=1;i