Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: median of consecutive groups - avoiding loops |
Date | Wed, 11 May 2011 23:19:15 +0100 |
This code won't work for various reasons. One is that the groups produced are disjoint, but they should overlap. On Wed, May 11, 2011 at 11:06 PM, daniel klein <klein.daniel.81@googlemail.com> wrote: > I guess in most situations there is a way to work around. > > Try > > g int new_group = cond(mod(group, 2), group, group-1) > bys new_group : egen median = median(value) > > However, in general I think there is no way you can use Stata > efficiently without loops. > * * 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/