Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Generating a list with combinations' counts and their description


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Generating a list with combinations' counts and their description
Date   Wed, 23 May 2007 07:55:41 +0100 (BST)

--- MA V <[email protected]> wrote:
> Dear Statalist users,
> 
> My problem is the following:
> 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.

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 )

Hope this helps,
Maarten


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


		
___________________________________________________________ 
Now you can scan emails quickly with a reading pane. Get the new Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index