Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: mata for-if-else
From
Sabrina Carrossa <[email protected]>
To
[email protected]
Subject
Re: st: mata for-if-else
Date
Wed, 14 Apr 2010 11:02:35 +0100
I am not sure, but I guess you'd better use the "if qualifier" instead
of the "if-else" command.
On 14 April 2010 10:54, Abhimanyu Arora
<[email protected]> wrote:
> Dear statalist,
> I have simplified my problem to a large extent, but essentially has to do
> with using for-if-else commands in mata. I would like to create a matrix 'a'
> whose values depend on an existing matrix 'b' (both are 1000X1 vectors to be
> precise). I need to tell mata the dimension of a first. But all I get after
> executing the commands below is the original vector 'a'. What could be the
> possible error? I have tried adding and removing braces but it is not
> working...
>
>
>
>
> a=J(1000,1,.)
> for(i=1,i<1001,i++) {
> if (b[i]==1){
> a[i]=2
> }
> else {a[i]=3
> }
> }
> a
> end
>
>
> Thanks a lot
> Abhimanyu
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
--
sabrina
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/