Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: summary statistics


From   Clyde B Schechter <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: summary statistics
Date   Mon, 1 Oct 2012 16:14:11 +0000

Don Spady was looking for a command that would take variables HSS1-HSS18, each with a discrete 1 to 5 response set and create a table like:

                Col 1    Col2     Col 3    Col 4   Col5
HSS1        n1            n2            n3             n4           n5
HSS2        n1            n2            n3             n4           n5
HSS3

And Nick Cox pointed him to a user-written command that does this.

I would just add that this can also be easily done using a few built-in Stata commands:

(I assume there is another variable, called id, which identifies the observations.  If not, it can be generated first)

reshape long HSS, i(id) j(varnum)
collapse (count) Col = id, by(varnum HSS)
reshape wide Col, i(varnum) j(HSS)
gen variable= "HSS"+string(varnum)
list variable Col*, noobs clean


I suppose it is a matter of taste which way to do these things.  In general, if it is something I do repeatedly, I find the convenience of a single command (which I might write an ado file for myself) worthwhile.  But if it's a one-off, it's generally faster to write a few lines of code and also not later be bothered with trying to remember what some unfamiliar command name means.

Clyde Schechter
Albert Einstein College of Medicine
Bronx, New York, USA


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index