Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: "record" values (high- or low-water marks)


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: Re: "record" values (high- or low-water marks)
Date   Mon, 14 Jul 2003 16:05:14 -0400

On Saturday, Jul 12, 2003, at 02:33 US/Eastern, Bayard wrote:

I have variables Category, Date and Amount and I need to generate two new
variables described as follows.

minAmount = smallest Amount in Category as of Date
maxAmount = largest Amount in Category as of Date


Example:
Category Date Amount min max
1 1/1/2001 50 50 50
2 1/1/2001 100 100 100
1 1/2/2001 52 50 52
2 1/2/2001 98 98 100
1 1/3/2001 47 47 52
2 1/3/2001 105 98 105
1 1/4/2001 55 47 55
2 1/4/2001 93 93 105

I've looked, but I can't come up with the right gen or egen commands and
I've not yet tackled programming. I'm hoping someone can spot some tricky
way of accomplishing this.

Any help would be appreciated.
ssc install egenmore

. egen maxi=record(amount), by(category)

. egen mini= record(-amount), by(category)

. replace mini=-mini
(8 real changes made)

. list

     +--------------------------------------------+
     | category       date   amount   maxi   mini |
     |--------------------------------------------|
  1. |        1   1/1/2001       50     50     50 |
  2. |        2   1/1/2001      100    100    100 |
  3. |        1   1/2/2001       52     52     50 |
  4. |        2   1/2/2001       98    100     98 |
  5. |        1   1/3/2001       47     52     47 |
     |--------------------------------------------|
  6. |        2   1/3/2001      105    105     98 |
  7. |        1   1/4/2001       55     55     47 |
  8. |        2   1/4/2001       93    105     93 |
     +--------------------------------------------+


Kit

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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