Dear all,
I'm writing a Stata program, using pieces of Mata in it.
I face troubles when trying to put a Mata if condition in it, I think because the closing bracket } is read as a Stata bracket and not a Mata one.
Or if I try to write all Mata code into a mata -- end environment, the end command leads to the following error "unexpected end of line"
Let me drawn an example :
Using a line by line mata indicator
Using a mata - end environment.
I'm writing a Stata program, using pieces of Mata in it.
I face troubles when trying to put a Mata if condition in it, I think because the closing bracket } is read as a Stata bracket and not a Mata one.
Or if I try to write all Mata code into a mata -- end environment, the end command leads to the following error "unexpected end of line"
Let me drawn an example :
Using a line by line mata indicator
Code:
clear nwclear mata : mata clear *local mat=0 /*Pick one of the two configuration, in reality depends on the options specified in the program*/ local mat=1 if `mat'==1{ mata A =(0,3, 10\ 2, 0, 5\ 1, 1, 0) /*In reality the matrix considered comes from the program itself*/ noi display "case 1 : matrix A exists, should be modified if not symmetric " mata : sym=issymmetric(A) mata : sym mata : if (sym==0) { mata : Z = A :* (A :< A') + A' :* (A' :< A) /*min of symmetrics elements : reciprocated ties*/ } } if `mat'!=1{ noi di "case 2 : matrix A does not exit" }
Using a mata - end environment.
Code:
clear nwclear mata : mata clear *local mat=0 /*Pick one of the two configuration, in reality depends on the options specified in the program*/ local mat=1 if `mat'==1{ mata A =(0,3, 10\ 2, 0, 5\ 1, 1, 0) /*In reality the matrix considered comes from the program itself*/ noi display "case 1 : matrix A exists, should be modified if not symmetric " mata : sym=issymmetric(A) sym if (sym==0) { Z = A :* (A :< A') + A' :* (A' :< A) /*min of symmetrics elements : reciprocated ties*/ } end } if `mat'!=1{ noi di "case 2 : matrix A does not exit" }
Comment