[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: Multiple commands under "By varlist"? |

Date |
Sat, 26 Jun 2004 09:57:20 -0400 |

Thanks Nick, I tried the -statsby- command as Scott Merryman suggested and the -forval- command that you are suggesting. But both these take almost exactly the same amount of time as the -while- looping command... (Given my program code, each simulation round is taking about 240-330 seconds, and I have got 1000 simulation rounds, if not more). The -by- command is so much faster than the -while- command... If I compare by month: regress returns factor vs. local i = 1 while i <= 1000 { regress returns factor if `i' == month local i = `i' + 1 } I find that the -by- command is atleast 15-20 times faster than the -while- loop. Given this, it would be really wonderful to be able to execute multiple commands under -by-... Some wishful thinking! ----- Original Message ----- From: "Nick Cox" <n.j.cox@durham.ac.uk> To: <statalist@hsphsun2.harvard.edu> Sent: Saturday, June 26, 2004 8:18 AM Subject: st: RE: Multiple commands under "By varlist"? > The short answer is that -by:- cannot > be extended in this way. But there > are several nearly equivalent procedures. > > Scott Merryman suggested -statsby- > which is one good answer. You may > or may not want the data reduction > (collapsing of the data) that produces. > > You could write a program to be "byable". > That way, an arbitrarily complex operation > can be carried out by your own program. > > For this kind of example, however, an approach > based on -forval- or -foreach- is indicated. > You may want something like > > gen tintcp = . > gen tslope = . > forval i = 1/12 { > regress returns factor if month == `i' > replace tintcp = _b[_con] if month == `i' > replace tslope = _b[factor] if month == `i' > } > > There is a much fuller discussion at > http://www.stata.com/support/faqs/data/foreach.html > > Nick > n.j.cox@durham.ac.uk > > Subhankar Nayak > > > > Is it possible to give multiple commands following a particular > > by varlist command? > > > > Can I give something like: > > > > by month: { > > regress returns factor > > replace tintcp = _b[_con] > > replace tslope = _b[factor] > > } > > > > > > Of course, what I give here is not working, but is there > > anyway to make it functional? > > * > * 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/ > * * 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: Re: RE: Multiple commands under "By varlist"?***From:*"Michael Blasnik" <michael.blasnik@verizon.net>

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

- Prev by Date:
**st: RE: RE: Avoiding loops (the while loop)** - Next by Date:
**st: RE: RE: Re: RE: Multiple commands under "By varlist"?** - Previous by thread:
**st: RE: Multiple commands under "By varlist"?** - Next by thread:
**st: 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 |