On Wed, 22 Oct 2008, Ignacio Diaz-Emparanza wrote:

>> Hi folks. What is the GRETL translation of the command "REPLACE ... IF"
>> in STATA?
>>
>> Specifically, in STATA I would use        REPLACE W=. IF L==0      to
>> change my data in STATA (making the variable W missing if the variable L
>> is zero).
>>
>> Messing around in GRETL I have come up with the following 3 lines:
>>
>> smpl L=0 --restrict
>> genr W=NA
>> smpl --full
>>
>> Is there a simpler/briefer way to do this is GRETL? Maybe using IF?
>> Thanks for any suggestions -- jim irwin (economic historian, moving from
>> STATA to GRETL).
>
> May be the following command works as you want:
>
> series W=W*misszero(L)/L

Or, better still, use the ternary assignment operator, as in

genr W = (L=0) ? NA : W

See the manual, chap. 13.


Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche

r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti

Reply via email to