Statalist


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

st: RE: A query about min in stata


From   philippe van kerm <philippe.vankerm@ceps.lu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: A query about min in stata
Date   Fri, 22 Aug 2008 13:16:02 +0200

Not sure I understand the problem. What you suggest, that is

  sysuse auto
  gen minimum  = min(price, price[_n-1], price[_n-2], price[_n-3], price[_n-4], price[_n-5], price[_n-6], price[_n-7], price[_n-8], price[_n-9]) if _n>=9

... seems to do what you ask for.

HTH
Philippe



> -----Message d'origine-----
> De : owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] De la part de Ashim Kapoor
> Envoyé : vendredi 22 août 2008 12:43
> À : statalist@hsphsun2.harvard.edu
> Cc : surjit.bhalla@oxusinvestments.com
> Objet : st: A query about min in stata
>
> Hello everyone,
>
> I am trying to do the following : -
>
> I have a variable r. I want to create a variable m=min( r, r[_n-1],
> ... ,r[_n-9])
>
> I guess I can use a while loop to do this but that is quite slow.
> An
> alternative would be to define r0=r,r1=r[_n-1],..,r9=r[_n-9]
> and then say m=rmin ( r0 r1 ... r9).
>
> My question is that is there a built in way in stata to do this ?
> like
> say by using egen ?
>
> Thank you all for your time and effort.
>
> Ashim. : )
> *
> *   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/



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