For an economics assignment, I need to use data from the quarterly GDP growth rate data from Fed website and figure out how many technical recessions have occurred from 1952-2010.
This means I need to count the number of sequences which have 3 or more consecutive negative growth rates.
This is the code I have so far:
Data = xlsread('Q3.xls','D14:E271');
matlab_dates = Data(:,1)
real_GDP_growth = Data(:,2);
growth_data = [matlab_dates real_GDP_growth];
T = length(growth_data);
recession_tracker = zeros(T,1);
for i=2:T
if growth_data(i,2) < 0
recession_tracker(i,1) = recession_tracker(i-1,1) + 1;
else recession_tracker(i,1) = 0;
end
end
So Q3.xls contains 2 columns (D and E). Column D is the date column (with Quarterly dates formatted like yyyy-mm-dd, e.g. 1952-01-01, 1952-04-01); Column E is the growth rate column.
Matlab refuses to import the data from the Date column, and consequently my whole code doesn't work!
I would appreciate any suggestions on how to debug, or how to do this better!
If you are trying to get at the dates, then you may find the following useful.
You can get the formatted dates by grabbing the second output of xlsread(), then unformatting using datenum().
[M,txt] = xlsread('Q3.xls','D14:E271');
for row = 1:size(txt, 1)
try
% assuming date in the first column
date = datenum( txt{row, 1}, 'yyyy-mm-dd');
catch
continue;
end
... do something with date ...
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With