jeudi 25 juin 2015

Data tranfromation with if then else

I have a table as below:

  id   term   subj   degree
  32    2015   AA     Yes
  32    2016   AA     No
  25    2011   NM     No
  25    2001   ts     No
  18    2007   ww     Yes
  18    2010   ww     No

I need another variable term2 if the degree is Yes, and I will write to term2 whatever same id and subj's term. So means:

  id    term   subj   degree   term2
  32    2015   AA     Yes       2016
  32    2016   AA     No         0
  25    2011   NM     No         0
  25    2001   ts     No         0
  18    2007   ww     Yes       2010
  18    2010   ww     No         0

What I did with if then else doesn't work. Any idea? Thank you

Aucun commentaire:

Enregistrer un commentaire