Good suggestions, thanks. I will test in my own data
-
Login or Register
- Log in with
capture program drop myprogram program define myprogram // perhaps rclass, eclass, etc. syntax whatever, by(varlist) // MAYBE OTHER OPTIONS, TOO // IDENTIFY GROUP SIZE AND VERIFY IT IS CONSTANT tempvar size by `by', sort: gen `size' = _N // NOW DO IT local start = 1 local end = `size'[1] while `start' <= _N { command1 in `start'/`end' command2 in `start'/`end' ... local start = `start' + `size'[`start'] local end = `start' + `size'[`start'] - 1 } // MAYBE OTHER STUFF end
sortpreserve states that the program changes the sort order of the data and that Stata is to restore the original order when the program concludes. See [P] byable and [P] sortpreserve for a discussion of this important option.
Comment