Hi,

I'm having difficulty in creating a variable after using "max" command. Below illustrates it.

The initial four variables are ID, Type, p (proportion), and se1 (standard error for p). I used max(p) to assign the maximum of p within each ID and type:

bys ID type: egen pmax = max(p)

The last column, se2, is what I want to get. Each se2 value should be the value of se1 that corresponds to pmax (and p). For example, the se2 value for pmax=0.3 should be 0.03 because se1 = 0.03 when p = 0.3.

What should I code to get the variable, se2? - Thanks in advance.

ID Type p se1 pmax se2
1 1 0.5 0.02 0.5 0.02
1 2 0.3 0.03 0.3 0.03
1 2 0.1 0.05 0.3 0.03
2 1 0.4 0.07 0.4 0.07