My objective is to find the max of a certain variable for each group and then assign generate for every observation in a particular group a new variable that equals the max. So that means for every observation in the group, the max variable would have the same value.
The code I have been trying to use is the following:
Of course the problem with this is that r(max) is still fixed at the value of summarize, and the summarize isn't being repeated for each group.
Code:
unique_identifier group value 56 1 2048 12 1 5005 78 1 7080 46 2 9898 82 2 6568 97 2 7000 //After the code the above should look like the following: unique_identifier group value num_max 56 1 2048 7080 12 1 5005 7080 78 1 7080 7080 46 2 9898 9898 82 2 6568 9898 97 2 7000 9898
Code:
summarize counter bysort group: gen num_max = r(max)
Comment