On Mon, 30 Jun 2008, Gordon Hughes wrote:
My apologies if I have missed something, but I would like to ask
whether it
is possible to extend genr in some way so as to provide conditional
definitions of variables. To give an illustration, in Stata one can do the
following:
gen ln_x = -10000 [where ln_x is a series]
replace ln_x = ln(x) if x > 0
You have the ternary assignment operator:
series ln_x = (x>0) ? ln(x) : -10000
or, better still,
series ln_x = (x>0) ? ln(x) : NA
See chapter 13 of the User's guide.
Note, however, that in the above example such a construct would be
unnecessary, since the log() function automatically outputs NA when
applied to a negative value.
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti