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

RE: st: how do i increment a counter


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: how do i increment a counter
Date   Wed, 31 Aug 2005 22:15:34 +0100

This is true, but note also that 

foreach a of numlist 1/20 { 
	di `a' 
} 

is a cleaner way to get the same output, as is 

forval a = 1/20 { 
	di `a' 
} 

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

Christian Holz
 
> Annemarie,
> your example seems to be quite confused... a good advice might be to 
> make sure that you truly understand the differences between variables 
> and macros - the code you presented gives the impression that you 
> confuse these concept a bit.
> Implementing a counter in Stata, however, is pretty easy. Try 
> something like
> 
> local i=0
> foreach a of numlist 1/20 {
>    local i=`i'+1
>    di `i'
> }
> 
> If you'd provide some more detail on what you're planning to do some 
> more advice could potentially be given.
 
aine dooley wrote:

> > I am finding in Stata that there does not seem to be an easy way to 
> > increment a counter despite countless trys and readings of 
> the manal.
> > 
> > I want to do something llike the following, this is just an example:
> > 
> > generate byte total_sum =0
> > 
> > for each variable of varlist {
> > if age > 50
> >    total_sum = total_sum + age
> > }
> > 
> > Stata doesn't seem to allow the if... then construct unless 
> it is in a 
> > program. Although I have written a simple program (crazy 
> that I have to 
> > do this) passing arguments, I still can't get it to work.

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