[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
Johannes Geyer <JGeyer@diw.de> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Re: Loop syntax |

Date |
Thu, 27 Mar 2008 10:06:10 +0100 |

> gen tcount=0 > forvalues i=1/236{ > forvalues j=1/57{ > if patient==`i' & t>0 { > then tcount==tcount+1 > continue > } > } > } One question was, why this loop did not work. Vladimir gave the following answer: > Talking just on a syntax matter, -then tcount==tcount+1- is incorrect. > If you need just a number at the end, announce a local first before > the loop and then increment this local within the loop: > local tcount=0 > forvalues <...> { > if <...> { > local ++tcount > } > } < di `tcount' I understand that this (a local) is more efficient than creating a variable but I cannot see the mistake. I guess the loop does not work as it is expected because "if" is used as a command and not as a qualifier: http://www.stata.com/support/faqs/lang/ifqualifier.html . The loop would look like this if you used "if" as a qualifier: local tcount=0 forvalues i=1/236{ forvalues j=1/57{ local ++tcount if patient==`i' & t>0 continue } } } -- @Nick: What is the difference between -total()- and -sum()- that makes the latter better than the other? Johannes * * 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/

**Follow-Ups**:**Re: st: Re: Loop syntax***From:*Maarten buis <maartenbuis@yahoo.co.uk>

**References**:**Re: st: Re: Loop syntax***From:*"Vladimir Vakhitov" <vvakhitov@gmail.com>

- Prev by Date:
**st: RE: xtivreg2 with clustered standard errors - very high first stage F** - Next by Date:
**Re: st: parameterising strs to avoid cumulative relative survival increase** - Previous by thread:
**Re: st: Re: Loop syntax** - Next by thread:
**Re: st: Re: Loop syntax** - Index(es):

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