%Analysis of a stylized technology-only rbc model, here I implement %a transformation and Metropolis-Hastings method as well close all; clear all; clc; addpath(genpath('C:/Matlab7/toolbox/KalmanAll')) %data [time, gdp, cons, inv1, hours,inv2] = textread('datarbc.txt','%d %f %f %f %f %f'); T=size(cons,1); gdphp=hpfilter(gdp,100); y0=log(gdp./gdphp); conshp=hpfilter(cons,100); c0=log(cons./conshp); hourshp=hpfilter(hours,100); l0=hours./hourshp-1;%l0=log(hours./hourshp); [capital] = textread('capital.txt','%f'); capitalhp=hpfilter(capital,100); k0=log(capital./capitalhp); %predefined parameters beta=0.96; g=0.0018; ro=3; alpha=1/3; fi=0.17; lambda=0.65; delta=0.1; sigmay=0.05; sigmak=0.0000000001; sigmac=0.0001; sigmal=0.00015; vol=0.00007; %set of parameters q0=[beta; g; ro; alpha; fi; lambda; delta; sigmay; sigmak; sigmac; sigmal; vol]; qmax=[1; 1; 10; 1; 1; 1; 1; 1; 1; 1; 1; 1]; qmin=[0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0]; q1=transform(q0,qmax,qmin,1); y2=[y0,k0,c0,l0]; % find likelihood maximizer with csminwel - Classical inference %H0=0.0001*eye(12); crit=0.00001; nit=1000; %[fh,xh,gh,H,itct,fcount,retcodeh] = csminwel(@neolike2, q1, H0, [], crit, nit, qmax, qmin, y2); %use Metropolis-Hastings + Bayesian inference %0) set prior variances: a=0.1; st=0.5; vo=1; s2=[a; st; a; a; st; st; st; vo; vo; vo; vo; vo]; %set initial values and compute initial likelihood and probability M=30000; z(:,1)=q1; L0=exp(neolike2(z(:,1),qmax, qmin, y2)); P0=normpdf(z(:,1),q1,s2); P0=exp(log(P0)'*ones(size(P0))); rej=0; %1) generate for i=2:M z(:,i)=z(:,i-1)+s2.*randn(size(s2))/460; %new likelihood L1=exp(neolike2(z(:,i),qmax, qmin, y2)); P1=normpdf(z(:,i),q1,s2); P1=exp(log(P1)'*ones(size(P1))); ratio=L1*P1/(L0*P0); anton=rand; % accept/reject rule if anton