================================================================================
REPLICATION PACKAGE

"Production Networks and Monetary Policy in Distorted Economies"
================================================================================


1. OVERVIEW
--------------------------------------------------------------------------------

This package reproduces every figure and table in the paper that is generated
from data. Three driver scripts sit in the root directory:

    main.m                        main text figures      -> figures/
    appendix.m                    appendix figures       -> figures_appendix/
    tabularwelfaregiandecomp.m    welfare gain table     -> Command Window

Each driver is self-contained: it clears the workspace, loads the cleaned data
from data_clean/, adds functions/ to the path, and writes its own output. They
may be run in any order and do not depend on one another.

The cleaned data are shipped as .mat files, so the package runs without any
Excel or CSV import step.


2. SOFTWARE REQUIREMENTS
--------------------------------------------------------------------------------

MATLAB R2020a or later.
    exportgraphics, used by appendix.m, was introduced in R2020a.

Statistics and Machine Learning Toolbox.
    Required only by tabularwelfaregiandecomp.m, for mvnrnd.

No other toolboxes are used. main.m and appendix.m run on base MATLAB.

Third-party code included in functions/:
    latexTable.m    Eli Duenisch, 2016. BSD 2-Clause license, reproduced in
                    the file header. Obtained from the MATLAB File Exchange.
                    Used only to format the welfare gain table as LaTeX.

All other code in this package was written by the authors.


3. HOW TO RUN
--------------------------------------------------------------------------------

Set the MATLAB working directory to the root of this package, that is, the
directory containing this README, and run:

    >> main.m
    >> appendix.m
    >> tabularwelfaregiandecomp.m

The drivers build their file paths from the current directory, so they must be
started from the package root. appendix.m creates figures_appendix/ if it does
not already exist.

Runtime. main.m and appendix.m complete in well under a minute. The Monte Carlo
in tabularwelfaregiandecomp.m is far more expensive: it evaluates 10,000
productivity draws under three policies, and welfarefunction.m and
solveoutputgap.m rebuild their input-output matrices at every draw even though
those matrices depend only on the calibration. Allow a long run for this script.


4. MAP FROM CODE TO EXHIBITS
--------------------------------------------------------------------------------

  Exhibit     Output file                                    Driver
  ---------   --------------------------------------------   -----------------
  Figure 1    figures/supplysideeffectdecomp.png             main.m
              figures/supplysideeffectdecomp_ucmarkup.eps
  Figure 2    figures/inflationbiasdecomp_ucmarkup.eps       main.m
  Table 2     printed to the Command Window                  tabularwelfaregiandecomp.m
  Figure 3    figures/RBT_inflationbiasdecomp_preferences.png  main.m
              figures/RBT_inflationbiasdecomp_preferences.eps
  Figure A.1  figures_appendix/IndustryContribution.png      appendix.m
  Figure A.2  figures_appendix/scatterplot.png               appendix.m
  Figure A.3  figures_appendix/outputresponsedecomp_ucmarkup.png   appendix.m
              figures_appendix/outputresponsedecomp_ucmarkup.eps
  Figure A.4  figures_appendix/RBT_supplysideeffectdecomp.png      appendix.m
              figures_appendix/RBT_supplysideeffectdecomp.eps

Table 1 in the paper lists the definitions of the three input-output matrices
and is typeset directly in the paper source; no code produces it.

Section 5 of appendix.m additionally produces four robustness figures under the
accounting profit and production function markup measures:

    figures_appendix/supplysideeffectdecomp_apmarkup.eps
    figures_appendix/supplysideeffectdecomp_pfmarkup.eps
    figures_appendix/inflationbiasdecomp_apmarkup.eps
    figures_appendix/inflationbiasdecomp_pfmarkup.eps

These are not reported in the current draft.


5. DIRECTORY STRUCTURE
--------------------------------------------------------------------------------

    README.txt                     this file
    main.m                         driver, main text figures
    appendix.m                     driver, appendix figures
    tabularwelfaregiandecomp.m     driver, welfare gain table

    data_raw/                      source files as downloaded
        FPA/                       frequency of price adjustment
        IO_table/                  BEA input-output use tables
        markup/                    industry markup series
        productivity/              BLS multifactor productivity

    data_clean/                    analysis data plus the scripts that build it
        FPA/           FPA_import.m           -> FPA_sum.mat
        IO_table/      IO_import.m            -> IO_sum.mat
        markup/        markup_sum_import.m    -> markup_sum.mat
        productivity/  productivity_import.m  -> MFP.mat
                       productivity_disaggregate.m

    functions/                     model and utility functions
    figures/                       output of main.m
    figures_appendix/              output of appendix.m


6. DATA
--------------------------------------------------------------------------------

Analysis inputs, all under data_clean/. The three drivers read only these files.

  File                    Variable                Size            Contents
  ---------------------   ---------------------   -------------   ----------------
  FPA/FPA_sum.mat         FPA                     66 x 1          monthly frequency
                                                                  of price adjustment
  IO_table/IO_sum.mat     IO_matrix_sum           79 x 94 x 25    use tables, 1997-2021
                          indname                 79 x 1          industry names
  markup/markup_sum.mat   mu_sum                  66 x 19 x 3     markups, 1997-2015
  productivity/MFP.mat    Sigmaz                  66 x 66         covariance of
                                                                  productivity shocks
                          log_MFP_linear_detrended 129 x 66       detrended log MFP

The analysis uses 66 industries and the years 1997-2015, so the trailing years of
IO_matrix_sum are not used.

The third dimension of mu_sum indexes the markup measure:
    (:,:,1) user cost (UC)   (:,:,2) accounting profit (AP)
    (:,:,3) production function (PF)
All exhibits in the paper use UC markups.

Rebuilding the cleaned data. The import scripts in data_clean/ regenerate the
.mat files from data_raw/. Each is guarded by a check on whether its .mat file
already exists, so with the shipped data in place they load rather than reimport.
To rerun an import, delete the corresponding .mat file, set the working directory
to that script's own folder, and run it there; the scripts resolve their raw data
paths relative to their own location.


7. FUNCTIONS
--------------------------------------------------------------------------------

  supplyside.m           Sufficient statistic for the supply-side effect of
                         monetary policy (Proposition 1), returned in total and
                         split into substitution between sectoral products and
                         substitution between labor and intermediate inputs,
                         both in aggregate and by sector.

  outputresponse.m       Decomposition of the output response to a monetary
                         shock into supply-side and demand-side effects
                         (Proposition 2).

  optimalpolicy.m        Sectoral inflation weights and inflation bias under
                         the optimal policy (Proposition 5), together with the
                         weights for output-gap targeting and for the divine
                         coincidence index.

  solveoutputgap.m       Output gap implied by a policy and a realized
                         productivity draw.

  welfarefunction.m      Second-order welfare approximation (Proposition 4),
                         returned as the total and its six components.

  expectedwelfaregain.m  Converts expected welfare into a consumption
                         equivalent, in percent.

  weightedcov.m          Weighted covariance used throughout.

  latexTable.m           Third-party LaTeX table formatter, see section 2.

solveoutputgap.m and welfarefunction.m take the calibration from the global
workspace rather than through their argument lists, which is why
tabularwelfaregiandecomp.m declares those variables global before calling them.


8. REPRODUCIBILITY
--------------------------------------------------------------------------------

main.m and appendix.m are deterministic.

tabularwelfaregiandecomp.m draws productivity shocks by Monte Carlo. The
generator is reset immediately before the draw with

    rng('default');
    rng(1);

so the reported table is reproduced exactly on any machine running a MATLAB
version with the same default generator.


9. EXHIBITS NOT PRODUCED BY THIS PACKAGE
--------------------------------------------------------------------------------

The following figures appear in the paper but are not generated by any script
included here:

    figures_appendix/InflationIndex.png             industry weights of the
                                                    inflation index by sector
    figures_appendix/supplysideeffectdecomp_appendix.png
                                                    nested CES economy
    figures/phillipscurveslope_withIO.png           flattening of the Phillips
                                                    curve

================================================================================
