% % ch3ex1.m is an example matlab file to read in % deJongs rbc data and filter it % %format bank % ----- simulate different types of growths ----- % % - time trend - % for j = 1:25 coef=rand(1); for i = 1:150 tt(i,j) = i*log(1+coef) + randn(1); end end % - stochastic trend - % st(1,1:25) = 0; for j = 1:25 coef=rand(1); for i = 1:149 st(i+1,j) = coef + st(i,j) + randn(1); end end figure(1) subplot(2,1,1); plot(tt) subplot(2,1,2); plot(st) % ----- load data from dejong ----- % X = load('rbc1.txt') ; % - log real personal total expenditures c = log(X(:,1)); nsac = log(X(:,6)); % - log Real Personal Consumption Expenditures: Nondurable Goods cnd = log(X(:,2)); % - log Real Gross Private Domestic Investment inv = log(X(:,3)); % - Nonfarm Business Sector: Hours of All Persons h = log(X(:,4)); % ----- make time trend ----- % time=[1948:.25:2004.75]'; % ----- filter the series for the trend ----- % tc = hpfilter(c,1600); tcnd = hpfilter(cnd,1600); tinv = hpfilter(inv,1600); th = hpfilter(h,1600); % ----- filter the detrended series ----- % sc = c - tc; scnd = cnd - tcnd; sinv = inv - tinv; sh = h - th ; % ---- plot graphs of series and hp trend trend ------ % figure(2) subplot(2,2,1); plot(time,c,time,tc) subplot(2,2,2); plot(time,cnd,time,tcnd) subplot(2,2,3); plot(time,inv,time,tinv) subplot(2,2,4); plot(time,h,time,th) % ----- plot stationry hp series ----- % figure(3) subplot(2,2,1); plot(time,sc) subplot(2,2,2); plot(time,scnd) subplot(2,2,3); plot(time,sinv) subplot(2,2,4); plot(time,sh) % ----- bandpass the series ----- % [bpc] = bpass(c,6,40); [bpcnd] = bpass(cnd,6,40); [bpinv] = bpass(inv,6,40); [bph] = bpass(h,6,40); [bpnsac] = bpass(nsac,6,40); % ----- plot bandpass graphs ---- % figure(4) subplot(2,2,1); plot(time,bpc) subplot(2,2,2); plot(time,bpcnd) subplot(2,2,3); plot(time,bpinv) subplot(2,2,4); plot(time,bph) % --- plot bandpass of sa and nsa ----- % figure(5) subplot(2,1,1); plot(time,bpc) subplot(2,1,2); plot(time,bpnsac) % ----- compute summary stats ----- % % - std deviation - % std([bpc bpcnd bpinv bph ]) % - correlation coeff - % corrcoef([bpc bpcnd bpinv bph ]) % - auto correlation - % corrcoef([bpc(3:228) bpc(2:227) bpc(1:226)]) corrcoef([bph(3:228) bpc(2:227) bph(1:226)]) % ----- simulate the economy from midterm ----- % %- solutions from midterm - % f1 =[0.4681 0.4957 0.3569 -0.1313] f2 =[0.9000 0 0.2459 0.8858 ] C = [0.1;0] % - compute states - % x(1:2,1)=[0;0]; for i = 1:1000 x(:,i+1) = f2*x(:,i) + C*randn(1); end % - compute endo vars - % for i = 1:1000 y(:,i) = f1*x(:,i) ; end % - other endo vars go here - % for i = 1:1000 out(:,i) = x(1,i) + .3*x(2,i)+ (1-.3)*y(2,i) ; end std([out(1,100:1000)' y(1,100:1000)' y(2,100:1000)']) corrcoef([out(1,100:1000)' y(1,100:1000)' y(2,100:1000)'])