clear all close all x = load('hist_data_no.txt'); time = x(:,1); gnp = x(:,2); c = x(:,3); g = x(:,4); inv = x(:,5); ex = x(:,6); im = x(:,7); n = length(time); lgnp = log(gnp); figure plot(time,lgnp) title('gross national product') ylabel('log') %% growth rates gnp_gr_avg = (lgnp(n) - lgnp(1))/(n-7); % gnp_gr = gnp(2:n)./gnp(1:n-1)-1; % gnp_gr_avg2 = geomean(1+gnp_gr)-1; disp('annual average gnp growth rate (1865 - 2008)') disp([gnp_gr_avg ]) %%gnp_gr_avg2]) %% shares cy_share = c./gnp; iy_share = inv./gnp; gy_share = g./gnp; nx = ex - im; nxy_share = nx./gnp; figure plot(time,[cy_share, iy_share, gy_share, nxy_share]) legend('C/Y','I/Y','G/Y','NX/Y') title('shares to gnp') sample = find(~isnan(gnp)); disp('cy_share, iy_share, gy_share, nxy_share') disp([mean(cy_share(sample)), mean(iy_share(sample)), mean(gy_share(sample)), mean(nxy_share(sample))]) %% cyclical properties prewar w = find(time==1939); prewar = (1:w)'; t = time(prewar); lgnp = log(gnp(prewar)); lc = log(c(prewar)); linv = log(inv(prewar)); lg = log(g(prewar)); nxy_share = nx./gnp; nxy_share = nxy_share(prewar); [lgnp_trend,lgnp_gap] = hp(lgnp,100); [lc_trend,lc_gap] = hp(lc,100); [linv_trend,linv_gap] = hp(linv,100); [lg_trend,lg_gap] = hp(lg,100); [nxy_share_trend,nxy_share_gap] = hp(nxy_share,100); figure plot(t,[lgnp_gap, lc_gap]) legend('gap gnp','gap c') figure plot(t,[lgnp_gap, linv_gap]) legend('gap gnp','gap inv') figure plot(t,[lgnp_gap, lg_gap]) legend('gap gnp','gap g') figure plot(t,[lgnp_gap, nxy_share_gap]) legend('gap gnp','gap nx share') save prewar.mat %% cyclical properties postwar ww = find(time==1946); postwar = (ww:n)'; t = time(postwar); lgnp = log(gnp(postwar)); lc = log(c(postwar)); linv = log(inv(postwar)); lg = log(g(postwar)); nxy_share = nx./gnp; nxy_share = nxy_share(postwar); [lgnp_trend,lgnp_gap] = hp(lgnp,100); [lc_trend,lc_gap] = hp(lc,100); [linv_trend,linv_gap] = hp(linv,100); [lg_trend,lg_gap] = hp(lg,100); [nxy_share_trend,nxy_share_gap] = hp(nxy_share,100); figure plot(t,[lgnp_gap, lc_gap]) legend('gap gnp','gap c') figure plot(t,[lgnp_gap, linv_gap]) legend('gap gnp','gap inv') figure plot(t,[lgnp_gap, lg_gap]) legend('gap gnp','gap g') figure plot(t,[lgnp_gap, nxy_share_gap]) legend('gap gnp','gap nx share') save postwar.mat cc = corrcoef(lgnp_gap,lc_gap); cg = corrcoef(lgnp_gap,lg_gap); ci = corrcoef(lgnp_gap,linv_gap); cnx = corrcoef(lgnp_gap,nxy_share_gap); disp('contemporaneous correlation coefficient with GNP') disp(' C INV G NX share') disp([cc(1,2) cg(1,2) ci(1,2) cnx(1,2)])