Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Biljana Dlab" <dlab@isb.uzh.ch> |

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

Subject |
st: simplifying foreach loop |

Date |
Mon, 11 Oct 2010 21:33:26 +0200 |

Dear Statalist, I have firms sorted by SIC from 2000-3999 and would like to compute the 3-digit industry median. How do I simplify this loop, so that the increment in sic_n are increasing by 10 without writing out every line? . foreach v of var r_d { 2. gen d`v'=. 3. by sic_n, sort: egen datmedian=median(r_d) if sic_n>=2010 & sic_n<=2019 4. by sic_n, sort: egen datmedian=median(r_d) if sic_n>=2020 & sic_n<=2029 5. by sic_n, sort: egen datmedian=median(r_d) if sic_n>=2030 & sic_n<=2039 6. by sic_n, sort: egen datmedian=median(r_d) if sic_n>=2040 & sic_n<=2049 7. by sic_n, sort: egen datmedian=median(r_d) if sic_n>=2050 & sic_n<=2059 8. by sic_n, sort: egen datmedian=median(r_d) if sic_n>=2060 & sic_n<=2069 9. by sic_n, sort: egen datmedian=median(r_d) if sic_n>=2070 & sic_n<=2079 (...) till by sic_n, sort: egen datmedian=median(r_d) if sic_n>3990 & sic_n<3999 } Thanks a lot. Best, Biljana * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**st: RE: simplifying foreach loop***From:*Nick Cox <n.j.cox@durham.ac.uk>

**References**:**Re: st: twoway lfit and time series operators***From:*vwiggins@stata.com (Vince Wiggins, StataCorp)

**Re: st: twoway lfit and time series operators***From:*"David Cancel" <dacancel@ucsd.edu>

- Prev by Date:
**RE: st: twoway lfit and time series operators** - Next by Date:
**AW: st: xtmixed with option residuals** - Previous by thread:
**RE: st: twoway lfit and time series operators** - Next by thread:
**st: RE: simplifying foreach loop** - Index(es):