# One-sided HP filter

**URL:** <https://forum.dynare.org/t/one-sided-hp-filter/3976>\
**Category:** ML/Bayesian estimation\
**Created:** [18 June 2014 12:40 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976 "2014-06-18T12:40:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![brasidas1](https://forum.dynare.org/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brasidas1](https://forum.dynare.org/u/brasidas1)\
**Post date:** [18 June 2014 12:40 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/1 "2014-06-18T12:40:23Z")

</div>

Hi,

I hope I’m posting the question in the right part of the forum. Johannes Pfeifer discusses the one-sided HP filter in his guide to observation equations (thanks Johannes, I found it very useful) and mentions that the resulting de-trended variable will always have a mean of zero.  
I have been using the add-in from Eviews to carry this out as well as the Matlab file from the file exchange and both yield identical, but not mean-zero, output. I could of course de-mean the result but it’s somewhat puzzling.

Does anyone have any suggestions?  
Many thanks

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [18 June 2014 13:32 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/2 "2014-06-18T13:32:30Z")

</div>

Which Matlab file are you talking about? Most HP filters provide the trend component as the first argument. This one is not mean zero. Only the cyclical component is mean zero.

---

<div class="post-metadata">

**Author:** ![brasidas1](https://forum.dynare.org/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brasidas1](https://forum.dynare.org/u/brasidas1)\
**Post date:** [18 June 2014 14:22 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/3 "2014-06-18T14:22:41Z")

</div>

Dear Johannes,

Thank you for your reply.  
All I did was  
[Ytrend, Yobs] = one\_sided\_hp\_filter\_serial(log(Y))

where Yobs gives the cyclical component. Alternatively, Yobs = 100\*(log(Y)-Ytrend) still gives the same output, which has a non-zero mean.

The Matlab file came from ([ideas.repec.org/c/dge/qmrbcd/181.html](http://ideas.repec.org/c/dge/qmrbcd/181.html)) and the Eviews add-in (from their website) gives identical results.  
[us\_gdp1.xls](https://forum.dynare.org/uploads/default/original/2X/d/d862bdb4a6f067e6685a416820743ce8736576df.xls) (33.5 KB)  
[one\_sided\_hp\_filter\_kalman.m](https://forum.dynare.org/uploads/default/original/2X/0/0135597d67e5f80a3d8ac204e833ef152523a6b9.m) (5.38 KB)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [18 June 2014 15:45 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/4 "2014-06-18T15:45:30Z")

</div>

Because of the Kalman filtering approach, the sample mean of the trend component is always approximately zero (and not exactly zero as for HP-filtering) and becomes closer to zero the longer the data series (asymptotically). I will update the guide accordingly. Thanks for pointing this out.

---

<div class="post-metadata">

**Author:** ![Cyy](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/e480ec/32.png) [@Cyy](https://forum.dynare.org/u/Cyy)\
**Post date:** [21 March 2018 13:46 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/5 "2018-03-21T13:46:32Z")

</div>

Continuing the discussion from [One-sided HP filter](https://forum.dynare.org/t/one-sided-hp-filter/3976/4):

Hello, I also meet with this problem. After the one-side hp filter, the de-trended series of log gdp isn’t stationary and the mean isn’t zero either. This may be due to the low number of observations in my datafile. So should i demean the de-trended series(that is the hpcycle series)? However, after I demean the HPcycle series, it is still non stationary. My model is Log-linearisation, so the gdp is the log deviation from steady state. The observation series should also be mean zero and stationary. so how can i solve this problem?

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [22 March 2018 18:50 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/6 "2018-03-22T18:50:20Z")

</div>

What do you mean? Having a small non-zero constant is normal and can usually be tolerated. But having the data not be stationary is (almost) impossible. How do you judge it is not stationary?

---

<div class="post-metadata">

**Author:** ![Cyy](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/e480ec/32.png) [@Cyy](https://forum.dynare.org/u/Cyy)\
**Post date:** [22 March 2018 23:44 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/7 "2018-03-22T23:44:01Z")

</div>

Thanks for your reply. First I have the gdp data. Then I do the seasonal adjustment. After that I take the log form. The log gdp is stationary by the test of ADF using eviews. Then I use the one side hp filter to filter the log gdp and keep the cycle term by eviews. However, when i do the ADF test of the cycle terms, It shows that the p value is 0.34. So it is non stationary.

The real gdp data is as following. Really hope for your kind help.

| 2000-03 | 213.299 |
| --- | --- |
| 2000-06 | 248.8002441 |
| 2000-09 | 261.3800708 |
| 2000-12 | 294.7115773 |
| 2001-03 | 242.1917786 |
| 2001-06 | 272.8245636 |
| 2001-09 | 287.798543 |
| 2001-12 | 321.525367 |
| 2002-03 | 266.3359632 |
| 2002-06 | 300.1913481 |
| 2002-09 | 319.5012579 |
| 2002-12 | 356.0297806 |
| 2003-03 | 299.4649475 |
| 2003-06 | 333.6591504 |
| 2003-09 | 356.9139348 |
| 2003-12 | 392.2881064 |
| 2004-03 | 336.7250932 |
| 2004-06 | 378.3854757 |
| 2004-09 | 402.764045 |
| 2004-12 | 450.6723996 |
| 2005-03 | 384.3338654 |
| 2005-06 | 431.1500558 |
| 2005-09 | 458.3462072 |
| 2005-12 | 512.8031906 |
| 2006-03 | 443.3769955 |
| 2006-06 | 489.2228305 |
| 2006-09 | 510.9572225 |
| 2006-12 | 569.5431871 |
| 2007-03 | 504.7745339 |
| 2007-06 | 568.7419709 |
| 2007-09 | 595.716941 |
| 2007-12 | 661.2175279 |
| 2008-03 | 565.4562047 |
| 2008-06 | 644.9199349 |
| 2008-09 | 675.8111695 |
| 2008-12 | 736.5438709 |
| 2009-03 | 610.6191933 |
| 2009-06 | 699.456999 |
| 2009-09 | 743.0006542 |
| 2009-12 | 824.0493984 |
| 2010-03 | 706.8870209 |
| 2010-06 | 807.0640416 |
| 2010-09 | 847.8062136 |
| 2010-12 | 933.1525321 |
| 2011-03 | 799.8676755 |
| 2011-06 | 906.5173585 |
| 2011-09 | 954.0361671 |
| 2011-12 | 1038.3629 |
| 2012-03 | 867.7099621 |
| 2012-06 | 981.4559715 |
| 2012-09 | 1022.922083 |
| 2012-12 | 1116.171519 |
| 2013-03 | 939.0780889 |
| 2013-06 | 1045.355007 |
| 2013-09 | 1095.073391 |
| 2013-12 | 1204.353416 |
| 2014-03 | 994.0573082 |
| 2014-06 | 1110.144512 |
| 2014-09 | 1167.786636 |
| 2014-12 | 1274.847824 |
| 2015-03 | 1052.869064 |
| 2015-06 | 1179.183594 |
| 2015-09 | 1225.736222 |
| 2015-12 | 1335.101762 |
| 2016-03 | 1100.201755 |
| 2016-06 | 1240.229301 |
| 2016-09 | 1295.344785 |
| 2016-12 | 1432.873049 |

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [23 March 2018 16:40 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/8 "2018-03-23T16:40:09Z")

</div>

Have you tried logging before doing the seasonal adjustment? Note also that a failure to reject the Null of a unit root does not mean there must be a unit root. It could be type 2 error.

---

<div class="post-metadata">

**Author:** ![Cyy](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/e480ec/32.png) [@Cyy](https://forum.dynare.org/u/Cyy)\
**Post date:** [24 March 2018 02:07 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/9 "2018-03-24T02:07:26Z")

</div>

Thanks for your kind reply. Yes, I tried taking the log form before doing the seasonal adjustment. However, the ADF test of the cycle term still shows a p value of 0.33. Then I  
test the unit root in the first difference, the p value is 0.00000. I agree with your viewpoint of type 2 error. But in statistics it is often hard to identify this error. My sample size is limited. And I think the p value is so high, if we want to reject the null hypothesis, the significance level α would be very high. So is it in some sense unreasonable? This is just my own thinking. Do you have any good idea to solve this problem and the type 2 error?

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [24 March 2018 12:21 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/10 "2018-03-24T12:21:28Z")

</div>

Please provide a plot of the final data after filtering. But I would not worry too much about this. From theory you know that the HP-filter should induce stationarity unless your data has really crazy properties.

---

<div class="post-metadata">

**Author:** ![Cyy](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/e480ec/32.png) [@Cyy](https://forum.dynare.org/u/Cyy)\
**Post date:** [24 March 2018 12:55 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/11 "2018-03-24T12:55:28Z")

</div>

Thanks for your reply. I upload the graph. The first is the cycle term. The second is the trend term. The third is the log form of the real gdp after seasonal adjustment.

[the plot.pdf](https://forum.dynare.org/uploads/default/original/2X/4/424d1d5d5f60a5ac1bcc6290aa5c7139109f4eef.pdf) (24.1 KB)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [24 March 2018 12:56 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/12 "2018-03-24T12:56:21Z")

</div>

That does not look to bad. I would accept the series as stationary.

---

<div class="post-metadata">

**Author:** ![Cyy](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/e480ec/32.png) [@Cyy](https://forum.dynare.org/u/Cyy)\
**Post date:** [24 March 2018 13:00 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/13 "2018-03-24T13:00:39Z")

</div>

OK. Thank you. The mean is not zero either. so should I demean it?

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [24 March 2018 13:03 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/14 "2018-03-24T13:03:55Z")

</div>

How big is the mean? I would tend to say no

---

<div class="post-metadata">

**Author:** ![Cyy](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/e480ec/32.png) [@Cyy](https://forum.dynare.org/u/Cyy)\
**Post date:** [24 March 2018 13:09 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/15 "2018-03-24T13:09:47Z")

</div>

The mean is -0.00649401.

Besides, is it due to the small sample size about the non stationary cycle term? And if i just want to remove the long-term trend, is it acceptable to use two side hp filter? After all, from the perspective of data processing, it is just a measure to get the data disposed. And the seasonal adjustment also use the moving averaging process to remove the seasonal feature.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [24 March 2018 13:13 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/16 "2018-03-24T13:13:25Z")

</div>

1. That is -0.6% and sufficiently small, so I would not remove it.
2. No, you cannot use the two-sided filter for estimation.
3. You are right that in principle the same issue applies to seasonal adjustment. But here we have no true alternative.

---

<div class="post-metadata">

**Author:** ![Cyy](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/e480ec/32.png) [@Cyy](https://forum.dynare.org/u/Cyy)\
**Post date:** [24 March 2018 13:18 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/17 "2018-03-24T13:18:19Z")

</div>

Ok, I got it. Thank you so much. By the way, I have another question about estimation. The calvo price stickiness parameter is 0.28. Is it too small to accept when estimation?

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [24 March 2018 13:37 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/18 "2018-03-24T13:37:47Z")

</div>

Not necessarily. If we knew the answer ex ante, we would not need to do estimation. However, if you think that this is a sign of other problems in the model, I would check again.

---

<div class="post-metadata">

**Author:** ![Cyy](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/e480ec/32.png) [@Cyy](https://forum.dynare.org/u/Cyy)\
**Post date:** [24 March 2018 13:42 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/19 "2018-03-24T13:42:02Z")

</div>

Ok, I will check the model again. Besides, after estimation, I should use the post mean or post mode to do stochastic simulation? I see some posts that say it is better to use the mode.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [24 March 2018 14:07 UTC](https://forum.dynare.org/t/one-sided-hp-filter/3976/20 "2018-03-24T14:07:38Z")

</div>

I would to the mode. But it is a lot more common to do the mean of the statistic over the posterior draws instead of evaluating the statistic at a particular parameter value.

[Next page](https://forum.dynare.org/t/one-sided-hp-filter/3976.md?page=2)
