Collapsing Data in Stata
Long after a dataset has been created, we might discover that for some purposes it has the wrong organization. Fortunately, several commands facilitate drastic restructuring of datasets. The simplest of these, collapse, aggregates data into means, medians or other statistics for groups defined by one or more variables. For illustration, we return to the