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

st: RE: table help


From   "Nick Cox" <[email protected]>
To   <[email protected]>
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 
[email protected] 

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