I am currently working with Mata. The dataset in Mata currently contains vectors A and B of dimension N*1 each. In summary, what I am trying to do is to :
!
This does not work- I still get values greater than 1 and less than 0.
I think I see the problem, but not the syntax. There should be another condition here to keep on doing the drawing of the term till the statement is true. I am not sure if the while statement enforces this. Any help is greatly appreciated!
- create another vector of random terms of the same dimension drawn from a normal distribution
- Sum element wise this vector to vectors A and B
- Evaluate if the sum is greater than 1 or less than 0
- If 3) is true for a particular element , redraw the random term till the condition holds
- Do this for all terms until each element of this vector which is the sum of A, B and the error term is either less than 1 or greater than 0. The following is the code I have written till now
Code:
putmata A B \\this inputs these vectors in mata
Sum=J(rows(A), 1,0) \\\Creates a vector with each element 0- to loop over.
for (i=1;i<=rows(A);i++) {
Random[i,1] = rnormal(1,1,0,1)
Sum[i,1]=A[i,1]+B[i,1]+Random[i,1]
while (Sum[i,1]>1) {
Random[i,1]= rnormal(1,1,0,1))
}
}
end
This does not work- I still get values greater than 1 and less than 0.
I think I see the problem, but not the syntax. There should be another condition here to keep on doing the drawing of the term till the statement is true. I am not sure if the while statement enforces this. Any help is greatly appreciated!

Comment