

 cd C:\Users\mjaremski\Desktop\Replication\Data\

**************
 import delimited "SurvivingBanks.csv", clear
 keep state bank location survivedloose
 save temp1.dta, replace

**************
 use Bank-LevelDataFull.dta, clear

 joinby using temp1.dta, unmatched(master)
 drop _merge

 gen deflator=1

 gen fedmember=0
 replace fedmember=1 if beginyrfedmemb~=.
 replace fedmember=1 if type=="national" 

 gen distart=9999
 replace distart=1908 if state=="OK"
 replace distart=1909 if state=="KS"
 replace distart=1914 if state=="MS"
 replace distart=1916 if state=="SD"
 replace distart=1911 if state=="NE"

 gen DIstateever=0
 replace DIstateever=1 if distart~=9999

 gen DIstate=0
 replace DIstate=1 if distart~=. & yr>=distart

 gen sb=sbanks if statebank==0
 replace sb=sbanks-1 if statebank==1

 gen nb=nbanks if statebank==1
 replace nb=nbanks-1 if statebank==0

 gen pop=ln(totpop+1)
 gen Black=1-whtot/totpop
 gen urban=urb/totpop
 gen Illit=tillit10/t10tot
 gen mout=ln(mfgout/(totpop*deflator)+1)
 gen pyoung=young/totpop
 gen fout=ln(cropval/(farmland*deflator)+1)
 gen fout2=fout^2

 gen loas=(loans/assets)
 gen reserves2=(specieduefrombanks)/assets
 gen capas=(capital+profits)/assets
 replace assets=ln(assets/(deflator)+1)
 replace loans=ln(loans/(deflator)+1)

 egen gp=group(state bank location)
 egen cgp=group(state countycode)

 bysort gp: egen beginyr=min(yr)

 egen minyear=min(yr), by(gp)

 keep if yr==1914 | yr==1920
 xtset gp yr, delta(6)

 gen dloans=D.loans
 gen dassets=D.assets

 drop if yr~=1920

 gen mtgdebt=.
 replace mtgdebt=mtgprin1910 if yr==1910
 replace mtgdebt=mtgprin1920 if yr==1920
 replace mtgdebt=ln(mtgdebt/(farmland1910*deflator)) if yr==1910
 replace mtgdebt=ln(mtgdebt/(farmland1920*deflator)) if yr==1920

 gen dmtgdebt=ln(mtgprin1920/(farmland1920))-ln(mtgprin1910/(farmland1910))
 gen debtPA=ln(mtgprin1920/farmland1920+1)

 gen pctmtglb=.
 replace pctmtglb=pctmtglb1910 if yr==1910
 replace pctmtglb=pctmtglb1920 if yr==1920
 
 egen mincap=max(capital), by(gp)
 drop if mincap<=0
 egen maxcapas=max(capas), by(gp)
 drop if maxcapas>0.95
 egen maxreserves=max(reserves2), by(gp)
 drop if maxreserves>.95
 egen minloas=min(loas), by(gp)
 drop if minloas<0.10
 egen mindeposits=min(deposits), by(gp)
 drop if mindeposits<500
 drop if mindeposits==.

 gen diint=0
 replace diint=1 if DIstate==1 & statebank==1

 gen dimp=(impac1920-impac1910)/impac1910

 drop if urb25>0
 drop if urb>25000
 drop if farms1910<250
 drop if farms1920<250
 drop if impac1910<15000
 drop if impac1920<15000
 
 gen lnage=ln((yr-minyear)/2+1)
 gen age=(yr-minyear)/2+1
 
 gen boom=ln(farmval1920/(farmland1920))-ln(farmval1910/(farmland1910))
 gen bust=ln(farmval1925/(farmland1925))-ln(farmval1920/(farmland1920))
 gen boombust=boom*bust

 replace DL1910=1 if state=="OH" | state=="MS"
 replace mincap1910=15 if state=="SD"
 replace mincap1910=10 if state=="IL"

 gen bustint=0
 replace bustint=bust if statebank==1

  gen DIstatebank=0
 replace DIstatebank=1 if DIstate==1 & statebank==1
 replace DIstatebank=0 if state=="KS" & dimember==0

 gen DIstatebankint=0
 replace DIstatebankint=boom if DIstatebank==1 

 gen fedint=0
 replace fedint=fedmember if statebank==1

 gen fedcrop=0
 replace fedcrop=boom if fedmember==1
 
 gen fedintcrop=0
 replace fedintcrop=boom if statebank==1 & fedmember==1

 gen dlint=0
 replace dlint=boom if DL1910==1

 gen sdl=0
 replace sdl=1 if DL1910==1 & statebank==1
 replace sdl=1 if statebank==0

 gen mincapdum=0
 replace mincapdum=1 if mincap1910>10

 gen smincap=0
 replace smincap=1 if mincap1910>10 & statebank==1

 gen mincapint=0
 replace mincapint=boom if mincap1910>10
 
 gen DIcrop=0
 replace DIcrop=boom if DIstate==1

 gen sDIcrop=0
 replace sDIcrop=boom if statebank==1 & DIstatebank==1

 gen closed=0
 replace closed=1 if maxyr<=1923 & state~="FL" & state~="MN" & state~="OK"
 replace closed=1 if survivedloose==0 & state=="FL"
 replace closed=1 if survivedloose==0 & state=="MN"
 replace closed=1 if survivedloose==0 & state=="OK"


********Generates Tables 4 and A.13
 preserve 
 drop if statebank==0

  xi: dprobit closed boom dmtgdebt debtPA dimp pop mout Black urban pyoung fout Illit avgrain stdrain lnarea MSdist Atlanticdist Gldist Pacificdist sb nb i.age assets loas capas reserves2 i.state i.district, cluster(cgp)
 estimates store v1

  xi: dprobit closed boom fedmember fedcrop DIstatebank sDIcrop mincapint dlint dmtgdebt debtPA dimp pop mout Black urban pyoung fout Illit avgrain stdrain lnarea MSdist Atlanticdist Gldist Pacificdist sb nb i.age assets loas capas reserves2 i.state i.district, cluster(cgp)
 estimates store v2

  xi: dprobit closed boom bust boombust dmtgdebt debtPA dimp pop mout Black urban pyoung fout Illit avgrain stdrain lnarea MSdist Atlanticdist Gldist Pacificdist sb nb i.age assets loas capas reserves2 i.state i.district, cluster(cgp)
 estimates store v3

 drop if minyr>1914

  xi: dprobit closed boom fedmember fedcrop DIstatebank sDIcrop mincapint dlint dloans dmtgdebt debtPA dimp pop mout Black urban pyoung fout Illit avgrain stdrain lnarea MSdist Atlanticdist Gldist Pacificdist sb nb i.age assets loas capas reserves2 i.state i.district, cluster(cgp)
 estimates store v4

  xi: dprobit closed boom bust boombust dloans dmtgdebt debtPA dimp pop mout Black urban pyoung fout Illit avgrain stdrain lnarea MSdist Atlanticdist Gldist Pacificdist sb nb i.age assets loas capas reserves2 i.state i.district, cluster(cgp)
 estimates store v5

 restore
 preserve
 drop if statebank==1

  xi: dprobit closed boom dmtgdebt debtPA dimp pop mout Black urban pyoung fout Illit avgrain stdrain lnarea MSdist Atlanticdist Gldist Pacificdist sb nb i.age assets loas capas reserves2 i.state i.district, cluster(cgp)
 estimates store v6

  xi: dprobit closed boom bust boombust dmtgdebt debtPA dimp pop mout Black urban pyoung fout Illit avgrain stdrain lnarea MSdist Atlanticdist Gldist Pacificdist sb nb i.age assets loas capas reserves2 i.state i.district, cluster(cgp)
 estimates store v7

 drop if minyr>1914
  xi: dprobit closed boom dmtgdebt debtPA dimp dloans pop mout Black urban pyoung fout Illit avgrain stdrain lnarea MSdist Atlanticdist Gldist Pacificdist sb nb i.age assets loas capas reserves2 i.state i.district, cluster(cgp)
 estimates store v8

  xi: dprobit closed boom bust boombust dmtgdebt debtPA dimp dloans pop mout Black urban pyoung fout Illit avgrain stdrain lnarea MSdist Atlanticdist Gldist Pacificdist sb nb i.age assets loas capas reserves2 i.state i.district, cluster(cgp)
 estimates store v9

 esttab v1 v2 v4 v6 v8 using "Table4.csv", b(3) se(3) replace  margin pr2 starlevels(* 0.10 ** 0.05 *** 0.01) brackets label title("Table ?: ") wrap order(boom dmtgdebt dimp debtPA dloans fedcrop dlint mincapint sDIcrop assets loas capas reserves2 fedmember DIstatebank)
 
 esttab v3 v5 v7 v9 using "TableA13.csv", b(3) se(3) replace  margin pr2 starlevels(* 0.10 ** 0.05 *** 0.01) brackets label title("Table ?: ") wrap order(boom bust boombust dmtgdebt dimp debtPA dloans fedcrop dlint mincapint sDIcrop assets loas capas reserves2 fedmember DIstatebank)
 

********Generate Table A.12
 restore 
 drop sDIcrop
 local list boom bust boombust assets loas capas reserves2 fedmember fedcrop dlint mincapint DIstate DIcrop dmtgdebt debtPA dimp dloans 
 foreach x of local list{
	gen s`x'=0
	replace s`x'=`x' if statebank==1 
	}

  xi: dprobit closed statebank boom sboom dmtgdebt sdmtgdebt debtPA sdebtPA dimp sdimp fedmember fedcrop dlint sdlint mincapint smincapint DIcrop sDIcrop pop mout Black urban pyoung fout Illit avgrain stdrain lnarea MSdist Atlanticdist Gldist Pacificdist sb nb i.age assets loas capas reserves2 sassets sloas scapas sreserves2 i.state i.district, cluster(cgp)
 estimates store v1

 test _b[sboom]=0,  notest 
 test _b[sdmtgdebt]=0,  notest accum
 test _b[sdebtPA]=0,  notest accum
 test _b[sdimp]=0,  notest accum
 *test _b[sfedmember]=0,  notest accum
 test _b[sdlint]=0,  notest accum
 test _b[smincapint]=0,  notest accum
 test _b[sDIcrop]=0,  notest accum
 test _b[sassets]=0,  notest accum
 test _b[sloas]=0,  notest accum
 test _b[scapas]=0,  notest accum
 test _b[sreserves2]=0,  accum

 drop if minyr>1914

  xi: dprobit closed statebank boom sboom dmtgdebt sdmtgdebt debtPA sdebtPA dimp sdimp dloans sdloans fedmember fedcrop dlint sdlint mincapint smincapint DIcrop sDIcrop pop mout Black urban pyoung fout Illit avgrain stdrain lnarea MSdist Atlanticdist Gldist Pacificdist sb nb i.age assets loas capas reserves2 sassets sloas scapas sreserves2 i.state i.district, cluster(cgp)
 estimates store v2
 
 test _b[sboom]=0,  notest 
 test _b[sdmtgdebt]=0,  notest accum
 test _b[sdebtPA]=0,  notest accum
 test _b[sdimp]=0,  notest accum
 *test _b[sfedmember]=0,  notest accum
 *test _b[sfedcrop]=0,  notest accum
 test _b[sdlint]=0,  notest accum
 test _b[smincapint]=0,  notest accum
 test _b[sDIcrop]=0,  notest accum
 test _b[sassets]=0,  notest accum
 test _b[sloas]=0,  notest accum
 test _b[scapas]=0,  notest accum
 test _b[sreserves2]=0,  accum

 esttab v1 v2 using "TableA12.csv", b(3) se(3) replace  margin pr2 starlevels(* 0.10 ** 0.05 *** 0.01) brackets label title("Table ?: ") wrap order(statebank boom sboom dmtgdebt sdmtgdebt dimp sdimp debtPA sdebtPA dloans sdloans fedcrop dlint sdlint mincapint smincapint DIcrop sDIcrop assets sassets loas sloas capas scapas reserves2 sreserves2)
  


