Dear community,
How can I generate new_var based on ID, var1, and var2?
Note: the labels in new_var should not be composed of adding characters from var2. The labels can also simply be generated/written. For example, the label a_c could also be "option_five" or something arbitrary.
I seem to need to somehow test whether there is non-zero value in var1 for each var2 within each ID, and then attach a label (it is only 6 or so different values) to the ID.
ID | var1 | var2 | new_var |
1 | 114315 | a | a |
1 | 0 | b | a |
1 | 0 | c | a |
1 | 0 | d | a |
2 | 14225 | a | a_c |
2 | 0 | b | a_c |
2 | 343522 | c | a_c |
2 | d | a_c | |
3 | 0 | a | b |
3 | 423422 | b | b |
3 | null | c | b |
3 | 0 | d | b |
Please let me know if you have questions.
Solved! Go to Solution.
@johand_erst are you looking for some thing like below. My logic is if there is a non numeric value in var1 based on Var2 and ID then flag with a value if leave it as null. Please let me know my understanding is correct or not?
@johand_erst
I hope this is what you need.