# How to set external function onesidedhptrend\_?

**URL:** <https://forum.dynare.org/t/how-to-set-external-function-onesidedhptrend/19141>\
**Category:** General DSGE Modeling\
**Created:** [21 October 2021 12:11 UTC](https://forum.dynare.org/t/how-to-set-external-function-onesidedhptrend/19141 "2021-10-21T12:11:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![freefish](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@freefish](https://forum.dynare.org/u/freefish)\
**Post date:** [21 October 2021 12:11 UTC](https://forum.dynare.org/t/how-to-set-external-function-onesidedhptrend/19141/1 "2021-10-21T12:11:11Z")

</div>

Hello everyone,  
I am trying to use the onesidedhptrend command in my model, but dynare stops and it says something like:  
Check for an incorrect parameter data type or missing parameters in the call to the function ‘onesidedhptrend\_’.  
The function used in my model is as follows:  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
variable …;  
…  
parameters…;  
external\_function(name = onesidedhptrend\_,nargs=1);

model;  
…  
S\_GAP=S-onesidedhptrend\_(S);  
b\_y\_ratio\_GAP=b/y-onesidedhptrend\_(b/y);  
…  
estimation(…);  
stoch\_simul(…);  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Could anyone give me a hand? Thank you very much in advance!

---

<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:** [21 October 2021 12:21 UTC](https://forum.dynare.org/t/how-to-set-external-function-onesidedhptrend/19141/2 "2021-10-21T12:21:04Z")

</div>

What exactly are you trying to do here?

---

<div class="post-metadata">

**Author:** ![freefish](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@freefish](https://forum.dynare.org/u/freefish)\
**Post date:** [21 October 2021 12:23 UTC](https://forum.dynare.org/t/how-to-set-external-function-onesidedhptrend/19141/3 "2021-10-21T12:23:10Z")

</div>

I want to make variable in gap form, that is, hpfiltered cycle of the variable.

---

<div class="post-metadata">

**Author:** ![freefish](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@freefish](https://forum.dynare.org/u/freefish)\
**Post date:** [21 October 2021 12:30 UTC](https://forum.dynare.org/t/how-to-set-external-function-onesidedhptrend/19141/4 "2021-10-21T12:30:42Z")

</div>

Let me put it in detail.  
In my model, I have variable b y, where b is bond, y is output. and I construct a third variable constructed from these two variables, b\_y\_ratio=b/y. I need gap form of the constructed ratiio variable in the model. That is ,variable b\_y\_ratio\_gap which means the deviation of the ratio from its trend in my model.

---

<div class="post-metadata">

**Author:** ![freefish](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@freefish](https://forum.dynare.org/u/freefish)\
**Post date:** [21 October 2021 12:41 UTC](https://forum.dynare.org/t/how-to-set-external-function-onesidedhptrend/19141/5 "2021-10-21T12:41:39Z")

</div>

Following the above warning are errors like:

```auto
error DSGE_model.static_resid_tt (line 225 )
TEF_0 = onesidedhptrend_(y(79)/y(55));

error DSGE_model.static_resid (line 19 )
    T = DSGE_model.static_resid_tt(T, y, x, params);

error DSGE_model.static (line 4 )
        residual = DSGE_model.static_resid(T, y, x, params, true);

error evaluate_static_model (line 63 )
        residuals = feval(fh_static,ys,exo_ss,params);

error evaluate_steady_state_file (line 108 )
    [residuals, check] = evaluate_static_model(ys, exo_ss, params, M, options);

error evaluate_steady_state (line 210 )
    [ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M, options,steadystate_check_flag);

error steady_ (line 55 )
[steady_state,params,info] = evaluate_steady_state(oo_.steady_state,M_,options_,oo_,~options_.steadystate.nocheck);

error steady (line 80)
[oo_.steady_state,M_.params,info] = steady_(M_,options_,oo_);

error DSGE_model.driver (line 2391 )
steady;

error dynare (line 293 )
evalin('base',[fname '.driver']) ;

error DSGE_model_loop (line232 )
dynare DSGE_model noclearall

```

I can’t understand what does it mean by these errors, can you help me? jpfeifer, 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:** [21 October 2021 12:50 UTC](https://forum.dynare.org/t/how-to-set-external-function-onesidedhptrend/19141/6 "2021-10-21T12:50:22Z")

</div>

> [@freefish](#):
>
> deviation of the ratio from its trend in my model.

But in your model, there is no trend. That’s why i am puzzled. In any case, it is possible to actually define a model-consistent HP-trend. See line 567 of [DSGE\_mod/Born\_Pfeifer\_2020/BP2020\_CES.mod at master · JohannesPfeifer/DSGE\_mod · GitHub](https://github.com/JohannesPfeifer/DSGE_mod/blob/master/Born_Pfeifer_2020/BP2020_CES.mod)

---

<div class="post-metadata">

**Author:** ![freefish](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@freefish](https://forum.dynare.org/u/freefish)\
**Post date:** [21 October 2021 13:02 UTC](https://forum.dynare.org/t/how-to-set-external-function-onesidedhptrend/19141/7 "2021-10-21T13:02:33Z")

</div>

You are right, jpfeifer. All the model variable has been detrended ones. But I need some variables in the gap form. How can I do that? I don’t know why I can’t open the link 😭

---

<div class="post-metadata">

**Author:** ![freefish](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@freefish](https://forum.dynare.org/u/freefish)\
**Post date:** [21 October 2021 14:52 UTC](https://forum.dynare.org/t/how-to-set-external-function-onesidedhptrend/19141/8 "2021-10-21T14:52:24Z")

</div>

Thank you jpfeifer,I’ve learned the BP2020.mod.Does it mean any other variable can be set in such way to get model-consistent variable gap? If I want to set HP-filtered b\_y\_ratio gap, I just only need to substitute the variable name for Y\_hp\_cyc as follows:  
`b_y_ratio_cyc*(1+6*1600)+b_y_ratio_cyc(-1)*(-4*1600)+b_y_ratio_cyc(+1)*(-4*1600)+b_y_ratio_cyc(-2)*1600+b_y_ratio_cyc(+2)*1600=b_y_ratio*(6*1600)+b_y_ratio(-1)*(-4*1600)+b_y_ratio(+1)*(-4*1600)+b_y_ratio(-2)*1600+b_y_ratio(+2)*1600;`  
Am I understanding it corretly?Hoping to get your response, many 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:** [21 October 2021 14:58 UTC](https://forum.dynare.org/t/how-to-set-external-function-onesidedhptrend/19141/9 "2021-10-21T14:58:15Z")

</div>

Yes. It is well-known that the HP-trend is just a two-sided moving average with the weights above. The reference for that approach would be [Has U.S. monetary policy tracked the efficient interest rate? - ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S0304393214001457) or [https://www.frbsf.org/economic-research/files/wp2014-12.pdf](https://www.frbsf.org/economic-research/files/wp2014-12.pdf)

---

<div class="post-metadata">

**Author:** ![freefish](https://forum.dynare.org/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@freefish](https://forum.dynare.org/u/freefish)\
**Post date:** [21 October 2021 15:03 UTC](https://forum.dynare.org/t/how-to-set-external-function-onesidedhptrend/19141/10 "2021-10-21T15:03:14Z")

</div>

Got it, thanks a lot.
