* this code makes a Stata dataset out of the two Excel files downloaded from OECD.Stats in May 2014

clear all
set more off
* CHANGE DIRECTORY TO THE REPLICATION MATERIALS FOLDER HERE, THEN:
cd datageneration/datasources

tempfile oecdgini
gen ISO3code=""
gen year=.
save `oecdgini', replace emptyok

foreach type in pre post {
	import excel inequality/OECD/Gini_`type'_tax_transfer, cellra(A6:AE41) firstrow clear
	drop B
	rename Year country
	drop if _n==1
	foreach var of varlist C-AE {
		replace `var'="" if `var'==".."
		destring `var', replace
		local year : variable label `var'
		rename `var' gini_oecd_`type'`year'
		}
	merge 1:1 country using ISO3.dta, keep(1 3) keepusing(ISO) nogenerate
	replace ISO="KOR" if country=="Korea"
	replace ISO="SVK" if country=="Slovak Republic"
	drop country
	reshape long gini_oecd_`type', i(ISO) j(year)
	replace gini=gini*100
	merge 1:1 ISO year using `oecdgini', nogenerate
	save `oecdgini', replace
	}

replace gini_oecd_post=gini_oecd_post/100
replace gini_oecd_pre=gini_oecd_pre/100
label var gini_oecd_post "Gini (at disposable income, after taxes and transfers) (OECD 2013)"
label var gini_oecd_pre "Gini before taxes and transfers (OECD 2013)"
compress
save inequality/OECD/OECDgini.dta, replace
