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

st: implementing a counter

From   Kit Baum <>
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

* For searches and help try:

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