Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: create a contingency table


From   Jean-Benoit Hardouin <[email protected]>
To   [email protected]
Subject   Re: st: create a contingency table
Date   Wed, 05 Nov 2003 00:28:49 +0100

Thank you Nick, but my question is :
How to obtain a data table and not to display the results ?
How, with a simple syntax, create the variables of the second table ?
Jean-Benoit Hardouin

On Tue, 4 Nov 2003 23:05:33 -0000, Nick Cox <[email protected]> wrote:

Jean-Benoit Hardouin

I search a method to transform a data as :
Item1 Item2 Item3 Item4 0 0 1 2 1 3 0 1
3 0 2 1

(table of the responses of individuals to four items) in
Item1 Item2 Item3 Item4 Count
0 0 0 0 125
0 0 0 1 88
0 0 0 2 72
0 0 0 3 52
0 0 1 0 28
0 0 1 1 65
0 0 1 2 42
...

where 125 is the number of individuals who have respond 0 to each
item, 88
is the number of individuals who have respond 0 to the first three
item and
1 to the last item, etc.

I don't find how to obtain this kind of table with "reshape" or
"egen" (for
example).

I have idea to program that with four "forvalues..." but perhaps it
exist a
specific command.
For a first-principles solution:

bysort Item? : gen Count = _N
by Item? : gen tag = _n == 1
list Item? Count if tag

For a canned solution, with extra bells and whistles:

ssc inst groups
groups Item? , show(f) showhead(Count)
whelp groups

Nick
[email protected]

*
*   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/




--
Jean-Benoit Hardouin
37, rue Arrachart
41000 Blois
tél : 02 54 45 39 75
email : [email protected]
http://www.jb-hardouin.fr.st
http://www.anaqol.fr.st
*
*   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