Hi, Suppose, I have the following dataset:
I want to generate three variable as follows:
ID | GrouID | X1 | X2 |
1 | 1 | 7 | 10 |
2 | 1 | 7 | 100 |
3 | 1 | 11 | 200 |
4 | 1 | 11 | 100 |
5 | 1 | 50 | 10 |
- Variable 1: For each individual i, the value of this variable is the average over X2 for all j≠i, given that X2i = X2j. Example: for ID=1, the new variable would take a value of 100.
- Variable 2: For each individual i, the value of this variable is the average over X2 for all j≠i, given that X2i < X2j. Example: for ID=1, the new variable would take a value of (200+100+10)/3.
- Variable 3: For each individual i, the value of this variable is the average over X2 for all j≠i, given that X2i < X2j. Example: for ID=1, the new variable would take a value of (10+100+200+100)/4.
Comment