clear
use "数据.dta",replace
winsor2 Upstream Upstream_change Manage Manage_ind Manage_pro LAP CAP FIC TIC IE IE_1 IE_2 IE_3 IE_4 IE_5 Size Age Ind Lev Subsidy GDP FDI sub_Manage,replace cuts(1 99)
xtset id year


***1.基准回归***
reghdfe Upstream Manage ,absorb (id industry ) vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto m1

reghdfe Upstream Manage Size Age Ind Lev Subsidy ,absorb (industry id )  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto m2

reghdfe Upstream Manage Size Age Ind Lev Subsidy GDP FDI ,absorb (industry id )  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto m3

esttab m1 m2 m3 using 1.基准回归结果.rtf,replace


***2.内生性检验***

**工具变量：企业管理能力同行业均值
reghdfe Upstream Manage_ind Size Age Ind Lev Subsidy GDP FDI,absorb(id industry) vce(cluster id)  
est sto k1
ivregress  2sls Upstream (Manage=Manage_ind) Size Age Ind Lev Subsidy GDP FDI i.industry c.id,cluster(id)
est sto k2

**工具变量：企业管理能力同地区均值
reghdfe Upstream Manage_pro Size Age Ind Lev Subsidy GDP FDI,absorb(id industry) vce(cluster id)  
est sto k3
ivregress  2sls Upstream (Manage=Manage_pro) Size Age Ind Lev Subsidy GDP FDI i.industry c.id,cluster(id)
est sto k4

esttab k1 k2 k3 k4 using 2.内生性问题检验.rtf,replace

**检验工具变量合理性
tab year,gen(dyear)
xtivreg2 Upstream Size Age Ind Lev Subsidy GDP FDI  dyear*  (Manage=Manage_ind ) , fe cluster(id)  
xtivreg2 Upstream Size Age Ind Lev Subsidy GDP FDI  dyear*  (Manage=Manage_pro) , fe cluster(id)

***3.稳健性检验***
**第一种：将全球价值链生产长度替换为全球价值链参与指数
reghdfe Upstream_change Manage Size Age Ind Lev Subsidy GDP FDI ,absorb (id industry )  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto o1


**第二种：企业管理能力代理变量替换为组织资本
*gen lnsub_Manage=log(sub_Manage)
*bysort id:gen Mange_change1 = sub_Manage-sub_Manage[_n-1]

bysort id:gen Mange_change=(sub_Manage-l.sub_Manage)/sub_Manage

reghdfe Upstream Mange_change Size Age Ind Lev Subsidy GDP FDI ,absorb (id industry )  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto o2

**第三种：考虑中国加入WTO对中国外贸的冲击，选用2002年以后的数据进行回归
gen WTO = .

replace WTO = 1 if year<=2002

replace WTO = 2 if year>2002

reghdfe Upstream Manage Size Age Ind Lev Subsidy GDP FDI if WTO == 2,absorb (id industry)  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto o3

**第四种：考虑金融危机的影响，剔除2009年的样本
reghdfe Upstream Manage Size Age Ind Lev Subsidy GDP FDI if year != 2009,absorb (id industry)  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto o4


esttab o1 o2 o3 o4 using 3.稳健性检验结果.rtf,replace


*****************进一步分析***********************
***1.异质性分析***
**第一种：一般贸易与加工贸易
drop 贸易方式代码
gen MODE=. 
replace MODE = 0 if regex(贸易方式, "一般贸易")
replace MODE = 1 if MODE==.
tab MODE

reghdfe Upstream Manage Size Age Ind Lev Subsidy GDP FDI if MODE==0 ,absorb (id industry )  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto t1

reghdfe Upstream Manage Size Age Ind Lev Subsidy GDP FDI if MODE==1 ,absorb (id industry)  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto t2

***组间系数差异检验
**邹检验(可行)
reghdfe Upstream i.MODE##(c.Manage c.Size c.Age c.Ind c.Lev c.Subsidy c.GDP c.FDI),absorb (id industry)  vce(cluster id)

**第二种：国有企业与非国有企业
rename 企业性质代码 ENID
destring ENID,replace
tab ENID
replace ENID=0 if ENID!=1
reghdfe Upstream Manage Size Age Ind Lev Subsidy GDP FDI if ENID==1,absorb (id industry)  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto t3

reghdfe Upstream Manage Size Age Ind Lev Subsidy GDP FDI if ENID==0,absorb (id industry)  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto t4

reghdfe Upstream i.ENID##(c.Manage c.Size c.Age c.Ind c.Lev c.Subsidy c.GDP c.FDI),absorb (id industry)  vce(cluster id)

esttab t1 t2 t3 t4 using 4.异质性分析结果一.rtf,replace


**第三种：将企业分为低技术、中低技术、中高技术、高技术
gen OECDcode=substr(OECD2021code,2,3)
gen tecnology=.
destring OECDcode,replace
replace tecnology=1 if OECDcode==3
replace tecnology=1 if OECDcode==4
replace tecnology=1 if OECDcode==5
replace tecnology=1 if OECDcode==6
replace tecnology=1 if OECDcode==7
replace tecnology=1 if OECDcode==16
replace tecnology=2 if OECDcode==8
replace tecnology=2 if OECDcode==10
replace tecnology=2 if OECDcode==11
replace tecnology=2 if OECDcode==12
replace tecnology=3 if OECDcode==9
replace tecnology=3 if OECDcode==13
replace tecnology=3 if OECDcode==15
replace tecnology=4 if OECDcode==14

reghdfe Upstream Manage Size Age Ind Lev Subsidy GDP FDI if tecnology==1,absorb (id industry)  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto h1

reghdfe Upstream Manage Size Age Ind Lev Subsidy GDP FDI if tecnology==2,absorb (id industry)  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto h2

reghdfe Upstream Manage Size Age Ind Lev Subsidy GDP FDI if tecnology==3,absorb (id industry)  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto h3

reghdfe Upstream Manage Size Age Ind Lev Subsidy GDP FDI if tecnology==4,absorb (id industry) vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto h4

gen group=.
replace group=1 if tecnology=1
replace group=1 if tecnology==2
reghdfe Upstream i.tecnology##(c.Manage c.Size c.Age c.Ind c.Lev c.Subsidy c.GDP c.FDI) ,absorb (id industry)  vce(cluster id)  if group=1

replace group=2 if tecnology==1
replace group=2 if tecnology==3
reghdfe Upstream i.tecnology##(c.Manage c.Size c.Age c.Ind c.Lev c.Subsidy c.GDP c.FDI) ,absorb (id industry)  vce(cluster id)  if group=2

replace group=3 if tecnology==1
replace group=3 if tecnology==4
reghdfe Upstream i.tecnology##(c.Manage c.Size c.Age c.Ind c.Lev c.Subsidy c.GDP c.FDI) ,absorb (id industry)  vce(cluster id)  if group=3

replace group=4 if tecnology==2
replace group=4 if tecnology==3
reghdfe Upstream i.tecnology##(c.Manage c.Size c.Age c.Ind c.Lev c.Subsidy c.GDP c.FDI) ,absorb (id industry)  vce(cluster id)  if group=4

replace group=5 if tecnology==2
replace group=5 if tecnology==4
reghdfe Upstream i.tecnology##(c.Manage c.Size c.Age c.Ind c.Lev c.Subsidy c.GDP c.FDI) ,absorb (id industry)  vce(cluster id)  if group=5

replace group=6 if tecnology==3
replace group=6 if tecnology==4
reghdfe Upstream i.tecnology##(c.Manage c.Size c.Age c.Ind c.Lev c.Subsidy c.GDP c.FDI) ,absorb (id industry)  vce(cluster id)  if group=6

esttab h1 h2 h3 h4 using 5.异质性分析结果二.rtf,replace


***2.滞后效应分析***
reghdfe Upstream Manage l.Manage Size Age Ind Lev Subsidy GDP FDI,absorb (id industry)  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto g1

reghdfe Upstream Manage l.Manage l2.Manage Size Age Ind Lev Subsidy GDP FDI,absorb (id industry)  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto g2

reghdfe Upstream Manage l.Manage l2.Manage l3.Manage Size Age Ind Lev Subsidy GDP FDI,absorb (id industry)  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto g3
esttab g1 g2 g3 using 6.滞后效应分析结果.rtf,replace

*******************机制检验******************************
**1.影响渠道检验
drop if LAP==.
drop if FIC==. 
drop if TIC==.

reghdfe Upstream Manage Size Age Ind Lev Subsidy GDP FDI ,absorb (industry id )  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto n1

reghdfe LAP Manage Size Age Ind Lev Subsidy GDP FDI,absorb (id industry ) vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto n2


reghdfe FIC Manage Size Age Ind Lev Subsidy GDP FDI,absorb (id industry) vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto n3 


reghdfe TIC Manage Size Age Ind Lev Subsidy GDP FDI,absorb (id industry ) vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto n4

esttab n1 n2 n3 n4  using 2.中介效应检验结果.rtf,replace


**2.调节效应检验
clear
use "D:\数据.dta",replace
winsor2 Upstream Upstream_change Manage Manage_ind Manage_pro LAP CAP FIC TIC IE IE_1 IE_2 IE_3 IE_4 IE_5 Size Age Ind Lev Subsidy GDP FDI sub_Manage,replace cuts(1 99)
xtset id year

center Manage IE IE_1 IE_2 IE_3 IE_4 IE_5  LAP FIC TIC
gen interact1=c_Manage*c_IE
gen interact2=c_Manage*c_IE_1
gen interact3=c_Manage*c_IE_2
gen interact4=c_Manage*c_IE_3
gen interact5=c_Manage*c_IE_4
gen interact6=c_Manage*c_IE_5
reghdfe Upstream Manage IE interact1 Size Age Ind Lev Subsidy GDP FDI,absorb (id industry )  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto p1
		  
reghdfe Upstream Manage IE_1 interact2 Size Age Ind Lev Subsidy GDP FDI,absorb (id industry )  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto p2

reghdfe Upstream Manage IE_2 interact3 Size Age Ind Lev Subsidy GDP FDI,absorb (id industry )  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto p3

reghdfe Upstream Manage IE_3 interact4 Size Age Ind Lev Subsidy GDP FDI,absorb (id industry )  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto p4

reghdfe Upstream Manage IE_4 interact5 Size Age Ind Lev Subsidy GDP FDI,absorb (id industry )  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto p5

reghdfe Upstream Manage IE_5 interact6 Size Age Ind Lev Subsidy GDP FDI,absorb (id industry )  vce(cluster id)
estadd local year "Yes"
estadd local id "Yes"
est sto p6

esttab p1 p2 p3 p4 p5 p6 using 3.调节效应结果.rtf,replace
