Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: mata conditional operator element-by-element?


From   László Sándor <sandorl@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: mata conditional operator element-by-element?
Date   Fri, 27 Apr 2012 14:24:16 -0400

Hi,

I checked the help for -m2_op_conditional- on up-to-date Stata 12.1 MP
for mac, and it looks like the conditional operator only works for
"general conditions", i.e. scalars, not element-by-element in vectors.
Much of my code did use -st_select-, but I thought some parts could
still be cleaner and/or more efficient if I could use something like
the conditional operator for vectors (as Matlab does allow). Please
let me know if you have good advice how to get from this

(t:/psc:^2 + (-1:*t:+1):/(-1:+psc):^2))

to something like this

(t == 1 ? psc : psc:-1)^2

[Yes, I would immediately see a problem with this syntax a colon
operator confusing the conditional operator…]

Thanks!

Laszlo

*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index