%
% STATS    Some statistics based on Smets-Wouters (2007) results
%

load usmodel_results
load usmodel_data.csv
load table1_1_5Q.dat

%
% Annualized interest rate (r) and shock (b/.1219)
% where (1-chabb/cgamma)/(csigma*(1+chabb/cgamma)) = 0.1219
% and chabb  = 0.7124
%     cgamma = 1.0043
%     csigma = 1.3952
%
%
t      = ptime(1965.1,160,4);
r      = oo_.SmoothedVariables.r;
b      = oo_.SmoothedVariables.b;
epsb   = -b/.1219;

figure(1)
plot(t,r*4,t,epsb*4)
title('Annualized Interest Rate and Interest Rate Less Premium','Fontsize',16)
set(gca,'Fontsize',16)
legend('r*4','\epsilon_b*4')

%
% Real government spending versus exogenous spending as in Smets and Wouters
%
ctrend = oo_.posterior_mode.parameters.ctrend;
cgamma = 1+ctrend/100 ;
pop    = usmodel_data(73:232,10);
def    = usmodel_data(73:232,3);
ng     = table1_1_5Q(22,73:232)';
nii    = table1_1_5Q(14,73:232)';
nex    = table1_1_5Q(16,73:232)';
nim    = table1_1_5Q(19,73:232)';
ngdp   = table1_1_5Q(3,73:232)';
gdat   = ng./(def.*pop);
gdat   = gdat./(gdat(1)*cgamma.^[0:159]');
gdat2  = (ng+nii+nex-nim)./(def.*pop);
gdat2  = gdat2./(gdat2(1)*cgamma.^[0:159]');
gd     = (log(gdat)-mean(log(gdat)))*100;
gd2    = (log(gdat2)-mean(log(gdat2)))*100;
gshare = mean((ng+nii+nex-nim)./ngdp); 
gm     = oo_.SmoothedVariables.g ;

figure(2)
plot(t,gd,t,gd2,t,gm/gshare)
title('Detrended Real Government Spending','Fontsize',16);
set(gca,'Fontsize',16)
legend('Data, G only','Data, G+NX+Inventories','SW Smoothed Variable g/g share')
