Can anybody explain to me how the following code from a Stata FAQ works. It is confusing to me. This is the FAQ: http://www.stata.com/support/faqs/da...ble-recording/
And this is the section:
Second, what if missing values are present? For numeric variables, missing counts as higher than any other numeric value, but egen, max() is smart enough to ignore it. Only if all values in a group are missing will the result variable be missing.
Occasionally, you may want a strict definition of all—that literally all values in a group must possess the characteristic, with no missing values allowed. Here is one approach
. egen anymiss = max(sex), by(family)
. egen allfem = min(sex) if !anymiss, by(family)
I've played around with it and it doesn't seem to accomplish what the FAQ claims it does, namely, flag families that have all females and no missing sex values.
And this is the section:
Second, what if missing values are present? For numeric variables, missing counts as higher than any other numeric value, but egen, max() is smart enough to ignore it. Only if all values in a group are missing will the result variable be missing.
Occasionally, you may want a strict definition of all—that literally all values in a group must possess the characteristic, with no missing values allowed. Here is one approach
. egen anymiss = max(sex), by(family)
. egen allfem = min(sex) if !anymiss, by(family)
I've played around with it and it doesn't seem to accomplish what the FAQ claims it does, namely, flag families that have all females and no missing sex values.

Comment