
*********************************
* OSW MS Supplementary Material *
*********************************

by

Nikolay Osadchiy, Emory University
William Schmidt, Cornell University
Jing Wu, Chinese University of Hong Kong

For questions, please contact Jing Wu at jingwu@cuhk.edu.hk

This readme file describes the supplementary material that accompanies the article "The Bullwhip Effect In Supply Networks", Management Science (2020). The code is written in Stata (Version 15) and Matlab and uses data from Factset Revere and S&P Compustat databases. Additionally used: Table 2BUI. Implicit Price Deflators for Manufacturing and Trade Sales [Index base 2009, 1997 forward, NAICS], Input-output Use tables for years 2007 and 2012, and replication files from Antras et al. "Measuring the Upstreamness of Production and Trade Flows", AER Papers and Proceedings (2012).

To replicate the results in the paper:
1. Extract the contents of this archive into "9. Replication" folder. All addresses below are given relative to the location of that folder, which we denote as "."

2. Obtain the Factset Revere Dataset from Factset or WRDS with the data coverage from 2003 to 2015 and save it as "./Revere201512.dta. The file should have the following fields: start_ end_ id rel_type source_company_id target_company_id subsidiaries revenue_percent percent_estimated source_company_subsidiaries target_company_subsidiaries source_name source_ticker source_cusip source_isin source_sedol target_name target_ticker target_cusip target_isin target_sedol
2.1 Run ./create_revere_quartely_dta.do

3. Create network measures
3.1 Run ./NetworkMeasures/prepare_revere_input.do
3.2 Run ./NetworkMeasures/compute_network_r1.m
3.3 Run ./NetworkMeasures/create_revere_measures_dta.do

4. Obtain the S&P Compustat database (Compustat Daily Updates - Fundamentals Quarterly) from WRDS with data coverage for all companies from Jan 1, 2000 through Dec 31, 2017, and save it to "./Data/" as "COMPUSTAT 20180608.dta". The file should have the following fields: gvkey datadate fyearq fqtr indfmt consol popsrc datafmt tic cusip curcdq datacqtr datafqtr atq ceqq cogsq cshoq dlcq dlttq invtq ltq oiadpq ppentq saleq costat prccq naics sic apq gsector
4.1 Obtain the S&P Compustat database (Compustat Daily Updates - Fundamentals Quarterly) from WRDS with data coverage for all companies from Jan 1, 2000 through Dec 31, 2017, and save it to "./Data/" as "COMPUSTATMarketValue.dta". The file should have the following fields: gvkey datadate cusip datacqtr datafqtr mkvaltq

5. Prepare events and variables
5.1 Run ./Data/Deflators/generate_price_deflators.do to generate "price_deflators.dta"
5.2 Run ./s_cogs(3-4).do to generate "compustat_s_naics3-4.dta"
5.3 Run ./modelfree_add.do to generate "mf_add4.dta", "mf_add8.dta", and "mf_add12.dta"
5.4 Run ./modelfree_drop.do to generate "mf_drop4.dta", "mf_drop8.dta", and "mf_drop12.dta"
5.5 Run ./modelfree_addswap.do to generate "mf_add4swap4.dta", "mf_add8swap4.dta", and "mf_add12swap4.dta"
5.6 Run ./1_VariablePrep.do

6. To replicate Tables 1,2,3,4,7, OA1-OA3, OA10-OA19:
6.1 Run ./NetworkMeasures/outdegree_by_layer.do (Table 1) and spread_of_customers.do (Table 1)
6.2 Run ./BWE/prep_cogs_deflated.do (Table 2) and ./BWE/prep_cogs_deflated_deseason.do
6.3 Run ./BWE/summarize_BWE_DV.do (Tables 3, 4, OA1, OA2, OA3)
6.4 Run ./BWE/summarize_BWE_DV_deseason.do (Tables OA10-OA12)
6.5 Run ./BWE/Correlations/vc_random_vs_selected_by_sic2.do (Table 7)
6.5 Run ./BWE/robustness_UP2007_Dist2_LM.do (Tables OA13-OA18)
6.6 Run ./BWE/BWE_LT.do (Table OA19)

7. To replicate Tables 5, OA4, OA22:
7.1 Run ./modelfree_add.do, modelfree_drop.do, modelfree_addswap.do (Table 5)
7.2 Run ./events/add.do, drop.do, swap.do (Table OA4)
7.3 Run ./deseason/modelfree_add_deseason.do, modelfree_drop_deseason.do, modelfree_addswap_deseason.do (Table OA22)

8. Run the following scripts in Stata:
8.1 Run ./2A_CEM_as.do
8.2 Run ./2A_CEM_CISER.do
8.3 Run ./2A_CEM_drop.do
8.4 Run ./2B_CEM_as.do
8.5 Run ./2B_CEM_CISER.do
8.6 Run ./2B_CEM_drop.do
8.7 Run ./2C_CEM_as.do
8.8 Run ./2C_CEM_CISER.do
8.9 Run ./2C_CEM_drop.do

9. To replicate Tables 9, OA5, OA7-9, OA21 (each file produces a portion of each table):
9.1 Run ./3A_Analysis.do
9.2 Run ./3A_Analysis_as.do
9.3 Run ./3A_Analysis_drop.do

10. To replicate Table 10:
10.1 Run ./3B_Analysis_CapUtil_Moderator.do

11. To replicate Table OA6:
11.1 Run ./4_Balance_Test.do

12. To replicate Table OA20:
12.1 Run ./5_PlaceboTest.do

13. To replicate Table OA23:
13.1 Run ./6A_Variable_Prep.do
13.2 Run ./6B_CEM_4Qtr.do
13.3 Run ./6B_CEM_8Qtr.do
13.4 Run ./6B_CEM_12Qtr.do
13.5 Run ./6C_Analysis.do (this generates the final table results)

14. To replicate Table 6: 
14.1 Run ./7_Change_Event_MacroImpact.do