12/30/2022
This file explains how to produce the tables and figures in the "tail risk in production networks". It explains data sources and then gives instructions for generating each figure and the table. The outputs are saved in the main directory. 

** data availability statement:

The only empirical data used in this paper is from the BEA input -output tables. The files used are:
IOUse_After_Redefinitions_PRO_DET.xlsx (from https://apps.bea.gov/industry/xls/io-annual/IOUse_After_Redefinitions_PRO_DET.xlsx")
IOUse_Before_Redefinitions_PRO_1997-2020_Summary.xlsx (from https://apps.bea.gov/histdata/Releases/Industry/2021/GDP_by_Industry/Q2/Annual_September-29-2021/AllTablesIO.zip)
IOUse_Before_Redefinitions_PRO_1963-1996_Summary.xlsx (from https://apps.bea.gov/industry/xls/io-annual/IOUse_Before_Redefinitions_PRO_1963-1996_Summary.xlsx)

The files rows_97_20.csv, columns_97_20.csv, rows_63_96.csv, and columns_63_96.csv are sets of row and column names copied directly from the two previous files. 

The folder "csv files" contains csv copies of all files that are not already available here in a generic raw format. 

** References:
U.S. Bureau of Economic Analysis, “Input-output accounts" (accessed 7/31/2023)
U.S. Bureau of Economic Analysis, "Data Archive: Gross Domestic Product by Industry and Input-Output Statistics, 2021, Q2"

** Metadata:
In all three cases, this data represents uses of commodities by industry in the US. The files differ based on the level of industry detail and also whether secondary products produced by industry have been reallocated to the primary producing industry. 

****
* computing:
This was all run on Windows 10. I used Stata version 17.0, Matlab 2022b, and Microsoft Excel version 2306. 
The expected running time is less than one minute for any of the code. 


*************
Specific figures and tables

Figure 2:
Created in latex using the tikz code in figure2.txt. This is just a plot of analytic functions. There is neither data nor a simulation involved. 

Figure 3:
Run the stata script fig3.do. That file uses data from fig_data.txt, which is itself created in the spreadsheet fig_data.xlsx. Sheet 1 uses formulas from the paper, the numbers are then collected in sheet 2 and you can copy them into fig_data.txt. These are just graphs of analytic formulas -- they involve neither empirical data nor a simulation. The figure is saved as example.pdf.


Figure 4 and Table 1:
The original data is in the "2012" sheet in IOUse_After_Redefinitions_PRO_DET.xlsx (which is directly from the BEA). 
The file gdp2012.txt is a column with the sum of the data for consumption, private and public investment (excluding inventories) and exports for each good (this is in column OS of the "2012" sheet). It is created by copying column OS in the sheet included here (which is a formula added into the file downloaded from the BEA). 
IO2012.txt is the full input-output matrix from the spreadsheet. It is columns C-OB and rows 7-395. (there are formulas for getting the zeros in cells C421 to OB809). 
vadd2012.txt is the value added row (code T006, which is row 416 in the spreadheet). 
The matlab data file names_codes.mat has the list of names and commodity codes from columns A and B.
The table and figure are created in matlab by the script IO.m. The table is output in the matlab terminal and the figure is saved as centrality_fig.pdf

Figure 5:
The figure is produced using the stata file hospitals.do. The original data is in the files IOUse_Before_Redefinitions_PRO_1997-2020_Summary.xlsx and IOUse_Before_Redefinitions_PRO_1963-1996_Summary.xlsx. 
Specifically:
IO_63_96.txt is obtained from cells C81-AJ5960 in the sheet "1963" in IOUse_Before_Redefinitions_PRO_1963-1996_Summary.xlsx
IO_97_20.txt  is obtained from cells C91-Z7516 in the sheet "1997" in IOUse_Before_Redefinitions_PRO_1997-2020_Summary.xlsx
Stata produces the numbers, and they are then copied into "hospital computer plot.xlsx" as described in the code. 

