I'm running the distinct command repeatedly on different subsets of my data. I'd like to create a second dataset that stacks the results of the distinct command. Here's a very simple example, which counts the makes and models of foreign and domestic cars.
Instead of having the results in the output window (or in addition), though, I'd like to create a new dataset that looks something like this:
What's the most efficient way to do this? Thanks!
Code:
sysuse auto, clear split make, limit(2) drop make rename make1 make rename make2 model display "All cars" distinct make display "Foreign cars" distinct make if foreign display "Domestic cars" distinct make if !foreign
Subset | Makes | Models |
All cars | 23 | 74 |
Foreign cars | 12 | 22 |
Domestic cars | 11 | 52 |
Comment