historical decomposition
Posted: Sun Jun 30, 2019 6:31 am
Dear Tom
I am tried to modify history.rpf. It seems that there is a problem with the stacked bar even if I changed depvar(1) to depvar(4) to get decomposition result for ip variable, it still gives me the decomposition for int variable .
Regards
I am tried to modify history.rpf. It seems that there is a problem with the stacked bar even if I changed depvar(1) to depvar(4) to get decomposition result for ip variable, it still gives me the decomposition for int variable .
Regards
Code: Select all
open data 2019_rats_data_eys.xlsx
cal(m) 1986:01
data(format=xlsx, org=columns) 1986:01 2019:01
table
set lrer = log(rer)
set lcpi = log(cpi)
set lip = log(ip)
@varlagselect(crit=bic,lags=13)
# int lrer lcpi lip
compute p = 3
* VAR modeli asagidaki gibi tahmin edilir.
system(model=varlevel)
variables int lrer lcpi lip
lags 1 to p
det constant
end(system)
estimate(resids=varresids, noprint)
compute hstart=1990:1
compute hend =2019:12
*
compute neqn=%modelsize(varlevel)
dec vect[int] depvar(neqn)
dec vect[string] varlabels(neqn) shocklabels(neqn)
ewise varlabels(i)=%modellabel(varlevel,i)
ewise shocklabels(i)=%modellabel(varlevel,i)
compute depvar=%modeldepvars(varlevel)
*
* If you want non-Cholesky shocks, you can use a FACTOR option on the
* HISTORY. You might want to input more descriptive values for the
* SHOCKLABELS if you do that.
*
history(model=varlevel,add,base=base,effects=effects,from=hstart,to=hend)
*
do j=1,neqn
spgraph(vfields=2,hfields=2,window=varlabels(j),$
header="Historical Decomposition of "+varlabels(j))
do i=1,neqn
*
* This graphs the actual data (including four pre-sample values),
* the base forecast, and the effects of shock I on variable J.
*
graph(header="Effect of "+shocklabels(i)) 3
# depvar(j) hstart-4 hend
# base(j)
# effects(j,i)
end do j
spgraph(done)
end do i
*
* This does a stacked bar graph for the effects of the shocks,
* overlaid with the actual data (just for the first dependent
* variable, Canadian GDP). (For various reasons, this probably
* isn't a great idea but is being shown for illustration).
*
* This uses the NOADD option so the effects of the shocks are
* separated from the underlying forecast.
*
history(model=varlevel,noadd,base=base,effects=effects,from=hstart,to=hend)
*
* Arrange the series to be graphed to have the effects of the shocks
* first and the dependent variable last.
*
dec vect[int] byshock(%nvar+1)
ewise byshock(i)=%if(i==%nvar+1,depvar(4),effects(1,i))
*
* Put together the corresponding key labels
*
dec vect[strings] histlabels(%nvar+1)
ewise histlabels(i)=%if(i==%nvar+1,%l(depvar(4)),shocklabels(i))
*
* This shifts the colors so the overlay line for the data is black and
* the bars are colored.
*
dec vect[int] symbols(%nvar+1)
ewise symbols(i)=%if(i==%nvar+1,1,i+1)
*
smpl hstart hend
graph(series=byshock,style=stackedbar,overlay=line,$
symbols=symbols,key=below,klabels=histlabels,$
vlabel="Shocks",ovlabel="Data")
smpl