On StackOverflow, the estimable Nick Cox posted the code quoted below in answer to a question. The second egen command caught my eye with the unfamiliar (to me) by(varlist) option. Unlike the by varlist: prefix, it apparently does not require the data to be sorted.
I have not been able to find support in the Stata help files or documentation for the by(varlist) option with egen. [Documentation and help from Stata/SE 13.1 for Mac (64-bit Intel) Revision 19 Dec 2014.] I did stumble across by(varlist) for collapse and statsby, and noted that no mention was made of sorting one way or the other for those commands.
Can anyone point this newbie to further enlightenment in Stata's documentation?
I have not been able to find support in the Stata help files or documentation for the by(varlist) option with egen. [Documentation and help from Stata/SE 13.1 for Mac (64-bit Intel) Revision 19 Dec 2014.] I did stumble across by(varlist) for collapse and statsby, and noted that no mention was made of sorting one way or the other for those commands.
Can anyone point this newbie to further enlightenment in Stata's documentation?
Code:
clear input str1 pos str5 name flag A Joe 1 A Joe 1 B Frank 0 C Mike 2 C Ted 0 D Mike 2 D Mike 2 E Bill 1 F Bill 1 end egen tag = tag(name pos) egen npos = total(tag), by(name) list , sepby(pos) +---------------------------------+ | pos name flag tag npos | |---------------------------------| 1. | A Joe 1 1 1 | 2. | A Joe 1 0 1 | |---------------------------------| 3. | B Frank 0 1 1 | |---------------------------------| 4. | C Mike 2 1 2 | 5. | C Ted 0 1 1 | |---------------------------------| 6. | D Mike 2 1 2 | 7. | D Mike 2 0 2 | |---------------------------------| 8. | E Bill 1 1 2 | |---------------------------------| 9. | F Bill 1 1 2 | +---------------------------------+
Comment