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

From |
Roberto Mura <roberto.mura3@tin.it> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: Fwd: Neverending loop.... |

Date |
Thu, 12 Dec 2002 17:41:13 +0100 |

Hi everyone I am a PHD student in Economics in York University (UK). I have been working on a do file, trying to re-rank some 60 variables I have in my database. My problem is that i cannot make my loop a "smart" loop so to speak. My re-ranking do file (is probably very inefficient because i am relatively new to Stata) is based on pair-wise differences among variables. So I need Stata to keep on performing the series of programs I wrote until the condition that none of these 59 differences is negative. I have been able to create a "dumb loop" like: local i=1 while `i' <=23 { set more off quietly zero quietly primo quietly secondo finale_bis display `i' local i=`i'+1 }

it takes 23 iterations until all differences are >=0

What I would need is for stata to do something like

while diff1<0 | diff2<0 | diff3<0 | diff4<0 | diff5<0 |diff6<0 |diff7<0 |diff8<0 |diff9<0 |diff10<0 | diff11<0 | diff12<0 | diff13<0 | diff14<0 | diff15<0 |diff16<0 |diff17<0 |diff18<0 |diff19<0 |diff20<0 | diff21<0 | diff22<0 | diff23<0 | diff24<0 | diff25<0 |diff26<0 |diff27<0 |diff28<0 |diff29<0 |diff30<0 | diff31<0 | diff32<0 | diff33<0 | diff34<0 | diff35<0 |diff36<0 |diff37<0 |diff38<0 |diff39<0 |diff40<0 | diff41<0 | diff42<0 | diff43<0 | diff44<0 | diff45<0 |diff46<0 |diff47<0 |diff48<0 |diff49<0 |diff50<0 | diff51<0 | diff52<0 | diff53<0 | diff54<0 | diff55<0 |diff56<0 |diff57<0 |diff58<0 |diff59<0 { set more off quietly zero quietly primo quietly secondo finale_bis }

Now, for some reason I cannot explain myself, it works for only 9 iterations and then it stops. So it is not "understanding" the if condition properly.This statement is reinforced by the fact that if I run this when only, say, 3 more iterations are needed it does nothing as after the first nine.

The third and last way I could come up with was to "encapsulate" that huge if condition into a single variable......

by firm: gen elio=1 replace elio=0 if diff1<0 | diff2<0 | diff3<0 | diff4<0 | diff5<0 |diff6<0 |diff7<0 |diff8<0 |diff9<0 |diff10<0 | diff11<0 | diff12<0 | diff13<0 | diff14<0 | diff15<0 |diff16<0 |diff17<0 |diff18<0 |diff19<0 |diff20<0 | diff21<0 | diff22<0 | diff23<0 | diff24<0 | diff25<0 |diff26<0 |diff27<0 |diff28<0 |diff29<0 |diff30<0 | diff31<0 | diff32<0 | diff33<0 | diff34<0 | diff35<0 |diff36<0 |diff37<0 |diff38<0 |diff39<0 |diff40<0 | diff41<0 | diff42<0 | diff43<0 | diff44<0 | diff45<0 |diff46<0 |diff47<0 |diff48<0 |diff49<0 |diff50<0 | diff51<0 | diff52<0 | diff53<0 | diff54<0 | diff55<0 |diff56<0 |diff57<0 |diff58<0 |diff59<0

while elio ==1 { quietly drop elio set more off quietly zero quietly primo quietly secondo finale_bis by firm: gen elio=1 replace elio=0 if diff1<0 | diff2<0 | diff3<0 | diff4<0 | diff5<0 |diff6<0 |diff7<0 |diff8<0 |diff9<0 |diff10<0 | diff11<0 | diff12<0 | diff13<0 | diff14<0 | diff15<0 |diff16<0 |diff17<0 |diff18<0 |diff19<0 |diff20<0 | diff21<0 | diff22<0 | diff23<0 | diff24<0 | diff25<0 |diff26<0 |diff27<0 |diff28<0 |diff29<0 |diff30<0 | diff31<0 | diff32<0 | diff33<0 | diff34<0 | diff35<0 |diff36<0 |diff37<0 |diff38<0 |diff39<0 |diff40<0 | diff41<0 | diff42<0 | diff43<0 | diff44<0 | diff45<0 |diff46<0 |diff47<0 |diff48<0 |diff49<0 |diff50<0 | diff51<0 | diff52<0 | diff53<0 | diff54<0 | diff55<0 |diff56<0 |diff57<0 |diff58<0 |diff59<0 }

but that's where I get into a never ending loop! finale_bis produces the number of differences (count if.....) still negative but, after reaching the zero, it keeps on performing the operations.

Thank you all very much for your kind attention

Best regards Ciao

********************************************************************

Roberto Mura

address in the UK

22, Turners Croft

Heslington

York

YO105EL

tel: 0044 (0)1904 412 869

indirizzo in Italia

via Capo Sandalo 4

09042 Monserrato, Cagliari

work related email: rmura@unica.it

roberto.mura@crenos.it

rm143@york.ac.uk

personal email: fellowsh@tiscali.it

fellowsh@libero.it

roberto.mura3@tin.it

********************************************************************

*

* 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**:**st: RE: Fwd: Neverending loop....***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: RE: RE: [programming] using -if- in do file** - Next by Date:
**st: RE: RE: RE: [programming] using -if- in do file** - Previous by thread:
**st: RE: RE: [programming] using -if- in do file** - Next by thread:
**st: RE: Fwd: Neverending loop....** - Index(es):

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