# Calibration to match second moments of real data

**URL:** <https://forum.dynare.org/t/calibration-to-match-second-moments-of-real-data/19853>\
**Category:** General DSGE Modeling\
**Created:** [22 February 2022 21:56 UTC](https://forum.dynare.org/t/calibration-to-match-second-moments-of-real-data/19853 "2022-02-22T21:56:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaomingzhende666](https://forum.dynare.org/letter_avatar_proxy/v4/letter/x/e19adc/32.png) [@xiaomingzhende666](https://forum.dynare.org/u/xiaomingzhende666)\
**Post date:** [22 February 2022 21:56 UTC](https://forum.dynare.org/t/calibration-to-match-second-moments-of-real-data/19853/1 "2022-02-22T21:56:37Z")

</div>

Hi all

I want to calibrate parameters (eta & rho) to match the second moments of real data (variance and autocorrelation of output). But I have no idea how to calibrate in this way. I tried to follow this [post](https://forum.dynare.org/t/perform-moment-matching-with-matlab/19031), but I don’t know why my matlab can not resolve oo\_.var (maybe I make a mistake here). Can someone give me some suggestions about the coding.

My mod file and m file are uploaded.

Thanks.  
Ben  
[yy.mod](https://forum.dynare.org/uploads/short-url/o0jbct0EgKuAw3R2jrcHHxtQrEF.mod) (1.3 KB)  
[Untitled3.m](https://forum.dynare.org/uploads/short-url/8s9eNPEcduCasrqfRyxZPNIoz3J.m) (663 Bytes)

---

<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 February 2022 12:37 UTC](https://forum.dynare.org/t/calibration-to-match-second-moments-of-real-data/19853/2 "2022-02-23T12:37:25Z")

</div>

In Dynare 5.0,

```auto
eta_start=0.68;
target_moments=3.71;
var_list_={'y'};
dynare yy;
options_.noprint=1;
options_.nocorr=1;
options_.nofunctions=1;

eta_opt=fsolve(@(eta)moment_distance(eta,target_moments,M_, options_, oo_,var_list_),eta_start)

function V = moment_distance(eta,target_moments,M_, options_, oo_,var_list_)
M_.params(strmatch('eta',M_.param_names,'exact'))=eta;
[info, oo_] = stoch_simul(M_, options_, oo_, var_list_);
if info(1)==0
    V=oo_.var(1,1)-target_moments^2
end
end

```

should work. But be careful with parameter dependence in your mod-file.

---

<div class="post-metadata">

**Author:** ![xiaomingzhende666](https://forum.dynare.org/letter_avatar_proxy/v4/letter/x/e19adc/32.png) [@xiaomingzhende666](https://forum.dynare.org/u/xiaomingzhende666)\
**Post date:** [23 February 2022 20:49 UTC](https://forum.dynare.org/t/calibration-to-match-second-moments-of-real-data/19853/3 "2022-02-23T20:49:01Z")

</div>

Yes, thank you very much.
