%MAKETABS    makes tables shown in main text and appendices.
%
%            Ellen McGrattan, 8-31-14
%            Revised, erm, 3-14-15


%
% Show all tables?
%

showall  = input('Which tables? (1=main text, 2=main text and appendix) ');
if (showall==1);
  ntab = 5;
else
  ntab = 20;
end;

%
% Fill in GDP, net worth, wages, and labor input from the baseline
%


%
% Table 7. Transition Paths
%
!rm -f tables.tex
printtex = 1;
icount   = 1;
diary tables.tex
disp('TRANSITION RESULTS FOR SR472/SR473')
disp('----------------------------------')
disp(' ')
diary

for icase=1:ntab;
  !rm -f trantf.dat

  % 
  % Baseline estimates
  %

  if (icase>=1)
    GNP0     = 0.745;
    NWhh0    = 5.574*.745;
    W0       = 1.484;
    L0       = 0.294;
  end;
  if (icase==10)
    GNP0     = 0.733;
    NWhh0    = 6.108*.733;
    W0       = 1.465;
    L0       = 0.293;
  end; 
  if (icase==11)
    GNP0     = 0.760;
    NWhh0    = 5.478*.760;
    W0       = 1.474;
    L0       = 0.301;
  end;
  if (icase==12)
    GNP0     = 0.731;
    NWhh0    = 5.601*.731;
    W0       = 1.503;
    L0       = 0.285;
  end;
  if (icase==13)
    GNP0     = 0.733;
    NWhh0    = 5.600*.733;
    W0       = 1.486;
    L0       = 0.288;
  end;
  if (icase==14)
    GNP0     = 0.681;
    NWhh0    = 5.364*.681;
    W0       = 1.402;
    L0       = 0.283;
  end;
  if (icase==15)
    GNP0     = 0.739;
    NWhh0    = 5.711*.739;
    W0       = 1.517;
    L0       = 0.286;
  end;
  if (icase==16)
    GNP0     = 0.729;
    NWhh0    = 5.752*.729;
    W0       = 1.468;
    L0       = 0.290;
  end;
  if (icase==17)
    GNP0     = 0.745;
    NWhh0    = 5.259*.745;
    W0       = 1.431;
    L0       = 0.303;
  end;
  if (icase==18)
    GNP0     = 0.771;
    NWhh0    = 5.752*.771;
    W0       = 1.527;
    L0       = 0.296;
  end;
  if (icase==19)
    GNP0     = 0.792;
    NWhh0    = 3.540*.792;
    W0       = 1.795;
    L0       = 0.296;
  end;
  if (icase>=20)
    GNP0     = 0.740;
    NWhh0    = 5.717*.740;
    W0       = 1.519;
    L0       = 0.285;
  end;
 
  %
  % Fill in details for appendix
  %


  labelA     = ['                           A. Continue U.S.~Policy                             '];
  labelB     = ['             B. Social Security, Medicare, and FICA Taxes Phased Out,          ';
                '                   Worker Net Tax Functions Temporarily Changed                '];
  labelC     = ['             C. Social Security, Medicare, and FICA Taxes Phased Out,          ';
                '                   Worker Net Tax Functions Permanently Changed                '];
  labelD     = ['             D. Social Security, Medicare, and FICA Taxes Phased Out,          ';
                '                   Worker Net Tax Functions Permanently Changed,               ';
                '                         Capital Income Taxes Phased Out                       '];
  labelE     = ['             E. Social Security, Medicare, and FICA Taxes Phased Out,          ';
                '                   Worker Net Tax Functions Permanently Changed,               ';
                '                Transfers to Low- and Middle-Income Families Increased         '];
  labelF     = ['                Social Security, Medicare, and FICA Taxes Phased Out,          ';
                '                      Taxes and Transfers Phased Out at Same Rate              '];
  labelG     = ['                Social Security, Medicare, and FICA Taxes Phased Out,          ';
                '                     Taxes Phased Out More Quickly Than Transfers              '];
  labelH     = ['                Social Security, Medicare, and FICA Taxes Phased Out,          ';
                '                       Nonmarginal Employer Benefits Phased Out                '];
  labelI     = ['                Social Security, Medicare, and FICA Taxes Phased Out,          ';
                '                   Worker Net Tax Functions Permanently Changed                '];

  %
  % Tables for the Main Text
  %

  if icase==1;
    !cp ../benchmark/continue.dat trantf.dat
    label = labelA;
  elseif icase==2;
    !cp ../benchmark/reverse.dat trantf.dat
    label = labelB;
  elseif icase==3;
    !cp ../benchmark/nomedss.dat trantf.dat
    label = labelC;
  elseif icase==4;
    !cp ../benchmark/nocaptax.dat trantf.dat
    label = labelD;
  elseif icase==5;
    !cp ../benchmark/eqgain.dat trantf.dat
    label = labelE;

  %
  % Tables for the Auxiliary Appendix
  %


  elseif icase==6;

    %
    %  No FICA case with a taxes phased out as same rate as transfers
    %
    !cp ../benchmark/noficas.dat trantf.dat
    label = labelF;

  elseif icase==7;

    %
    %  No FICA case with a taxes phased out more quickly
    %

    !cp ../benchmark/nofica.dat trantf.dat
    label = labelG;

  elseif icase==8;

    %
    %  No FICA case with fringe benefits also phased out
    %

    !cp ../benchmark/nofringe.dat trantf.dat
    label = labelH;


  elseif icase==9;

    %
    %  Only SS phased out
    %

    !cp ../sensitivity/ssonly/nomedss.dat trantf.dat
    label = [labelI;'                         (Medicare transfers not phased out)                   '];

  elseif icase==10;
    %
    %  Debt to GDP = 1
    %

    !cp ../sensitivity/bigdebt/nomedss.dat trantf.dat
    label = [labelI;'                              (Debt to GNP = 1)                                '];

  elseif icase==11;
    %
    %  Government spending (G) includes more categories
    %

    !cp ../sensitivity/biggovt/nomedss.dat trantf.dat
    label = [labelI;'                    (More spending categories included in G)                   '];

  elseif icase==12;
    %
    %  Government spending (G) includes fewer categories
    %

    !cp ../sensitivity/smallgovt/nomedss.dat trantf.dat
    label = [labelI;'                    (Fewer spending categories included in G)                  '];

  elseif icase==13;
    %
    %  Life expectancy depends on productivity (and hence income)
    %

    !cp ../sensitivity/lifeexp/nomedss.dat trantf.dat
    label = [labelI;'                    (Life expectancy depends on productivity)                  '];

  elseif icase==14;
    %
    %  No annuity markets
    %

    !cp ../sensitivity/noannuity/nomedss.dat trantf.dat
    label = [labelI;'                             (No annuity markets)                              ']; 

  elseif icase==15;
    %
    %  Add intergenerational transfers to the no annuity case
    %
    !cp ../sensitivity/bequests/nomedss.dat trantf.dat
    label = [labelI;'                     (Intergenerational transfers included)                    '];

  elseif icase==16;
    %
    %  Cut the labor elasticity in half
    %

    !cp ../sensitivity/elasticity/nomedss.dat trantf.dat
    label = [labelI;'                        (Labor elasticity cut in half)                         '];

  elseif icase==17;
    %
    %  Use the Hansen (1983) productivity profile
    %

    !cp ../sensitivity/epsrising/nomedss.dat trantf.dat
    label = [labelI;'                        (Age-dependent productivities)                         '];

  elseif icase==18;
    %
    %  More AGI bins for net tax function
    %

    !cp ../sensitivity/moretau/nomedss.dat trantf.dat
    label = [labelI;'                      (More AGI bins for net tax function)                     '];

  elseif icase==19;
    %
    %  One-sector, one-capital model (and more AGI bins)
    %

    !cp ../sensitivity/onesector/nomedss.dat trantf.dat
    label = [labelI;'                        (One-sector, one-capital model)                        '];

  elseif icase==20;
    %
    %     Increase number of productivity levels
    %

    !cp ../sensitivity/morebins/nomedss.dat trantf.dat
    label = [labelI;'                         (Seven productivity levels)                           '];

  end;

  load trantf.dat
  if (icase==16);
    plottrantf_e
  else
    plottrantf
  end;

  ii               = [1:5,7];
  Table6(1,:)      = AVG(ii,36)-AVG(ii,32);  
  tabstr(1,:)      = '  Tax revenues (net)           %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f'; 
  texstr(1,:)      = '  \\strut& Tax revenues (net)                    && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(2,:)      = AVG(ii,40);
  tabstr(2,:)      = '    Profits, Schedule C        %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f'; 
  texstr(2,:)      = '    \\strut& \\ \\ \\ Profits, Schedule C        && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(3,:)      = AVG(ii,39);
  tabstr(3,:)      = '    Distributions, Schedule C  %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f'; 
  texstr(3,:)      = '    \\strut& \\ \\ \\ Distributions, Schedule C  && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(4,:)      = AVG(ii,41);
  tabstr(4,:)      = '    Distributions, Other       %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f'; 
  texstr(4,:)      = '    \\strut& \\ \\ \\ Distributions, Other       && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(5,:)      = AVG(ii,37);
  tabstr(5,:)      = '    Consumption                %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f'; 
  texstr(5,:)      = '    \\strut& \\ \\ \\ Consumption                && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(6,:)      = AVG(ii,38)-AVG(ii,32);
  tabstr(6,:)      = '    Labor inc. (net), by type  %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f'; 
  texstr(6,:)      = '    \\strut& \\ \\ \\ Labor inc. (net), by type  && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(7,:)      = AVG2(ii,1)-AVG(ii,72+5*ne);
  tabstr(7,:)      = '      Low                      %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f'; 
  texstr(7,:)      = '      \\strut& \\ \\ \\ \\ \\ \\ Low             && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  for n=2:ne-1;
    Table6(6+n,:)  = AVG2(ii,n)-AVG(ii,71+5*ne+n);
    tabstr(6+n,:)  = '      Medium                   %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f'; 
    texstr(6+n,:)  = '      \\strut& \\ \\ \\ \\ \\ \\ Medium          && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  end;
  k                = 6+ne;
  Table6(k,:)      = AVG2(ii,ne)-AVG(ii,71+6*ne);
  tabstr(k,:)      = '      Top 1 pct                %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k,:)      = '      \\strut& \\ \\ \\ \\ \\ \\ Top 1 pct       && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+1,:)    = AVG(ii,31);
  tabstr(k+1,:)    = '  Retiree transfers, by type   %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+1,:)    = '  \\strut& Retiree transfers, by type            && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+2,:)    = AVG(ii,72+4*ne)+0*AVG(ii,72+5*ne);
  tabstr(k+2,:)    = '    Low                        %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+2,:)    = '    \\strut& \\ \\ \\ Low                        && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  k                = k+3;
  for n=2:ne-1;
    Table6(k,:)    = AVG(ii,71+4*ne+n)+0*AVG(ii,71+5*ne+n);
    tabstr(k,:)    = '    Medium                     %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f'; 
    texstr(k,:)    = '     \\strut& \\ \\ \\ Medium                    && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
    k              = k+1;
  end;
  Table6(k,:)      = AVG(ii,71+5*ne)+0*AVG(ii,71+6*ne);
  tabstr(k,:)      = '    Top 1 pct                  %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k,:)      = '    \\strut& \\ \\ \\ Top 1 pct                  && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+1,:)    = AVG(ii,34);
  tabstr(k+1,:)    = '  Interest on debt             %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+1,:)    = '  \\strut& Interest on debt                      && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+2,:)    = AVG(ii,20);
  tabstr(k+2,:)    = '  Labor income                 %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+2,:)    = '  \\strut& Labor income                          && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+3,:)    = sum(AVG(ii,[17,21,25])')';
  tabstr(k+3,:)    = '  Capital income               %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+3,:)    = '  \\strut& Capital income                        && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+4,:)    = AVG(ii,12);
  tabstr(k+4,:)    = '  Consumption                  %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+4,:)    = '  \\strut& Consumption                           && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+5,:)    = AVG(ii,13);
  tabstr(k+5,:)    = '  Tangible investment          %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+5,:)    = '  \\strut& Tangible investment                   && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+6,:)    = AVG(ii,28);
  tabstr(k+6,:)    = '  Intangible investment        %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+6,:)    = '  \\strut& Intangible investment                 && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+7,:)    = AVG(ii,16);
  tabstr(k+7,:)    = '  Defense                      %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+7,:)    = '  \\strut& Defense                               && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+8,:)    = AVG(ii,46);
  tabstr(k+8,:)    = '  Tangible capital             %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+8,:)    = '  \\strut& Tangible capital                      && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+9,:)    = AVG(ii,49);
  tabstr(k+9,:)    = '  Intangible capital           %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+9,:)    = '  \\strut& Intangible capital                    && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  nshr             = k+9;
  Table6(k+10,:)   = AVG(ii,9);
  tabstr(k+10,:)   = '  Interest rate                %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+10,:)   = '  \\strut& Interest rate                         && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+11,:)   = AVG(ii,10)/W0;
  tabstr(k+11,:)   = '  Wage rate                    %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+11,:)   = '  \\strut& Wage rate                             && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+12,:)   = AVG(ii,68)/L0;
  tabstr(k+12,:)   = '  Labor input                  %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+12,:)   = '  \\strut& Labor input                           && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+13,:)   = AVG(ii,69)/GNP0;
  tabstr(k+13,:)   = '  GNP                          %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+13,:)   = '  \\strut& GNP                                   && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 
  Table6(k+14,:)   = AVG(ii,60).*AVG(ii,69)/NWhh0;
  tabstr(k+14,:)   = '  Net worth                    %9.3f%9.3f%9.3f%9.3f%9.3f%9.3f';
  texstr(k+14,:)   = '  \\strut& Net worth                             && %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&& %9.3f&\\cr'; 


  diary tables.tex
  disp(' ')
  disp(' ')
  if printtex==0;
    disp('         Table 7. Transitions from Current US Policy to New Policies  ')
    disp(label)
    disp('=============================================================================')
    disp('                        2011-20  2021-30  2031-40  2041-70  2071-99  BG path')
    disp('                        -----------------------------------------------------')  
    disp('Shares of GNP:')
    for i=1:nshr;
      disp(sprintf(tabstr(i,:),Table6(i,:)))
    end;
    disp('Levels')
    for i=nshr+1:nshr+5;
      disp(sprintf(tabstr(i,:),Table6(i,:)))
    end;
    disp('=============================================================================')
  else
    disp('\newpage')
    if (icase<=5);
      disp(['\centerline{\smcaps Table 7. Transitions from Current U.S.~Policy to New Policies}'])
    else
      disp(['\centerline{\smcaps Table A',int2str(icount),'. Transitions from Current U.S.~Policy to New Policies}'])
      icount = icount+1;
    end;
    [n,m]=size(label);
    for irow=1:n;
      disp('\vskip -5pt')
      disp(['\centerline{',label(irow,:),'}'])
    end;
    disp('\medskip')
    disp('\centerline{\vbox{\tabskip=0pt\offinterlineskip')
    disp('\def\tablerule{\noalign{\hrule}}')
    disp('\halign to450pt{\tabskip=1em plus2em')
    disp('#&#\hfil&')
    disp('#&\hfil#&')
    disp('#&\hfil#&')
    disp('#&\hfil#&')
    disp('#&\hfil#&')
    disp('#&\hfil#&')
    disp('#&\hfil#&')
    disp('#\tabskip=0pt\cr')
    disp('\noalign{\medskip}')
    disp('\tablerule')
    disp('\noalign{\vskip 2pt}')
    disp('\tablerule')
    disp('\noalign{\bigskip}')
    disp('\strut&   && \omit\hidewidth 2011-20\hidewidth&&')
    disp('              \omit\hidewidth 2021-30\hidewidth&&')
    disp('              \omit\hidewidth 2031-40\hidewidth&&')
    disp('              \omit\hidewidth 2041-70\hidewidth&&')
    disp('              \omit\hidewidth 2071-99\hidewidth&&')
    disp('              \omit\hidewidth $\infty$\hidewidth&\cr')
    disp('\strut& & \multispan{13}\hrulefill\cr')
    disp('\noalign{\vskip -5pt}')
    disp('\strut&\hskip -.2truein {\smcaps Shares of GNP:} && && && && && && &\cr')
    disp('\noalign{\medskip}')
    for i=1:nshr;
      disp(sprintf(texstr(i,:),Table6(i,:)))
      if ne<5;
        disp('\noalign{\vskip 3pt}')
      else 
        disp('\noalign{\vskip 1pt}')
      end
    end;
    disp('\noalign{\medskip}')
    disp('\strut&\hskip -.2truein {\smcaps Levels:} && && && && && && &\cr')
    for i=nshr+1:nshr+5;
      disp(sprintf(texstr(i,:),Table6(i,:)))
      if ne<5;
        disp('\noalign{\vskip 3pt}')
      else
        disp('\noalign{\vskip 1pt}')
      end
    end;
    disp('\noalign{\vskip 3pt}')
    disp('\tablerule')
    disp('\noalign{\vskip 2pt}')
    disp('\tablerule}}}')

  end;
  disp(' ')
  disp(' ')
  diary 

end;
!rm -f trantf.dat
