Dear Stata users,
I have rarely used Mata. I want to display r(sum) that returned by Mata function, but the display command gives nothing.
I have rarely used Mata. I want to display r(sum) that returned by Mata function, but the display command gives nothing.
Code:
sysuse auto
tab rep78, matcell(blended)
mata: b = st_matrix("blended")
mata: f = 100 * b :/ sum(b)
mata: sum( abs(f :-10 ) )/2
display as txt "Myers Blended Index = " as result r(sum)
Code:
. tab rep78, matcell(blended)
Repair |
Record 1978 | Freq. Percent Cum.
------------+-----------------------------------
1 | 2 2.90 2.90
2 | 8 11.59 14.49
3 | 30 43.48 57.97
4 | 18 26.09 84.06
5 | 11 15.94 100.00
------------+-----------------------------------
Total | 69 100.00
.
. mata: b = st_matrix("blended")
. mata: f = 100 * b :/ sum(b)
. mata: sum( abs(f :-10 ) )/2
32.10144928
.
. display as txt "Myers Blended Index = " as result r(sum)
Myers Blended Index = .
Comment