collapse can yield unexpected (and to my eyes, incorrect) results when all values in a group are missing:
The result is
The max is correct, but the min is not. The problem is that collapse sorts a temporary variable, "gen `revx' = -x", which is regular missing (.) when x is any missing value. Sorting by x correctly sorts extended missing values, but sorting by `revx' does not. If min/max are not intended to preserve extended missing values, then the result should be regular missing (.), but if they are intended to preserve missing values, the result should be ".a"
Code:
clear set obs 3 gen x = . replace x = .a in 1 replace x = .z in 2 replace x = .e in 3 collapse (min) min_x = x (max) max_x= x
Code:
. l +---------------+ | min_x max_x | |---------------| 1. | .e .z | +---------------+
Comment