//---------Cus Data Handle(3)---------//
// --------Mouth to Year---------//
//---------Cus Data Handle(3)---------//
// --------Mouth to Year---------//
cd E:\Research\GVCs\data\Chinese_trade_data\2007
forvalue i=1(+3)12{
use 2007_`i'    //Master 
append  using 2007_`i+1' 2007_`i+2',force
//append  using 2002_2 2002_3,force
bysort party_id expimp exp_impid hs_id: egen value_qy_3m=sum(value_qy)    
bysort party_id expimp exp_impid hs_id: egen value_qt_3m=sum(value_qt) 
bysort party_id expimp exp_impid hs_id: gen value_added_3m= value_qy_3m/value_qt_3m
duplicates drop party_id hs_id expimp exp_impid value_added_3m,force
save "E:\Research\GVCs\data\Chinese_trade_data\2007\2007_3m`i'.dta",replace
}


use 2007_3m1
append  using 2007_3m4 2007_3m7 2007_3m10,force
//append  using 2002_2 2002_3,force
bysort party_id expimp exp_impid hs_id: egen value_qy_y=sum(value_qy_3m)    
bysort party_id expimp exp_impid hs_id: egen value_qt_y=sum(value_qt_3m) 
bysort party_id expimp exp_impid hs_id: gen value_added_y= value_qy_y/value_qt_y
duplicates drop party_id hs_id expimp exp_impid value_added_y,force
save "E:\Research\GVCs\data\Chinese_trade_data\2007\2007.dta",replace
clear

//-------- Drop the data -------//
cd E:\Research\GVCs\data\Chinese_trade_data\last
forvalue i=4(+1)6{
use 200`i'
drop shipment_date
drop exp_imp
drop pdesc
drop value quantity valperunit perunit
drop email
drop companytype
drop exp_imptype
drop firmid
drop value_qy value_qt value_added value_qy_3m value_qt_3m value_added_3
save "E:\Research\GVCs\data\Chinese_trade_data\last\200`i'",replace
}
 
cd E:\Research\GVCs\data\Chinese_trade_data\last
forvalue i=4(+1)6{
use 200`i'
drop location
drop fax
drop paddr
save "E:\Research\GVCs\data\Chinese_trade_data\last\200`i'",replace
}
 
//--------- Append to Year -----------//


forvalue i=3(+1)7{
use 200`i'
destring zip, generate(youb) force 
drop zip
drop party_id
drop pperson
save "E:\Research\GVCs\data\Chinese_trade_data\last\200`i'",replace
clear
}

forvalue i=6(+1)7{
use 200`i'
gen year="200`i'"
save "E:\Research\GVCs\data\Chinese_trade_data\last\200`i'",replace
clear
}



cd "E:\Research\GVCs\data\Chinese_trade_data\last"
forvalue i=5(+1)7{
use 200`i'

drop pdesc
drop location
drop paddr
drop fax
drop email pperson
drop sou_pur costum
drop countrybyway
drop perunit


save "E:\Research\GVCs\data\Chinese_trade_data\concise\200`i'",replace
clear
}

cd "E:\Research\GVCs\data\Chinese_trade_data\concise"
use 2002
append using 2003,force
append using 2004,force
append using 2005,force
append using 2006,force
save "E:\Research\GVCs\data\Chinese_trade_data\concise\2002-2007",replace







