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]

Re: st: too many values for -tabulate twoway, summarize-, but not -tabulate twoway-


From   Eric Booth <[email protected]>
To   [email protected]
Subject   Re: st: too many values for -tabulate twoway, summarize-, but not -tabulate twoway-
Date   Wed, 4 Apr 2012 11:54:20 -0500

<>

When you introduce the summarize() option to include the mean, SD, and Freq in the -tabulate- table cells, you hit a similar issue with Stata limits as if you tried to -tabulate- 2 categorical variables with too many categories (see -help limits- for -tabulate- and -tabulate, summarize- to those limitations).

2 solutions you might consider: (1) subset the data you run in a single -tabulate, summarize- or (2) create your table using other commands (like -collapse- and -reshape- below).


******************!
clear
set obs 10000
g x = int(runiform()*50)
g by = int(runiform()*20)
g w = int(runiform()*100)
g y = runiform()


**This works without an error:
tab x by [aw=w]

**While this gives me r(134):
	**adds  Means, Standard Deviations, Frequencies to table cells
**tab x by [aw=w] , sum(y) //doesnt work

**1. subset your data:	
tab x by [aw=w] in 1/100, sum(y) mean //works
tab x by [aw=w] in 101/200, sum(y) mean //or use [if] 

*2. or collapse & reshape:
preserve
 collapse (mean) y (sd) ysd=y [aw=w], by(x by)
 reshape wide y ysd, i(x) j(by)
	**outsheet, export, etc.
restore
******************!


- Eric
__
Eric A. Booth
Public Policy Research Institute 
Texas A&M University
[email protected]
+979.845.6754

On Apr 4, 2012, at 11:25 AM, László Sándor wrote:

> Hi,
> 
> I am still fiddling around with -tab, sum()- (using Stata MP 12.1 for
> mac). I encountered some curious behavior that I could not track down.
> 
> This works without an error:
> tab x by [aw=w]
> 
> While this gives me r(134):
> tab x by [aw=w], sum(y)
> 
> Why should there be a difference? Are these limits documented somewhere?
> 
> FWIW, at the end I paste how I generated data for my particular test run.
> 
> Thanks,
> 
> Laszlo
> 
> For reference, here is the help on this error:
> 
> [P]     error . . . . . . . . . . . . . . . . . . . . . . . .  Return code 134
>        too many values;
>        1) You attempted to encode a string variable that takes on
>        more than 65,536 unique values.  2) You attempted to tabulate
>        a variable or pair of variables that take on too many values.
>        If you specified two variables, try interchanging them.
>        3) You issued a graph command using the by option.  The
>        by-variable takes on too many different values to construct
>        a readable chart.
> 
> 
> set obs 1000
> set seed 19821009
> g y = rnormal()
> g y2 = rnormal()
> g by = y2 > 0.5
> g w = runiform()
> g x = runiform()
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/


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


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