Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, 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:36:54 +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/ * * 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/

- Prev by Date:
**AW: st: xtmixed with option residuals** - Next by Date:
**st: Unable to open .smcl file** - Previous by thread:
**st: xtlogit, margins & xtrho** - Next by thread:
**st: Can GLLAMM Allow for Autocorrelation?** - Index(es):