I have what I assume is a painfully simple question: is there a faster way to produce a table of averages by a grouping variable? For instance, if I had a continuous variable (var1) and binary variable (var2), and I wanted to get the mean of var1 for the whole dataset, for var2 == 0, and for var2 == 1, I could just do:
Is there a way to get those all in one line of code to be produced in a single table? Something like the equivalent of -tab var1 var2, col- but collapsed into an average for var1 somehow.
Code:
sum var1 sum var1 if var2==0 sum var1 if var2==1
Comment