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

 set matsize 8500

 import delimited "County-LevelPanelBiannual.csv", clear

 drop if farms1910==. 
 drop if farms1920==.
 replace riceac1910=0
 replace rice1910=0

 gen deflator=1

 gen cropindex1910=cornpriceperbushel*corn1910+barleypriceperbushel*barley1910+flaxseedpriceperbushel*flax1910+oatspriceperbushel*oats1910+wheatpriceperbushel*wheat1910+ryepriceperbushel*rye1910+buckwheatpriceperbushel*buckwh1910+tobaccopriceperpound*tobacco1910+ricepriceperbushel*rice1910+irishpotatoepricebushel*potatoes1910+sweetpotatoepricebushel*swpotato1910+cottonpriceperbale*cotton1910

 gen cropindexavgmin=cornpriceperbushelavg*corn1910+barleypriceperbushelavg*barley1910+flaxseedpriceperbushelavg*flax1910+oatspriceperbushelavg*oats1910+wheatpriceperbushelavg*wheat1910+ryepriceperbushelavg*rye1910+buckwheatpriceperbushelavg*buckwh1910+tobaccopriceperpoundavg*tobacco1910+ricepriceperbushelavg*rice1910+irishpotatoepricebushelavg*potatoes1910+sweetpotatoepricebushelavg*swpotato1910+cottonpriceperbaleavg*cotton1910

 gen cropindexavgc=cropindex1910/cropindexavgmin
 replace cropindex1910=ln(cropindex1910+1)

 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) 
 gen nb=(nbanks)

 egen sqmi=max(area), by(state countycode)
 gen openland=(sqmi-(impac*.0015625))/sqmi

 gen pop=ln(totpop+1)
 gen Black=1-whtot/totpop
 gen urban=urb/totpop
 gen Illit=tillit10/t10tot
 gen mout=ln(mfgout/(totpop)+1)
 gen pyoung=young/totpop

 gen fv=ln(farmval/(totpop)+1)

 keep if yr==1908 | yr==1910 | yr==1912 | yr==1914 | yr==1916 | yr==1918 | yr==1920

 xtset gp yr, delta(2)

 gen dimp=(impac1920-impac1910)/impac1910

 egen cgp=group(state countycode)

 egen maxurb25=max(urb25), by(gp)
 drop if maxurb25>0

 egen maxurb=max(urb), by(gp)
 drop if maxurb>25000

 drop if farms1910<250
 drop if impac1910<15000

 gen lsb=L.sbanks
 gen lnb=L.nbanks

 gen ltn=L.banks
 gen lsn=L.sbanks
 gen lnn=L.nbanks

 gen dcropindexavgc=D.cropindexavgc

 gen newbankscount=newbanks
 gen newsbankscount=newsbanks
 gen newnbankscount=newnbanks

 replace newbanks=newbanks/(ltn)
 replace newsbanks=newsbanks/(lsn)
 replace newnbanks=newnbanks/(lnn)

 drop if yr==1908

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

 gen dlint=0
 replace dlint=cropindexavgc if dl1910==1
 replace dlint=cropindexavgc if state=="OH" & yr>=1911
 replace dlint=cropindexavgc if state=="MS" & yr>=1914

 gen mincapint=0
 replace mincapint=cropindexavgc if mincap1910>10
 replace mincapint=cropindexavgc if state=="SD" & yr>1914
 replace mincapint=0 if state=="IL" & yr>1918
 
 gen DIcrop=0
 replace DIcrop=cropindexavgc if DIstate==1

 gen mincapdum=0
 replace mincapdum=1 if mincap1910>10
 replace mincapdum=1 if state=="SD" & yr>1914
 replace mincapdum=0 if state=="IL" & yr>1918

 gen dldum=0
 replace dldum=dl1910
 replace dldum=1 if state=="OH" & yr>=1911
 replace dldum=1 if state=="MS" & yr>=1914

 drop if state=="AL" & yr<1912
 
************Generates Table 1
  xi: xtnbreg newsbankscount cropindexavgc pop mout Black urban pyoung Illit lsb lnb i.yr, fe
 estimates store t1

 xi: xtnbreg newsbankscount cropindexavgc dlint mincapint DIcrop pop mout Black urban pyoung Illit lsb lnb dldum mincapdum DIstate i.yr, fe
 estimates store t2

 xi: xtnbreg newnbankscount cropindexavgc pop mout Black urban pyoung Illit lsb lnb i.yr, fe
 estimates store t3

 xi: xtnbreg newnbankscount cropindexavgc dlint mincapint DIcrop pop mout Black urban pyoung Illit lsb lnb dldum mincapdum DIstate i.yr, fe
 estimates store t4

 esttab t1 t2 t3 t4 using "Table1.csv", b(3) se(3) replace  margin r2 starlevels(* 0.10 ** 0.05 *** 0.01) brackets label title("Table ?: ") wrap order(cropindexavgc dlint mincapint DIcrop dldum mincapdum DIstate lsb lnb pop urban Black Illit mout)


*************Generates Table A.2
 gen dDIstatebankint=0
 replace dDIstatebankint=dcropindexavgc if DIstatebank==1 

 gen ddlint=0
 replace ddlint=dcropindexavgc if dl1910==1
 replace ddlint=dcropindexavgc if state=="OH" & yr>=1911
 replace ddlint=dcropindexavgc if state=="MS" & yr>=1914

 gen dmincapint=0
 replace dmincapint=dcropindexavgc if mincap1910>10
 replace dmincapint=dcropindexavgc if state=="SD" & yr>1914
 replace dmincapint=0 if state=="IL" & yr>1918
 
 gen dDIcrop=0
 replace dDIcrop=dcropindexavgc if DIstate==1

 gen dmincapdum=0
 replace dmincapdum=1 if mincap1910>10
 replace dmincapdum=1 if state=="SD" & yr>1914
 replace dmincapdum=0 if state=="IL" & yr>1918

 gen ddldum=0
 replace ddldum=dl1910
 replace ddldum=1 if state=="OH" & yr>=1911
 replace ddldum=1 if state=="MS" & yr>=1914

 xi: xtnbreg newsbankscount dcropindexavgc pop mout Black urban pyoung Illit lsb lnb i.yr, fe 
 estimates store t1

 xi: xtnbreg newsbankscount dcropindexavgc ddlint dmincapint dDIcrop pop mout Black urban pyoung Illit lsb lnb dldum mincapdum DIstate i.yr, fe
 estimates store t2

 xi: xtnbreg newnbankscount dcropindexavgc pop mout Black urban pyoung Illit lsb lnb i.yr, fe
 estimates store t3

 xi: xtnbreg newnbankscount dcropindexavgc ddlint dmincapint dDIcrop pop mout Black urban pyoung Illit lsb lnb dldum mincapdum DIstate i.yr, fe
 estimates store t4

 esttab t1 t2 t3 t4 using "TableA2.csv", b(3) se(3) replace  margin r2 starlevels(* 0.10 ** 0.05 *** 0.01) brackets label title("Table ?: ") wrap order(dcropindexavgc ddlint dmincapint dDIcrop dldum mincapdum DIstate lsb lnb pop urban Black Illit mout)


*************Generates Table A.3
 preserve
 drop if yr<=1912
 bysort gp: egen totalnewsbankscount=total(newsbankscount)
 bysort gp: egen totalnewnbankscount=total(newnbankscount)
 bysort gp: egen totalnewbankscount=total(newbankscount)

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

 drop lsb lnb
 gen lsb=L.sbanks
 gen lnb=L.nbanks 

 keep if yr==1920

 xi: nbreg totalnewsbankscount dcropindex1914_1919 pop mout Black urban pyoung Illit lsb lnb i.state i.district, cluster(cgp)
 estimates store t1

 xi: nbreg totalnewnbankscount dcropindex1914_1919 pop mout Black urban pyoung Illit lsb lnb i.state i.district, cluster(cgp)
 estimates store t2

 esttab t1 t2 using "TableA3.csv", b(3) se(3) replace  margin r2 starlevels(* 0.10 ** 0.05 *** 0.01) brackets label title("Table ?: ") wrap order(dcropindex1914_1919 lsb lnb pop urban Black Illit mout)


**************Generates Table A.4
 restore
 preserve

 expand 2
 bysort gp yr: gen countobs=_n

 gen newbankscomb=0
 replace newbankscomb=newsbankscount if countobs==1
 replace newbankscomb=newnbankscount if countobs==2

 local list cropindexavgc dlint mincapint DIcrop pop mout Black urban pyoung Illit lsb lnb dldum mincapdum DIstate

 foreach x of local list {
	gen s`x'=0
	replace s`x'=`x' if countobs==1
	}
	
 xi: xtnbreg newbankscomb cropindexavgc scropindexavg pop mout Black urban pyoung Illit lsb lnb i.yr, fe
 estimates store t1

 test _b[scropindexavg]=0

 xi: xtnbreg newbankscomb cropindexavgc scropindexavg dlint mincapint DIcrop dldum mincapdum DIstate sdlint smincapint sDIcrop sdldum smincapdum sDIstate pop mout Black urban pyoung Illit lsb lnb i.yr, fe
 estimates store t2

 test _b[scropindexavg]=0,  notest 
 test _b[sdlint]=0,  notest accum
 test _b[smincapint]=0,  notest accum
 test _b[sDIcrop]=0,  accum

 test _b[scropindexavg]=0,  notest 
 test _b[sdlint]=0,  notest accum
 test _b[smincapint]=0,  notest accum
 test _b[sDIcrop]=0,  notest accum
 test _b[sdldum]=0,  notest accum
 test _b[smincapdum]=0,  notest accum
 test _b[sDIstate]=0, accum

 esttab t1 t2 using "TableA4.csv", b(3) se(3) replace  margin r2 starlevels(* 0.10 ** 0.05 *** 0.01) brackets label title("Table ?: ") wrap order(cropindexavgc scropindexavgc dlint sdlint mincapint smincapint DIcrop sDIcrop dldum sdldum mincapdum smincapdum DIstate sDIstate lsb lnb pop urban Black Illit mout)


************Generates Table A.5
 restore

 xi: tobit newsbanks cropindexavgc pop mout Black urban pyoung Illit lsb lnb i.yr i.cgp, cluster(cgp) ll(0)
 estimates store t1

 xi: tobit newsbanks cropindexavgc dlint mincapint DIcrop pop mout Black urban pyoung Illit lsb lnb dldum mincapdum DIstate i.yr i.cgp, cluster(cgp) ll(0)
 estimates store t2

 xi: tobit newnbanks cropindexavgc pop mout Black urban pyoung Illit lsb lnb i.yr i.cgp, cluster(cgp) ll(0)
 estimates store t3

 xi: tobit newnbanks cropindexavgc dlint mincapint DIcrop pop mout Black urban pyoung Illit lsb lnb dldum mincapdum DIstate i.yr i.cgp, cluster(cgp) ll(0)
 estimates store t4

 esttab t1 t2 t3 t4 using "TableA5.csv", b(3) se(3) replace  margin r2 starlevels(* 0.10 ** 0.05 *** 0.01) brackets label title("Table ?: ") wrap order(cropindexavgc dlint mincapint DIcrop dldum mincapdum DIstate lsb lnb pop urban Black Illit mout)


***********Generates Table A.6
 gen sentry=0
 replace sentry=1 if newsbankscount>0 & newsbankscount~=. 

 gen nentry=0
 replace nentry=1 if newnbankscount>0 & newnbankscount~=. 

 xi: probit sentry cropindexavgc pop mout Black urban pyoung Illit lsb lnb i.yr i.cgp, cluster(cgp)
 estimates store t1

 xi: probit sentry cropindexavgc dlint mincapint DIcrop pop mout Black urban pyoung Illit lsb lnb dldum mincapdum DIstate i.yr i.cgp, cluster(cgp)
 estimates store t2

 xi: probit nentry cropindexavgc pop mout Black urban pyoung Illit lsb lnb i.yr i.cgp, cluster(cgp)
 estimates store t3

 xi: probit nentry cropindexavgc dlint mincapint DIcrop pop mout Black urban pyoung Illit lsb lnb dldum mincapdum DIstate i.yr i.cgp, cluster(cgp)
 estimates store t4

 esttab t1 t2 t3 t4 using "TableA6.csv", b(3) se(3) replace  margin r2 starlevels(* 0.10 ** 0.05 *** 0.01) brackets label title("Table ?: ") wrap order(cropindexavgc dldum dlint mincapdum mincapint DIstate DIcrop lsb lnb pop urban Black Illit mout)



















