clear
set more off
global PATH "J:\2006"
cd $PATH

forvalue i=1(+1)1{
//use "E:\科研项目\融资约束与全球价值链\data\Chinese_trade_data\2006\20060`i'.dta"
use 2006_`i'.dta

//一起执行//
local x : type value
dis "`x'"
if "`x'"=="str12"{
destring value, generate(value_qy) force 
drop value
rename value_qy value

destring quantity, generate(quantity_qy) force 
drop quantity
rename quantity_qy quantity
}

//egen firmid=group(party_id)  // 形成firmid用以识别

//--------进口还是出口---------------//
//gen expimp=0 
//replace expimp=1 if exp_imp=="进口" //分类不够具体

//--------分类贸易方式----------------//
 
replace exp_impid="0" if exp_impid=="一般贸易"
replace exp_impid="1" if exp_impid=="来料加工装配贸易"       // PA of a firm
replace exp_impid="2" if exp_impid=="进料加工贸易"  
replace exp_impid="3" if exp_impid=="出口加工区进口设备"
replace exp_impid="4" if exp_impid!="0" & exp_impid!="1"  &  exp_impid!="2" &  exp_impid!="3"



//-------同一类的合并在一起----------//
bysort party_id expimp exp_impid hs_id: egen value_qy=sum(value)    
bysort party_id expimp exp_impid hs_id: egen value_qt=sum(quantity) 
 


//--------从单笔数据到阅读整体数据-------------///
duplicates drop party_id expimp exp_impid hs_id,force


sort party_id
bysort expimp exp_impid :tabstat value_qy,s(mean sd n)  //看一下统计指标
save "E:\Research\GVCs\data\chinese_trade_data\2006_`i'",replace
clear
}
