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

st: RE: about sums


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: about sums
Date   Thu, 31 Mar 2005 18:28:23 +0100

-summarize- calculates the sum, but does not present it. 
This is documented at [R] summarize p.153. 

Here is a quick hack. 

program mysum
	version 8 
	syntax varlist(numeric) [if] [in] 
	marksample touse 
	qui count if `touse' 
	if r(N) == 0 error 2000 

	di 
	foreach v of local varlist { 
		su `v' if `touse', meanonly 
		di as txt "`v'{col 33}" as res %12.0g r(sum) 
	}
end 

e.g. mysum <varlist> 

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

Rodrigo Briceno
 
> I was reviewing the manuals and FAQs and I 
> didn't find a solution for my need.
> I have a file with 42 variables and 1 million observations, 
> and I would like
> to have the sum of the values for each variable in the same 
> table. Let's say:
> 
> Variable	sum
> X		200
> Y		300
> Z		2000
> ZZ		5000, etc.
> 
> What can I use in Stata 8 for that purpose? Summarize has 
> some statistics,
> but no sum of variables seem to appear.

*
*   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