I have 11 variables named num_pih1 to num_pih11 scored 0 to 8.
I need to reverse the values of variables so that the one scored 0 in original variable becomes 8 in new variable.
I tried this code, it works but I was wondering if there is a shorter way to do it for all 11 variables.
Thanks
I need to reverse the values of variables so that the one scored 0 in original variable becomes 8 in new variable.
Code:
gen pih1=. replace pih1=0 if num_pih1==8 replace pih1=1 if num_pih1==7 replace pih1=2 if num_pih1==6 replace pih1=3 if num_pih1==5 replace pih1=4 if num_pih1==4 replace pih1=5 if num_pih1==3 replace pih1=6 if num_pih1==2 replace pih1=7 if num_pih1==1 replace pih1=8 if num_pih1==0
Thanks
Comment