clear
set more off
global PATH1 "E:\Research\GVCs\data\financial_constraint\by_year_upstreamness2"
global PATH2 "E:\Research\GVCs\data\financial_constraint\by_year_upstreamness2\results"

cd $PATH1
use  workhouse_bench_2.dta	  

merge m:1 IO using alpha_90.dta
drop _merge

sum alphac
return list

 gen r1 =  11.77529525756836
 gen r2 =  19.21074104309082
 gen r3 =  26.84132957458496    // quntile from alpha——90

gen alphac_0=1 if alphac<r1	
replace alphac_0=0 if alphac_0==.	

forvalues i=1(1)2{
  local j=`i'+1
  gen alphac_`i'=1 if alphac>=r`i' & alphac<r`j'
  replace alphac_`i'=0 if alphac_`i'==.
  }	
gen alphac_3=1 if alphac>=r3 
replace alphac_3=0 if alphac_3==.

forvalues i=0(1)3{
gen fin1_up_alphac_`i'=alphac_`i'*upstream_fin1
}

forvalues i=0(1)3{
gen fin2_up_alphac_`i'=alphac_`i'*upstream_fin2
}

forvalues i=0(1)3{
gen fin3_up_alphac_`i'=alphac_`i'*upstream_fin3
}

forvalues i=0(1)3{
gen fin4_up_alphac_`i'=alphac_`i'*upstream_fin4
}

duplicates drop id year,force
xtset id year
xtreg dvar     fin1_up_alphac_* in_I in_K in_S tfp_lp $dum_con  if dvar<0.985,fe 
est store m1
xtreg dvar     fin2_up_alphac_* in_I in_K in_S tfp_lp $dum_con  if dvar<0.985,fe
est store m2
xtreg dvar     fin4_up_alphac_* in_I in_K in_S tfp_lp $dum_con  if dvar<0.985,fe 
est store m3
esttab  m1 m2 m3  using "$PATH2\Table2.2.rtf", ///
   p star(* 0.1 ** 0.05 *** 0.01) r2 drop($dum_con) nogap replace
  