README - Replication Code for "Externalities of Policy-Induced Scrappage: The Case of Automotive Regulations" by Connor R. Forsythe, Akshaya Jha, Jeremy J. Michalek, and Kate S. Whitefoot

*****Directory Structure*****

This folder contains the necessary data and code to recreate all primary results contained in "Externalities of Policy-Induced Scrappage: The Case of Automotive Regulations" that don't require access to proprietary data. There is one primary directories which are described below along with descriptions of the contents in each sub-directory. Note, running the full code on a 14" 2021 MacBook Pro with 32 GB of RAM takes roughly 7 hours. Leave-one-out analyses and random treatment analyses often take the most time. For much faster results, comments these sections out of the "RunModel.do" file.


- Primary Model
	--Data; Data used to estimate primary model and various sensitivity cases.
	--Data; Data saved in this directory during the process of running model. Used to save Bacon Decomposition results.
	--Logs; Stata logs saved to this directory.
	--Plots; Plots saved to this directory.
		---LOO; Plots describing leave-one-out analyses saved here.
		---NeighborAnalysis; Plots describing spillover analysis (i.e. treatment impact on neighboring states) saved here.
		---RandTreatSim; Plots describing random treatment simulation analysis saved here.
		---ResidualPlots; Plots of residuals saved here.
	--PythonScripts; Scripts called by Stata during analysis are stored here.
		---Data; Various intermediate data necessary for result estimation/calculation.
		---Plots
			----Elasticities; Plots of elasticity comparison saved here.
			----Externalities; Plots of externality comparison saved here.
		---Tables
			----externalities.xlsx; stored externality data
		---plotResiduals.py;
		---plotExternalities.py;
		---PlotElasticityComparisons.py;
		---outputLOO.py;
		---Inflator.py;
		---combineIV.py;
		---calculateExternalities.py;
		---calculateARStat.py;
		---addNeighboringStateVariables.py;
	--Tables; Tables are saved to this directory.
		---iv.xlsx; Final results from all IV analyses are stored in this file. Separate files are created for each specification and combined into this one file.
		---Elasticities; Tables of elasticity comparison saved here.
		---LOO; Tables describing leave-one-out analyses saved here.
		---NeighborAnalysis; Tables describing spillover analysis (i.e. treatment impact on neighboring states) saved here.
		----Externalities; Folder where several tables are stored
		---RandTreatSim; Tables describing random treatment simulation analysis saved here.
	--bacondecomp2.do; A slightly edited version of the bacondecomp package (available at https://ideas.repec.org/c/boc/bocode/s458676.html) that corrects a small bug in the current version of the code. Reproduced with the permission of the corresponding author Austin Nichols.
	--BaconEstimation.do; Estimates Bacon Decomposition.
	--externalityAnalysis.do; Performs externality analysis comparisons.
	--GasUseIV.do; Estimates gas use outcome IV models.
	--GasUseIVLOO.do; Runs leave one out analysis for gas use IV models under primary specification.
	--GasUseRFDiD.do; Estimated reduced form models with gas use outcomes.
	--GasUseRFES.do; Estimate event study models with gas use outcomes.
	--LoadDataBacon.do; Loads and clean data utilized in Bacon Decomposition. Ensures for a balanced panel.
	--LoadDataGasUse.do; Loads and cleans data utilized in gas use analyses.
	--LoadDataVMT.do; Loads and cleans data utilized in travel analyses.
	--neighborStateAnalysis.do; Estimates spillover analyses with registration outcomes.
	--LOO.do; Runs leave one out analysis for the registration difference in differences under the primary specification.
	--neighborStateAnalysisGasUse.do; Estimates spillover analyses with gas use outcomes.
	--neighborStateAnalysisVMT.do; Estimates spillover analyses with travel outcomes.
	--programs.do; Contains various programs used for model estimation and storing results.
	--RandTreatSimReg.do; Randomly simulates treatment and estimates difference in differences models.
	--RegDiD.do; Estimates registration difference in differences models.
	--RegES.do; Estimates registration event studies.
	--RegESWoTT.do; Estimates registration event studies without the inclusion of state-specific time trends.
	--RunModel.do; Primary script that should be used to run full analysis. Running individual scripts may not work properly as there are data/program dependencies handled across scripts. Best practice is to run sections of this script if one would like to recreate specific results.
	--summarizeLOO.do; Creates the summary information for the leave one out analyses.
	--SummarizeRandTreatment.do; Summarizes the output from randomized treatment exercise.
	--VMTIV.do; Estimates both the travel outcome IV models presented in the paper.
	--VMTIVLOO.do; Runs leave one out analysis for the travel IV model under the primary specification.
	--VMTRFDiD.do; Estimates reduced form model for travel outcomes.
	--VMTRFES.do; Estimates event study for travel outcomes.




*****Main Body Plot and Table Locations*****
-Tables
	-- Table 4: Subset of columns in table located at PrimaryModel/Tables/DiD/RegDiD
	-- Table 5: Subset of columns in table located at PrimaryModel/Tables/IV/VMTiv
	-- Table 6: Subset of columns in table located at PrimaryModel/Tables/IV/GasUseiv
	-- Table B.1: PrimaryModel/Tables/DiD/RegDiD
	-- Table B.2: PrimaryModel/Tables/IV/VMTiv
	-- Table B.3: PrimaryModel/Tables/IV/GasUseiv
	-- Table B.4: PrimaryModel/Tables/DiD/RegDiDWoTT
	-- Table B.5: PrimaryModel/Tables/LOO/LOO-VMT
	-- Table B.6: PrimaryModel/Tables/LOO/LOO-Gas
	-- Table B.7: PrimaryModel/Tables/LOO/LOO-DiDPValues
	-- Table B.8: PrimaryModel/Tables/DiD/RegPerCapitaDiD
	-- Table B.9: PrimaryModel/Tables/IV/VMTPerCapitaiv
	-- Table B.10: PrimaryModel/Tables/IV/GasUsePerCapitaiv
	-- Table B.11: PrimaryModel/Tables/RandTreatSim/RandTreatRejectionRates
-Figures
	-- Figure 4.a: PythonScripts/Plots/Elasticities/VMT/VMTElasticities
	-- Figure 4.b: PythonScripts/Plots/Elasticities/VMT/GasUseElasticities
	-- Figure 5: PrimaryModel/Plots/ES/RegESSpec26.png
	-- Figure 6: PrimaryModel/Plots/NeighborAnalysis/NeighborStateSpec26.png
	-- Figure 7: PrimaryModel/Plots/Externalities/TotalExternalities.png
	-- Figure B.1: PrimaryModel/PlotsResidualPlots/Spec1ResPlot.png; PrimaryModel/PlotsResidualPlots/Spec2ResPlot.png; PrimaryModel/PlotsResidualPlots/Spec3ResPlot.png; PrimaryModel/PlotsResidualPlots/Spec4ResPlot.png
	-- Figure B.2: PrimaryModel/Plots/ES/RegESSpec16.png; PrimaryModel/Plots/ES/RegESSpec26.png; PrimaryModel/Plots/ES/RegESSpec36.png; PrimaryModel/Plots/ES/RegESSpec46.png;
	-- Figure B.3: PrimaryModel/Plots/ES/RegESSpec111.png; PrimaryModel/Plots/ES/RegESSpec211.png; PrimaryModel/Plots/ES/RegESSpec311.png; PrimaryModel/Plots/ES/RegESSpec411.png;
	-- Figure B.4: PrimaryModel/Plots/ES/RegESSpec1WoTT6.png; PrimaryModel/Plots/ES/RegESSpec2WoTT6.png; PrimaryModel/Plots/ES/RegESSpec3WoTT6.png; PrimaryModel/Plots/ES/RegESSpec4WoTT6.png; 
	-- Figure B.5: PrimaryModel/Plots/ES/RegESSpec1WoTT11.png; PrimaryModel/Plots/ES/RegESSpec2WoTT11.png; PrimaryModel/Plots/ES/RegESSpec3WoTT11.png; PrimaryModel/Plots/ES/RegESSpec4WoTT11.png; 
	-- Figure B.6: PrimaryModel/Plots/LOO/ivHistogram.png
	-- Figure B.7: PrimaryModel/Plots/LOO/didHistogram.png
	-- Figure B.8: PrimaryModel/Plots/NeighborAnalysis/NeighborStateJointSpec26.png
	-- Figure B.9: PrimaryModel/PlotsES/RegESSpec2PerCapita11.png
	-- Figure B.10: PrimaryModel/Plots/RandTreatSim/RandTreatRegTreatedStatesCombined.png
	-- Figure B.11: PrimaryModel/Plots/RandTreatSim/RandTreatRegAllStatesCombined.png
	-- Figure B.12: PrimaryModel/Plots/Bacon/bacReg.png; PrimaryModel/Plots/Bacon/bacVMT.png; PrimaryModel/Plots/Bacon/bacGas.png; 
	-- Figure B.13: PrimaryModel/Plots/Bacon/bacRegOverTime.png; PrimaryModel/Plots/Bacon/bacVMTOverTime.png; PrimaryModel/Plots/Bacon/bacGasOverTime.png; 


*****Tables and Figures Produced with Propietary Data*****
-Tables
	-- Table 2
-Figures
	-- Figure 3

*****Software Requirements*****
The Stata codes leverages a relatively new feature that enables Stata to call Python scripts directly within Stata .do files. Therefore, one must properly set up their Python settings within Stata as well as ensure the referenced Python executable has access to the required packages (listed below).

***Stata Package Requirements***
-reghdfe; Documentation available at http://scorreia.com/software/reghdfe/
-bacondecomp: Documentation available at https://ideas.repec.org/c/boc/bocode/s458676.html
-coefplot: Documentation available at http://repec.sowi.unibe.ch/stata/coefplot/getting-started.html
-estout; Documentation available at http://repec.sowi.unibe.ch/stata/estout/

***Python Package Requirements***
-numpy;
-scipy;
-matplotlib;
-pandas;
-seaborn;
-xlxswriter;