% % Economics 303: % Graphs for Lecture 1 % % George J Hall % Brandeis University % August 2006 % close all clear % % First, graph industrial production % load INDPRO.DAT year = INDPRO(:,1); mth = INDPRO(:,2); day = INDPRO(:,3); IP = INDPRO(:,4); date = year + (mth-1)/12; figure(1) plot(date,log(IP)) xlabel('date (year)'); ylabel('logarithm of Industrial Production'); title('INDUSTRIAL PRODUCTION'); hold on disp('i am pausing, hit the enter key to continue'); pause % % compute and plot a linear trend % regress IP on a constant term and time dummy % T = length(IP); X = [ ones(T,1) (1:T)' ]; Y = log(IP); beta = inv(X'*X)*X'*Y; annual_gr = 12*beta(2,1); disp('annual growth rate of IP'); disp([100*annual_gr]); trend = X*beta; plot(date,trend,'r'); hold off disp('i am pausing, hit the enter key to continue'); pause % % Second, graph real gross domestic product % load GDPC1.DAT year = GDPC1(:,1); mth = GDPC1(:,2); day = GDPC1(:,3); RGDP = GDPC1(:,4); date = year + (mth-1)/12; figure(2) plot(date,log(RGDP)) xlabel('date (year)'); ylabel('logarithm of real GDP'); title('GROSS DOMESTIC PRODUCT'); hold on disp('i am pausing, hit the enter key to continue'); pause % % compute and plot linear trend % regress GDP on a constant term and time dummy % T = length(RGDP); X = [ ones(T,1) (1:T)' ]; Y = log(RGDP); beta = inv(X'*X)*X'*Y; annual_gr = 4*beta(2,1); disp('annual growth rate of RGDP'); disp([100*annual_gr]); trend = X*beta; plot(date,trend,'r'); hold off disp('i am pausing, hit the enter key to continue'); pause % % compute and plot deviations of RGDP from its linear trend % deviations = 100*(log(RGDP) - trend); figure(3) plot(date,deviations,date,zeros(T,1),'r'); xlabel('date (year)'); ylabel('GDP deviations (in percent)'); title('LINEARLY DETRENDED GDP'); disp('i am pausing, hit the enter key to continue'); pause % % A more flexible trend, the Hodrick-Prescott trend. For now, you can % treat this as a black box % [hp_tr,hp_dev] = hptrend(log(RGDP),1600); figure(4) plot(date,log(RGDP),date,trend,'r',date,hp_tr,'g'); xlabel('date (year)'); ylabel('log(GDP)'); title('LOG GDP AND TWO TRENDS'); disp('i am pausing, hit the enter key to continue'); pause figure(5) plot(date(1:floor(T/3)),log(RGDP(1:floor(T/3))),date(1:floor(T/3)),trend(1:floor(T/3)),'r',date(1:floor(T/3)),hp_tr(1:floor(T/3)),'g'); xlabel('date (year)'); ylabel('log(GDP)'); title('LOG GDP AND TWO TRENDS'); disp('i am pausing, hit the enter key to continue'); pause figure(6) plot(date,hp_dev,date,zeros(T,1),'r'); xlabel('date (year)'); ylabel('log deviations from trend'); title('DEVIATIONS FROM FLEXIBLE TREND'); disp('i am pausing, hit the enter key to continue'); pause figure(7) plot(date(1:T-1),(log(RGDP(2:T))-log(RGDP(1:T-1))),date(1:T-1),zeros(T-1,1),'r'); xlabel('date(year)'); ylabel('first differences (in logs)'); title('LOG FIRST DIFFERENCES IN GDP'); disp('i am pausing, hit the enter key to continue'); pause