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

st: Re: linear filter (moving average)


From   Christopher Baum <[email protected]>
To   [email protected]
Subject   st: Re: linear filter (moving average)
Date   Tue, 13 May 2003 06:55:43 -0400

On Tuesday, May 13, 2003, at 02:33 AM, Ernest wrote:

I had the same kind of problem, and I tackled that with a simple "generate"
and explicit subscripting.
Essential is it that the data are in long format, and that you sort on the
timevariable first.

bysort (QUARTER): gen zkd_smooth4 = ( PLOTVAR[_n] + PLOTVAR[_n-1]
+ PLOTVAR[_n-2] + PLOTVAR[_n-3] )/4


This solution requires a good deal of the user, and will not work at all on panel data. The filter function of egenmore (ssc install egenmore) is a much safer solution:

filter(timeseriesvar) , lags(numlist) coef(numlist) [ { normalise
| normalize } ] calculates the linear filter which is the sum of terms

coef_i * Li.timeseriesvar or coef_i * Fi.timeseriesvar

filter(y), l(0/3) c(0.4(0.1)0.1) calculates

0.4 * y + 0.3 * L1.y + 0.2 * L2.y + 0.1 * L3.y

Leads are specified as negative lags. normalise (or normalize,
according to taste) specifies that coefficients are to be divided by
their sum so that they add to 1 and thus specify a weighted mean.

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