R For Economic Research - 11 Multiple Equations Model
R For Economic Research - 11 Multiple Equations Model
For example, interest rate hikes are expected to lower inflation through their contractionary impact on
economic activity. In addition, the more restrictive monetary policy stance should lead to an appreciation of
the exchange rate through greater capital inflows – this is especially true for emerging markets.
In the Phillips Curve we saw in the previous section, all these links were present but implicit. We could make all
these links explicit by creating specific equations for both the exchange rate and capital inflows. In summary,
working with systems of endogenous equations makes it possible to greatly expand the scope of the analysis
by incorporating any conceived relationship.
This can be cumbersome to do manually, but it becomes quite simple with the bimets package. It provides a
very concise and friendly interface to write down the whole system of equations, estimate its parameters and
forecast based on scenarios for the exogenous variables. Those who want to delve deeper into all the features
available in the package can refer to the vignette (https://cran.r-
project.org/web/packages/bimets/vignettes/bimets.pdf). For the purpose of this section, it will suffice to
present a variation of the standard three-equation macroeconomic model composed of an IS curve, a Phillips
Curve and a Monetary policy rule. The model is described as follows.
The IS curve relates the output gap to its own lag, the deviation of the real ex-ante interest rate from its
equilibrium and the deviation of the terms of trade from its trend.
~
~ ~ e eq ~ y
y t = β 1 y t−1 + β 2 (i t − π − i t ) t−3 + β 3 T oT t + ϵt
t,t+4|t
The Phillips Curve is the same from the previous section and relates the core CPI to its own lag, the expectation
for the next twelve months, the percentage change in imported prices and output gap.
e ~ π
π t = β 4 π t−1 + β 5 π + (1 − β 4 − β 5 )Δe t−1 + β 7 y t−1 + ϵ t
t,t+4|t
Lastly, the monetary policy rule relates the nominal interest rate to its own lags, the deviation of expected
inflation from the target and the nominal equilibrium rate.
e eq i
i t = β 8 i t−1 + β 9 i t−2 + (1 − β 8 − β 9 )(π − π̄ t ) + β 11 (i + π̄ t ) + ϵ t
t,t+4|t t
The first step is to write down the system of equations according to the standard adopted by the package. A
careful look at the equations blocks below should be enough to understand how they work.
COMMENT> IS Curve
BEHAVIORAL> YGAP
TSRANGE 2005 1 2022 4
EQ> YGAP = b1*TSLAG(YGAP,1) + b2*TSLAG((MPR- CPI_EXP - IR_EQ),1) + b3*TOT_GAP
https://book.rleripio.com/multiple_equations 1/6
05/11/2024, 14:17 R for Economic Research - 11 Multiple equations model
COEFF> b1 b2 b3
END
"
The next step is to load the model specification and the data. The data must be supplied as a list of time series
objects ( ts ).
library(tidyverse)
library(bimets)
Analyzing behaviorals...
Analyzing identities...
Optimizing...
Loaded model "model_spec":
3 behaviorals
0 identities
11 coefficients
...LOAD MODEL OK
https://book.rleripio.com/multiple_equations 2/6
05/11/2024, 14:17 R for Economic Research - 11 Multiple equations model
Finally, we can use our estimated model to produce forecasts for future values. For this, we first need to
provide future values for the exogenous variables. The TSEXTEND function makes this process very simple by
providing several ways to extend the time series of the exogenous variables. In the example below, I made
different assumptions to illustrate some of the possibilities.
For example, I assumed that both the CPI target and the equilibrium real interest rate will remain constant; the
expectations for CPI will evolve according to a linear trend; the gap of terms of trade will decrease by 2.4% each
quarter, which is the mean of the last four quarters; and the imported prices will decrease 2% each quarter,
partially reverting the surge of the last years.
CPI_EXP = TSEXTEND(
CPI_EXP,
UPTO = c(2026,1),
EXTMODE = 'LINEAR'
)
CI_USD = TSEXTEND(
CI_USD,
UPTO = c(2026,1),
EXTMODE = 'MYRATE',
FACTOR = (1-0.02)
)
IR_EQ = TSEXTEND(
IR_EQ,
UPTO = c(2026,1),
EXTMODE = 'CONSTANT'
)
TOT_GAP = TSEXTEND(
TOT_GAP,
https://book.rleripio.com/multiple_equations 3/6
05/11/2024, 14:17 R for Economic Research - 11 Multiple equations model
UPTO = c(2026,1),
EXTMODE = 'MYCONST',
FACTOR = -2.4
)
}
)
We can convert this object into tidy format in order to make it easier to plot all the extended time series in a
single panel.
https://book.rleripio.com/multiple_equations 4/6
05/11/2024, 14:17 R for Economic Research - 11 Multiple equations model
In the last step we call the SIMULATE function. Again, with a few lines of code we can transform the output into
tidy format to produce a prettier plot.
output %>%
select(date, YGAP, CPI_CORE, MPR, type) %>%
pivot_longer(-c(date, type), names_to = 'var', values_to = 'value') %>%
ggplot(aes(x = date)) +
geom_line(aes(y = value, color = type, linetype = type)) +
scale_linetype_manual(values = c(2,1)) +
zoo::scale_x_yearqtr(n = 5, format = '%YQ%q') +
facet_wrap(~ var, scales = 'free_y', nrow = 3) +
theme(legend.position = 'top') +
labs(
title = 'Forecasts for economic variables',
x = '',
y = '',
linetype = '',
color = ''
)
https://book.rleripio.com/multiple_equations 5/6
05/11/2024, 14:17 R for Economic Research - 11 Multiple equations model
https://book.rleripio.com/multiple_equations 6/6