% This code gets and treats data from Fred 
url = 'https://fred.stlouisfed.org/';
c = fred(url);

series1 = 'NGDPRSAXDCBRQ'  ;    %  y    
series2 = 'NAEXKP02BRQ189S';    %  c
series3 = 'NAEXKP04BRQ652S';    %  inv
series4 = 'BRACPIALLQINMEI';    %  inflnet  
series5 = 'CPALTT01BRQ659N';    %  inflnet  
series6 = 'NCGGRSAXDCBRQ';    %  g  

startdate = '01/01/1997';
enddate = '12/31/2019';
d1 = fetch(c,series1,startdate,enddate);
d2 = fetch(c,series2,startdate,enddate);
d3 = fetch(c,series3,startdate,enddate);
d4 = fetch(c,series4,startdate,enddate);
d5 = fetch(c,series5,startdate,enddate);
d6 = fetch(c,series6,startdate,enddate);

close(c);


% plot(d1.Data(:,2)); hold on; plot(d2.Data(:,2)); hold off;

[yt , logy] = hpfilter(log(d1.Data(:,2)), 1600 );
[ct ,logc] = hpfilter(log(d2.Data(:,2)), 1600 );
[invt , loginv] = hpfilter(log(d3.Data(:,2)), 1600 );
[inflt , inflnet] = hpfilter(log(d4.Data(:,2)), 1600 );
[gt , logg] = hpfilter(log(d6.Data(:,2)), 1600 );

save('savefile037.mat', 'logy', 'logc', 'loginv','inflnet','logg');
