Svend and Maarten are both right. Deep down, their answer
is the same, as -groups- is based on exactly the Stata
logic that Maarten exposes, plus bells and whistles.
Your original idea was good too.
egen group = group(var1 var2 var3), label
tab group
will do what you want as well. The -label- option
is crucial to get close to the display you want.
For examples more complicated, -groups- has more
handles.
Nick
n.j.cox@durham.ac.uk
Svend Juul
==========
Nick Cox made the -groups- command; it does what you want. Get it by:
ssc install groups
Maarten Buis
============
A rather blunt solution is shown below:
*-------------- begin example ------------
drop _all
input obs var1 var2 var3
1 2 2 1
2 2 2 1
3 1 2 3
4 3 3 3
end
preserve
drop if missing(var1, var2, var3)
bys var1 var2 var3: gen N = _N
bys var1 var2 var3: keep if _n == 1
list var1 var2 var3 N
restore
*---------- end example -----------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )
V MA
====
I have 3 variables that can take the values 1 up to 3 and the data looks
something like this
obs var1 var2 var3
1 2 2 1
2 2 2 1
3 1 2 3
4 3 3 3
I would like to obtain a table that says how many observations I have of
each existing combination. But I would like this table to have a
"description" for each of the combinations. i.e. the resulting table
would be something like this:
var1 var2 var3 count
1 2 3 1
2 2 1 2
3 3 3 1
Note also that the lines in the table are ordered by the values of var1,
var2 and var3.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/