Statalist The Stata Listserver


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

Re: st: generate max of past values


From   [email protected]
To   [email protected]
Subject   Re: st: generate max of past values
Date   Tue, 27 Jun 2006 07:27:07 -0500

Do you mean something like this:

sysuse auto,clear
gen time = _n
tsset fore time
sort fore time
gen max_mpg = mpg
replace max = max(l.mpg, l.max ,max)

or just:

egen max2 = max(mpg), by(fore)


Note:  The expression "l0.x&l1.x&l3.x" is a logical operation that 
will return 1 if it is true - it will interpret any nonzero values as 
true and zero as false.  See [U] 13 Functions and expressions.

Scott


----- Original Message -----
From: Thomas <[email protected]>
Date: Tuesday, June 27, 2006 6:19 am
Subject: st: generate max of past values
To: [email protected]

> Dear all,
> 
> I am trying to get the maximum of all past or present values, i.e.
> 
> x[i] = max x[j, j<=i]
> 
> I tried the following commands:
> 
> bysort id (yr): egen x1 = max(l0.x&l1.x&l3.x), which returns 1 
> instead 
> of the max,
> and
> bysort id (yr): egen x1 = max(l(0/3).x), which produces an error.
> 
> Any idea on how to do this correctly?
> 
> Many thanks,
> 
> Thomas


*
*   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