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

st: RE: about sums

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

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

e.g. mysum <varlist> 

[email protected] 

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:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index