Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: If in Mata

From   Jesper Kjr Hansen <>
To   <>
Subject   st: RE: If in Mata
Date   Wed, 12 Apr 2006 01:44:02 +0200

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 Kjr Hansen

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index