function B=quartsumavg(A,n)
%Translate monthly data into quarterly

%MAY STILL NEED TO CHECK THIS

%*A* is a matrix with data at a monthly frequency in columns. 
%The first column are Matlabdates
%First, there are *n* series for which quarterly averages need to be computed
%(this INcludes the Matlabdates)
%Further to the right are the series for which quarterly sums need to be
%computed

rows=size(A,1);
cols=size(A,2);

B=nan(rows/3+2,cols);

%Compute the quarterly average for the first n series (including the dates)
for i=1:n
    for j=3:3:rows
        %B(j/4,i)=(A(j-3,i)+A(j-2,i)+A(j-1,i)+A(j,i))/4;
        B(j/3,i)=mean(A(j-2:j,i));
    end
end

%Compute the quarterly sums for the other series
for i=n+1:cols
    for j=3:3:rows
        %B(j/4,i)=A(j-3,i)+A(j-2,i)+A(j-1,i)+A(j,i);
        B(j/3,i)=sum(A(j-2:j,i));
    end
end
