clear
set more off

set seed 696 // Random integer between 0 and 10000 from https://www.random.org
set sortseed 248 // Random integer between 0 and 10000 from https://www.random.org

* Load "find_synth3" program
do "$do\12_0_SCM_individual_level_program_define.do"

foreach dep in abret comply dist{

use "$temp/final_data", clear

keep if sample_res == 1 // Keep only affiliates' firms

* Select dependent variable
if "`dep'" == "abret"{
local var an_abret_index_SBF120_30_1
keep  if  type == "Purchase"
}
if "`dep'" == "comply"{
local var diff_comply
}
if "`dep'" == "dist"{
local var dist_next_res_all
}

find_synth3 `var' after connect id_ind 5000 10

local pre_gap_`dep' = pre_gap[1]
local post_gap_`dep' = post_gap[1]
}

clear
set obs 3
foreach x in pre_gap post_gap{
gen `x' = .
}
gen dep = ""

local a = 0
foreach dep in abret comply dist{
local a = `a' + 1
replace dep = "`dep'" if _n == `a'
foreach x in pre_gap post_gap{
replace `x' = ``x'_`dep'' if _n == `a'
}
}

save "$temp/scm_individual_dependent_variables_res", replace
