%NONTAXED    Use Flow of Funds data to estimate fraction of 
%            equity that is not taxed.

%            Ellen McGrattan, 5-31-01
%            Revised, 6-15-11


% Data to load:
%     FOF  Table F.6,     quarterly 1952:1-2011:1
%     FOF  Table B.100,   quarterly 1952:1-2011:1
%     FOF  Table L.213,   quarterly 1952:1-2011:1
%     FOF  Table L.100.a, annually  1987-2000
%     FOF  Table B.100.e, annually  1952-2010
%     FOF  Table L.225.i, annually  1981-2010
%     ICI  Fundamentals,  2010
%     ICI  MF Fact Book,  1997,2005,2011
%

load ../FOF/atab6d.dat
load ../FOF/btab100d.dat
load ../FOF/ltab213d.dat
load ../FOF/btab100e.dat
load ../FOF/ltab100a.dat
load ../FOF/ltab225i.dat
load mf_npo_type.dat
load mf_ira_type.dat


ltab100a = [[1952:1986]',zeros(35,26);
             ltab100a;
            [2001:2010]',zeros(10,26)];
ltab225i = [[1952:1980]',zeros(29,8);
             ltab225i];

npoe     = (mf_npo_type(:,2)+.5*mf_npo_type(:,3))./mf_npo_type(:,5);
npoe(1:6)= npoe(7);
npoe     = [[1952:2010]',[npoe(1)*ones(38,1);npoe]];
irae     = (sum(mf_ira_type(:,[2,4])')'+.5*mf_ira_type(:,6))./ ...
           (mf_ira_type(:,12)-mf_ira_type(:,10));
irae     = [[1952:2009]',[irae(1)*ones(38,1);irae];2010,irae(20)];

%
% Years to load: Y0 through Y1
%

Y0       = 1952;
Y1       = 2010;

%
% Extract data:
%

atab6a         = qtr2ann(atab6d);
atab6a         = atab6a(Y0-1951:Y1-1951,2:42)'/1000;
ltab213a       = qtr2ann(ltab213d,1);
ltab213a       = ltab213a(Y0-1951:Y1-1951,2:24)'/1000;
btab100a       = qtr2ann(btab100d,1);
btab100a       = btab100a(Y0-1951:Y1-1951,2:51)';
btab100e       = btab100e(Y0-1951:Y1-1951,2:22)'/1000;
ltab100a       = ltab100a(Y0-1951:Y1-1951,2:27)'/1000;
ltab225i       = ltab225i(Y0-1951:Y1-1951,2:9)'/1000;
irae           = irae(Y0-1951:Y1-1951,2);
npoe           = npoe(Y0-1951:Y1-1951,2);

%
% Intermediate variables
%

t              = [Y0:Y1]';
gdp            = atab6a(1,:)';
pfunds         = sum(btab100e([9,10,13,14],:))';
nonprf         = ltab100a(13,:)'+ltab100a(14,:)'.*npoe;
iras           = ltab225i(1,:)'.*irae;
total          = btab100e(6,:)';
v              = ltab213a(23,:)';
nonprf         = nonprf./v;
t00            = find(t==2000);
tp             = t00+1:length(t);
nonprf(tp)     = nonprf(t00);
nontax         = (pfunds+iras)./v +nonprf;

tem            = [[Y0:Y1]',v./gdp,nontax,pfunds./v,iras./v,nonprf];
disp('---------------------------------------------------------------------------')
disp('         Ratio of     Fraction of     Fraction of Total Equity Value in    ')
disp('          Equity        Equity      ---------------------------------------')
disp(' Year  Value to GDP    Sheltered    Pension Funds     IRAs      Nonprofits*')
disp('---------------------------------------------------------------------------')
disp(sprintf(' %4g %10.3f %13.3f %13.3f %13.3f %13.3f \n',tem'))
disp('---------------------------------------------------------------------------')
disp(' * data only available 1987-2000, later periods use estimate for 2000')
