Hi Statalist

This is an admittedly general question but I've struggled to find the answer to it despite having looked at many places. From https://www.stata.com/support/faqs/d...ions-in-group/, the syntax of the code used is:

Code:
 
 by eid (egenotype), sort: gen diff = egenotype[1] != egenotype[_N] 
Question: when we go need to add another variable in brackets following the -by- option (in this case, (egenotype))? Moreover, why wouldn't the above work if it is simply

Code:
 
 bysort eid: gen diff = egenotype[1] != egenotype[_N] 
Thanks.