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/