eststo clear

if("`c(os)'"=="Windows"){
	local tableSaveDir = "Tables\DiD\"
	local plotSaveDir = "Plots\"
	local pythonSaveDir = "PythonScripts\"
}
else{
	local tableSaveDir = "Tables/DiD/"
	local plotSaveDir = "Plots/"
	local pythonSaveDir = "PythonScripts/"
}

//Establish Control Variable Sets
local spec1Controls = "ib51.stateGroup ib1995.year c.normYear#i.stateGroup asinhMetroPop asinhNonMetroPop asinhMetroInc asinhNonMetroInc logrealmeangasprice logemployment loglicenseddrivers logrealstategdp logroadmileage"
local spec2Controls = "`spec1Controls'"
local spec3Controls = "`spec2Controls' i.regDummyExtSpec3"
local spec4Controls = "`spec2Controls' i.regDummyExtSpec4"


//Establish Cluster Variable
local clusterVar = "stateGroup"

//Absorb Vars are always time and state fixed effects
local absorbVars = "ib51.stateGroup ib1995.year"

//Establish ci level
local ciLevel = 95

//Estimate Models
//Estimate Spec. 1 Travel RF-DiD Model
qui reghdfe logvmt i.nosafetyind `spec1Controls', cluster(`clusterVar') absorb(`absorbVars')
eststo vanilla
local df = e(N_clust)-1

//Estimate Spec. 2 Travel RF-DiD Model 
qui reghdfe logvmt i.nosafetyind `spec2Controls', cluster(`clusterVar') absorb(`absorbVars')
eststo base
local df = e(N_clust)-1

//Estimate Spec. 3 Travel RF-DiD Model
qui reghdfe logvmt i.nosafetyind `spec3Controls', cluster(`clusterVar') absorb(`absorbVars')
eststo centrist
local df = e(N_clust)-1

//Estimate Spec. 4 Travel RF-DiD Model
qui reghdfe logvmt i.nosafetyind `spec4Controls', cluster(`clusterVar') absorb(`absorbVars')
eststo liberal
local df = e(N_clust)-1


//Export Model Results to TeX Files
//Establish Format
local fmtDiD = `"cells(b(fmt(3) star) se(par fmt(3))) keep(1.nosafetyind *log* *asinh*) nocon label compress longtable mtitles("\makecell{No \\ DSCs}" "\makecell{Documented \\ DSCs}" "\makecell{Suspected \\ DSCs}" "\makecell{Potential \\ DSCs}") starlevels(* 0.1 ** 0.05 *** 0.01) addnotes("* p \textless 0.1, ** p \textless 0.05, *** p \textless 0.01" "Note: All models include state and year fixed effects as well as state-level time trends." "All models cluster standard errors  by state.")"'


//Export Table
esttab vanilla base centrist liberal using "`tableSaveDir'VMTRFDiD.tex", `fmtDiD' depvars title("Reduced Form Diff-in-Diff Results - VMT \label{tab:RFDiD}") stats(N r2, labels( "Observation" "R\textsuperscript{2}")fmt(%8.0f %8.3f)) replace


