set more off
clear all
set mem 4M
set matsize 11000
set maxvar 10000

* BRING IN EORA AND MERGE WITH CEPII GRAVITY DATA

use EORA_ALL_YEARS.dta, clear
keep if year==2011

merge iso_o iso_d using dist_cepii.dta
gen ldist=ln(dist)
keep if flow~=.
gen own=0
replace own=1 if iso_o==iso_d
replace contig=1 if own==1
replace comlang_off=1 if own==1
sort iso_o iso_d year
collapse (mean) flow contig comlang_off comlang_ethno colony comcol col45 curcol distcap distw distwces ldist own, by(iso_o iso_d year)
gen lflow=ln(2*flow)
*Here we multiply by 2 because we have collapsed by mean rather than sum
egen country_pair = group(iso_o iso_d)


tab iso_o, gen(d_source)
tab iso_d, gen(d_dest)



*First Column (standard gravity)
qui regress lflow ldist d_source* d_dest*, noconstant cluster(country_pair)
outreg2 using  ElasticityEvidence_2011, keep(ldist) dec(3)

*Second Column (standard gravity with more controls)
qui regress lflow ldist contig comlang_off own d_source* d_dest*, noconstant cluster(country_pair)
outreg2 using  ElasticityEvidence_2011, keep(ldist contig comlang_off own) dec(3)


* BRING IN EORA AND MERGE WITH CEPII GRAVITY DATA (WILL NOW DO FINAL GOODS AND INPUTS SEPARATELY)

use EORA_ALL_YEARS.dta, clear
keep if year==2011

merge iso_o iso_d using dist_cepii.dta
gen ldist=ln(dist)
keep if flow~=.
gen own=0
replace own=1 if iso_o==iso_d
replace contig=1 if own==1
replace comlang_off=1 if own==1
egen country_pair = group(iso_o iso_d)

tab iso_o, gen(d_source)
tab iso_d, gen(d_dest)

*Third Column (standard gravity for final goods)
qui regress lflow ldist d_source* d_dest* if input==0, noconstant cluster(country_pair)
outreg2 using  ElasticityEvidence_2011, keep(ldist) dec(3)

*Fourth Column (standard gravity for final goods with more controls)
qui regress lflow ldist contig comlang_off own d_source* d_dest* if input==0, noconstant cluster(country_pair)
outreg2 using  ElasticityEvidence_2011, keep(ldist contig comlang_off own) dec(3)

*Fifth Column (standard gravity for inputs)
qui regress lflow ldist d_source* d_dest* if input==1, noconstant cluster(country_pair)
outreg2 using  ElasticityEvidence_2011, keep(ldist) dec(3)

*Sixth Column (standard gravity for inputs with more controls)
qui regress lflow ldist contig comlang_off own d_source* d_dest* if input==1, noconstant cluster(country_pair)
outreg2 using  ElasticityEvidence_2011, keep(ldist contig comlang_off own) dec(3)



* OUTPUT SHOULD APPEAR ON FILE ElasticityEvidence_2011.txt
