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

st: RE: table help


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: table help
Date   Fri, 12 Dec 2003 13:38:06 -0000

Without a -stack- or -reshape-, I guess
it's knit-your-own. Here's a sketch (not tested). 

qui foreach v of var x1-x5 { 
	gen pc`v' = . 
	foreach i of num 1/4 { 
		count if `v' == `i' 
		replace pc`v' = r(N) in `i' 
	} 
	su pc`v', meanonly 
	replace pc`v' = 100 * pc`v' / r(sum) 
} 
gen value = _n 
list value pc* in 1/4 

Nick 
n.j.cox@durham.ac.uk 

Steven Stillman 
 
> Hi.  I am trying to create a one-way table which is causing 
> me problems.  I
> have 5 version of the same variable (let's call them X1, 
> X2, etc) which take
> on the same 4 categories.  I am trying to get a table that 
> looks like:
> 
> categories	x1	x2	x3	x4	x5
> 1		10%	15%
> 2		20%	25%
> 3		30%	25%
> 4		40%	35%
> 
> etc.
> 
> Does anyone have a solution for creating this table that 
> doesn't involve
> reshaping the data (this is dimensionality issue, the data 
> already has
> 20,000 obs * 64 time-periods of  records)?  This seems like 
> it should have a
> simple answer but I have yet to find it.

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index