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

Re: st: A query about min in stata

From   Nick Winter <[email protected]>
To   [email protected]
Subject   Re: st: A query about min in stata
Date   Fri, 22 Aug 2008 11:48:33 -0400

Combining fun/elegance and speed, perhaps:

forval i=1/9 {
  local list `list',L`i'.r
gen min=min(r,`list')

--Nick Winter

Nick Cox wrote:
As a curiosity note this alternative:
gen min = r qui forval i = 1/9 { replace min = min(min, L`i'.r) }
I'll guess that it will be slower, but it looks more fun.
The tedious solution of just writing out all the terms is probably
Nick [email protected]
Eva Poen

if you can -tsset- your data, you could do

gen min = min(r, L1.r, L2.r, L3.r)

etc. up to L9.r. If your data are not a time series or a panel, you
can still generate a row identifier and -tsset- on that:

gen id = _n
tsset id

2008/8/22 Ashim Kapoor <[email protected]>:

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 ?
*   For searches and help try:
Nicholas Winter                                 434.924.6994 t
Assistant Professor                             434.924.3359 f
Department of Politics                  [email protected] e
University of Virginia w
PO Box 400787, 100 Cabell Hall
Charlottesville, VA 22904

*   For searches and help try:

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