generated from donotdespair/mcxs-report-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.qmd
1339 lines (985 loc) · 45.6 KB
/
index.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Sign and Zero Restrictions: Optimism Shock on the Australian Business Cycle"
author: "Adam Wang"
execute:
echo: false
# eval: false
warning: false
cache: true
bibliography: references.bib
---
<!-- latex shortcuts -->
\def\*#1{\mathbf{#1}}
\def\e{\boldsymbol{\varepsilon}}
> **Abstract.** This article investigates the effects of optimism shocks on the Australian economy using a Bayesian Structural Vector Autoregression (BSVAR) model. We implement the sign and zero restrictions algorithm proposed by @arias2018inference to identify the optimism shock. Impulse response functions (IRF) and forecast error variance decomposition (FEVD) are used to analyse the effects of the optimism shock on five key macroeconomic variables: productivity, stock prices, consumption, real interest rate and hours worked.
>
> **Keywords.** Bayesian Structural VAR, sign restrictions, zero restrictions, optimism shock
<!-- [Replication Package](https://www.econometricsociety.org/publications/econometrica/2018/03/01/inference-based-structural-vector-autoregressions-identified) -->
# Introduction
**Objective**: The goal of this research project is to implement the sign and zero restrictions algorithm proposed by @arias2018inference in the [bsvarSIGNs](https://github.com/bsvars/bsvarSIGNs) package, and apply it to analyse the optimism shock to Australian economy.
**Question**: Does optimism shocks drive the business cycles in Australian economy?
**Motivation**: In macroeconomics, there has been a longstanding belief that fluctuations in business cycles can be largely attributed to episodes of optimism and pessimism. An optimism shock is defined as a positive shock to stock prices that does not affect productivity. Using a penalty function approach (PFA), @beaudry2011mood finds significant evidence that optimism shocks are a key driver of business cycles in the United States as it creates a simultaneous boom in consumption and hours worked. But, @arias2018inference argue that PFA imposes additional restrictions, and they find less significant results using an importance sampler algorithm. This research project aims to extend the analysis to the Australian economy by implementing the importance sampler algorithm, and compare the results with United-States data.
# Data
<!-- load data -->
```{r include=FALSE}
library(readrba)
library(readabs)
library(tidyquant)
library(tseries)
library(tidyverse)
library(knitr)
library(zoo)
consumer_price_index = read_rba(series_id = 'GCPIAG')
productivity = read_rba(series_id = 'GNFPROSQI')
asx200 = tq_get('^AXJO', from = '1994-01-01')
# aord = tq_get('^AORD', from = '1994-01-01')
# stock_prices = asx200 / consumer_price_index
retail_turnover = read_abs(series_id = 'A3348585R')
# consumption = retail_turnover / consumer_price_index
cash_rate = read_rba(series_id = 'FIRMMCRI')
inflation = read_rba(series_id = 'GCPIAGSAQP')
# real_interest_rate = cash_rate - inflation
hours_worked = read_abs(series_id = 'A85389461V')
```
<!-- concat datasets -->
```{r include=FALSE}
df_consumer_price_index = consumer_price_index |>
select(date, value) |>
rename(consumer_price_index = value) |>
mutate(date = as.yearmon(date))
df_productivity = productivity |>
select(date, value) |>
rename(productivity = value) |>
mutate(date = as.yearmon(date))
df_asx200 = asx200 |>
rename(asx200 = close) |>
na.locf(fromLast = TRUE) |>
mutate(ym = as.yearmon(date)) |>
slice_max(date, by = ym) |>
select(date, asx200) |>
mutate(date = as.yearmon(date))
# df_aord = aord |>
# rename(aord = close) |>
# na.locf(fromLast = TRUE) |>
# mutate(ym = as.yearmon(date)) |>
# slice_max(date, by = ym) |>
# select(date, aord) |>
# mutate(date = as.yearmon(date))
df_retail_turnover = retail_turnover |>
select(date, value) |>
rename(retail_turnover = value) |>
mutate(date = as.yearmon(date))
df_cash_rate = cash_rate |>
select(date, value) |>
rename(cash_rate = value) |>
mutate(date = as.yearmon(date))
df_inflation = inflation |>
select(date, value) |>
rename(inflation = value) |>
mutate(date = as.yearmon(date))
df_hours_worked = hours_worked |>
select(date, value) |>
rename(hours_worked = value) |>
mutate(date = as.yearmon(date))
df =
merge(df_consumer_price_index, df_productivity, by = 'date') |>
merge(df_asx200, by = 'date') |>
merge(df_retail_turnover, by = 'date') |>
merge(df_cash_rate, by = 'date') |>
merge(df_inflation, by = 'date') |>
merge(df_hours_worked, by = 'date') |>
mutate(productivity = log(productivity),
stock_prices = log(asx200 / consumer_price_index),
consumption = log(retail_turnover / consumer_price_index),
real_interest_rate = cash_rate - inflation,
hours_worked = log(hours_worked)
) |>
select(date, productivity, stock_prices, consumption, real_interest_rate, hours_worked)
```
All data are collected from the Reserve Bank of Australia (RBA), the Australian Bureau of Statistics (ABS) and Yahoo Finance. The sample period covers 1994 Q3 to 2023 Q4. Following @beaudry2011mood, we select the following five variables for our analysis
- **Productivity**: non-farm labour productivity per hour (source: RBA, series ID GNFPROSQI).
```{r}
#| fig-cap: "Productivity"
library(ggplot2)
covid_index = 103
df |>
ggplot(aes(x = date, y = productivity)) +
geom_line() +
geom_vline(xintercept = df$date[covid_index], color = "red", linetype = "dashed") +
annotate("text", x = df$date[covid_index+8], y = min(df$productivity), label = "Covid-19", color = "red") +
theme_bw()
```
- **Stock prices**: end-of-period ASX 200 index (source: Yahoo Finance, ticker symbol \^AXJO), divided by the consumer price index.
```{r}
#| fig-cap: "Stock prices"
df |>
ggplot(aes(x = date, y = stock_prices)) +
geom_line() +
geom_vline(xintercept = df$date[covid_index], color = "red", linetype = "dashed") +
annotate("text", x = df$date[covid_index+8], y = min(df$stock_prices), label = "Covid-19", color = "red") +
theme_bw()
```
- **Consumption**: retail turnover (source: ABS, series ID A3348585R), divided by the consumer price index.
```{r}
#| fig-cap: "Consumption"
df |>
ggplot(aes(x = date, y = consumption)) +
geom_line() +
geom_vline(xintercept = df$date[covid_index], color = "red", linetype = "dashed") +
annotate("text", x = df$date[covid_index+8], y = min(df$consumption), label = "Covid-19", color = "red") +
theme_bw()
```
- **Real interest rate**: over-night cash rate nets inflation (source: RBA, series ID FIRMMCRI and GCPIAGSAQP).
```{r}
#| fig-cap: "Real interest rate"
df |>
ggplot(aes(x = date, y = real_interest_rate)) +
geom_line() +
geom_vline(xintercept = df$date[covid_index], color = "red", linetype = "dashed") +
annotate("text", x = df$date[covid_index+8], y = min(df$real_interest_rate), label = "Covid-19", color = "red") +
theme_bw()
```
- **Hours worked**: total hours worked (source: ABS, series ID A85389611R).
```{r}
#| fig-cap: "Hours worked"
df |>
ggplot(aes(x = date, y = hours_worked)) +
geom_line() +
geom_vline(xintercept = df$date[covid_index], color = "red", linetype = "dashed") +
annotate("text", x = df$date[covid_index+8], y = min(df$hours_worked), label = "Covid-19", color = "red") +
theme_bw()
```
The first two variables (productivity and stock prices) are chosen to identify the optimism shock, the last three variables (consumption, real interest rate and hours worked) are chosen to capture the business cycle dynamics as in standard macroeconomic theory.
To capture multiplicative relationships in macroeconomic time series and percentage change interpretation, all variables are log transformed (except for real interest rate). A preview of first 6 rows of the concatenated dataset is shown below.
```{r}
library(kableExtra)
library(tidyverse)
kable(head(df), digits = 4, align = "c")
```
## ACF and PACF plot
```{r}
#| echo: false
#| message: false
#| warning: false
#| label: fig-acf-plot
#| fig-cap: "ACF Plots"
Y = df |>
select(-date) |>
ts(start = c(year(min(df$date)), quarter(min(df$date))), frequency = 4)
N = ncol(Y)
par(mfrow = c(2, N - 2))
for (i in 1:ncol(Y)) {
acf(Y[, i], main = colnames(Y)[i])
}
```
The autocorrelation function (ACF) plot shows all variables have a consistent pattern of autocorrelation, this suggests that the time series are non-stationary. Stationarity is formally tested using the Augmented Dickey-Fuller test in the next section.
```{r}
#| echo: false
#| message: false
#| warning: false
#| label: fig-pacf-plot
#| fig-cap: "PACF Plots"
par(mfrow = c(2, N - 2))
for (i in 1:ncol(Y)) {
pacf(Y[, i], main = colnames(Y)[i])
}
```
The partial autocorrelation function (PACF) plot shows that the partial autocorrelation of all variables is significant at lag 1, real interest rate is also significant at lag 2. Therefore, choosing a lag length for the VAR model greater than or equal to 2 is reasonable, following convention for quarterly data, we will adopt a lag length of 4 for the VAR model.
## Augmented Dickey-Fuller test
### Level
All five variables are non-stationary at 5% significance level base on the Augmented Dickey-Fuller test.
```{r}
p_value = sapply(1:N, \(i) adf.test(Y[, i])$p.value)
variable = colnames(Y)
adf = cbind(variable, p_value) |>
data.frame() |>
mutate(p_value = round(as.numeric(p_value), 4)) |>
mutate(non_stationary = as.numeric(p_value > 0.05))
kable(adf, digits = 4)
```
### First difference
Applying Augmented Dickey-Fuller test to the first difference of the variables, we find that all variables are stationary at 5% significance level. Therefore, all variables are integrated of order one $I(1)$ and it is reasonable to put them in a VAR system without further transformation.
```{r}
Y_diff = diff(Y)
p_value = sapply(1:N, \(i) adf.test(Y_diff[, i])$p.value)
variable = colnames(Y)
cbind(variable, p_value) |>
data.frame() |>
mutate(p_value = round(as.numeric(p_value), 4)) |>
mutate(non_stationary = as.numeric(p_value > 0.05)) |>
kable(digits = 4)
```
# Model
## Specification
Adopting notations from @rubio2010structural, the SVAR model is specified as follows.
The endogenous variables are
$$
\*y_t = [\text{productivity}_t,\ \text{stock prices}_t,\ \text{consumption}_t,\ \text{real interest rate}_t,\ \text{hours worked}_t]'
$$
### Structural form
$$
\begin{align*}
\*y_t' \*A_0 &= \sum_{l=1}^{p} \*y_{t-l}'\*A_l + \*c + \e_t' \\
\e_t | \*Y_{t-1} &\overset{\text{iid}}{\sim} \mathcal{N}_N(\*0, \*I)
\end{align*}
$$
where $\*y_t$ is an $N\times1$ vector of endogenous variables, $\e_t$ is an $N\times1$ vector of exogenous structural shocks, $\*A_l$ is an $N\times N$ matrix of parameters with $\*A_0$ invertible, $\*c$ is an $1\times N$ vector of parameters, and $p$ is the lag length, and $T$ is the sample size. This can be compactly written as
$$
\begin{align*}
\*y_t' \*A_0 &= \*x_t' \*A_+ + \e_t'
\end{align*}
$$
where $\*A_+ = [\*A_1'\ \cdots\ \*A_p'\ \hspace{4mm}\*c']$ and $\*x_t = [\*y_{t-1}'\ \cdots\ \*y_{t-p}'\hspace{4mm}\ 1]$. The dimension of $\*A_+$ is $K\times N$ where $K=Np+1$.
In matrix form,
$$
\begin{align*}
\*Y \*A_0 &= \*X \*A_+ + \e \\
\e | \* X &\sim \mathcal{MN}_{T\times N}(\*0, \*I_N, \*I_T)
\end{align*}
$$
where $\*Y = [\*y_1\ \cdots\ \*y_T]'$,\ $\*X = [\*x_1\ \cdots\ \*x_T]'$, and $\e = [\e_1\ \cdots\ \e_T]'$.
The matrices $\*A_0$ and $\*A_+$ are structural parameters.
### Reduced form
$$
\begin{align*}
\*y_t' &= \*x_t' \*B + \*u_t' \\
\*u_t | \*Y_{t-1} &\overset{\text{iid}}{\sim} \mathcal{N}_N(\*0, \*\Sigma)
\end{align*}
$$
where $\*B = \*A_ + \*A_0^{-1},\ \*u_t' = \e_t' \*A_0^{-1}$, and
$$
\*\Sigma = \mathbb{E}[\*u_t\*u_t'] = (\*A_0^{-1})' (\*A_0^{-1}) = (\*A_0 \*A_0')^{-1}
$$
In matrix form,
$$
\begin{align*}
\*Y &= \*X \*B + \*u \\
\*u | \* X &\sim \mathcal{MN}_{T\times n}(\*0, \*\Sigma, \*I_T)
\end{align*}
$$
where $\*u = [\*u_1\ \cdots\ \*u_T]'$.
The matrices $\*B$ and $\*\Sigma$ are reduced-form parameters.
### Orthogonal reduced-form parameterization
Since SVAR model are identified up to a rotation matrix $\*Q$, we can explicitly specified the reduced-form model as
$$
\*y_t' = \*x_t' \*B + \e_t' \*Q' h(\*\Sigma)
$$
Where $\*Q'h(\*\Sigma) = \*A_0^{-1}$ or $\*Q=h(\*\Sigma) \*A_0$, and $h$ is some differentiable decomposition, one specific choice is the upper triangular Cholesky decomposition.
Then, we can define a mapping $f_h$ between the reduced-form parameters $(\*B, \*\Sigma, \*Q)$ and structural-form parameters $(\*A_0, \*A_+)$ as
$$
\begin{align*}
f_h(\*A_0, \*A_+) &= (
\underbrace{\*A_+ \*A_0^{-1}}_\*B,
\underbrace{(\*A_0 \*A_0')^{-1}}_{\*\Sigma},
\underbrace{h((\*A_0 \*A_0')^{-1}) \*A_0}_\*Q
) \\
f_h^{-1}(\*B, \*\Sigma, \*Q) &= (
\underbrace{h(\*\Sigma)^{-1} \*Q}_{\*A_0},
\underbrace{\*B h(\*\Sigma)^{-1} \*Q}_{\*A_+}
)
\end{align*}
$$
## Algorithm
### Reduced form
The first step is to sample the reduced-form parameters ($\*B$, $\*\Sigma$). Adopting the conjugate Normal-Inverse-Wishart prior,
$$
\begin{align*}
\*B|\*\Sigma &\sim \mathcal{MN}_{K\times N}(\underline{\*B}, \underline{\*V},\*\Sigma) \\
\*\Sigma &\sim \mathcal{IW}_N(\underline{\*S}, \underline{\nu})
\end{align*}
$$
and let
$$
\begin{align*}
\hat{\*B} &= (\*X'\*X)^{-1}\*X'\*Y \\
\*R &= (\*Y-\*X\hat{\*B})'(\*Y-\*X\hat{\*B})
\end{align*}
$$
the conjugate posterior distribution can be derived from
\begin{align*}
p(\*B,\*\Sigma|\*Y)
&\propto |\*\Sigma|^{-T/2}\exp\left\{ -\frac{1}{2}\text{tr}\left[ \*\Sigma^{-1}(\*Y-\*X\*B)'(\*Y-\*X\*B) \right] \right\} \\
&\quad\times |\*\Sigma|^{-T/2}\exp\left\{ -\frac{1}{2}\text{tr}[\*\Sigma^{-1}(\*B-\underline{\*B})'\underline{\*V}^{-1}(\*B-\underline{\*B})] \right\} \\
&\quad\times |\*\Sigma|^{-(\underline\nu+N+1)/2}\exp\left\{ -\frac{1}{2} \text{tr}(\underline{\*S}\*\Sigma^{-1}) \right\} \\
&\propto |\*\Sigma|^{-T/2}\exp\left\{ -\frac{1}{2}\text{tr}\left[ \left( \*R+(\*B-\hat{\*B})'\*X'\*X(\*B-\hat{\*B}) \right) \*\Sigma^{-1} \right] \right\} \\
&\quad\times |\*\Sigma|^{-T/2}\exp\left\{ -\frac{1}{2}\text{tr}[(\*B-\underline{\*B})'\underline{\*V}^{-1}(\*B-\underline{\*B})\*\Sigma^{-1}] \right\} \\
&\quad\times |\*\Sigma|^{-(\underline\nu+N+1)/2}\exp\left\{ -\frac{1}{2} \text{tr}(\underline{\*S}\*\Sigma^{-1}) \right\} \\
&\propto |\*\Sigma|^{-T/2}\exp\left\{ -\frac{1}{2} \text{tr}\left[ \left( (\*B-\hat{\*B})'\*X'\*X(\*B-\hat{\*B})+(\*B-\underline{\*B})'\underline{\*V}^{-1}(\*B-\underline{\*B}) \right) \*\Sigma^{-1} \right] \right\} \\
&\quad\times |\*\Sigma|^{-(\underline\nu+T+N+1)/2}\exp\left\{ -\frac{1}{2}\text{tr}\left[ (\*R+\underline{\*S})\*\Sigma^{-1} \right] \right\} \\
&=|\*\Sigma|^{-T/2}\exp\left\{ -\frac{1}{2} \text{tr}\left[ (\*B-\overline{\*B})'\overline{\*V}^{-1}(\*B-\overline{\*B}) \*\Sigma^{-1} \right] \right\} \\
&\quad\times |\*\Sigma|^{-(\underline\nu+T+N+1)/2}\exp\left\{ -\frac{1}{2}\text{tr}\left[ (\*R+\underline{\*S}+\hat{\*B}'\*X'\*X\hat{\*B}+\underline{\*B}'\underline{\*V}^{-1}\underline{\*B}-\overline{\*B}'\overline{\*V}^{-1}\overline{\*B})\*\Sigma^{-1} \right] \right\} \\
&=|\*\Sigma|^{-T/2}\exp\left\{ -\frac{1}{2} \text{tr}\left[ (\*B-\overline{\*B})'\overline{\*V}^{-1}(\*B-\overline{\*B}) \*\Sigma^{-1} \right] \right\} \\
&\quad\times |\*\Sigma|^{-(\underline\nu+T+N+1)/2}\exp\left\{ -\frac{1}{2}\text{tr}\left[ (\*Y'\*Y+\underline{\*S}+\underline{\*B}'\underline{\*V}^{-1}\underline{\*B}-\overline{\*B}'\overline{\*V}\overline{\*B})\*\Sigma^{-1} \right] \right\} \\
&=p(\*B|\*\Sigma,\*Y)\times p(\*\Sigma|\*Y)
\end{align*}
Therefore, the posterior distribution of the reduced-form parameters is given by
$$
\begin{align*}
\*B|\*\Sigma,\*Y &\sim \mathcal{MN}_{K\times N}(\overline{\*B}, \overline{\*V},\*\Sigma) \\
\*\Sigma|\*Y &\sim \mathcal{IW}_N(\overline{\*S}, \overline{\nu})
\end{align*}
$$
where
$$
\begin{align*}
\overline{\*B} &= \overline{\*V}(\*X'\*Y+\underline{\*V}^{-1}\underline{\*B}) \\
\overline{\*V} &= (\*X'\*X+\underline{\*V}^{-1})^{-1} \\
\overline{\*S} &= \underline{\*S}+\*Y'\*Y+\underline{\*B}'\underline{\*V}^{-1}\underline{\*B}-\overline{\*B}'\overline{\*V}^{-1}\overline{\*B} \\
\overline{\nu} &= \underline{\nu}+T
\end{align*}
$$
### Structural form
To perform zero and sign restrictions, we need an algorithm to sample from the posterior distribution of the structural parameters ($\*A_0$, $\*A_+$) conditional on the zero and sign restrictions.
However, the set of structural parameters satisfying the zero restrictions is of Lebesgue measure zero in the set of all structural parameters (akin to $\mathbb{P}(X=x)=0$ for continuous $X$). Luckily, we can sample the set of structural parameters satisfying the sign restrictions conditional on satisfying the zero restrictions.
Here is a high level outline of the algorithm proposed by @arias2018inference:
1. Sample reduced-form parameters $\*B,\*\Sigma\sim \mathcal{NIW}(\overline{\*B},\overline{\*V},\overline{\*S},\overline{\*\nu})$.
2. Sample $\*Q$ conditional on the zero restrictions and set $(\*A_0, \*A_+) = f_h^{-1}(\*B, \*\Sigma, \*Q)$.
3. If the sign restrictions are satisfied, keep $(\*A_0, \*A_+)$ and compute an importance weight, otherwise discard.
4. Repeat steps 1-3 until the desired number of samples is obtained.
5. Resample with replacement using the importance weights.
Where step 5 (importance sampling) is needed to manipulate the density induced by step 1 to the desired Nomral-Generalized-Normal posterior density $\mathcal{NGN}$.
To be explicit, starting with a Uniform-Normal-Inverse-Wishart prior distribution, the importance weight in step 3 is given by (posterior condition on $\*Y$ is dropped for brevity):
$$
\begin{align*}
\frac{\mathcal{NGN}(\*A_0,\*A_+|\mathcal Z, \mathcal S)}{\mathcal{UNIW}(\*B,\*\Sigma,\*Q)v_{(g\circ f_h)|\mathcal Z}(\*A_0,\*A_+)}
&=\frac{\mathcal{UNIW}(\*B,\*\Sigma,\*Q|\mathcal Z, \mathcal S)v_{f_h}(\*A_0,\*A_+)}{\mathcal{UNIW}(\*B,\*\Sigma,\*Q)v_{(g\circ f_h)|\mathcal Z}(\*A_0,\*A_+)}\\
&\propto\frac{|\text{det}(\*A_0)|^{-(2N+K+1)}}{v_{(g\circ f_h)|\mathcal Z}(\*A_0,\*A_+)}
\end{align*}
$$
where $\mathcal Z$ denotes zero restrictions and $\mathcal S$ denotes sign restrictions. The numerator is the target density, and the denominator is the proposal density from steps 1-2.
### Implementations
For computational efficiency, main functions in the ``bsvarSIGNs`` package are written in C++. The first function is compute posterior parameters as derived above.
```cpp
Rcpp::List niw_cpp(
const arma::mat& Y,
const arma::mat& X,
const Rcpp::List prior
) {
const int T = Y.n_rows;
mat prior_B = as<mat>(prior["B"]);
mat prior_V = as<mat>(prior["V"]);
mat prior_S = as<mat>(prior["S"]);
int prior_nu = as<int>(prior["nu"]);
// analytic solutions
mat prior_V_inv = inv_sympd(prior_V);
mat post_V_inv = prior_V_inv + X.t() * X;
mat post_V = inv_sympd(post_V_inv);
mat post_B = post_V * (X.t() * Y + prior_V_inv * prior_B);
// marginal posterior of Sigma
mat post_S = prior_S + Y.t() * Y + prior_B.t() * prior_V_inv * prior_B - post_B.t() * post_V_inv * post_B;
post_S = symmatu(post_S);
int post_nu = prior_nu + T;
return List::create(
Named("B") = post_B,
Named("V") = post_V,
Named("S") = post_S,
Named("nu") = post_nu
);
}
```
The second function is to draw from the matrix normal distribution.
```cpp
arma::mat rmatnorm_cpp(
const arma::mat& M,
const arma::mat& U,
const arma::mat& V
) {
mat X = mat(size(M), fill::randn);
return M + chol(U).t() * X * chol(V);
}
```
To draw from the inverse Wishart distribution, we use the ``iwishrnd`` function from the ``RcppArmadillo`` package. Using these three functions together, we are able to estimate the reduced-form BVAR model.
The following code calculates the volume element $v_{(g\circ f_h)|\mathcal Z}$ in the resampling step for the structural parameters
```cpp
double log_volume_element(
const arma::field<arma::mat>& Z, //Field of matrices representing narrative restrictions
const arma::mat& A0,
const arma::mat& Aplus
) {
colvec vec_structural = join_vert(vectorise(A0), vectorise(Aplus));
// Compute the derivative of the narrative restrictions wrt the structural parameters
mat Dz = Df([Z](const colvec& x) { return zero_restrictions(Z, x); }, vec_structural);
// Compute derivative of combined mapping function g_fh_vec wrt the structural parameters
mat Dgf = Df([Z](const colvec& x) { return g_fh_vec(Z, x); }, vec_structural);
// Compute the null space of the derivative of the narrative restrictions
mat DN = Dgf * null(Dz);
// Logarithm of determinant, then take the real part
return 0.5 * log_det(DN.t() * DN).real();
}
```
### Comparison with PFA
The PFA uses a loss function to find a rotation matrix $\*Q$ that satisfies the zero restrictions and satisfies or close to satisfying the sign restrictions, thus it is not an exact solution. In comparison, the importance sampler algorithm is an exact solution satisfying all the restrictions.
Mathematically, the PFA solves the following minimization problem:
$$
\begin{aligned}
q^* &= {\arg\min}_q \Psi(q) \quad s.t. (1)\ q'q=1,\ (2)\ R_{zero}q=0
\end{aligned}
$$
where $q$ is a column of $\*Q$. This step is analogous to steps 2-3 of the importance sampler algorithm. Intuitively, by minimizing $\Psi(q)$ we can find something close to satisfying the sign restrictions, condition (1) makes sure $\*Q$ is orthogonal and condition (2) makes sure $\*Q$ satisfies the zero restrictions.
Detailed definitions of $\Psi$ and $R_{zero}$ is beyond the scope of this project, but it is evident that the minimization problem gives an unique solution and therefore the PFA is not set-identifying $\*Q$.
### Extension
Besides the zero and sign restrictions, another popular identification scheme proposed by @antolin2018narrative is to impose narrative restrictions on the structural shocks and historical decomposition. For example, restricting a structural shock to be negative during some period, and we will apply this to restrict the optimism shock during the Covid-19 pandemic.
But, the difficulty is that the narrative restrictions $\mathcal{R}$ requires another resample with some importance weight:
$$
\frac{1}{\omega(\*B,\*\Sigma,\*Q)} \propto \frac{\mathcal{UNIW}(\*B,\*\Sigma,\*Q|\mathcal S, \mathcal R)}{\mathcal{UNIW}(\*B,\*\Sigma,\*Q)}
$$
To combine these two identifications, we need to calculate the importance weight when **all** of the three restrictions, zero, sign, and narrative, are present. Intuitively, it is the product of the importance weight for the narrative restrictions and the importance weight for the zero and sign restrictions.
Here is an preliminary proof. The insight is to notice that $\frac{\mathcal{UNIW}(\*B,\*\Sigma,\*Q|\mathcal Z, \mathcal S, \mathcal R)}{\mathcal{UNIW}(\*B,\*\Sigma,\*Q|\mathcal S, \mathcal R)}\propto 1$ since adding zero restrictions does not change the likelihood and only truncates uniform conditional prior $\pi(\*Q|\*B,\*\Sigma)$.
$$
\begin{align*}
\frac{\mathcal{NGN}(\*A_0,\*A_+|\mathcal Z, \mathcal S, \mathcal R)}{\mathcal{UNIW}(\*B,\*\Sigma,\*Q)v_{(g\circ f_h)|\mathcal Z}(\*A_0,\*A_+)}
=&\frac{\mathcal{UNIW}(\*B,\*\Sigma,\*Q|\mathcal Z, \mathcal S, \mathcal R)v_{f_h}(\*A_0,\*A_+)}{\mathcal{UNIW}(\*B,\*\Sigma,\*Q)v_{(g\circ f_h)|\mathcal Z}(\*A_0,\*A_+)}\\
=&\frac{\mathcal{UNIW}(\*B,\*\Sigma,\*Q|\mathcal S, \mathcal R)}{\mathcal{UNIW}(\*B,\*\Sigma,\*Q)}
\frac{\mathcal{UNIW}(\*B,\*\Sigma,\*Q|\mathcal Z, \mathcal S, \mathcal R)}{\mathcal{UNIW}(\*B,\*\Sigma,\*Q|\mathcal S, \mathcal R)}\\
&\times
\frac{v_{f_h}(\*A_0,\*A_+)}{v_{(g\circ f_h)|\mathcal Z}(\*A_0,\*A_+)}\\
\propto&\frac{1}{\omega(\*B,\*\Sigma,\*Q)}\frac{v_{f_h}(\*A_0,\*A_+)}{v_{(g\circ f_h)|\mathcal Z}(\*A_0,\*A_+)}\\
\propto&\frac{1}{\omega(\*B,\*\Sigma,\*Q)}\frac{|\text{det}(\*A_0)|^{-(2N+K+1)}}{v_{(g\circ f_h)|\mathcal Z}(\*A_0,\*A_+)}
\end{align*}
$$
The following code calculates $\omega(\*B,\*\Sigma,\*Q)$ for the narrative restrictions
```cpp
double weight_narrative(
const int& T,
arma::mat sign_narrative,
const arma::cube& irf
) {
const int M = 1e+04; // number of draws to approximate normal distribution
double n_success = 1.0e-15;
cube Z(irf.n_rows, sign_narrative.col(5).max() + 1, M, fill::randn);
// change all starting period to the first period
// since we use the same M draws for all narrative restrictions
sign_narrative.col(4) = ones(sign_narrative.n_rows, 1);
for (int m=0; m<M; m++) {
if (match_sign_narrative(Z.slice(m), sign_narrative, irf)) {
n_success++;
}
}
return M / n_success;
}
```
@arias2018inference provides a sufficient condition for the partial identification of the first $k$ shocks: at least $N-j$ zero restrictions and at least 1 sign restriction on the IRFs to the $j$-th shock for $1\le j\le k$. At this stage, there is no theoretical result how to incorporate narrative restrictions in this sufficient condition. Generally, narrative restrictions are used to sharpen the inference (i.e. narrower highest density interval) and does not make the structural shocks exactly identified.
If given some narrative restrictions there is an uniquely identified $\*Q^*$, step 3 of the importance sampling algorithm would never work, since the probability a randomly sampled $\*Q=\*Q^*$ is $0$. In the later empirical work, we show the algorithm can still work with narrative restrictions, therefore at least the narrative restrictions considered here are not binding. But, the advantage of narrative (and sign) restrictions is that they are less controversial and the result can be agreed upon by more researchers.
## Simulation
### Reduced form
To test the validity of our code, we simulate 1,000 observations from a bi-variate Gaussian random walk process with the covariance matrix equal to the identity matrix of order 2.
Then, we compute 1,000 posterior draws from a SVAR model with a constant term and one lag, using the default identification scheme: positive sign restrictions on the diagonal of $\*A_0$.
```{r include=FALSE}
# devtools::install_github("bsvars/bsvarSIGNs")
library(bsvarSIGNs)
set.seed(123)
# simulate data
N = 2
T = 1000
sim_Y = apply(matrix(rnorm(T*N), ncol = N), 2, cumsum)
# Initialize a Bayesian structural VAR model using simulated data `sim_Y` and lag order `p = 1`
specification = specify_bsvarSIGN$new(sim_Y, p = 1)
posterior = estimate(specification, S = 1000)
```
The posterior mean of the $\*B$ is
```{r}
mean_B = posterior$posterior$A |>
apply(c(1, 2), mean) |>
t()
rownames(mean_B) = c("y1_lag", "y2_lag", "constant")
colnames(mean_B) = c("y1", "y2")
kable(mean_B, digits = 4)
```
The posterior mean of $\*\Sigma$ is
```{r}
mean_Sigma = apply(posterior$posterior$Sigma, c(1, 2), mean)
rownames(mean_Sigma) = c("y1", "y2")
colnames(mean_Sigma) = c("y1", "y2")
kable(mean_Sigma, digits = 4)
```
They are close to the true values of the simulated data.
### Structural form
Suppose the true structural model is
$$
\begin{bmatrix}
-1 & 1\\
1 & 0\\
\end{bmatrix}
\begin{bmatrix}
y_{1,t}\\
y_{2,t}\\
\end{bmatrix}
=
\begin{bmatrix}
-1 & 1\\
1 & 0\\
\end{bmatrix}
\begin{bmatrix}
y_{1,t-1}\\
y_{2,t-1}\\
\end{bmatrix}
+
\begin{bmatrix}
\varepsilon_{1,t}\\
\varepsilon_{2,t}\\
\end{bmatrix},
\begin{bmatrix}
\varepsilon_{1,t}\\
\varepsilon_{2,t}\\
\end{bmatrix}
\sim
\mathcal{N}(
\begin{bmatrix}
0 \\
0
\end{bmatrix}
,
\begin{bmatrix}
1 & 0 \\
0 & 1 \\
\end{bmatrix}
)
$$
equivalently, we can simulate 1,000 observations from the reduced-form
$$
\begin{bmatrix}
y_{1,t}\\
y_{2,t}\\
\end{bmatrix}
=
\begin{bmatrix}
1 & 0\\
0 & 1\\
\end{bmatrix}
\begin{bmatrix}
y_{1,t-1}\\
y_{2,t-1}\\
\end{bmatrix}
+
\begin{bmatrix}
u_{1,t}\\
u_{2,t}\\
\end{bmatrix},
\begin{bmatrix}
u_{1,t}\\
u_{2,t}\\
\end{bmatrix}
\sim
\mathcal{N}(
\begin{bmatrix}
0 \\
0
\end{bmatrix}
,
\begin{bmatrix}
1 & 1 \\
1 & 2 \\
\end{bmatrix}
)
$$
```{r include=FALSE}
# devtools::install_github("bsvars/bsvarSIGNs")
library(bsvarSIGNs)
set.seed(123)
# simulate data
N = 2
T = 1000
U = mvtnorm::rmvnorm(T, rep(0, N), matrix(c(1, 1, 1, 2), N, N))
sim_Y = apply(U, 2, cumsum)
sign_irf = array(matrix(c(0, 1, 1, 1), 2, 2), dim = c(2, 2, 1))
zero_irf = matrix(c(1, 0, 0, 0), 2, 2)
specification = specify_bsvarSIGN$new(sim_Y,
p = 1,
sign_irf = sign_irf,
zero_irf = zero_irf
)
posterior = estimate(specification, S = 1000)
```
Putting zero and sign restrictions on the inverse of the structural matrix
$$
\begin{bmatrix}
-1 & 1\\
1 & 0\\
\end{bmatrix}^{-1}
=
\begin{bmatrix}
0 & 1\\
1 & 1\\
\end{bmatrix}
\Rightarrow
\begin{bmatrix}
0 & +\\
+ & +\\
\end{bmatrix}
$$
Posterior mean of 1,000 draws of the structural matrix is
```{r}
posterior$posterior$B |>
apply(c(1, 2), mean) |>
t() |>
round(4)
```
## Identification
The following restrictions are imposed on the contemporaneous impulse response to identify the optimism shock.
| Productivity | Stock prices | Consumption | Real interest rate | Hours worked |
|--------------|--------------|-------------|--------------------|--------------|
| 0 | Positive | Unrestricted| Unrestricted | Unrestricted |
The identification strategy is based on the assumption that the optimism shock positively affects stock prices, and has no contemporaneous effect on productivity.
## Interpretation
Two popular methods to interpret the SVAR model are impulse response function (IRF) and forecast error variance decomposition (FEVD) [@kilian2017structural, Chap 4].
### IRF
The impulse response function (IRF) of the SVAR model is used to interpret the effect of the optimism shock on the endogenous variables. Specifically, we are interested in whether a positive optimism shock leads to a simultaneous boom in consumption and hours worked (as in the United States).
Mathematically, the response of the $i$-th variable to the $j$-th shock at horizon $k$ is given by the element at row $i$ columns $j$ of $\*\Theta_k$, where $\*\Theta_k$ is defined recursively as
\begin{aligned}&\*\Theta_{0} = \left(\mathbf{A}_{0}^{-1}\right)^{\prime},\quad\*\Theta_{h} = \sum_{l=1}^{h}\bigl(\mathbf{A}_{\ell}\mathbf{A}_{0}^{-1}\bigr)^{\prime}\*\Theta_{h-\ell},\quad\mathrm{} 1 \leq h \leq p,\\&\*\Theta_{h} = \sum_{\ell=1}^{p}\bigl(\mathbf{A}_{\ell}\mathbf{A}_{0}^{-1}\bigr)^{\prime}\*\Theta_{h-\ell},\quad\mathrm{} p < h < \infty.\end{aligned}
### FEVD
The forecast error variance decomposition (FEVD) is used to quantify the relative importance of the optimism shock in explaining the variability of a $h$-step ahead forecast of a particular variable. For example, we will examine the proportion of the variability of consumption and hours worked explained by the optimism shock.
Mathematically, the $i$-th variable's forecast error variance decomposition of the $j$-th shock at horizon $h$ is given by
$$
\text{FEVD}_j^i(h) = \frac{\text{MSFE}_{j}^{i}(h)}{\sum_{n=1}^{N}\text{MSFE}_{j}^{n}(h)}, \quad \text{MSFE}_{j}^{i}(h) = \sum_{l=0}^{h-1} \*\Theta_{ij,l}^{2}
$$
# Results
## United States
```{r include=FALSE}
data(optimism)
zero_irf = matrix(0, nrow = 5, ncol = 5)
zero_irf[1, 1] = 1
sign_irf = array(0, dim = c(5, 5, 1))
sign_irf[2, 1, 1] = 1
specification = specify_bsvarSIGN$new(
optimism*100,
p = 4,
sign_irf = sign_irf,
zero_irf = zero_irf
)
posterior = estimate(specification, S = 10000)
irf = compute_impulse_responses(posterior, horizon = 40)
```
First, we apply the package to the data from the United States, and replicate the results in @arias2018inference.
### History
Historical values of the optimism shock is
```{r us-shock}
optimism_shock = posterior$posterior$shocks[1, , ] |>
apply(1, quantile, c(0.16, 0.50, 0.84)) |>
t()
bsvars::plot_ribbon(
optimism_shock,
probability = 0.68,
main = "optimism shock",
bty = "n",
xaxt = "n",
)
abline(h = 0)
# abline(v = covid_index - 4 - 1, lty = 5)
label_index = seq(1, dim(optimism_shock)[1], 20)
axis(1, at = label_index,
labels = as.yearqtr(index(optimism))[label_index + 4 + 1])
```
Most of the historical values of the optimism shock are not significantly different from 0, perhaps putting only one zero and one sign restriction is not enough to identify the optimism shock.
### IRF
The impulse response functions are
```{r us-irf}
#| fig-cap: "US IRF (median and 68% highest density interval)"
# devtools::install_github("bsvars/bsvars")
# plot irf of one shock
plot_irf1 = function(irf) {
N = dim(irf)[1]
ylab = rep("Percent", N)
ylab[4] = "Percentage Point"
par(mfrow = c(2, 3))
for (i in 1:N) {
bsvars::plot_ribbon(
irf[i, 1, , ],
probability = 0.68,
main = colnames(Y)[i],
xlab = "Quarter",
ylab = ylab[i],
bty = "n",
)
abline(h = 0)
}
}
plot_irf1(irf)
```
which is very close to the ones in the original paper. Although consumption and hours worked have a boom in the median IRF, they are not significantly different from 0. Therefore, base on this identification strategy, the optimism shock does not drive business cycles in the US.
### FEVD
```{r}
compute_fevd = function(irf, horizon = 40) {
N = dim(irf)[1]
S = dim(irf)[4]
fevd = array(NA,c(N,N,horizon,S))
for (s in 1:S){
for (i in 1:(horizon)){
for (n in 1:N){
for (nn in 1:N){
fevd[n,nn,i,s] = sum(irf[n,nn,1:i,s]^2)
}
}
fevd[,,i,s] = diag(1/apply(fevd[,,i,s],1,sum))%*%fevd[,,i,s]
}
}
fevd = 100*fevd
class(fevd) = "fevd"
fevd
}
```
Share of FEVD attributed to the optimism shock at horizon 40 (median 50%) and its 68% highest probability interval (16% and 84%) are
```{r}
fevd = compute_fevd(irf, 40)
fevd_40 =
fevd[, 1, 40, ] |>
apply(1, quantile, c(0.16, 0.50, 0.84)) |>
t() |>
round(2)
rownames(fevd_40) = colnames(Y)
kable(fevd_40)
```
which is very close to the ones in the original paper. As the median values are relatively small (<20%), the optimism shock does not contribute significantly to the FEVD of consumption and hours worked in the US.
## Australia
All subsequent analysis are performed on the Australian data.
```{r include=FALSE}
zero_irf = matrix(0, nrow = 5, ncol = 5)
zero_irf[1, 1] = 1
sign_irf = array(0, dim = c(5, 5, 1))
sign_irf[2, 1, 1] = 1
specification = specify_bsvarSIGN$new(
Y*100,
p = 4,
sign_irf = sign_irf,
zero_irf = zero_irf
)
posterior = estimate(specification, S = 10000)
```
### History
Historical values of the optimism shock is
```{r au-shock}
optimism_shock = posterior$posterior$shocks[1, , ] |>
apply(1, quantile, c(0.16, 0.50, 0.84)) |>
t()