Dear,
I am currently handling a data where I want to create a new variable based on a specific value of two ID's. For example, my data looks like
ID1-----ID2-----ID3-----prop1-----prop2
1 ------100-----200---- 5 ------ .
2 ------100-----100---- 5 ------ .
3 ------500-----100---- 4 ------ .
4 ------200-----500---- 3 ------ .
So for example, I have 5 variables labelled as ID1, ID2, ID3, prop1 (propensity1) and prop2. Now I want to replace prop2 in the following manner:
1) if ID2==ID3, then replace prop2 by prop1
2) However, if if ID2 != ID3, then prop2 for any specific value 'i' of ID3 will be replaced by the prop1 value of ID2 with same 'i'. I am really struggling how to do that.
The first part is fairly simple which is 'replace prop2=prop1 if ID2==ID3' but I do not understand how to code the second part.
Would appreciate if anyone can help.
Thanks
Mohammad Zariab Hossain
I am currently handling a data where I want to create a new variable based on a specific value of two ID's. For example, my data looks like
ID1-----ID2-----ID3-----prop1-----prop2
1 ------100-----200---- 5 ------ .
2 ------100-----100---- 5 ------ .
3 ------500-----100---- 4 ------ .
4 ------200-----500---- 3 ------ .
So for example, I have 5 variables labelled as ID1, ID2, ID3, prop1 (propensity1) and prop2. Now I want to replace prop2 in the following manner:
1) if ID2==ID3, then replace prop2 by prop1
2) However, if if ID2 != ID3, then prop2 for any specific value 'i' of ID3 will be replaced by the prop1 value of ID2 with same 'i'. I am really struggling how to do that.
The first part is fairly simple which is 'replace prop2=prop1 if ID2==ID3' but I do not understand how to code the second part.
Would appreciate if anyone can help.
Thanks
Mohammad Zariab Hossain
Comment