// ----- basic environment --------//

clear
use  workhouse_bench.dta


merge m:1 IO using alpha_90.dta
drop _merge
keep if sigma_cp!=0
gen sigma_cp_o=sigma_cp
replace sigma_cp=sigma_cp-alpha  // 
  

sum sigma_cp
return list
gen x=r(max)

sort sigma_cp
_pctile sigma_cp, nq(4)
return list   

gen sigma_cp_0=1 if sigma_cp<r(r1)	
replace sigma_cp_0=0 if sigma_cp_0==.	

forvalues i=1(1)2{
  local j=`i'+1
  gen sigma_cp_`i'=1 if sigma_cp>=r(r`i') & sigma_cp<r(r`j')
  replace sigma_cp_`i'=0 if sigma_cp_`i'==.
  }	
gen sigma_cp_3=1 if sigma_cp>=r(r3) & sigma_cp<x
drop x
replace sigma_cp_3=0 if sigma_cp_3==.


forvalues i=0(1)3{
gen fin1_up_sigma_cp_`i'=sigma_cp_`i'*upstream_fin1
}

forvalues i=0(1)3{
gen fin2_up_sigma_cp_`i'=sigma_cp_`i'*upstream_fin2
}

forvalues i=0(1)3{
gen fin3_up_sigma_cp_`i'=sigma_cp_`i'*upstream_fin3
}

forvalues i=0(1)3{
gen fin4_up_sigma_cp_`i'=sigma_cp_`i'*upstream_fin4
}


xtreg dvar     fin1_up_sigma_cp_* in_I in_K in_S tfp_lp  if dvar<0.985 ,fe robust
est store m1
xtreg dvar     fin2_up_sigma_cp_* in_I in_K in_S tfp_lp  if dvar<0.985 ,fe robust
est store m2
xtreg dvar     fin4_up_sigma_cp_* in_I in_K in_S tfp_lp  if dvar<0.985 ,fe robust
est store m3
esttab  m* using "Table_4_1.rtf",  ///
    p star(* 0.1 ** 0.05 *** 0.01) r2  drop(in_I in_K in_S tfp_lp ) nogap replace






