
* ROBUSTNESS TEST EXCLUDING HUMAN CAPITAL
clear all
set more off

cd "/Users/vesarach/Library/CloudStorage/OneDrive-NationalInstituteofDevelopmentAdministration/EUBA/2026_data"

import excel "OSI_TII.xlsx", sheet("OSI") clear


keep A E-M
rename A country_id

local yr = 2008
foreach col in E F G H I J K L M {
    rename `col' osi`yr'
    local yr = `yr' + 2
}

drop if missing(country_id)
replace country_id = strtrim(country_id)

reshape long osi, i(country_id) j(year)
destring osi, replace
replace osi = osi / 100

isid country_id year

tempfile osi_data
save `osi_data'

import excel "OSI_TII.xlsx", sheet("TII") clear

keep A E-M
rename A country_id

local yr = 2008
foreach col in E F G H I J K L M {
    rename `col' tii`yr'
    local yr = `yr' + 2
}

drop if missing(country_id)
replace country_id = strtrim(country_id)

reshape long tii, i(country_id) j(year)
destring tii, replace
replace tii = tii / 100

isid country_id year

merge 1:1 country_id year using `osi_data'
assert _merge == 3
drop _merge

save "OSI_TII_panel.dta", replace

use "ODDEA_LSDVC_annual_2003_2024.dta", clear

keep if inrange(year, 2008, 2024)
keep if mod(year - 2008, 2) == 0
keep if egdi_observed == 1
keep if !missing(egdi_original)

isid country_id year

decode country_id, gen(country_name)

rename country_id country_id_original

rename country_name country_id

replace country_id = strtrim(country_id)

list country_id country_id_original if year == 2024, noobs

isid country_id year

merge 1:1 country_id year using "OSI_TII_panel.dta", ///
    keep(master match)

tabulate _merge

assert _merge == 3
drop _merge

count
assert r(N) == 162

egen byte country_tag = tag(country_id)
count if country_tag == 1
assert r(N) == 18
drop country_tag

capture drop frontier gap

bysort year: egen double frontier = max(egdi_original)

gen double gap = frontier - egdi_original

replace gap = 0 if abs(gap) < 1e-10 & !missing(gap)

label variable gap "Original EGDI frontier gap"

assert gap >= 0 if !missing(gap)

summarize gap frontier

assert inrange(osi, 0, 1) if !missing(osi)
assert inrange(tii, 0, 1) if !missing(tii)

assert !missing(osi, tii)

gen double egdi_nohci = (osi + tii) / 2

bysort year: egen double frontier_nohci = max(egdi_nohci)

gen double gap_nohci = frontier_nohci - egdi_nohci

replace gap_nohci = 0 ///
    if abs(gap_nohci) < 1e-10 & !missing(gap_nohci)

assert gap_nohci >= 0 if !missing(gap_nohci)

label variable egdi_nohci "Alternative EGDI excluding HCI"
label variable gap_nohci "Frontier gap excluding HCI"

capture drop wave

gen byte wave = (year - 2008)/2 + 1

isid country_id_original wave

xtset country_id_original wave

xtdescribe

gen byte common_sample = !missing( ///
    gap, gap_nohci, iq, loggdp, to, fdi, te, gse)

count if common_sample == 1
assert r(N) == 162

* ORIGINAL TWO-WAY FIXED-EFFECTS

xtreg gap iq loggdp to fdi te gse i.wave ///
    if common_sample == 1, ///
    fe vce(cluster country_id_original)

estimates store TWFE_ORIGINAL

* ALTERNATIVE MODEL EXCLUDING HCI

xtreg gap_nohci iq loggdp to fdi te gse i.wave ///
    if common_sample == 1, ///
    fe vce(cluster country_id_original)

estimates store TWFE_NOHCI

* COMPARE RESULTS

estimates table TWFE_ORIGINAL TWFE_NOHCI, ///
    keep(iq loggdp to fdi te gse) ///
    b(%10.6f) se(%10.6f) stats(N)

estimates replay TWFE_ORIGINAL
estimates replay TWFE_NOHCI

************************************************************
* 12. CHECK CORRELATIONS
************************************************************

pwcorr iq loggdp to fdi te gse ///
    if common_sample == 1, sig obs

************************************************************
* 13. SAVE DATA
************************************************************

save "ODDEA_Comment9_noHCI_robustness.dta", replace

************************************************************
* END
************************************************************
