//-------Match data with HS02 to HS07--------//
cd "E:\Research\GVCs\data\Chinese_trade_data\concise"
use 2002-2007  // now only use 2002-2006
//-------修改HS编码为7位的情况----------//
tostring hs_code, generate(HScode) force
gen str hscode = HScode 
replace hscode = HScode if length(hscode) == 8
replace hscode = "0" + HScode if length(hscode) == 7
drop hs_code
drop HScode
rename hscode hs_code

//-------math the HS02 to HS07--------//
//-----the reason of to 07 is only IO 2007 have realtionship between IO code with HS_code//
gen hssix=substr(hs_id,1,6)
drop hs_id
rename hssix hs_id
merge m:m hs_id using HS02_HS07
drop hs_id
rename hs2007 hs_id
drop _merge
save 2002-2007.dta,replace

use 2002-2007.dta
append using 2007.dta
save 2002-2007.dta,replace


