Thanks for sharing. For those of you following along, it looks like by passing hiv_cat into max(), Stata evaluates if hiv_cat is true (1) or false (0). I would have expected you had to use a full expression (hiv_cat == 1) but looks like Stata recognizes the shorthand for binary variables.