Hi, I'm new to mata and I have two problems related to MATA. Can someone please help me to find solutions to these.
(1) Looping through matrices in MATA
The output will be
When j=1
1 2
+---------+
1 | 0 1 |
2 | 2 4 |
+---------+
When j=2
1 2
+-----------+
1 | -1 -1 |
2 | -2 -1 |
+-----------+
When j=3
1 2
+-----------+
1 | -4 -1 |
2 | -5 -4 |
+-----------+
(2) saving MATA string vector as variables of STATA
This creates two variables named a1 and a2 in stata
I have a string vector in MATA. I need to do the same thing using MATA. (i.e. store the string names as variables)
Thank you for your time
(1) Looping through matrices in MATA
Code:
mata for (j=1;j<=3;j++) { X=(1,2\3,5) m_1=(1,1\1,1) m_2=(2,3\5,6) m_3=(5,3\8,9) X-m_j // here I need to refer to the jth matrix at each iteration. i.e. when j=1 m_ j should equal to m_1 and so on.. } end
When j=1
1 2
+---------+
1 | 0 1 |
2 | 2 4 |
+---------+
When j=2
1 2
+-----------+
1 | -1 -1 |
2 | -2 -1 |
+-----------+
When j=3
1 2
+-----------+
1 | -4 -1 |
2 | -5 -4 |
+-----------+
(2) saving MATA string vector as variables of STATA
Code:
STATA code gen a1=1 gen a2=1
I have a string vector in MATA. I need to do the same thing using MATA. (i.e. store the string names as variables)
Code:
mata mat1="a1","a2" // here I need the equivalent MATA code to generate the a1 and a2 variables end
Comment