I am not using it interactively. But it doesn't matter whether I go
mata
if (1==1) "Hello world"
end
Or
mata: if (1==1) "Hello world"
Both don't work and if I understand the documentation correctly, they
should.
I am using the if-function as part of a larger script that uses some
matrices to store and manipulate results from a couple of regression
models (actually, a lot, so no, I can't use the non-mata matrix commands
for several reasons). I have to use the mata-if function, because I
check a feature of a mata-matrix and then ask it to execute a
mata-command on that matrix - but I reduced the if-command to the simple
version that I have shown in the email because it is fairly fail-proof
in terms of other errors in the coding.
The solution you suggested (mata: if (1==1) {} "Hello world") doesn't
really work. It does not really run the if check, so if you use
mata: if (1==0) {} "Hello world"
You still get a "Hello World" as output (and it shouldn't, because 1 is
obviously not 0).
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of
> Jesper Kjær Hansen
> Sent: Tuesday, April 11, 2006 4:44 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: RE: If in Mata
>
>
> Daniel Schneider wrote:
>
> > I am lost, and I do not know anymore what I am doing wrong
> with this
> > very simple problem. I have been trying to get a very
> simple if-clause
> > to run in Mata, but it hasn't worked at all. I have finally reduced
> > the if-statement to the most simple form:
> >
> > mata: if (1==1) results[1,1]
> >
> >
> > (results[1,1] should just output a number)
> >
> > What I get is
> >
> > unexpected end of line
> > <istmt> incomplete
> >
>
> I guess the real question is, why you would want to use an
> if statement interactively (from Stata's dot-prompt or from
> Mata's colon-prompt) (?)
>
> I don't know why this doesn't work in Mata. Maybe it is not
> meant to work interactively. It works with Stata's if command:
>
> . if 1==1 display "Hello world"
> Hello world
>
> You can, however, trick Mata into getting what you want:
>
> . mata if (1==1) {} "Hello world"
> Hello world
>
> . mata: if (1==1) {} "Hello world"
> Hello world
>
> . mata:
> -----------------------------
> : if (1==1) {} "Hello world"
> Hello world
>
> but I am not sure that it is recommendable to do this at all,
> and I am pretty sure that it is not documented. And again:
> I don't know why you would want to do this. Please note that
> you will get yet another error, if the matrix or scalar res
> is not defined beforehand.
>
> /Jesper
>
>
>
> Jesper Kjær Hansen
> mailto:kjaer.hansen@oncable.dk
>
>
> *
> * For searches and help try:
> * http://www.stata.com/support/faqs/res/findit.html
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/