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

st: RE: RE: RE: RE: ci, return lists, and statsby commands


From   "Wallace, John" <John_Wallace@affymetrix.com>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: RE: RE: ci, return lists, and statsby commands
Date   Tue, 30 Sep 2003 10:36:27 -0700

Thanks for the reply, Nick.  I guess I have a more general question about
how to compile the results of a series of tests and display them in a single
summary.  Can you point me to a reference that discusses building an array
of values and then performing operations on the array?  Your suggestion
about doing -statsby- for each variable and then merging the results seems
like a step in that direction, but rather than using a series of saved
datasets can you put the results into memory somewhere, merge them, then
save the final result?  There may be no advantage to doing this, other than
not having a bunch of intermediate variable.dta files to delete.

-----Original Message-----
From: Nick Cox [mailto:n.j.cox@durham.ac.uk] 
Sent: Tuesday, September 30, 2003 4:18 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: RE: RE: ci, return lists, and statsby commands

Wallace, John
> 
> Sorry for the cryptic original message.  The problem arises 
> when you have
> more than one variable you're using ci on:
> 
> . sysuse auto 
> . statsby "ci price mpg" mean = r(mean) upper = r(ub) lower = r(lb)
> foldrange = (r(ub)/r(lb)), by(for)
> 
> The output will only show the data for mpg, the price data 
> gets overwritten
> before statsby acts on it.
> 
> Is there some sort of dataset structure I could use to loop 
> through a series
> of variables summarizing them with -ci- and tabulating the 
> r() values?

Here's one way. Another way would be to 
do -statsby- separately for each variable 
and -merge- the results. Another way 
would be to -stack- your responses into 
one variable and then apply -statsby-. 
There are, no doubt, yet other ways. 

qui foreach v of var price mpg { 
	gen `v'mean = . 
	gen `v'upper = . 
	gen `v'lower = . 
	levels foreign, local(F) 
	foreach f of local F { 
		ci `v' if foreign == `f' 
		replace `v'mean = r(mean) if foreign == `f'
		replace `v'upper = r(ub) if foreign == `f'
		replace `v'lower = r(lb) if foreign == `f' 
	}
} 	

Nick 
n.j.cox@durham.ac.uk 
*
*   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/
*
*   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–2022 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index