. bysort rep78: gen ab=_n . order ab,after(rep78) . bysort rep78: gen abb=sum(rep78) . order abb,after(rep78)