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

From |
"Subhankar Nayak" <nayak@bellsouth.net> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: Re: RE: Re: RE: Multiple commands under "By varlist"? |

Date |
Sat, 26 Jun 2004 10:53:17 -0400 |

Nick, Yes, that's a very interesting point that I had missed. I now see why -while- is so inefficient: it reads such a huge fraction of unneccesary observations. I can avoid that by more efficient treatment of the observation: avoid reading all those unneccesary observations repeatedly. Thanks for the very important tip. Subh ----- Original Message ----- From: "Nick Cox" <n.j.cox@durham.ac.uk> To: <statalist@hsphsun2.harvard.edu> Sent: Saturday, June 26, 2004 10:22 AM Subject: st: RE: Re: RE: Multiple commands under "By varlist"? > Interesting, but your interpretation of the timings > conflates two distinct issues. Also, it should not be > generalised without care. > > 1. The interpretative overhead of -while- > (e.g. as compared to -forval- or -by:- > when the approaches are comparable). > > 2. The way -if- is implemented. The > command > > regress returns factor if `i' == month > > is implemented by testing every observation > to see whether it should be included in > the regression. In your case 99.9% of > the observations are irrelevant to each > regression, but Stata takes no special > action to avoid that. You should be > able to substitute -if- by -in-: > > gen long obsno = _n > sort month port > forval i = 1/1000 { > local min = ... > local max = ... > regress returns factor in `min'/`max' > ... > } > > and by Blasnik's Law this should be much faster. > > In short, your -while- loop is slow mostly > because of what happens within it, or so > I guess. > > Note that my code was based, in the absence > of precise information, on a guess that > -month- took on 12 distinct values. As > your -month- variable takes on 1000 values, > other approaches become very competitive. > That is, doing something 12 times, on > each which 11/12 of the data are irrelevant, > is not the same as doing something 1000 > times, on each of which 999/1000 of the > data are irrelevant. > > You comment > > > Given this, it would be really wonderful to be able to > > execute multiple commands under -by-... > > Some wishful thinking! > > but this isn't wishful thinking at all, as I indicated, > so long as you are willing to do programming. > See help -byable-. > > Nick > n.j.cox@durham.ac.uk > * * 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/

**References**:**st: RE: Re: RE: Multiple commands under "By varlist"?***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: RE: Re: RE: Re: RE: Multiple commands under "By varlist"?** - Next by Date:
**st: Re: Re: Re: Re: RE: Multiple commands under "By varlist"?** - Previous by thread:
**st: RE: Re: RE: Multiple commands under "By varlist"?** - Next by thread:
**st: RE: Re: RE: Re: RE: Multiple commands under "By varlist"?** - Index(es):

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