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

st: implementing a counter


From   Kit Baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: implementing a counter
Date   Wed, 31 Aug 2005 16:36:18 -0400

Annemarie said

> generate byte total_sum =0
>
> for each variable of varlist {
> if age > 50
> total_sum = total_sum + age
> }
>

This looks like syntax from some alternative software where you have to loop over the observations. You never have to do that in Stata to generate a summary statistic. If what you mean is the sum of the observations on age conditional on age>50,

summarize age if age>50
scalar sumage = r(sum)
display "The sum is " sumage

If you are trying to compute a number, store it as a scalar, not in a new Stata variable.

Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html


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