Skip to contents

Writes the model as Dynare source so that anyone can re-solve it in Dynare and compare. This is deliberate: qpmR's solver is pinned in its own tests to analytic solutions, but "does it agree with Dynare?" is the first question a modeller asks, and the answer should be cheap to check rather than something to take on trust.

Usage

write_dynare(model, file = NULL, irf = 40, order = 1, extra = NULL)

Arguments

model

A qpm_model.

file

Output path. The default NULL returns the Dynare source as a character vector; a file is written only when a path is given.

irf

Horizon for stoch_simul; 0 omits impulse responses.

order

Approximation order passed to stoch_simul (the models are linear, so first order is exact).

extra

Character vector of extra Dynare statements appended after stoch_simul, e.g. code to export results.

Value

The file path invisibly, or the Dynare source as a character vector when file is NULL.

Details

The original equations are exported, not qpmR's internal first-order system: Dynare creates its own auxiliary variables for long leads and lags, so the two implementations agree only if both handle them correctly. Expectation wrappers are dropped (E(pi[+1]) becomes pi(+1)), since leads in Dynare are already model-consistent expectations.

Examples

src <- write_dynare(qpm_template("bkl"), file = NULL)
cat(head(src, 15), sep = "\n")
#> // Generated by qpmR::write_dynare()
#> // model: Canonical small open economy QPM (BKL, stationary trends)
#> // qpmR 1.1.0
#> //
#> // Cross-check: solve this in Dynare and compare its IRFs with
#> // qpmR::irf() on the same model. They should agree to solver tolerance.
#> 
#> var
#> y_gap pi pi4 i r r_gap q q_gap q_bar r_bar dy_obs dy_bar ystar_gap istar
#> pistar rstar prem
#> ;
#> 
#> varexo
#> eps_y eps_pi eps_i eps_q eps_qbar eps_rbar eps_g eps_dy eps_ystar
#> eps_istar eps_pistar eps_prem