% plotintro.m

% MATLAB contains commands for loading data from ascii-files and for
% plotting, as this program illustrates.

% The ascii file gdp.txt
% contains quarterly nominal gdp for the U.S. from 197Q1-2004Q1, downloaded from
% the website of the Federal Reserve Bank of St. Louis which maintains an
% easy to use set of data files on a large number of macro and financial 
% aggregates. The web link is http://research.stlouisfed.org/fred/

% To load the data in this file, we type

load GDPDAT.txt

% which contains observations of the form 
%1947-01-01    237.2
%1947-04-01    240.5
%1947-07-01    244.6
%1947-10-01    254.4

% Hence, the gdp data that we want is the second column of the matrix 
% GDPDAT that was loaded. To get this second column, we type

gdp=GDPDAT(:,2);

% which is the use of a selection command from a matrix which says to take
% all of the elements from this first column. To get the first four
% elements only, we could type

% display the first four observations of the data
disp('First four data observations')
GDPDAT(1:4,2)
pause

% which means take rows elements 1 through 4 from column 2 
% Additional information on selecting components from matrices
% is available in the MATLAB help manual under the section PROGRAMMING
% and the subsection DATA STRUCTURES. 

% Since the data is quarterly from 1947Q1 through 2004Q1, we can create a date vector 
% as follows.

date=1947:.25:2004;

% This command says to generate a sequence (vector) beginning with 47 and
% ending with 2004, taking increments of .25 since the data is quarterly.

plot(date,log(gdp))
xlabel('date')
ylabel('log(billions of dollars)')
title('U.S. Nominal GDP in the last half century')

% HW1 studied the "Exponential Smoothing Filter".
% The program esmf implements this filter and can be used to produce the
% following results.

lam=20;

g=esmf(log(gdp),lam);

plot(date,log(gdp),date,g),title('Log GDP and ESMF trend')
pause

plot(date,log(gdp)-g),title('Deviations of log GDP from ESMF trend')
