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

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


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: ci, return lists, and statsby commands
Date   Tue, 30 Sep 2003 12:17:33 +0100

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 
[email protected] 
*
*   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