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

RE: st: RE: (Moving Maximum in Unbalanced panel) Max of a variable in the last 12 months?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: (Moving Maximum in Unbalanced panel) Max of a variable in the last 12 months?
Date   Wed, 6 Jul 2005 22:44:31 +0100

Better as e.g. 

gen max = x 
forval i = 1/11 { 
	replace max = max(max, l`i'.x) 
} 

Nick 
[email protected] 

Nick Cox

> For just 12 previous months, you could try 
> 
> forval i = 1/12 { 
> 	gen lag`i' = l`i'.x 
> 	local lagvars = cond(`i' < 12, "`lagvars'lag`i',", 
> "`lagvars'lag`i'") 
> }
> gen max = max(`lagvars') 
> 
> If your definition includes the present month, 
> you could try 
> 
> local lagvars 
> forval i = 1/11 { 
> 	gen lag`i' = l`i'.x 
> 	local lagvars = cond(`i' < 11, "`lagvars'lag`i',", 
> "`lagvars'lag`i'") 
> }
> gen max = max(x, `lagvars') 
> 

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