I need to generate two variables for my research.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(x_id y_id z_id) int(x y z x' y' z') 1 2 3 130 120 100 4 5 3 1 2 3 100 120 120 10 8 9 1 2 3 300 350 350 3 3 2 1 2 3 300 300 310 2 2 2 1 2 3 360 360 90 8 8 4 1 2 3 250 60 30 5 10 12 1 2 3 250 15 30 5 2 12 1 2 3 35 25 35 2 2 1 1 2 3 300 270 100 8 4 5 1 2 3 41 225 225 2 9 9 1 2 3 100 70 140 4 2 3 1 2 3 300 300 330 9 6 6 1 2 3 300 60 30 6 4 4 1 2 3 330 300 350 4 6 3 1 2 3 345 200 300 9 3 2 1 2 3 200 200 300 2 1 6 1 2 3 300 80 300 4 2 4 1 2 3 100 300 100 2 9 1 1 2 3 20 280 230 2 2 4 1 2 3 340 200 50 9 6 6 1 2 3 60 180 180 10 8 7 1 2 3 145 130 195 6 4 6 end
1st variable needed
ID_max=x_id if x is greater than y and z
ID_max=y_id if y is greater than x and z
ID_max=z_id if z is greater than x and y
2nd variable needed
ID_min=x_id if x is less than y and z
ID_min=y_id if y is less than x and z
ID_min=z_id if z is less than x and y
Tie-breaking rules:
If tie while generating ID_min, then the minimum of x * x' or y * y' or z * z' ( where * is for multiplication) should decide value that ID_min takes (from x_id, y_id, and z_id).
Similarly, if tie while generating ID_max, then the maximum of x * x' or y * y' or z * z' ( where * is for multiplication) should decide the value that ID_max takes.
If the tie still remains ( which is likely), then ID_max should take the value 1 (i.e., x_id)
May anyone please help?
regards,
ajay
0 Response to max or min of rows---- bysort and generate
Post a Comment