Page 1 of 1

how should i write codes about this? Thank you!

Posted: Wed Oct 29, 2008 11:22 am
by cystleren
I have a series called A (a1, a2, a3). What i want to do is if (a1,a2,a3) >65 then a new series B = (a1-65,a2-65,a3-65) generated; if not then the observation which below 65 returns 0. For example, A = (98,68,63) then B = (98-65,68-65,0)=(33,3,0). My code is like
if A > 65 then genr B = A-65 else genr B =0 endif
The problem is that the series B is always generated as all 0. Could you please suggest me how should I change this code? Thank you!!!

Re: how should i write codes about this? Thank you!

Posted: Wed Oct 29, 2008 11:31 am
by startz
I have a series called A (a1, a2, a3). What i want to do is if (a1,a2,a3) >65 then a new series B = (a1-65,a2-65,a3-65) generated; if not then the observation which below 65 returns 0. For example, A = (98,68,63) then B = (98-65,68-65,0)=(33,3,0). My code is like
if A > 65 then genr B = A-65 else genr B =0 endif
The problem is that the series B is always generated as all 0. Could you please suggest me how should I change this code? Thank you!!!
You want the @recode function

Code: Select all

series b = @recode(a>65,a-65,0)
Alternatively,

Code: Select all

series b = (a>65)*(a-65) + (a<=65)*0

Re: how should i write codes about this? Thank you!

Posted: Wed Oct 29, 2008 11:59 am
by cystleren
It works very well! Thanks a lot!