/*********************************************************************************************************************************
*************************************************** The World Bank ***************************************************************
*************************** Analysis of the impact evaluation of informal firms training in Togo *********************************
*************************************** Private Sector Development Support Project ***********************************************
********************************************************* Master Do-file *********************************************************
*********************************************************************************************************************************/

*********************
** Merge data sets **
*********************
set more off, permanently

use "$Baseline", clear
*changing dummy variables that had 1=yes 2=no to 1=yes 0=no
	cap label define dummy 0 "No" 1 "Yes"
	foreach var in  q42b q52 q55 q56 q58 q61 q62 q64c_01 q64c_02 q64c_03 q64c_04 q64c_05 q64c_06 q64c_07 q64c_08 q64c_09 q64c_10 q64d_01 q64d_02 q64d_03 q64d_04 q64d_05 q64d_06 q64d_07 q64d_08 q64d_09 q64d_10 q68 q68a q77 q80a q80b q87 q89 q102 q103 q104 q105 q109 q110 q111 q112 q114 q114a1 q114a2 q114a3 q114a4 q114b q116a q118 q118a q118b q121 q125a q125b q125c q125d q125e q125f q125i q126a q126b q126c q126d q126e q128 q129 q129a q130 q134 q134a q134b q139a1 q139b1 q139c1 q139d1 q139e1 q139f1 q139a2 q139b2 q139c2 q139d2 q139e2 q139f2 q152 q179b q179 q182a q184 q187 q188 {
		recode `var' (2=0)
		label values `var' dummy
		}

	ren * bl_*
	ren bl_id_entreprise id_ent
	ren bl_group group
	sort id_ent
	save "$data\baseline_rev.dta", replace

use "$Follow_up_1", clear
*changing dummy variables that had 1=yes 2=no to 1=yes 0=no
cap label define dummy 0 "No" 1 "Yes"
foreach var in p2q11 p3q6a p3q6b p3q6c p3q6d p3q6e p3q6f p4q2 p4q13 p4q14 p4q15 p4q17 p4q18 p4q171 p4q172 p4q173 p4q174 p4q19b p4q20 p4q22 p4q24d p4q24e p5q16a p5q17a p6q1 p6q2_1 p6q2_2 p6q2_3 p6q2_4 p6q2_5 p6q2_6 p6q2_7 p6q2_8 p6q2_9 p6q2_10 p6q2_11 p6q3 p6q8 p6q8bi p6q8bii p6q8biii p6q8biv p6q8bv p6q8bvi p6q8bvii p6q9 p6q10 {
	recode `var' (2=0) 		
	label values `var' dummy
	}
	
	ren * fu1_*
	ren fu1_id_entreprise id_ent
	sort id_ent
	save "$data\fu1_rev.dta",replace

use "$Follow_up_2", clear
*changing dummy variables that had 1=yes 2=no to 1=yes 0=no
cap label define dummy 0 "No" 1 "Yes"
foreach var in p2q12 p2q13 p2q131g p2q132g p2q133g p2q134g p2q135g p2q14 p2q15 p4q2 p4q17 p4q18 p4q19a p4q20 p4q24a p4q24b p4q24c p4q24d p4q24e p4q24f p4q24aa p4q25 p4q25a p4q26 p4q27 p4q29a p4q29b p4q29c p4q30 p4q34 p4q37 p4q38 p4q39 p4q41 p4q411g p4q412g p4q413g p4q414g p4q415g p4q42 p4q43 p4q44 p4q45 p4q46 p4q47 p4q47ai p4q47aii p4q47aiii p4q47aiv p4q47av p4q47avi p4q48c p4q48d p5q2 p5q3 p5q4 p5q5 p5q6 p5q7 p5q8 p5q9 p5q10 {
	recode `var' (2=0)
	label values `var' dummy
	}
	
	ren * fu2_*
	ren fu2_id_entreprise id_ent
	sort id_ent
	save "$data\fu2_rev.dta", replace

use "$Follow_up_3", clear
	
	** Dummies to recoded from 2 to 0 **
	cap label define dummy 0 "No" 1 "Yes"
	foreach var in p2q6 p2q12   p4q2 p4q4e p4q4f p4q12 p4q17 p4q18 p4q19a p4q20 p4q24aa p4q24a p4q24b p4q24c p4q24d ///
		p4q24e p4q24f p4q25 p4q251 p4q252 p4q253 p4q254 p4q26a p4q26b p4q26c p4q27 p4q29a p4q30 p4q31 p4q42 p4q44 p4q46 p4q47 ///
		p4q48 p4q50 p4q52 p4q53 p4q54 p4q55 p4q551g p4q552g p4q553g p4q554g p4q555g p4q56 p4q57 p4q58 p4q59 p4q60 p4q61 p4q73 ///
		p5q3 p5q4 p5q8 p6q3 p6q5 p6q7 p6q10 p6q16d {
		recode `var' (2=0) (1=1)
		label values `var' dummy
		}
	foreach var in p4q24a p4q24b p4q24c p4q24d p4q24e p4q24aa {
		recode `var' (2=0) 
		}
		
	ren * fu3_*
	ren fu3_id_entreprise id_ent
	sort id_ent
	save "$data\fu3_rev.dta", replace

use "$Follow_up_4", clear

	replace p3q36c3 = . if p3q36c3 ==-6 

	foreach x in p3q19 p3q25a p3q25b p3q25c p3q25d p3q25e p3q25f p3q26 p3q261 p3q262 p3q263 p3q264 p3q27 p3q27b p3q27c p3q41 p3q31 ///
		p3q32 p3q33{
		recode `x' (2=0)
		}
	ren * fu4_*
	ren fu4_id_entreprise id_ent
	sort id_ent
	save "$data\fu4_rev.dta", replace

clear
use "$data\baseline_rev",clear
merge 1:1 id_ent using "$data\fu1_rev.dta"
drop _merge
merge 1:1 id_ent using "$data\fu2_rev.dta"
drop _merge
merge 1:1 id_ent using "$data\fu3_rev.dta"
drop _merge
merge 1:1 id_ent using "$data\fu4_rev.dta"
drop _merge

** A few manual fixes **
tab1 *_interviewed, m
replace fu1_interviewed = 0 if fu1_interviewed==.
ren *_interviewed interviewed_*
saveold "$Master_cleaned", replace

******************************************
** Preparation of the data for analysis **
******************************************

use "$Master_cleaned", clear
tab1 interviewed_fu*, m

** Create Treatment variables **
tab group, m
tab group, gen(assign)
ren assign1 assign_man
ren assign2 assign_ent
ren assign3 control
ren group assign_group

** Create female **
tab bl_q40, m
ren bl_q40 female
codebook female
replace female=0 if female==2
label define female 0 "Male" 1 "Female"
label values female female

** Baseline variables **
ren bl_stratafinal strata
ren bl_q41_age bl_age

** Average years of education **
gen educ_years = 0 if bl_q155==1
replace educ_years = 1 if bl_q155==2
replace educ_years = 2 if bl_q155==3
replace educ_years = 3 if bl_q155==4
replace educ_years = 4 if bl_q155==5
replace educ_years = 5 if bl_q155==6
replace educ_years = 6 if bl_q155==7
replace educ_years = 7 if bl_q155==8
replace educ_years = 8 if bl_q155==9
replace educ_years = 9 if bl_q155==10
replace educ_years = 10 if bl_q155==11
replace educ_years = 11 if bl_q155==12
replace educ_years = 12 if bl_q155==13
replace educ_years = 13 if bl_q155==14
replace educ_years = 14 if bl_q156==1
replace educ_years = 15 if bl_q156==2
replace educ_years = 16 if bl_q156==3
replace educ_years = 17 if bl_q156==4
replace educ_years = 18 if bl_q156==5
replace educ_years = 19 if bl_q156==6
replace educ_years = 20 if bl_q156==7
replace educ_years = 21 if bl_q156==8
replace educ_years = 26 if bl_q156==14
replace educ_years=13 if bl_q154==8&bl_q156==0
ren educ_years bl_years_schooling

** Firm's age **
gen bl_firm_age = 2013-bl_q51
replace bl_firm_age = . if bl_firm_age==1914
sum bl_firm_age

** Create sector variable **
ren bl_bl_sector sector
tab sector, m
gen bl_commerce = (sector==2)
gen bl_production = (sector==1)
label var sector "1=Production 2=Commerce 3=Other services" 

**********************************************
** Adjust financial variables for inflation **
**********************************************

** Raw variables for inflation adjusted variables **
foreach var in fu4_p3q39b1ii fu4_p3q39a1ii fu4_p3q39b2ii fu4_p3q39a2ii fu4_p4q2aii fu3_p4q34b1ii fu3_p4q34a1ii fu3_p4q34a2ii ///
	fu3_p4q34b2ii fu3_p5q2aii fu2_p4q32b1ii fu2_p4q32b2ii fu2_p4q32a1ii fu2_p4q32a2ii fu2_p5q1aii fu1_p4q21b1ii fu1_p4q21a1ii ///
	fu1_p4q21a2ii fu1_p4q21b2ii fu1_p5q1aii {
	gen raw_`var' = `var'
	}

** Follow up 4 **
replace fu4_incide=101.41864 if fu4_incide==.
foreach var in fu4_p3q39b1ii fu4_p3q39a1ii fu4_p3q39b2ii fu4_p3q39a2ii fu4_p4q2aii fu4_p3q36a2 fu4_p3q36b2 fu4_p3q36c2 ///
	fu4_p3q36d2 fu4_p3q36e2 fu4_p3q36f2 fu4_p3q36a3 fu4_p3q36b3 fu4_p3q36c3 fu4_p3q36d3 fu4_p3q36e3 fu4_p3q36f3 fu4_p3q38 ///
	fu4_p3q40a3 fu4_p3q40b3 fu4_p3q40c3 fu4_p3q40d3 fu4_p3q40e3 fu4_p3q40f3 fu4_p3q40g3 fu4_p3q44 fu4_p3q45a {
	di "`var'"
	sum `var'
	replace `var' = `var'/(fu4_incide/100)
	label var `var' "CPI adjusted `var' - See raw variable"
	sum `var'
	}

** Follow up 3 **
codebook fu3_incide
replace fu3_incide=101.97115 if fu3_incide==.
foreach var in fu3_p4q34b1ii fu3_p4q34a1ii fu3_p4q34a2ii fu3_p4q34b2ii fu3_p5q2aii fu3_p4q41a2 fu3_p4q41b2 fu3_p4q41c2 ///
	fu3_p4q41d2 fu3_p4q41e2 fu3_p4q41f2 fu3_p4q41a3 fu3_p4q41b3 fu3_p4q41c3 fu3_p4q41d3 fu3_p4q41e3 fu3_p4q41f3 fu3_p4q43 ///
	fu3_p4q45a3 fu3_p4q45a4 fu3_p4q45b3 fu3_p4q45b4 fu3_p4q45c3 fu3_p4q45c4 fu3_p4q45d3 fu3_p4q45d4 fu3_p4q45e3 fu3_p4q45e4 /// 
	fu3_p4q45f3 fu3_p4q45f4 fu3_p4q45g3 fu3_p4q45g4 fu3_p4q49 fu3_p4q50a {
	di "`var'"	
	sum `var'
	replace `var' = `var'/(fu3_incide/100)
	label var `var' "CPI adjusted `var'  - See raw variable"
	sum `var'
	} 
		
** Follow up 2 **
codebook fu2_incide
replace fu2_incide=100.37132 if fu2_incide==.
foreach var in fu2_p4q32b1ii fu2_p4q32b2ii fu2_p4q32a1ii fu2_p4q32a2ii fu2_p5q1aii fu2_p4q33a2 fu2_p4q33b2 fu2_p4q33c2 ///
	fu2_p4q33d2 fu2_p4q33e2 fu2_p4q33f2 fu2_p4q33a3 fu2_p4q33b3 fu2_p4q33c3 fu2_p4q33d3 fu2_p4q33e3 fu2_p4q33f3 fu2_p4q35 /// 
	fu2_p4q36a3 fu2_p4q36a4 fu2_p4q36b3 fu2_p4q36b4 fu2_p4q36c3 fu2_p4q36c4 fu2_p4q36d3 fu2_p4q36d4 fu2_p4q36e3 fu2_p4q36e4 fu2_p4q36f3 fu2_p4q36f4 fu2_p4q40 {
	di "`var'"		
	sum `var'
	replace `var' = `var'/(fu2_incide/100)
	label var `var' "CPI adjusted `var' - See raw variable"
	sum `var'
	}

** Follow up 1 **
codebook fu1_incide
replace fu1_incide=100.1809 if fu1_incide==.
foreach var in fu1_p4q21b1ii fu1_p4q21a1ii fu1_p4q21a2ii fu1_p4q21b2ii fu1_p5q1aii fu1_p4q23 {
	di "`var'"
	sum `var'
	replace `var' = `var'/(fu1_incide/100)
	label var `var' "CPI adjusted `var' - See raw variable"
	sum `var'
	} 

**********************************************************************************************************************************
************************************ Part 1: Preparation of Primary Outcome variables ********************************************
**********************************************************************************************************************************

** Firm's Survival **
tab1 fu4_p2q2 fu4_p2q12 fu4_entreprise, m
	gen fu4_has_business = (fu4_p2q2==1)
	replace fu4_has_business = 1 if fu4_p2q12==1
	replace fu4_has_business = . if interviewed_fu4==0 
	replace fu4_has_business = 1 if fu4_entreprise=="oui"
	replace fu4_has_business = 0 if fu4_entreprise == "non"	
	label var fu4_has_business "Entrepreneur currently is owner or manager of a business"
	label define has_business 1 "Yes" 0 "No"
	label values fu4_has_business has_business


tab1 fu3_p2q2 fu3_p2q12 fu3_entreprise, m
	gen fu3_has_business=(fu3_p2q2==1)
	replace fu3_has_business = 1 if fu3_p2q12==1
	replace fu3_has_business = . if interviewed_fu3==0
	replace fu3_has_business = 1 if fu3_entreprise=="EXISTE"
	replace fu3_has_business = 0 if fu3_entreprise=="FERMEE"
	label var fu3_has_business "Entrepreneur currently is owner or manager of a business"
	label values fu3_has_business has_business
	
tab1 fu2_p2q2 fu2_p2q12 fu2_entreprise, m 
	gen fu2_has_business=(fu2_p2q2==1)
	replace fu2_has_business = 1 if fu2_p2q12==1
	replace fu2_has_business = . if interviewed_fu2==0
	replace fu2_has_business = 1 if fu2_entreprise=="oui"
	replace fu2_has_business = 0 if fu2_entreprise=="non"
	label var fu2_has_business "Entrepreneur currently is owner or manager of a business"
	label values fu2_has_business has_business

tab1 fu1_p2q1 fu1_p2q11, m
	gen fu1_has_business = (fu1_p2q1==1)
	replace fu1_has_business=1 if fu1_p2q11==1
	replace fu1_has_business = . if interviewed_fu1==0
	label var fu1_has_business "Entrepreneur currently is owner or manager of a business"
	label values fu1_has_business has_business
	
** Last month’s sales **
sum fu4_p3q39b1ii
	replace fu4_p3q39b1ii = (fu4_p3q39a1ii*52)/12 if fu4_p3q39b1ii==. & fu4_p3q39a1ii!=. 
	rename fu4_p3q39b1ii fu4_sales_lm 

sum fu3_p4q34b1ii
	replace fu3_p4q34b1ii = (fu3_p4q34a1ii*52)/12 if fu3_p4q34b1ii==. & fu3_p4q34a1ii!=. 
	rename fu3_p4q34b1ii fu3_sales_lm 

sum fu2_p4q32b1ii
	replace fu2_p4q32b1ii = (fu2_p4q32a1ii*52)/12 if fu2_p4q32b1ii==. & fu2_p4q32a1ii!=. 
	rename fu2_p4q32b1ii fu2_sales_lm 

sum fu1_p4q21b1ii
	replace fu1_p4q21b1ii = (fu1_p4q21a1ii*52)/12 if fu1_p4q21b1ii==. & fu1_p4q21a1ii!=. 
	rename fu1_p4q21b1ii fu1_sales_lm 

sum bl_q85b1ii
	replace bl_q85b1ii = (bl_q85a1ii*52)/12 if bl_q85b1ii==. & bl_q85a1ii!=. 
	rename bl_q85b1ii bl_sales_lm 
	gen bl_sales_lm_miss = (bl_sales_lm==.)

** Last weeks’ sales **
sum fu4_p3q39a1ii
	rename fu4_p3q39a1ii fu4_sales_lw

sum fu3_p4q34a1ii
	rename fu3_p4q34a1ii fu3_sales_lw

sum fu2_p4q32a1ii
	rename fu2_p4q32a1ii fu2_sales_lw

sum fu1_p4q21a1ii
	rename fu1_p4q21a1ii fu1_sales_lw

sum bl_q85a1ii 
	rename bl_q85a1ii bl_sales_lw
	gen bl_sales_lw_miss = (bl_sales_lw==.)
	 
** Last month’s profits **
sum fu4_p3q39b2ii 
	replace fu4_p3q39b2ii = (fu4_p3q39a2ii*52)/12 if fu4_p3q39b2ii==. & fu4_p3q39a2ii!=. 
	rename fu4_p3q39b2ii fu4_profits_lm 

sum fu3_p4q34b2ii
	replace fu3_p4q34b2ii = (fu3_p4q34a2ii*52)/12 if fu3_p4q34b2ii==. & fu3_p4q34a2ii!=. 
	rename fu3_p4q34b2ii fu3_profits_lm 

sum fu2_p4q32b2ii
	replace fu2_p4q32b2ii = (fu2_p4q32a2ii*52)/12 if fu2_p4q32b2ii==. & fu2_p4q32a2ii!=. 
	rename fu2_p4q32b2ii fu2_profits_lm 

sum fu1_p4q21b2ii
	replace fu1_p4q21b2ii = (fu1_p4q21a2ii*52)/12 if fu1_p4q21b2ii==. & fu1_p4q21a2ii!=. 
	rename fu1_p4q21b2ii fu1_profits_lm 

sum bl_q85b2ii 
	replace bl_q85b2ii = (bl_q85a2ii*52)/12 if bl_q85b2ii==. & bl_q85a2ii!=. 
	rename bl_q85b2ii bl_profits_lm 
	gen bl_profits_lm_miss = (bl_profits_lm==.)

** Last week’s profits **
sum fu4_p3q39a2ii
	rename fu4_p3q39a2ii fu4_profits_lw

sum fu3_p4q34a2ii
	rename fu3_p4q34a2ii fu3_profits_lw

sum fu2_p4q32a2ii 
	rename fu2_p4q32a2ii fu2_profits_lw

sum fu1_p4q21a2ii
	rename fu1_p4q21a2ii fu1_profits_lw

sum bl_q85a2ii 
	rename bl_q85a2ii bl_profits_lw
	gen bl_profits_lw_miss = (bl_profits_lw==.)

** Total business profits **
egen fu4_total_profits = rsum(fu4_profits_lm fu4_p4q2aii)
	replace fu4_total_profits = . if fu4_profits_lm==. & fu4_p4q2aii==.
	label var fu4_total_profits "Total profits from all businesses last month in fu4"

egen fu3_total_profits = rsum(fu3_profits_lm fu3_p5q2aii)
	replace fu3_total_profits=. if fu3_profits_lm==. & fu3_p5q2aii==.
	label var fu3_total_profits "Total profits from all businesses last month in fu3" 

egen fu2_total_profits = rsum(fu2_profits_lm fu2_p5q1aii)
	replace fu2_total_profits=. if fu2_profits_lm==. & fu2_p5q1aii==.
	label var fu2_total_profits "Total profits from all businesses last month in fu2"

egen fu1_total_profits = rsum(fu1_profits_lm fu1_p5q1aii)
	replace fu1_total_profits=. if fu1_profits_lm==. & fu1_p5q1aii==.
	label var fu1_total_profits "Total profits from all businesses last month in fu1"

egen bl_total_profits = rsum(bl_profits_lm bl_q166e_1 bl_q166e_2 bl_q166e_3 bl_q166e_4 bl_q166e_5)
	gen bl_total_profits_miss = (bl_profits_lm_miss==1 & bl_q166e_1==. & bl_q166e_2==. & bl_q166e_3==. & bl_q166e_4==. & ///
	bl_q166e_5==.)
	label var bl_total_profits "Total profits from all businesses last month in bl"
	
** Sales and profits variations **
foreach i in bl fu1 fu2 fu3 fu4 { 

	** Winsorized Sales **
	foreach var in `i'_sales_lm `i'_sales_lw {
		summarize `var', d
		gen win_`var' = `var'
		replace win_`var' = r(p99) if win_`var'>r(p99) & win_`var'!=.
		label var win_`var' "Winsorized `var'"
		}
	** Windsorized sales and profits **
	foreach var in `i'_profits_lm `i'_profits_lw `i'_total_profits {
		gen win_`var' = `var'
		winsor2 win_`var', replace cuts(1 99)
		label var win_`var' "Winsorized `var'"
		}
	** IHS of sales and profits **
	foreach var in `i'_sales_lm `i'_profits_lm {
		di `var'
		gen ihs_`var' = ln(`var' + sqrt(`var'^2+1))
		label var ihs_`var' "IHS transformation of `var'"
		}
	}

** Set sales and profits to 0 for those with no business **
forval i=1/4 {
	foreach var in fu`i'_sales_lm win_fu`i'_sales_lm ihs_fu`i'_sales_lm fu`i'_sales_lw win_fu`i'_sales_lw fu`i'_profits_lm ///
		win_fu`i'_profits_lm ihs_fu`i'_profits_lm fu`i'_profits_lw win_fu`i'_profits_lw fu`i'_total_profits win_fu`i'_total_profits {
		replace `var' = 0 if fu`i'_has_business==0 & `var'==.
		}
	}
	
** Z-scores for Hypothesis group A1 **
foreach i in bl fu1 fu2 fu3 fu4 { 
	foreach var in `i'_sales_lm win_`i'_sales_lm ihs_`i'_sales_lm win_`i'_sales_lw `i'_profits_lm win_`i'_profits_lm ///
		ihs_`i'_profits_lm win_`i'_profits_lw win_`i'_total_profits {
		summarize `var' if assign_group==3
		gen z_`var'=(`var'-r(mean))/r(sd)
		label var z_`var' "Z-score of `var'"
		sum z_`var' if assign_group==3
		}
	}
	
** Average z-score for hypothesis group A1 **
foreach i in bl fu1 fu2 fu3 fu4 { 
	egen `i'_avg_z_hyp_a1 = rowmean(z_`i'_sales_lm z_win_`i'_sales_lm z_ihs_`i'_sales_lm z_win_`i'_sales_lw z_`i'_profits_lm ///
		z_win_`i'_profits_lm z_ihs_`i'_profits_lm z_win_`i'_profits_lw z_win_`i'_total_profits)
		label var `i'_avg_z_hyp_a1 "Average z-score for variables in hypothesis group A1 for `i'"
		}
	gen bl_avg_z_hyp_a1_miss = (bl_avg_z_hyp_a1==.)
	
** Drop variables we dont need **
forval i=1/4 {
	drop fu`i'_sales_lw fu`i'_profits_lw fu`i'_total_profits
	}

**********************************************************************************************************************************
********************************** Part 2: Preparation of Secondary Outcome variables ********************************************
**********************************************************************************************************************************

*********************
** Labor variables **
*********************

** Winsorized numbers of hours worked personally **
sum fu4_p3q8 fu3_p4q7 fu2_p4q7 fu1_p4q6
	rename fu4_p3q8 fu4_own_labor
	rename fu3_p4q7 fu3_own_labor
	rename fu2_p4q7 fu2_own_labor
	rename fu1_p4q6 fu1_own_labor

	forval i=1/4 {
		replace fu`i'_own_labor=. if fu`i'_own_labor==99
		summarize fu`i'_own_labor, d
		gen win_fu`i'_own_labor = fu`i'_own_labor
		replace win_fu`i'_own_labor = r(p99) if win_fu`i'_own_labor>r(p99) & win_fu`i'_own_labor!=.
		label var win_fu`i'_own_labor "Windzorized own labor at fu`i'"
		}

** Number of workers **
sum fu4_p3q5 fu3_p4q4 fu2_p4q48 fu1_p4q24 bl_q63
	rename fu4_p3q5 fu4_no_workers
	rename fu3_p4q4 fu3_no_workers
	rename fu2_p4q48 fu2_no_workers
	rename fu1_p4q24 fu1_no_workers
	rename bl_q63 bl_no_workers
	gen bl_no_workers_miss = (bl_no_workers==.)
	label var fu4_no_workers "Number of workers that work for business, paid and unpaid"
	label var fu3_no_workers "Number of workers that work for business, paid and unpaid"
	label var fu2_no_workers "Number of workers that work for business, paid and unpaid"
	label var fu1_no_workers "Number of workers that work for business, paid and unpaid"
	label var bl_no_workers "Number of workers that work for business, paid and unpaid"
		
** Number of paid workers **
sum fu4_p3q5ai fu3_p4q4ai fu2_p4q48ai fu1_p4q24ai
	rename fu4_p3q5ai fu4_paid_workers
	rename fu3_p4q4ai fu3_paid_workers
	rename fu2_p4q48ai fu2_paid_workers
	rename fu1_p4q24ai fu1_paid_workers
	label var fu4_paid_workers "Number of paid workers that work for business"
	label var fu3_paid_workers "Number of paid workers that work for business"
	label var fu2_paid_workers "Number of paid workers that work for business"
	label var fu1_paid_workers "Number of paid workers that work for business"

** Number of workers receiving only stipend **
sum fu4_p3q5aii fu3_p4q4aii fu2_p4q48aii fu1_p4q24aii
	rename fu4_p3q5aii fu4_stipend_workers
	rename fu3_p4q4aii fu3_stipend_workers
	rename fu2_p4q48aii fu2_stipend_workers 
	rename fu1_p4q24aii fu1_stipend_workers
	label var fu4_stipend_workers "Number of workers who received a transport stipend"
	label var fu3_stipend_workers "Number of workers who received a transport stipend"
	label var fu2_stipend_workers "Number of workers who received a transport stipend"
	label var fu1_stipend_workers "Number of workers who received a transport stipend"

** Number of unpaid workers **
sum fu4_p3q5aiii fu3_p4q4aiii fu2_p4q48aiii fu1_p4q24aiii 
	rename fu4_p3q5aiii fu4_unpaid_workers
	rename fu3_p4q4aiii fu3_unpaid_workers
	rename fu2_p4q48aiii fu2_unpaid_workers
	rename fu1_p4q24aiii fu1_unpaid_workers
	label var fu4_unpaid_workers "Number of unpaid workers that work for business"
	label var fu3_unpaid_workers "Number of unpaid workers that work for business"
	label var fu2_unpaid_workers "Number of unpaid workers that work for business"
	label var fu1_unpaid_workers "Number of unpaid workers that work for business"
 
** Number of female workers **
egen bl_fem_workers_less10 = anycount(bl_q64b_01 bl_q64b_02 bl_q64b_03 bl_q64b_04 bl_q64b_05 bl_q64b_06 bl_q64b_07 bl_q64b_08 bl_q64b_09 bl_q64b_10), values (2)
	tab bl_fem_workers_less10
	egen bl_fem_workers=rsum(bl_fem_workers_less10 bl_q65g2) 

** Number of hours open per week **
replace fu2_p4q6 = . if fu2_p4q6==66

sum fu4_p3q6 fu4_p3q7
	gen fu4_hours_open = fu4_p3q6 * fu4_p3q7
	replace fu4_hours_open = . if fu4_p3q6==. | fu4_p3q7==.
	label var fu4_hours_open "Hours the business is open per week at fu4"

sum fu3_p4q5 fu3_p4q6
	gen fu3_hours_open = fu3_p4q5 * fu3_p4q6
	replace fu3_hours_open = . if fu3_p4q5==. | fu3_p4q6==.
	label var fu3_hours_open "Hours the business is open per week at fu3"

sum fu2_p4q5 fu2_p4q6
	gen fu2_hours_open = fu2_p4q5 * fu2_p4q6
	replace fu2_hours_open=. if fu2_p4q5==. | fu2_p4q6==.
	label var fu2_hours_open "Hours the business is open per week at fu2"

sum fu1_p4q4 fu1_p4q5
	gen fu1_hours_open = fu1_p4q4 * fu1_p4q5
	replace fu1_hours_open=. if fu1_p4q4==. | fu1_p4q5==.
	label var fu1_hours_open "Hours the business is open per week at fu1"

sum bl_q66 bl_q67
	gen bl_hours_open=bl_q66 * bl_q67
	replace bl_hours_open=. if bl_q66==. | bl_q67==.
	label var bl_hours_open "Hours the business is open per week at bl"
	gen bl_hours_open_miss = (bl_hours_open==.)
	
** Recode for closed business and no workers **
forval i = 1/4 {

	** No workers reported **
	foreach var in fu`i'_paid_workers fu`i'_stipend_workers fu`i'_unpaid_workers {
		replace `var' = 0 if `var'==. & fu`i'_no_workers==0
		}
				
	** Closed businesses **
	foreach var in win_fu`i'_own_labor fu`i'_no_workers fu`i'_paid_workers fu`i'_stipend_workers fu`i'_unpaid_workers ///
		fu`i'_hours_open {
		replace `var' = 0 if `var'==. & fu`i'_has_business==0
			}
}
** Z-score for labor variables **
forval i = 1/4 {
	foreach var in win_fu`i'_own_labor fu`i'_no_workers fu`i'_paid_workers fu`i'_stipend_workers fu`i'_unpaid_workers ///
		fu`i'_hours_open {
		summarize `var' if assign_group==3
		gen z_`var'=(`var'-r(mean))/r(sd)
		label var z_`var' "Z-score of `var'"
		sum z_`var' if assign_group==3
		}
	}

	foreach var in bl_no_workers bl_hours_open {
		sum `var' if assign_group==3
		gen z_`var'=(`var'-r(mean))/r(sd)
		label var z_`var' "Z-score of `var'"
		sum z_`var' if assign_group==3
	}		
	
** Drop variables we dont use **
drop fu1_own_labor fu2_own_labor fu3_own_labor fu4_own_labor

***********************
** Capital Variables **
***********************

** Capital stock **
sum fu4_p3q36a2 fu4_p3q36b2 fu4_p3q36c2 fu4_p3q36d2 fu4_p3q36e2 fu4_p3q36f2 
	sum fu4_p3q36a1 fu4_p3q36b1 fu4_p3q36c1 fu4_p3q36d1 fu4_p3q36e1
	replace fu4_p3q36b1=. if fu4_p3q36b1==9999
egen fu4_k_stock = rsum(fu4_p3q36a2 fu4_p3q36b2 fu4_p3q36c2 fu4_p3q36d2 fu4_p3q36e2 fu4_p3q36f2)
	egen fu4_k_num_0 = anycount(fu4_p3q36a1 fu4_p3q36b1 fu4_p3q36c1 fu4_p3q36d1 fu4_p3q36e1), values(0)
	egen fu4_k_stock_miss = rowmiss(fu4_p3q36a2 fu4_p3q36b2 fu4_p3q36c2 fu4_p3q36d2 fu4_p3q36e2 fu4_p3q36f2)
	replace fu4_k_stock = . if fu4_k_stock_miss ==6 & fu4_k_num_0 < 5
	label var fu4_k_num_0 "Number of values 0 for the number of capital stock in fu4"
	label var fu4_k_stock_miss "Number of missing values for the value of capital stock in fu4"
	label var fu4_k_stock "Sum of the current value of capital stock at fu4"

sum fu3_p4q41a2 fu3_p4q41b2 fu3_p4q41c2 fu3_p4q41d2 fu3_p4q41e2 fu3_p4q41f2
egen fu3_k_stock = rsum(fu3_p4q41a2 fu3_p4q41b2 fu3_p4q41c2 fu3_p4q41d2 fu3_p4q41e2 fu3_p4q41f2)
	egen fu3_k_num_0=anycount(fu3_p4q41a1 fu3_p4q41b1 fu3_p4q41c1 fu3_p4q41d1 fu3_p4q41e1 fu3_p4q41f1), values(0)
	egen fu3_k_stock_miss = rowmiss(fu3_p4q41a2 fu3_p4q41b2 fu3_p4q41c2 fu3_p4q41d2 fu3_p4q41e2 fu3_p4q41f2)
	replace fu3_k_stock=. if fu3_k_stock_miss==6 & fu3_k_num_0<5
	label var fu3_k_stock "CPI adjusted sum of the current value of capital stock at fu3"
	label var fu3_k_num_0 "Number of values 0 for the number of capital stock in fu3"
	label var fu3_k_stock_miss "Number of missing values for the value of capital stock in fu3"

sum fu2_p4q33a2 fu2_p4q33b2 fu2_p4q33c2 fu2_p4q33d2 fu2_p4q33e2 fu2_p4q33f2
egen fu2_k_stock=rsum(fu2_p4q33a2 fu2_p4q33b2 fu2_p4q33c2 fu2_p4q33d2 fu2_p4q33e2 fu2_p4q33f2)
	egen fu2_k_num_0=anycount(fu2_p4q33a1 fu2_p4q33b1 fu2_p4q33c1 fu2_p4q33d1 fu2_p4q33e1), values(0)
	egen fu2_k_stock_miss=rowmiss(fu2_p4q33a2 fu2_p4q33b2 fu2_p4q33c2 fu2_p4q33d2 fu2_p4q33e2 fu2_p4q33f2)
	replace fu2_k_stock=. if fu2_k_stock_miss==6 & fu2_k_num_0<5
	label var fu2_k_stock "CPI adjusted Sum of the current value of capital stock at fu2"
	label var fu2_k_num_0 "Number of values 0 for the number of capital stock in fu2"
	label var fu2_k_stock_miss "Number of missing values for the value of capital stock in fu2"

sum bl_q86a2 bl_q86b2 bl_q86c2 bl_q86d2 bl_q86e2 bl_q86f2
egen bl_k_stock=rsum(bl_q86a2 bl_q86b2 bl_q86c2 bl_q86d2 bl_q86e2 bl_q86f2)
	egen bl_k_num_0=anycount(bl_q86a1 bl_q86b1 bl_q86c1 bl_q86d1 bl_q86e1), values(0)
	egen bl_k_stock_rowmiss = rowmiss(bl_q86a2 bl_q86b2 bl_q86c2 bl_q86d2 bl_q86e2 bl_q86f2)
	replace bl_k_stock=. if bl_k_stock_rowmiss==6 & bl_k_num_0<5
	label var bl_k_stock "CPI adjusted sum of the current value of capital stock at bl"
	label var bl_k_num_0 "Number of values 0 for the number of capital stock in bl"
	label var bl_k_stock_rowmiss "Number of missing values for the value of capital stock in bl"
	gen bl_k_stock_miss = (bl_k_stock==.)
				
** Capital investments over past 12 months **
sum fu4_p3q36a3 fu4_p3q36b3 fu4_p3q36c3 fu4_p3q36d3 fu4_p3q36e3 fu4_p3q36f3
egen fu4_k_invest = rsum(fu4_p3q36a3 fu4_p3q36b3 fu4_p3q36c3 fu4_p3q36d3 fu4_p3q36e3 fu4_p3q36f3)
	replace fu4_k_invest = . if fu4_p3q36a3==. & fu4_p3q36b3==. & fu4_p3q36c3==. & fu4_p3q36d3==. & fu4_p3q36e3==. & ///
		fu4_p3q36f3==.
	label var fu4_k_invest "CPI adjusted Sum of capital investment over past 12 months at fu4"	

sum fu3_p4q41a3 fu3_p4q41b3 fu3_p4q41c3 fu3_p4q41d3 fu3_p4q41e3 fu3_p4q41f3
egen fu3_k_invest = rsum(fu3_p4q41a3 fu3_p4q41b3 fu3_p4q41c3 fu3_p4q41d3 fu3_p4q41e3 fu3_p4q41f3)
	replace fu3_k_invest = . if fu3_p4q41a3==. & fu3_p4q41b3==. & fu3_p4q41c3==. & fu3_p4q41d3==. & fu3_p4q41e3==. & ///
		fu3_p4q41f3==.
	label var fu3_k_invest "CPI adjusted Sum of capital investment over past 12 months at fu3"

sum fu2_p4q33a3 fu2_p4q33b3 fu2_p4q33c3 fu2_p4q33d3 fu2_p4q33e3 fu2_p4q33f3
egen fu2_k_invest = rsum(fu2_p4q33a3 fu2_p4q33b3 fu2_p4q33c3 fu2_p4q33d3 fu2_p4q33e3 fu2_p4q33f3)
	replace fu2_k_invest = . if fu2_p4q33a3==. & fu2_p4q33b3==. & fu2_p4q33c3==. & fu2_p4q33d3==. & fu2_p4q33e3==. & ///
		fu2_p4q33f3==.
	label var fu2_k_invest "CPI adjusted Sum of capital investment over past 12 months at fu2"	
	
sum bl_q86a3 bl_q86b3 bl_q86c3 bl_q86d3 bl_q86e3 bl_q86f3
egen bl_k_invest = rsum(bl_q86a3 bl_q86b3 bl_q86c3 bl_q86d3 bl_q86e3 bl_q86f3)
	gen bl_k_invest_miss = (bl_q86a3==. & bl_q86b3==. & bl_q86c3==. & bl_q86d3==. & bl_q86e3==. & bl_q86f3==.)
	replace bl_k_invest=. if bl_k_invest_miss==1
	label var bl_k_invest "CPI adjusted Sum of capital investment over past 12 months at bl"
	label var bl_k_invest_miss "Number of missing values for the value of capital investment in bl"
	
** Value of stocks **
sum bl_q88 fu1_p4q23 fu2_p4q35 fu3_p4q43 fu4_p3q38 fu4_p3q37
replace fu4_p3q38 = 0 if fu4_p3q37 == 2|0
	rename fu4_p3q38 fu4_stock_value
replace fu3_p4q43 = 0 if fu3_p4q42==0
	rename fu3_p4q43 fu3_stock_value
replace fu2_p4q35 = 0 if fu2_p4q34==0
	rename fu2_p4q35 fu2_stock_value
replace fu1_p4q23 = 0 if fu1_p4q22==0
	rename fu1_p4q23 fu1_stock_value
replace bl_q88 = 0 if bl_q87==0
	rename bl_q88 bl_stock_value
	gen bl_stock_value_miss = (bl_stock_value==.)
	
** Winsorized variables ** 
foreach x in bl fu2 fu3 fu4 {
	foreach var in `x'_k_stock `x'_k_invest `x'_stock_value {
		summarize `var', d
		gen win_`var' = `var'
		replace win_`var' = r(p99) if win_`var'>r(p99) & win_`var'!=.
		label var win_`var' "Winsorized `var' at 99th percentile"
		}
	}

	summarize fu1_stock_value, d
	gen win_fu1_stock_value = fu1_stock_value
		replace win_fu1_stock_value = r(p99) if win_fu1_stock_value > r(p99) & win_fu1_stock_value!=.
		sum fu1_stock_value win_fu1_stock_value, d
		label var win_fu1_stock_value "Winsorized `x' at 99th percentile"

** Made a large capital investment **
sum bl_profits_lm if bl_profits_lm_miss==0, d
gen fu4_big_invest = (fu4_k_invest >= (3*r(p50)) & fu4_k_invest!=.)
	replace fu4_big_invest=. if fu4_k_invest==.
	tab fu4_big_invest, m
	sum fu4_k_invest if fu4_big_invest == 1,d
	sum fu4_k_invest if fu4_big_invest == 0,d
	label var fu4_big_invest "Entrepreneur made an investment at fu4 higher or equal to 3 times median profits at bl"

sum bl_profits_lm if bl_profits_lm_miss==0, d
gen fu3_big_invest=(fu3_k_invest>=(3*r(p50)) & fu3_k_invest!=.)
	replace fu3_big_invest=. if fu3_k_invest==.
	tab fu3_big_invest,m
	sum fu3_k_invest if fu3_big_invest==1,d
	sum fu3_k_invest if fu3_big_invest==0,d
	label var fu3_big_invest "Entrepreneur made an investment at fu3 higher or equal to 3 times median profits at bl"

sum bl_profits_lm if bl_profits_lm_miss==0, d
gen fu2_big_invest=(fu2_k_invest>=(3*r(p50)) & fu2_k_invest!=.)
	replace fu2_big_invest=. if fu2_k_invest==.
	tab fu2_big_invest,m
	sum fu2_k_invest if fu2_big_invest==1,d
	sum fu2_k_invest if fu2_big_invest==0,d
	label var fu2_big_invest "Entrepreneur made an investment at fu2 higher or equal to 3 times median profits at bl"

sum bl_profits_lm if bl_profits_lm_miss==0, d
gen bl_big_invest=(bl_k_invest>=(3*r(p50)) & bl_k_invest!=.)
	tab bl_big_invest,m
	sum bl_k_invest if bl_big_invest==1,d
	sum bl_k_invest if bl_big_invest==0,d
	replace bl_big_invest=. if bl_k_invest==.
	label var bl_big_invest "Entrepreneur made an investment higher or equal to 3 times median profits at bl"
	gen bl_big_invest_miss = (bl_big_invest==.)
	
** Change values to 0 for closed businesses **
forval i= 2/4 {
	foreach var in win_fu`i'_k_stock win_fu`i'_k_invest win_fu`i'_stock_value fu`i'_big_invest {
		replace `var' = . if interviewed_fu`i'==0
		replace `var' = 0 if fu`i'_has_business== 0 &`var'==.
		}
}	
	replace win_fu1_stock_value = . if interviewed_fu1==0
	replace win_fu1_stock_value = 0 if fu1_has_business==0 & win_fu1_stock_value==.

** Z-score variable for capital **
foreach x in bl fu2 fu3 fu4 {
	foreach var in win_`x'_k_stock win_`x'_k_invest win_`x'_stock_value `x'_big_invest {
		summarize `var' if assign_group==3
		gen z_`var'=(`var'-r(mean))/r(sd)
		label var z_`var' "Z-score of `var'"
	}	
}
summarize win_fu1_stock_value if assign_group==3
	gen z_win_fu1_stock_value = (win_fu1_stock_value-r(mean))/r(sd)
	label var z_win_fu1_stock_value "Z-score of `var'"

** Average Z-scores for capital measures **
foreach x in bl fu2 fu3 fu4 {
	egen `x'_avg_z_hyp_b1_k = rowmean(z_win_`x'_k_stock z_win_`x'_k_invest z_win_`x'_stock_value z_`x'_big_invest)
	label var `x'_avg_z_hyp_b1_k "Average Z-score for capital outcomes in Hypothesis B1 for fu1"
}
egen fu1_avg_z_hyp_b1_k = rowmean(z_win_fu1_stock_value)
	label var fu1_avg_z_hyp_b1_k "Average Z-score for capital outcomes in Hypothesis B1 for fu1"

** Drop variables we wont need **
 forval i=2/4 {
	drop fu`i'_k_stock fu`i'_k_invest fu`i'_stock_value
	}
	drop fu1_stock_value

********************************
** Capital and Labor combined **
********************************

** Z-score for combined labor and capital **
forval x=2/4 {
	egen fu`x'_avg_z_hyp_b1 = rowmean(z_win_fu`x'_own_labor z_fu`x'_no_workers z_fu`x'_paid_workers z_fu`x'_stipend_workers ///
		z_fu`x'_unpaid_workers z_fu`x'_hours_open z_win_fu`x'_k_stock z_win_fu`x'_k_invest z_win_fu`x'_stock_value ///
		z_fu`x'_big_invest)
		label var fu`x'_avg_z_hyp_b1 "Average Z-score for outcomes in Hypothesis B1 for `x'"
	}
egen fu1_avg_z_hyp_b1 = rowmean(z_win_fu1_own_labor z_fu1_no_workers z_fu1_paid_workers z_fu1_stipend_workers ///
	z_fu1_unpaid_workers z_fu1_hours_open z_win_fu1_stock_value)
	label var fu1_avg_z_hyp_b1 "Average Z-score for outcomes in Hypothesis B1 for fu1"
egen bl_avg_z_hyp_b1 = rowmean(z_bl_no_workers z_bl_hours_open z_win_bl_k_stock z_win_bl_k_invest z_win_bl_stock_value ///
	z_bl_big_invest)
	label var bl_avg_z_hyp_b1 "Average Z-score for outcomes in Hypothesis B1 for bl"
	gen bl_avg_z_hyp_b1_miss = (bl_avg_z_hyp_b1==.)

**********************************************************************************************************************************
*********************************** Part 3: Preparation of Business practices variables ******************************************
**********************************************************************************************************************************
replace fu4_p3q5b=. if fu4_p3q5b==99
	
foreach var in bl_q116 fu2_p4q24a fu2_p4q24b fu2_p4q24c  fu2_p4q24d fu2_p4q24e fu2_p4q24aa bl_q126a  bl_q126b bl_q126c  bl_q126d bl_q126e fu2_p4q24a  fu2_p4q24b  fu2_p4q24c  fu2_p4q24d ///
	fu2_p4q24e fu2_p4q24aa   bl_q126a  fu2_p4q22 fu2_p4q29b fu2_p4q29c fu4_p3q26 fu3_p4q25 fu2_p4q25 fu1_p4q17 fu1_p4q171  fu1_p4q172 fu1_p4q172 fu1_p4q173 fu1_p4q174 bl_q114a1  ///
	bl_q114a2  bl_q114a3   bl_q114a4  fu3_p4q26  fu4_p3q30 fu3_p4q29 bl_q118 fu4_p3q34 fu2_p4q26 fu2_p4q27 fu3_p4q32 fu2_p4q28  fu4_p3q21 fu4_p3q18  fu4_p3q19 fu4_p3q20a fu4_p3q21 ///
	fu2_p4q20  fu1_p4q15  fu4_p3q18  fu2_p4q17 fu1_p4q13  fu4_p3q20a  fu2_p4q19a   fu4_p3q24 fu4_p3q49  fu4_p3q24 fu3_p4q23  fu2_p4q23 fu4_p3q49  fu2_p4q41 fu4_p3q5d  fu4_p3q5e ///
	fu4_p3q5d  fu4_p3q5e   fu2_p4q48d fu1_p4q24e fu2_p4q29 {
	
	recode `var' (2=0)
	}

replace fu1_p4q13 =. if fu1_p4q13==98
replace fu3_p4q26 =. if fu3_p4q26==-9
	
replace fu3_p4q29=0 if fu3_p4q29==-6
replace fu3_p4q23=0 if fu3_p4q23==-6
replace fu2_p4q22=0 if fu2_p4q22==3
replace fu2_p4q29=0 if fu2_p4q29==98
replace bl_q116=0 if bl_q116==98
replace fu3_p4q32=0 if fu3_p4q32==-9
replace fu2_p4q28=0 if fu2_p4q28==98
replace fu4_p3q24=0 if fu4_p3q24==-6
replace fu2_p4q23=0 if fu2_p4q23==3


**********************************************
** Marketing and customer service practices **
**********************************************

** Asks customers what products/services they would like to see **
codebook fu4_p3q17b
gen fu4_asks_customers = (fu4_p3q17b >= 2)
	replace fu4_asks_customers = . if fu4_p3q17b ==.
	label var fu4_asks_customers "Asks customers what products or services they would like to see at fu4"
codebook fu3_p4q16b
gen fu3_asks_customers = (fu3_p4q16b >= 2)
	replace fu3_asks_customers = . if fu3_p4q16b ==.
	label var fu3_asks_customers "Asks customers what products or services they would like to see at fu3"
codebook fu2_p4q16b
gen fu2_asks_customers = (fu2_p4q16b >= 2) 
	replace fu2_asks_customers  = . if fu2_p4q16b==.
	label var fu2_asks_customers "Asks customers what products or services they would like to see at fu2"
codebook fu1_p4q12b	
gen fu1_asks_customers = (fu1_p4q12b >=2)
	replace fu1_asks_customers  = . if fu1_p4q12b==.
	label var fu1_asks_customers "Asks customers what products or services they would like to see at fu1"
codebook bl_q120b
gen bl_asks_customers = (bl_q120b >=2)
	replace bl_asks_customers  = . if bl_q120b==.
	label var bl_asks_customers "Asks customers what products or services they would like to see at bl"

** Ask customers if they are satisifed with product/services **	
codebook fu4_p3q17s fu3_p4q16s fu2_p4q16c fu1_p4q12c
gen fu4_asks_satisfaction = (fu4_p3q17s >= 2)
	replace fu4_asks_satisfaction = . if fu4_p3q17s ==.
	label var fu4_asks_satisfaction "Ask customers if they are satisfied with products/services at fu4"

gen fu3_asks_satisfaction = (fu3_p4q16s >= 2)
	replace fu3_asks_satisfaction = . if fu3_p4q16s ==.
	label var fu3_asks_satisfaction "Ask customers if they are satisfied with products/services at fu3"

gen fu2_asks_satisfaction = (fu2_p4q16c >= 2)
	replace fu2_asks_satisfaction = . if fu2_p4q16c ==.
	label var fu2_asks_satisfaction "Ask customers if they are satisfied with products/services at fu2"

gen fu1_asks_satisfaction = (fu1_p4q12c >= 2)
	replace fu1_asks_satisfaction = . if fu1_p4q12c ==.
	label var fu1_asks_satisfaction "Ask customers if they are satisfied with products/services at fu1"

** Offers promotions **
codebook fu4_p3q17e fu3_p4q16e fu2_p4q16f fu1_p4q12f bl_q120e
gen fu4_offers_promotions = (fu4_p3q17e >= 2)
	replace fu4_offers_promotions = . if fu4_p3q17e ==.
	label var fu4_offers_promotions "Offers promotions to attract clients at fu4"

gen fu3_offers_promotions = (fu3_p4q16e >= 2)
	replace fu3_offers_promotions = . if fu3_p4q16e ==.
	label var fu3_offers_promotions "Offers promotions to attract clients at fu3"

gen fu2_offers_promotions = (fu2_p4q16f >= 2)
	replace fu2_offers_promotions = . if fu2_p4q16f ==.
	label var fu2_offers_promotions "Offers promotions to attract clients at fu2"

gen fu1_offers_promotions = (fu1_p4q12f >= 2)
	replace fu1_offers_promotions = . if fu1_p4q12f ==.
	label var fu1_offers_promotions "Offers promotions to attract clients at fu1"
	
gen bl_offers_promotions = (bl_q120e >= 2)
	replace bl_offers_promotions = . if bl_q120e ==.
	label var bl_offers_promotions "Offers promotions to attract clients at bl"

** Changes presentation to make them more attractive ** 
codebook fu4_p3q17r fu3_p4q16r fu2_p4q16s fu1_p4q12s
gen fu4_changes_presentation = (fu4_p3q17r >=2)
	replace fu4_changes_presentation = . if fu4_p3q17r ==.
	label var fu4_changes_presentation "Changes presentation of products or services to make them more attractive" 

gen fu3_changes_presentation = (fu3_p4q16r >=2)
	replace fu3_changes_presentation = . if fu3_p4q16r ==.
	label var fu3_changes_presentation "Changes presentation of products or services to make them more attractive" 

gen fu2_changes_presentation = (fu2_p4q16s >=2)
	replace fu2_changes_presentation = . if fu2_p4q16s ==.
	label var fu2_changes_presentation "Changes presentation of products or services to make them more attractive" 

gen fu1_changes_presentation = (fu1_p4q12s >=2)
	replace fu1_changes_presentation = . if fu1_p4q12s ==.
	label var fu1_changes_presentation "Changes presentation of products or services to make them more attractive" 

** Used at least one form of publicity **
ds fu4_p3q25*
codebook `r(varlist)'
replace fu4_p3q25aa=0 if fu4_p3q25aa==2
gen fu4_one_publicity = (fu4_p3q25a==1 | fu4_p3q25b==1 | fu4_p3q25c==1 | fu4_p3q25d==1 | fu4_p3q25e==1 | fu4_p3q25aa==1)
	replace fu4_one_publicity = . if fu4_p3q25a==. & fu4_p3q25b==. & fu4_p3q25c==. & fu4_p3q25d==. & fu4_p3q25e==. & fu4_p3q25aa==.
	label var fu4_one_publicity "Used at least one form of publicity at fu4"

ds fu3_p4q24*
codebook `r(varlist)'
gen fu3_one_publicity = (fu3_p4q24a==1 | fu3_p4q24b==1 | fu3_p4q24c==1 | fu3_p4q24d==1 | fu3_p4q24e==1 | fu3_p4q24aa==1)
	replace fu3_one_publicity =. if fu3_p4q24a==. & fu3_p4q24b==. & fu3_p4q24c==. & fu3_p4q24d==. & fu3_p4q24e==.& fu3_p4q24aa==.
	label var fu3_one_publicity "Used at least one form of publicity at fu3"	

ds fu2_p4q24*
codebook `r(varlist)'	
gen fu2_one_publicity =(fu2_p4q24a==1 | fu2_p4q24b==1 | fu2_p4q24c==1 | fu2_p4q24d==1 | fu2_p4q24e==1 | fu2_p4q24aa==1)
	replace fu2_one_publicity=. if fu2_p4q24a==.& fu2_p4q24b==.&fu2_p4q24c==.&fu2_p4q24d==.&fu2_p4q24e==. & fu2_p4q24aa==.
	label var fu2_one_publicity "Used at least one form of publicity at fu2"

ds bl_q126*
codebook `r(varlist)'	
gen bl_one_publicity =(bl_q126a==1 | bl_q126b==1 | bl_q126c==1 | bl_q126d==1 | bl_q126e==1)
	replace bl_one_publicity=. if (bl_q126a==.& bl_q126b==.& bl_q126c==.& bl_q126d==.& bl_q126e==.)
	label var bl_one_publicity "Used at least one form of publicity at bl"

** Used at least two forms of publicity **

egen a = rsum(fu4_p3q25a fu4_p3q25b fu4_p3q25c fu4_p3q25d fu4_p3q25e fu4_p3q25aa)
gen fu4_two_publicity = (a >= 2)
	replace fu4_two_publicity = . if fu4_p3q25a==. & fu4_p3q25b==. & fu4_p3q25c==. & fu4_p3q25d==. & fu4_p3q25e==. & fu4_p3q25aa==.
	label var fu4_two_publicity "Used at least 2 forms of publicity at fu4" 
	
egen b = rsum(fu3_p4q24a fu3_p4q24b fu3_p4q24c fu3_p4q24d fu3_p4q24e fu3_p4q24aa)
gen fu3_two_publicity = (b >= 2)
	replace fu3_two_publicity =. if fu3_p4q24a==.& fu3_p4q24b==.& fu3_p4q24c==. & fu3_p4q24d==. & fu3_p4q24e==. & fu3_p4q24aa==.
	label var fu3_two_publicity "Used at least 2 form of publicity at fu3"	

egen c = rsum(fu2_p4q24a fu2_p4q24b fu2_p4q24c fu2_p4q24d fu2_p4q24e fu2_p4q24aa)
gen fu2_two_publicity = (c >= 2) 
	replace fu2_two_publicity =. if fu2_p4q24a==.& fu2_p4q24b==.& fu2_p4q24c==.& fu2_p4q24d==.& fu2_p4q24e==.& fu2_p4q24aa==.
	label var fu2_two_publicity "Used at least 2 form of publicity at fu2"

egen d = rsum(bl_q126a bl_q126b bl_q126c bl_q126d bl_q126e)
gen bl_two_publicity = (d >= 2) 
	replace bl_two_publicity=. if bl_q126a==.& bl_q126b==.& bl_q126c==.& bl_q126d==.& bl_q126e==.
	label var bl_two_publicity "Used at least 2 forms of publicity at bl"
	drop a b c d

** Asked customers why they havent returned **
codebook fu4_p3q23 fu3_p4q22 fu2_p4q22
replace fu4_p3q23=0 if fu4_p3q23==-6|fu4_p3q23==2
replace fu3_p4q22=0 if fu3_p4q22==3|fu3_p4q22==2
gen fu4_asks_notback = (fu4_p3q23== 1)
	replace fu4_asks_notback = . if fu4_p3q23==.
	label var fu4_asks_notback "Asked customers why they havent returned at fu4"
	
gen fu3_asks_notback = (fu3_p4q22==1)
	replace fu3_asks_notback =. if fu3_p4q22==.
	label var fu3_asks_notback "Asked customers why they haven't returned fu3"
		
gen fu2_asks_notback = (fu2_p4q22==1)
	replace fu2_asks_notback =. if fu2_p4q22==.|fu2_p4q22==99
	label var fu2_asks_notback "Asked customers why they haven't returned fu2"

************************************************************	
** Good record keeping and financial management practices **
************************************************************

** Keeps accounting books **
codebook fu4_p3q26 fu3_p4q25 fu2_p4q25 fu1_p4q17 bl_q114
	ren fu4_p3q26 fu4_keeps_acc_books
	ren fu3_p4q25 fu3_keeps_acc_books
	ren fu2_p4q25 fu2_keeps_acc_books
	ren fu1_p4q17 fu1_keeps_acc_books
	ren bl_q114 bl_keeps_acc_books

** Keeps all types of accounting books **
ds fu4_p3q26*
codebook `r(varlist)'
gen fu4_all_acc_books = (fu4_p3q261==1 & fu4_p3q262==1 & fu4_p3q263==1 & fu4_p3q264==1)
	replace fu4_all_acc_books = . if fu4_p3q261==. & fu4_p3q262==. & fu4_p3q263==. & fu4_p3q264==.
	replace fu4_all_acc_books = 0 if fu4_all_acc_books==. & fu4_keeps_acc_books==0
	label var fu4_all_acc_books "Keeps all types of accounting books" 

ds fu3_p4q25*
codebook `r(varlist)'
gen fu3_all_acc_books = (fu3_p4q251==1& fu3_p4q252==1 & fu3_p4q253==1 & fu3_p4q254==1)
	replace fu3_all_acc_books = . if fu3_p4q251==.& fu3_p4q252==.& fu3_p4q253==.& fu3_p4q254==.
	replace fu3_all_acc_books = 0 if fu3_all_acc_books==. & fu3_keeps_acc_books==0
	label var fu3_all_acc_books "Keeps all types of accounting books" 

ds fu1_p4q17*
codebook `r(varlist)'	
gen fu1_all_acc_books = (fu1_p4q171==1&fu1_p4q172==1&fu1_p4q173==1&fu1_p4q174==1)
	replace fu1_all_acc_books =. if fu1_p4q171==.& fu1_p4q172==.& fu1_p4q173==.& fu1_p4q174==.
	replace fu1_all_acc_books = 0 if fu1_all_acc_books==. & fu1_keeps_acc_books==0
	label var fu1_all_acc_books "Keeps all accounting books in fu1"

ds bl_q114a*
codebook `r(varlist)'	
gen bl_all_acc_books =(bl_q114a1==1& bl_q114a2==1& bl_q114a3==1& bl_q114a4==1)
	replace bl_all_acc_books =. if bl_keeps_acc_books==.& bl_q114a1==.& bl_q114a2==.& bl_q114a3==.& bl_q114a4==.
	label var bl_all_acc_books "Keeps all accounting books in bl"

** Has a written budget **	
codebook fu4_p3q27 fu3_p4q26 fu2_p4q29 bl_q116
replace fu4_p3q27=0 if fu4_p3q27==-9
gen fu4_written_budget = (fu4_p3q27==1)
	replace fu4_written_budget = . if fu4_p3q27==.
	label var fu4_written_budget "Has a written budget at fu4"

gen fu3_written_budget = (fu3_p4q26==1)
	replace fu3_written_budget = . if fu3_p4q26==.
	label var fu3_written_budget "Has a written budget at fu3"

gen fu2_written_budget = (fu2_p4q29==1)
	replace fu2_written_budget = . if fu2_p4q29==.
	label var fu2_written_budget "Has a written budget at fu2"

gen bl_written_budget = (bl_q116==1)
	replace bl_q116 =. if bl_q116==.
	label var bl_q116 "Has a written budget at bl"

** Has a budget that shows a monthly balance **
codebook fu4_p3q27b fu3_p4q26b fu2_p4q29b
gen fu4_budget_monthly = (fu4_p3q27b==1)
	replace fu4_budget_monthly = . if fu4_p3q27b==.
	replace fu4_budget_monthly = 0 if fu4_budget_monthly==. & fu4_written_budget==0
	label var fu4_budget_monthly "Has a budget that shows monthly expenses at fu4"

gen fu3_budget_monthly = (fu3_p4q26b==1)
	replace fu3_budget_monthly = . if fu3_p4q26b==.
	replace fu3_budget_monthly = 0 if fu3_budget_monthly==. & fu3_written_budget==0
	label var fu3_budget_monthly "Has a budget that shows monthly expenses at fu3"
	
gen fu2_budget_monthly = (fu2_p4q29b==1)
	replace fu2_budget_monthly = . if fu2_p4q29b==.
	replace fu2_budget_monthly = 0 if fu2_budget_monthly==. & fu2_written_budget==0
	label var fu2_budget_monthly "Has a budget that shows monthly expenses at fu2"
	
** Has a budget that shows yearly expenses **
codebook fu4_p3q27c fu3_p4q26c fu2_p4q29c
gen fu4_budget_yearly = (fu4_p3q27c==1)
	replace fu4_budget_yearly = . if fu4_p3q27c==.
	replace fu4_budget_yearly = 0 if fu4_budget_yearly==. & fu4_written_budget==0
	label var fu4_budget_yearly "Has a budget that shows yearly expenses at fu4"

gen fu3_budget_yearly = (fu3_p4q26c==1)
	replace fu3_budget_yearly = . if fu3_p4q26c==.
	replace fu3_budget_yearly = 0 if fu3_budget_yearly==. & fu3_written_budget==0
	label var fu3_budget_yearly "Has a budget that shows yearly expenses at fu3"

gen fu2_budget_yearly = (fu2_p4q29c==1)
	replace fu2_budget_yearly = . if fu2_p4q29c==.
	replace fu2_budget_yearly = 0 if fu2_budget_yearly==. & fu2_written_budget==0
	label var fu2_budget_yearly "Has a budget that shows yearly expenses at fu2"

** Gives receipts to customers systematically **
codebook fu4_p3q29 fu3_p4q28 bl_q117
gen fu4_receipts_system = (fu4_p3q29==1)
	replace fu4_receipts_system = . if fu4_p3q29==.
	label var fu4_receipts_system "Gives receipts to customers systematically"

gen fu3_receipts_system = (fu3_p4q28==1)
	replace fu3_receipts_system = . if fu3_p4q28==.
	label var fu3_receipts_system "Gives receipts to customers systematically"
	
gen bl_receipts_system = (bl_q117==1)
	replace bl_receipts_system = . if bl_q117==.
	label var bl_receipts_system "Gives receipts to customers systematically"

** Keeps receipts from suppliers **
codebook fu4_p3q30 fu3_p4q29 bl_q118
replace fu4_p3q30=0 if fu4_p3q30==-6
gen fu4_keeps_receipts = (fu4_p3q30==1)
	replace fu4_keeps_receipts = . if fu4_p3q30==.
	label var fu4_keeps_receipts "Keeps receipts from suppliers"

gen fu3_keeps_receipts = (fu3_p4q29==1)
	replace fu3_keeps_receipts = . if fu3_p4q29==.
	label var fu3_keeps_receipts "Keeps receipts from suppliers"
	
gen bl_keeps_receipts = (bl_q118==1)
	replace bl_keeps_receipts = . if bl_q118==.
	label var bl_keeps_receipts "Keeps receipts from suppliers"

** Has a business account **	
codebook fu4_p3q41a fu3_p4q46 bl_q101a fu2_p4q37a
gen fu4_has_buss_bank = (fu4_p3q41a==1 | fu4_p3q41a==3)
	replace fu4_has_buss_bank = . if fu4_p3q41==. & fu4_p3q41a==.
	replace fu4_has_buss_bank = 0 if fu4_p3q41==2|fu4_p3q41==0
	label var fu4_has_buss_bank "Has business bank account at fu4"

gen fu3_has_buss_bank=(fu3_p4q46==1 & (fu3_p4q46a==1|fu3_p4q46a==3))
	replace fu3_has_buss_bank=. if fu3_p4q46==.&fu3_p4q46a==.
	replace fu3_has_buss_bank=0 if fu3_p4q46==2|fu3_p4q46==0
	label var fu3_has_buss_bank "Has business bank account at fu3"
gen bl_has_buss_bank=(bl_q101a==1|bl_q101a==3)
	replace bl_has_buss_bank=. if bl_q101==.&bl_q101a==.
	replace bl_has_buss_bank=0 if bl_q101==2|bl_q101==0
	label var bl_has_buss_bank "Has business bank account at bl"
	gen bl_has_buss_bank_miss = (bl_has_buss_bank==.)
gen fu2_has_buss_bank=(fu2_p4q37a==1|fu2_p4q37a==3)
	replace fu2_has_buss_bank=. if fu2_p4q37==.&fu2_p4q37a==.
	replace fu2_has_buss_bank=0 if fu2_p4q37==2|fu2_p4q37==0
	label var fu2_has_buss_bank "Has business bank account at fu2"

** Pays self a fixed salary **	
codebook fu4_p3q34 fu3_p4q44 bl_q89
ren fu4_p3q34 fu4_self_salary
ren fu3_p4q44 fu3_self_salary
ren bl_q89 bl_self_salary
	
** Does not mixed personal and business money **
codebook fu4_p3q28 fu3_p4q27 fu2_p4q30 fu1_p4q20 bl_q187
ren fu4_p3q28 fu4_no_mix_money 
	recode fu4_no_mix_money (0 2=1) (1=0)
	label var fu4_no_mix_money "Does not mix business and personal money, 1=does not mix, 0=mix"

ren fu3_p4q27 fu3_no_mix_money
	recode fu3_no_mix_money (0 2=1) (1=0)
	label var fu3_no_mix_money "Does not mix business and personal money, 1=does not mix, 0=mix"

ren fu2_p4q30 fu2_no_mix_money
	recode fu2_no_mix_money (0 2=1) (1=0)
	label var fu2_no_mix_money "Does not mix business and personal money, 1=does not mix, 0=mix"

ren fu1_p4q20 fu1_no_mix_money
	recode fu1_no_mix_money (0 2=1) (1=0)
	label var fu1_no_mix_money "Does not mix business and personal money, 1=does not mix, 0=mix"
	
ren bl_q187 bl_no_mix_money
	recode bl_no_mix_money (0 2=1) (1=0)
	label var bl_no_mix_money "Does not mix business and personal money, 1=does not mix, 0=mix"
	
** Registers all sales and purchases **
codebook fu4_p3q31 fu3_p4q30 fu2_p4q26
	ren fu4_p3q31 fu4_registers_all
	ren fu3_p4q30 fu3_registers_all
	ren fu2_p4q26 fu2_registers_all
	replace fu2_registers_all=0 if fu2_keeps_acc_books==0

** Able to see accounting books to check balance **
codebook fu4_p3q32 fu3_p4q31 fu2_p4q27
ren fu4_p3q32 fu4_money_acc 
	replace fu4_money_acc = 0 if fu4_money_acc==. & fu4_keeps_acc_books==0 & fu4_written_budget==0 & fu4_registers_all==0
	
ren fu3_p4q31 fu3_money_acc 
	replace fu3_money_acc = 0 if fu3_money_acc==. & fu3_keeps_acc_books==0 & fu3_written_budget==0 & fu3_registers_all==0

ren fu2_p4q27 fu2_money_acc
	replace fu2_money_acc = 0 if fu2_money_acc==. & fu2_keeps_acc_books==0 
	replace fu2_money_acc = 0 if fu2_money_acc==. & fu2_has_business==0

** Able to prove has money for paying a loan **
codebook fu4_p3q33 fu3_p4q32 
replace fu4_p3q33=0 if fu4_p3q33==-9
gen fu4_solvable_bank = (fu4_p3q33==1)
	replace fu4_solvable_bank = . if fu4_p3q33==.
	replace fu4_solvable_bank = 0 if fu4_solvable_bank==. & fu4_keeps_acc_books==0 & fu4_written_budget==0 & fu4_registers_all==0
	label var fu4_solvable_bank "Can prove solvable to a bank at fu4"

gen fu3_solvable_bank = (fu3_p4q32==1)
	replace fu3_solvable_bank = . if fu3_p4q32==.
	replace fu3_solvable_bank = 0 if fu3_solvable_bank==. & fu3_keeps_acc_books==0 & fu3_written_budget==0 & fu3_registers_all==0
	label var fu3_solvable_bank "Can prove solvable to a bank at fu3"

gen fu2_solvable_bank = (fu2_p4q28==1)
	replace fu2_solvable_bank = . if fu2_p4q28==.
	replace fu2_solvable_bank=0 if fu2_keeps_acc_books==0
	label var fu2_solvable_bank "Can prove solvable to a bank at fu2"

	foreach var in fu3_receipts_system fu3_keeps_receipts fu3_self_salary fu3_money_acc {
		replace `var' = 0 if `var'==. & fu3_has_business==0
		}

*****************************************************	
** Operations and performance management practices **
*****************************************************

** Sets sales objectives **
ren fu4_p3q21 fu4_sales_objectives
ren fu3_p4q20 fu3_sales_objectives
ren fu2_p4q20 fu2_sales_objectives
ren fu1_p4q15 fu1_sales_objectives
ren bl_q121 bl_sales_objectives

** Compares real sales to objectives **
codebook fu4_p3q22 fu3_p4q21 fu2_p4q21 fu1_p4q16 bl_q122
gen fu4_real_vs_objectives = (fu4_p3q22 >=2)
	replace fu4_real_vs_objectives = . if fu4_sales_objectives ==. & fu4_p3q22==.
	replace fu4_real_vs_objectives = 0 if fu4_sales_objectives==0
	label var fu4_real_vs_objectives "Compares real sales with objectives at fu4"
	
gen fu3_real_vs_objectives = (fu3_p4q21 >=2)
	replace fu3_real_vs_objectives = . if fu3_sales_objectives ==. & fu3_p4q21==.
	replace fu3_real_vs_objectives=0 if fu3_sales_objectives==0
	label var fu3_real_vs_objectives "Compares real sales with objectives at fu3"
	
gen fu2_real_vs_objectives = (fu2_p4q21 >=2)
	replace fu2_real_vs_objectives = . if fu2_sales_objectives ==. & fu2_p4q21==.
	replace fu2_real_vs_objectives=0 if fu2_sales_objectives==0
	label var fu2_real_vs_objectives "Compares real sales with objectives at fu2"
	
gen fu1_real_vs_objectives = (fu1_p4q16 >=2)
	replace fu1_real_vs_objectives = . if fu1_sales_objectives ==. & fu1_p4q16==.
	replace fu1_real_vs_objectives =0 if fu1_sales_objectives==0
	label var fu1_real_vs_objectives "Compares real sales with objectives at fu1"

gen bl_real_vs_objectives = (bl_q122 >=2)
	replace bl_real_vs_objectives = . if bl_sales_objectives ==. & bl_q122==.
	replace bl_real_vs_objectives=0 if bl_sales_objectives==0
	label var bl_real_vs_objectives "Compares real sales with objectives at BL"
	
** Negotiate with suppliers for better price **
codebook fu4_p3q17g fu3_p4q16g fu2_p4q16h fu1_p4q12h bl_q120g
gen fu4_negotiate_suppliers = (fu4_p3q17g >= 2)
	replace fu4_negotiate_suppliers = . if fu4_p3q17g == .
	label var fu4_negotiate_suppliers "Negotiates with suppliers to get a better price at fu4"
	
gen fu3_negotiate_suppliers = (fu3_p4q16g >=2)
	replace fu3_negotiate_suppliers = . if fu3_p4q16g == .
	label var fu3_negotiate_suppliers "Negotiates with suppliers to get a better price at fu3"

gen fu2_negotiate_suppliers = (fu2_p4q16h >=2)
	replace fu2_negotiate_suppliers = . if fu2_p4q16h == .
	label var fu2_negotiate_suppliers "Negotiates with suppliers to get a better price at fu2"

gen fu1_negotiate_suppliers = (fu1_p4q12h>=2)
	replace fu1_negotiate_suppliers = . if fu1_p4q12h == .
	label var fu1_negotiate_suppliers "Negotiates with suppliers to get a better price at fu1"

gen bl_negotiate_suppliers = (bl_q120g>=2)
	replace bl_negotiate_suppliers = . if bl_q120g == .
	label var bl_negotiate_suppliers "Negotiates with suppliers to get a better price at BL"

** Does not have insufficient stock **
codebook fu4_p3q17i fu3_p4q16i fu2_p4q16j fu1_p4q12j bl_q120i
gen fu4_sufficient_stock = (fu4_p3q17i==1)
	replace fu4_sufficient_stock = . if fu4_p3q17i ==.
	label var fu4_sufficient_stock "Always has sufficient stock"
	
gen fu3_sufficient_stock = (fu3_p4q16i==1)
	replace fu3_sufficient_stock = . if fu3_p4q16i ==.
	label var fu3_sufficient_stock "Always has sufficient stock"

gen fu2_sufficient_stock = (fu2_p4q16j==1)
	replace fu2_sufficient_stock = . if fu2_p4q16j ==.
	label var fu2_sufficient_stock "Always has sufficient stock"

gen fu1_sufficient_stock = (fu1_p4q12j==1)
	replace fu1_sufficient_stock = . if fu1_p4q12j ==.
	label var fu1_sufficient_stock "Always has sufficient stock"

gen bl_sufficient_stock = (bl_q120i==1)
	replace bl_sufficient_stock = . if bl_q120i ==.
	label var bl_sufficient_stock "Always has sufficient stock"
	
** Takes inventory stock **
codebook fu4_p3q17j fu3_p4q16j fu2_p4q16k fu1_p4q12k bl_q120j
gen fu4_inventory_stock = (fu4_p3q17j >=2)
	replace fu4_inventory_stock = . if fu4_p3q17j==.
	label var fu4_inventory_stock "Takes inventory of stock"

gen fu3_inventory_stock = (fu3_p4q16j >=2)
	replace fu3_inventory_stock = . if fu3_p4q16j==.
	label var fu3_inventory_stock "Takes inventory of stock"

gen fu2_inventory_stock = (fu2_p4q16k >=2)
	replace fu2_inventory_stock = . if fu2_p4q16k==.
	label var fu2_inventory_stock "Takes inventory of stock"

gen fu1_inventory_stock = (fu1_p4q12k >=2)
	replace fu1_inventory_stock = . if fu1_p4q12k==.
	label var fu1_inventory_stock "Takes inventory of stock"

gen bl_inventory_stock = (bl_q120j >=2)
	replace bl_inventory_stock = . if bl_q120j==.
	label var bl_inventory_stock "Takes inventory of stock"
	
** Analyzes trend sales **
codebook fu4_p3q17k fu3_p4q16k fu2_p4q16l fu1_p4q12l bl_q120k
gen fu4_analyzes_trends = (fu4_p3q17k >=2)
	replace fu4_analyzes_trends = . if fu4_p3q17k==.
	label var fu4_analyzes_trends "Analyzes sales trends"

gen fu3_analyzes_trends = (fu3_p4q16k >=2)
	replace fu3_analyzes_trends = . if fu3_p4q16k==.
	label var fu3_analyzes_trends "Analyzes sales trends"

gen fu2_analyzes_trends = (fu2_p4q16l >=2)
	replace fu2_analyzes_trends = . if fu2_p4q16l==.
	label var fu2_analyzes_trends "Analyzes sales trends"

gen fu1_analyzes_trends = (fu1_p4q12l >=2)
	replace fu1_analyzes_trends = . if fu1_p4q12l==.
	label var fu1_analyzes_trends "Analyzes sales trends"

gen bl_analyzes_trends = (bl_q120k >=2)
	replace bl_analyzes_trends = . if bl_q120k==.
	label var bl_analyzes_trends "Analyzes sales trends"
	
** Analyzes performance **	
codebook fu4_p3q17l fu3_p4q16l fu2_p4q16m fu1_p4q12m bl_q120l
gen fu4_analyzes_performance = (fu4_p3q17l >=2)
	replace fu4_analyzes_performance = . if fu4_p3q17l==.
	label var fu4_analyzes_performance "Analyzes firm performance"

gen fu3_analyzes_performance = (fu3_p4q16l >=2)
	replace fu3_analyzes_performance = . if fu3_p4q16l==.
	label var fu3_analyzes_performance "Analyzes firm performance"

gen fu2_analyzes_performance = (fu2_p4q16m >=2)
	replace fu2_analyzes_performance = . if fu2_p4q16m==.
	label var fu2_analyzes_performance "Analyzes firm performance"

gen fu1_analyzes_performance = (fu1_p4q12m >=2)
	replace fu1_analyzes_performance = . if fu1_p4q12m==.
	label var fu1_analyzes_performance "Analyzes firm performance"

gen bl_analyzes_performance = (bl_q120l >=2)
	replace bl_analyzes_performance = . if bl_q120l==.
	label var bl_analyzes_performance "Analyzes firm performance"

** Calculates costs **
ren fu4_p3q18 fu4_calculates_costs 
ren fu3_p4q17 fu3_calculates_costs
ren fu2_p4q17 fu2_calculates_costs
ren fu1_p4q13 fu1_calculates_costs
	
** Calculates benefit **
ren fu4_p3q19 fu4_calculates_benefit
ren fu3_p4q18 fu3_calculates_benefit
ren fu2_p4q18 fu2_calculates_benefit
ren fu1_p4q14 fu1_calculates_benefit

** Knows product contributes most to profits **
ren fu4_p3q20a fu4_knows_most_profit
ren fu3_p4q19a fu3_knows_most_profit
ren fu2_p4q19a fu2_knows_most_profit

*********************************************
** Seeks information and new opportunities **
*********************************************

** Visits competitors to know price/products **
codebook fu4_p3q17a fu3_p4q16aa fu3_p4q16a fu2_p4q16aa fu2_p4q16a fu1_p4q12a bl_q120a
gen fu4_visit_competitors = (fu4_p3q17a >=2)
	replace fu4_visit_competitors = . if fu4_p3q17a==.
	label var fu4_visit_competitors "Person visits competitors to know price"

gen fu3_visit_competitors = (fu3_p4q16aa >=2)
	replace fu3_visit_competitors = . if fu3_p4q16aa==.
	replace fu3_visit_competitors = 1 if fu3_p4q16a>=2&fu3_p4q16a!=.
	label var fu3_visit_competitors "Person visits competitors to know price"

gen fu2_visit_competitors = (fu2_p4q16aa >=2)
	replace fu2_visit_competitors = . if fu2_p4q16aa==.
	replace fu2_visit_competitors = 1 if fu2_p4q16a>=2&fu2_p4q16a!=.
	label var fu2_visit_competitors "Person visits competitors to know price"

gen fu1_visit_competitors = (fu1_p4q12a >=2)
	replace fu1_visit_competitors = . if fu1_p4q12a==.
	label var fu1_visit_competitors "Person visits competitors to know price"

gen bl_visit_competitors = (bl_q120a >=2)
	replace bl_visit_competitors = . if bl_q120a==.
	label var bl_visit_competitors "Person visits competitors to know price"

** Evaluates the need in the market for products/ services **
codebook fu4_p3q17c fu3_p4q16c fu2_p4q16d fu1_p4q12d bl_q120c
gen fu4_evaluates_need = (fu4_p3q17c >=2)
	replace fu4_evaluates_need = . if fu4_p3q17c==.
	label var fu4_evaluates_need "Evaluates the need in the market for their products or services"

gen fu3_evaluates_need = (fu3_p4q16c >=2)
	replace fu3_evaluates_need = . if fu3_p4q16c==.
	label var fu3_evaluates_need "Evaluates the need in the market for their products or services"
	
gen fu2_evaluates_need = (fu2_p4q16d >=2)
	replace fu2_evaluates_need = . if fu2_p4q16d==.
	label var fu2_evaluates_need "Evaluates the need in the market for their products or services"
	
gen fu1_evaluates_need = (fu1_p4q12d >=2)
	replace fu1_evaluates_need = . if fu1_p4q12d==.
	label var fu1_evaluates_need "Evaluates the need in the market for their products or services"

gen bl_evaluates_need = (bl_q120c >=2)
	replace bl_evaluates_need = . if bl_q120c==.
	label var bl_evaluates_need "Evaluates the need in the market for their products or services"
	
**Seeks new markets **
codebook fu4_p3q17d fu3_p4q16d fu2_p4q16e fu1_p4q12e bl_q120d
gen fu4_new_market = (fu4_p3q17d >=2)
	replace fu4_new_market = . if fu4_p3q17d==.
	label var fu4_new_market "Seeks new markets"

gen fu3_new_market = (fu3_p4q16d >=2)
	replace fu3_new_market = . if fu3_p4q16d==.
	label var fu3_new_market "Seeks new markets"

gen fu2_new_market = (fu2_p4q16e >=2)
	replace fu2_new_market = . if fu2_p4q16e==.
	label var fu2_new_market "Seeks new markets"

gen fu1_new_market = (fu1_p4q12e >=2)
	replace fu1_new_market = . if fu1_p4q12e==.
	label var fu1_new_market "Seeks new markets"

gen bl_new_market = (bl_q120d >=2)
	replace bl_new_market = . if bl_q120d ==.
	label var bl_new_market "Seeks new markets"
	
** Indentifies potential new customers **	
codebook fu4_p3q17f fu3_p4q16f fu2_p4q16g fu1_p4q12g bl_q120f
gen fu4_new_clients = (fu4_p3q17f >=2)
	replace fu4_new_clients = . if fu4_p3q17f==.
	label var fu4_new_clients "Identifies potential new customers, suppliers, competitors"

gen fu3_new_clients = (fu3_p4q16f >=2)
	replace fu3_new_clients = . if fu3_p4q16f==.
	label var fu3_new_clients "Identifies potential new customers, suppliers, competitors"

gen fu2_new_clients = (fu2_p4q16g >=2)
	replace fu2_new_clients = . if fu2_p4q16g==.
	label var fu2_new_clients "Identifies potential new customers, suppliers, competitors"

gen fu1_new_clients = (fu1_p4q12g >=2)
	replace fu1_new_clients = . if fu1_p4q12g==.
	label var fu1_new_clients "Identifies potential new customers, suppliers, competitors"

gen bl_new_clients = (bl_q120f >=2)
	replace bl_new_clients = . if bl_q120f==.
	label var bl_new_clients "Identifies potential new customers, suppliers, competitors"

** Compares prices or quality of suppliers **
codebook fu4_p3q17h fu3_p4q16h fu2_p4q16i fu1_p4q12i bl_q120h
gen fu4_compares_quality = (fu4_p3q17h >=2)
	replace fu4_compares_quality = . if fu4_p3q17h==.
	label var fu4_compares_quality "Compares prices or quality of suppliers"

gen fu3_compares_quality = (fu3_p4q16h >=2)
	replace fu3_compares_quality = . if fu3_p4q16h==.
	label var fu3_compares_quality "Compares prices or quality of suppliers"

gen fu2_compares_quality = (fu2_p4q16i >=2)
	replace fu2_compares_quality = . if fu2_p4q16i==.
	label var fu2_compares_quality "Compares prices or quality of suppliers"

gen fu1_compares_quality = (fu1_p4q12i >=2)
	replace fu1_compares_quality = . if fu1_p4q12i==.
	label var fu1_compares_quality "Compares prices or quality of suppliers"

gen bl_compares_quality = (bl_q120h >=2)
	replace bl_compares_quality = . if bl_q120h==.
	label var bl_compares_quality "Compares prices or quality of suppliers"

** Discusses business ideas with friends, consultants or other entrepreneurs **
codebook fu4_p3q17m fu3_p4q16m fu2_p4q16n fu1_p4q12n bl_q120m
gen fu4_discuss_ideas = (fu4_p3q17m >=2)
	replace fu4_discuss_ideas = . if fu4_p3q17m==.
	label var fu4_discuss_ideas "Discusses business ideas with friends, consultants or other entrepreneurs"

gen fu3_discuss_ideas = (fu3_p4q16m >=2)
	replace fu3_discuss_ideas = . if fu3_p4q16m==.
	label var fu3_discuss_ideas "Discusses business ideas with friends, consultants or other entrepreneurs"

gen fu2_discuss_ideas = (fu2_p4q16n >=2)
	replace fu2_discuss_ideas = . if fu2_p4q16n==.
	label var fu2_discuss_ideas "Discusses business ideas with friends, consultants or other entrepreneurs"

gen fu1_discuss_ideas = (fu1_p4q12n >=2)
	replace fu1_discuss_ideas = . if fu1_p4q12n==.
	label var fu1_discuss_ideas "Discusses business ideas with friends, consultants or other entrepreneurs"

gen bl_discuss_ideas  = (bl_q120m >=2)
	replace bl_discuss_ideas = . if bl_q120m==.
	label var bl_discuss_ideas "Discusses business ideas with friends, consultants or other entrepreneurs"
gen bl_discuss_ideas_miss = (bl_discuss_ideas==.)

** Seeks additional capital for the business **
codebook fu4_p3q17n fu3_p4q16n fu2_p4q16o fu1_p4q12o bl_q120n
gen fu4_more_capital = (fu4_p3q17n >=2)
	replace fu4_more_capital = . if fu4_p3q17n==.
	label var fu4_more_capital "Seeks additional capital for the business"

gen fu3_more_capital = (fu3_p4q16n >=2)
	replace fu3_more_capital = . if fu3_p4q16n==.
	label var fu3_more_capital "Seeks additional capital for the business"

gen fu2_more_capital = (fu2_p4q16o >=2)
	replace fu2_more_capital = . if fu2_p4q16o==.
	label var fu2_more_capital "Seeks additional capital for the business"

gen fu1_more_capital = (fu1_p4q12o >=2)
	replace fu1_more_capital = . if fu1_p4q12o==.
	label var fu1_more_capital "Seeks additional capital for the business"

gen bl_more_capital = (bl_q120n >=2)
	replace bl_more_capital = . if bl_q120n==.
	label var bl_more_capital "Seeks additional capital for the business"

** Uses internet, books, etc to learn new things in the sector **
codebook fu4_p3q17o fu3_p4q16o fu2_p4q16p fu1_p4q12p bl_q120o
gen fu4_read_sector = (fu4_p3q17o >=2)
	replace fu4_read_sector = . if fu4_p3q17o==.
	label var fu4_read_sector "Uses internet, books, magazines or newspapers to learn new things in the sector"

gen fu3_read_sector = (fu3_p4q16o >=2)
	replace fu3_read_sector = . if fu3_p4q16o==.
	label var fu3_read_sector "Uses internet, books, magazines or newspapers to learn new things in the sector"
	
gen fu2_read_sector = (fu2_p4q16p >=2)
	replace fu2_read_sector = . if fu2_p4q16p==.
	label var fu2_read_sector "Uses internet, books, magazines or newspapers to learn new things in the sector"

gen fu1_read_sector	 = (fu1_p4q12p >=2)
	replace fu1_read_sector = . if fu1_p4q12p==.
	label var fu1_read_sector "Uses internet, books, magazines or newspapers to learn new things in the sector"

gen bl_read_sector = (bl_q120o >=2)
	replace bl_read_sector = . if bl_q120o==.
	label var bl_read_sector "Uses internet, books, magazines or newspapers to learn new things in the sector"

** Discusses with other entrepreneurs in the sector **
codebook fu4_p3q17p fu3_p4q16p fu2_p4q16q fu1_p4q12q bl_q120p
gen fu4_discuss_entrep = (fu4_p3q17p >=2)
	replace fu4_discuss_entrep = . if fu4_p3q17p==.
	label var fu4_discuss_entrep "Discusses with other entrepreneurs in the sector"

gen fu3_discuss_entrep = (fu3_p4q16p >=2)
	replace fu3_discuss_entrep = . if fu3_p4q16p==.
	label var fu3_discuss_entrep "Discusses with other entrepreneurs in the sector"

gen fu2_discuss_entrep = (fu2_p4q16q >=2)
	replace fu2_discuss_entrep = . if fu2_p4q16q==.
	label var fu2_discuss_entrep "Discusses with other entrepreneurs in the sector"

gen fu1_discuss_entrep = (fu1_p4q12q >=2)
	replace fu1_discuss_entrep = . if fu1_p4q12q==.
	label var fu1_discuss_entrep "Discusses with other entrepreneurs in the sector"

gen bl_discuss_entrep = (bl_q120p >=2)
	replace bl_discuss_entrep = . if bl_q120p==.
	label var bl_discuss_entrep "Discusses with other entrepreneurs in the sector"
gen bl_discuss_entrep_miss = (bl_discuss_entrep==.)
		
** Seeks new production, marketing or admin techniques **
codebook fu4_p3q17q fu3_p4q16q fu2_p4q16r fu1_p4q12r bl_q120q
gen fu4_new_techniques = (fu4_p3q17q >=2)
	replace fu4_new_techniques = . if fu4_p3q17q==.
	label var fu4_new_techniques "Seeks new production, marketing or administrative techniques"

gen fu3_new_techniques = (fu3_p4q16q > 2)
	replace fu3_new_techniques = . if fu3_p4q16q==.
	label var fu3_new_techniques "Seeks new production, marketing or administrative techniques"

gen fu2_new_techniques = (fu2_p4q16r > 2)
	replace fu2_new_techniques = . if fu2_p4q16r==.
	label var fu2_new_techniques "Seeks new production, marketing or administrative techniques"

gen fu1_new_techniques = (fu1_p4q12r >=2)
	replace fu1_new_techniques= . if fu1_p4q12r==.
	label var fu1_new_techniques "Seeks new production, marketing or administrative techniques"
	
gen bl_new_techniques = (bl_q120q >=2)
	replace bl_new_techniques= . if bl_q120q==.
	label var bl_new_techniques "Seeks new production, marketing or administrative techniques"

** Asks suppliers what sells in sector **
codebook fu4_p3q24 fu3_p4q23 fu2_p4q23
gen fu4_sells_sector = (fu4_p3q24==1)
	replace fu4_sells_sector = . if fu4_p3q24==.
	label var fu4_sells_sector "Asks supplier what sells well in the sector"

gen fu3_sells_sector = (fu3_p4q23==1)
	replace fu3_sells_sector = . if fu3_p4q23==.
	label var fu3_sells_sector "Asks supplier what sells well in the sector"
	
gen fu2_sells_sector = (fu2_p4q23==1)
	replace fu2_sells_sector = . if fu2_p4q23==.
	label var fu2_sells_sector "Asks supplier what sells well in the sector"
	
** Meets with groups of entrepreneurs **
//integrate information for those who no longer have businesses
	codebook  fu2_p2q13 if fu2_p4q41==.
	codebook fu2_p4q41
	replace fu2_p4q41=fu2_p2q13 if fu2_p4q41==.
	
ren fu4_p3q49 fu4_meets_entrep
ren fu3_p4q55 fu3_meets_entrep
ren fu2_p4q41 fu2_meets_entrep


*****************************
** HR management practices **
*****************************


** Has written contracts wtih workers **
codebook fu4_p3q5b fu3_p4q4b fu2_p4q48b fu1_p4q24b
gen fu4_written_contract = (fu4_p3q5b>=1)
	replace fu4_written_contract = . if fu4_p3q5b==.
	replace fu4_written_contract=0 if fu4_no_workers==0
	label var fu4_written_contract "Has at least one worker with a written contract at fu4"	

gen fu3_written_contract = (fu3_p4q4b>=1)
	replace fu3_written_contract = . if fu3_p4q4b==.
	replace fu3_written_contract=0 if fu3_no_workers==0
	label var fu3_written_contract "Has at least one worker with a written contract"	

gen fu2_written_contract = (fu2_p4q48b>=1)
	replace fu2_written_contract = . if fu2_p4q48b==.
	replace fu2_written_contract=0 if fu2_no_workers==0
	label var fu2_written_contract "Has at least one worker with a written contract"	
	
gen fu1_written_contract = (fu1_p4q24b>=1)
	replace fu1_written_contract = . if fu1_p4q24b==.
	replace fu1_written_contract=0 if fu1_no_workers==0
	label var fu1_written_contract "Has at least one worker with a written contract"	
	
** Trained employees externally **
ren fu4_p3q5d fu4_training_external 
replace fu4_training_external=0 if fu4_training_external==. & fu4_no_workers==0
ren fu3_p4q4e fu3_training_external
replace fu3_training_external=0 if fu3_training_external==. & fu3_no_workers==0
ren fu2_p4q48c fu2_training_external
replace fu2_training_external=0 if fu2_training_external==. & fu2_no_workers==0
ren fu1_p4q24d fu1_training_external
replace fu1_training_external=0 if fu1_training_external==. & fu1_no_workers==0

** Provided traning internally to employees **
ren fu4_p3q5e fu4_training_internal
replace fu4_training_internal=0 if fu4_training_internal==. & fu4_no_workers==0
ren fu3_p4q4f fu3_training_internal
replace fu3_training_internal=0 if fu3_training_internal==. & fu3_no_workers==0
ren fu2_p4q48d fu2_training_internal
replace fu2_training_internal=0 if fu2_training_internal==. & fu2_no_workers==0
ren fu1_p4q24e fu1_training_internal
replace fu1_training_internal=0 if fu1_training_internal==. & fu1_no_workers==0

** Evaluated employee performance **
codebook fu4_p3q5f fu3_p4q4g fu2_p4q48e fu1_p4q24f
gen fu4_evaluates_employee = (fu4_p3q5f >=2)
	replace fu4_evaluates_employee = . if fu4_p3q5f==.
	replace fu4_evaluates_employee=0 if fu4_evaluates_employee==. & fu4_no_workers==0
	label var fu4_evaluates_employee "Evaluated employee performance" 

gen fu3_evaluates_employee = (fu3_p4q4g >=2)
	replace fu3_evaluates_employee = . if fu3_p4q4g==.
	replace fu3_evaluates_employee=0 if fu3_evaluates_employee==. & fu3_no_workers==0
	label var fu3_evaluates_employee "Evaluated employee performance" 

gen fu2_evaluates_employee  = (fu2_p4q48e >=2)
	replace fu2_evaluates_employee = . if fu2_p4q48e==.
	replace fu2_evaluates_employee=0 if fu2_evaluates_employee==. & fu2_no_workers==0
	label var fu2_evaluates_employee "Evaluated employee performance" 

gen fu1_evaluates_employee = (fu1_p4q24f >=2)
	replace fu1_evaluates_employee = . if fu1_p4q24f==.
	replace fu1_evaluates_employee=0 if fu1_evaluates_employee==. & fu1_no_workers==0
	label var fu1_evaluates_employee "Evaluated employee performance" 

** Provided feedback to employees **
codebook fu4_p3q5g fu3_p4q4h fu2_p4q48f fu1_p4q24g
gen fu4_provides_feedback =  (fu4_p3q5g >=2)
	replace fu4_provides_feedback = . if fu4_p3q5g==.
	replace fu4_provides_feedback=0 if  fu4_provides_feedback==. & fu4_no_workers==0
	label var fu4_provides_feedback "Provided feedback to employees"
 
gen fu3_provides_feedback = (fu3_p4q4h>=2)
	replace fu3_provides_feedback = . if fu3_p4q4h==.
	replace fu3_provides_feedback=0 if  fu3_provides_feedback==. & fu3_no_workers==0
	label var fu3_provides_feedback "Provided feedback to employees"
	
gen fu2_provides_feedback = (fu2_p4q48f >=2)
	replace fu2_provides_feedback = . if fu2_p4q48f==.
	replace fu2_provides_feedback=0 if  fu2_provides_feedback==. & fu2_no_workers==0
	label var fu2_provides_feedback "Provided feedback to employees"
	
gen fu1_provides_feedback = (fu1_p4q24g >=2)
	replace fu1_provides_feedback = . if fu1_p4q24g==.
	replace fu1_provides_feedback=0 if  fu1_provides_feedback==. & fu1_no_workers==0
	label var fu1_provides_feedback "Provided feedback to employees"

********************************
** Business practices indexes **
********************************

** Index for using good marketing and customer service practices **
forval i =2/4 {
egen fu`i'_marketing_index = rowmean(fu`i'_asks_customers fu`i'_asks_satisfaction fu`i'_offers_promotions fu`i'_changes_presentation ///
	fu`i'_one_publicity fu`i'_two_publicity fu`i'_asks_notback)
	replace fu`i'_marketing_index = . if fu`i'_asks_customers==. & fu`i'_asks_satisfaction==. & fu`i'_offers_promotions==. & ///
	fu`i'_changes_presentation==. & fu`i'_one_publicity==. & fu`i'_two_publicity==. & fu`i'_asks_notback==.
	label var fu`i'_marketing_index "Simple index of customer service and marketing practices fu`i'"
	}

egen fu1_marketing_index = rowmean(fu1_asks_customers fu1_asks_satisfaction fu1_offers_promotions fu1_changes_presentation)
	replace fu1_marketing_index = . if fu1_asks_customers==. & fu1_asks_satisfaction==. & fu1_offers_promotions==. & fu1_changes_presentation==.
	label var fu1_marketing_index "Simple index of customer service and marketing practices fu1"

egen bl_marketing_index = rowmean(bl_asks_customers bl_offers_promotions bl_one_publicity bl_two_publicity)
	replace bl_marketing_index = . if bl_one_publicity==. & bl_two_publicity==. & bl_asks_customers==. & bl_offers_promotions==.
	label var bl_marketing_index "Simple index of customer service and marketing practices bl"
	gen bl_marketing_index_miss = (bl_marketing_index==.)
	
** Index for good record keeping and financial management practices **
forval i= 3/4 {
egen fu`i'_record_index = rowmean(fu`i'_keeps_acc_books fu`i'_all_acc_books fu`i'_written_budget fu`i'_budget_monthly fu`i'_budget_yearly ///
	fu`i'_keeps_receipts fu`i'_receipts_system fu`i'_has_buss_bank fu`i'_no_mix_money fu`i'_registers_all fu`i'_money_acc fu`i'_solvable_bank fu`i'_self_salary)
	replace fu`i'_record_index=. if fu`i'_keeps_acc_books==.& fu`i'_all_acc_books==.& fu`i'_written_budget==.& fu`i'_budget_monthly==. & ///
	fu`i'_budget_yearly==.& fu`i'_has_buss_bank==.& fu`i'_no_mix_money==.& fu`i'_registers_all==.& fu`i'_money_acc==. & fu`i'_solvable_bank==. & ///
	fu`i'_keeps_receipts==. & fu`i'_receipts_system==. & fu`i'_self_salary==.
	label var fu`i'_record_index "Simple index of record keeping and financial management at fu`i'"
}
egen fu2_record_index = rowmean(fu2_keeps_acc_books fu2_written_budget fu2_budget_monthly fu2_budget_yearly ///
	fu2_has_buss_bank fu2_no_mix_money fu2_registers_all fu2_money_acc fu2_solvable_bank)
	replace fu2_record_index=. if fu2_keeps_acc_books==.& fu2_written_budget==.& fu2_budget_monthly==.& fu2_budget_yearly==.& ///
	fu2_has_buss_bank==.& fu2_no_mix_money==.& fu2_registers_all==.& fu2_money_acc==.& fu2_solvable_bank==.
	label var fu2_record_index "Simple index of record keeping and financial management at fu2"

egen fu1_record_index = rowmean(fu1_keeps_acc_books fu1_all_acc_books fu1_no_mix_money)
	replace fu1_record_index=. if fu1_keeps_acc_books==.&  fu1_all_acc_books==.&  fu1_no_mix_money==.
	label var fu1_record_index "Simple index of record keeping and financial management at fu1"

egen bl_record_index = rowmean(bl_keeps_acc_books bl_all_acc_books bl_written_budget bl_receipts_system bl_keeps_receipts bl_has_buss_bank bl_self_salary bl_no_mix_money)
	replace bl_record_index=. if bl_keeps_acc_books==.&bl_all_acc_books==.& bl_written_budget==.&bl_receipts_system==.&bl_keeps_receipts==.& bl_has_buss_bank==.& bl_self_salary==.&bl_no_mix_money==.
	label var bl_record_index "Simple index of record keeping and financial management at bl"
	gen bl_record_index_miss = (bl_record_index==.)
	
** Index for operations and performance management practices **
forval i= 2/4 {
egen fu`i'_operations_index= rowmean (fu`i'_sales_objectives fu`i'_real_vs_objectives fu`i'_negotiate_suppliers fu`i'_sufficient_stock fu`i'_inventory_stock ///
	fu`i'_analyzes_trends fu`i'_analyzes_performance fu`i'_calculates_costs fu`i'_calculates_benefit fu`i'_knows_most_profit fu`i'_calculates_costs)
	replace fu`i'_operations_index = . if fu`i'_sales_objectives==. & fu`i'_negotiate_suppliers==. & fu`i'_sufficient_stock==. & ///
	fu`i'_inventory_stock==. & fu`i'_analyzes_trends==. & fu`i'_analyzes_performance==. & fu`i'_calculates_costs==. & ///
	fu`i'_calculates_benefit==. & fu`i'_knows_most_profit==.&fu`i'_real_vs_objectives==.&fu`i'_calculates_costs==.
	label var fu`i'_operations_index "Simple index of operations and performance management practices at fu`i'"
}
egen fu1_operations_index= rowmean (fu1_sales_objectives fu1_real_vs_objectives fu1_negotiate_suppliers fu1_sufficient_stock fu1_inventory_stock ///
	fu1_analyzes_trends fu1_analyzes_performance fu1_calculates_costs fu1_calculates_benefit fu1_calculates_costs)
	replace fu1_operations_index = . if fu1_sales_objectives==. & fu1_negotiate_suppliers==. & fu1_sufficient_stock==. & ///
	fu1_inventory_stock==. & fu1_analyzes_trends==. & fu1_analyzes_performance==. & fu1_calculates_costs==. & ///
	fu1_calculates_benefit==.&fu1_real_vs_objectives==.&fu1_calculates_costs==.
	label var fu1_operations_index "Simple index of operations and performance management practices at fu1"

egen bl_operations_index = rowmean (bl_sales_objectives bl_real_vs_objectives bl_negotiate_suppliers bl_sufficient_stock bl_inventory_stock ///
	bl_analyzes_trends bl_analyzes_performance)
	replace bl_operations_index = . if bl_sales_objectives==. & bl_negotiate_suppliers==. & bl_sufficient_stock==. & ///
	bl_inventory_stock==. & bl_analyzes_trends==. & bl_analyzes_performance==.&bl_real_vs_objectives==.
	label var bl_operations_index "Simple index of operations and performance management practices at bl"
	gen bl_operations_index_miss = (bl_operations_index==.)

** Index for seeks information and new opportunities **
forval i= 2/4 {
egen fu`i'_information_index = rowmean(fu`i'_visit_competitors fu`i'_evaluates_need fu`i'_new_market fu`i'_new_clients ///
	fu`i'_compares_quality fu`i'_discuss_ideas fu`i'_more_capital fu`i'_read_sector fu`i'_discuss_entrep fu`i'_new_techniques ///
	fu`i'_sells_sector fu`i'_meets_entrep)
	replace fu`i'_information_index = . if fu`i'_visit_competitors==. & fu`i'_evaluates_need==. & fu`i'_new_market==. & ///
	fu`i'_new_clients==. & fu`i'_compares_quality==. & fu`i'_discuss_ideas==. & fu`i'_more_capital==. & fu`i'_read_sector==. & ///
	fu`i'_discuss_entrep==. & fu`i'_new_techniques==. & fu`i'_sells_sector==. & fu`i'_meets_entrep==.
	label var fu`i'_information_index "Simple index of seeking information and new opportunities at fu`i'"
}
egen fu1_information_index = rowmean(fu1_visit_competitors fu1_evaluates_need fu1_new_market fu1_new_clients ///
	fu1_compares_quality fu1_discuss_ideas fu1_more_capital fu1_read_sector fu1_discuss_entrep fu1_new_techniques)
	replace fu1_information_index = . if fu1_visit_competitors==. & fu1_evaluates_need==. & fu1_new_market==. & ///
	fu1_new_clients==. & fu1_compares_quality==. & fu1_discuss_ideas==. & fu1_more_capital==. & fu1_read_sector==. & ///
	fu1_discuss_entrep==. & fu1_new_techniques==.
	label var fu1_information_index "Simple index of seeking information and new opportunities at fu1"

egen bl_information_index = rowmean(bl_visit_competitors bl_evaluates_need bl_new_market bl_new_clients ///
	bl_compares_quality bl_discuss_ideas bl_more_capital bl_read_sector bl_discuss_entrep bl_new_techniques)
	replace bl_information_index = . if bl_visit_competitors==. & bl_evaluates_need==. & bl_new_market==. & ///
	bl_new_clients==. & bl_compares_quality==. & bl_discuss_ideas==. & bl_more_capital==. & bl_read_sector==. & ///
	bl_discuss_entrep==.&bl_new_techniques==.
	label var fu1_information_index "Simple index of seeking information and new opportunities at bl"
	gen bl_information_index_miss = (bl_information_index==.)
	
** Index for HR management practices **
forval i= 1/4 {
egen fu`i'_hr_index = rowmean(fu`i'_written_contract fu`i'_training_external fu`i'_training_internal fu`i'_evaluates_employee ///
	fu`i'_provides_feedback)
	replace fu`i'_hr_index = . if fu`i'_written_contract==. & fu`i'_training_external==. & fu`i'_training_internal==. & ///
	fu`i'_evaluates_employee==. & fu`i'_provides_feedback==.
	replace fu`i'_hr_index = 0 if fu`i'_hr_index==. & fu`i'_no_workers==0
	label var fu`i'_hr_index "Simple index of using good HR practices at fu`i'"
}

************OVERALL BUSINESS INDEX********

forval i =3/4 {
egen fu`i'_business_practice = rowmean(fu`i'_asks_customers fu`i'_asks_satisfaction fu`i'_offers_promotions fu`i'_changes_presentation ///
	fu`i'_one_publicity fu`i'_two_publicity fu`i'_asks_notback fu`i'_keeps_acc_books fu`i'_all_acc_books fu`i'_written_budget fu`i'_budget_monthly fu`i'_budget_yearly ///
	fu`i'_keeps_receipts fu`i'_receipts_system fu`i'_has_buss_bank fu`i'_no_mix_money fu`i'_registers_all fu`i'_money_acc fu`i'_solvable_bank fu`i'_self_salary fu`i'_sales_objectives fu`i'_real_vs_objectives fu`i'_negotiate_suppliers fu`i'_sufficient_stock fu`i'_inventory_stock ///
	fu`i'_analyzes_trends fu`i'_analyzes_performance fu`i'_calculates_costs fu`i'_calculates_benefit fu`i'_knows_most_profit fu`i'_calculates_costs fu`i'_visit_competitors fu`i'_evaluates_need fu`i'_new_market fu`i'_new_clients ///
	fu`i'_compares_quality fu`i'_discuss_ideas fu`i'_more_capital fu`i'_read_sector fu`i'_discuss_entrep fu`i'_new_techniques ///
	fu`i'_sells_sector fu`i'_meets_entrep fu`i'_written_contract fu`i'_training_external fu`i'_training_internal fu`i'_evaluates_employee ///
	fu`i'_provides_feedback)
	}
	
*FU2
egen fu2_business_practice=rowmean(fu2_asks_customers fu2_asks_satisfaction fu2_offers_promotions fu2_changes_presentation ///
	fu2_one_publicity fu2_two_publicity fu2_asks_notback fu2_keeps_acc_books fu2_written_budget fu2_budget_monthly fu2_budget_yearly ///
	fu2_has_buss_bank fu2_no_mix_money fu2_registers_all fu2_money_acc fu2_solvable_bank fu2_sales_objectives fu2_real_vs_objectives fu2_negotiate_suppliers fu2_sufficient_stock fu2_inventory_stock ///
	fu2_analyzes_trends fu2_analyzes_performance fu2_calculates_costs fu2_calculates_benefit fu2_knows_most_profit fu2_calculates_costs fu2_visit_competitors fu2_evaluates_need fu2_new_market fu2_new_clients ///
	fu2_compares_quality fu2_discuss_ideas fu2_more_capital fu2_read_sector fu2_discuss_entrep fu2_new_techniques ///
	fu2_sells_sector fu2_meets_entrep fu2_written_contract fu2_training_external fu2_training_internal fu2_evaluates_employee ///
	fu2_provides_feedback)
	
*FU1
egen fu1_business_practice=rowmean(fu1_asks_customers fu1_asks_satisfaction fu1_offers_promotions fu1_changes_presentation fu1_keeps_acc_books fu1_all_acc_books fu1_no_mix_money ///
	fu1_sales_objectives fu1_real_vs_objectives fu1_negotiate_suppliers fu1_sufficient_stock fu1_inventory_stock ///
	fu1_analyzes_trends fu1_analyzes_performance fu1_calculates_costs fu1_calculates_benefit fu1_calculates_costs fu1_visit_competitors fu1_evaluates_need fu1_new_market fu1_new_clients ///
	fu1_compares_quality fu1_discuss_ideas fu1_more_capital fu1_read_sector fu1_discuss_entrep fu1_new_techniques fu1_written_contract fu1_training_external fu1_training_internal fu1_evaluates_employee ///
	fu1_provides_feedback)
	

*BL
egen bl_business_practice=rowmean(bl_asks_customers bl_offers_promotions bl_one_publicity bl_two_publicity bl_keeps_acc_books bl_all_acc_books bl_written_budget bl_receipts_system bl_keeps_receipts bl_has_buss_bank bl_self_salary bl_no_mix_money ///
  bl_sales_objectives bl_real_vs_objectives bl_negotiate_suppliers bl_sufficient_stock bl_inventory_stock ///
	bl_analyzes_trends bl_analyzes_performance bl_visit_competitors bl_evaluates_need bl_new_market bl_new_clients ///
	bl_compares_quality bl_discuss_ideas bl_more_capital bl_read_sector bl_discuss_entrep bl_new_techniques)
	
gen bl_business_practice_miss=(bl_information_index_miss==1&bl_operations_index_mis==1&bl_record_index_miss==1&bl_marketing_index_miss==1)
	
foreach var in bl_business_practice fu1_business_practice fu2_business_practice fu3_business_practice fu4_business_practice {
	label var `var' "Overall business practice index"
	}


/* Overall Business index **
forval i= 1/4 {
egen fu`i'_business_practice = rowmean(fu`i'_hr_index fu`i'_information_index fu`i'_operations_index fu`i'_record_index fu`i'_marketing_index)
	label var fu`i'_business_practice "Simple index of using good business practices at fu`i'"
	replace fu`i'_business_practice= . if fu`i'_hr_index==. & fu`i'_information_index==. & fu`i'_operations_index==. & ///
	fu`i'_record_index==. & fu`i'_marketing_index==.
}
egen bl_business_practice = rowmean(bl_record_index bl_marketing_index)
	label var bl_business_practice "Simple index of using good business practices at BL"
	replace bl_business_practice= . if bl_record_index==. & bl_marketing_index==.
	gen bl_business_practice_miss = (bl_business_practice==.)
*/

** Recode if no longer in business **
forval i=1/4 {
	foreach var in fu`i'_hr_index fu`i'_information_index fu`i'_operations_index fu`i'_record_index fu`i'_marketing_index fu`i'_business_practice { 
		replace `var' = 0 if `var'==. & fu`i'_has_business==0 
		}
	}
	
forval x=1/4 {
	foreach var in fu`x'_marketing_index fu`x'_record_index fu`x'_operations_index fu`x'_information_index fu`x'_hr_index fu`x'_business_practice {
	sum `var'
	}
	}
foreach var in bl_marketing_index bl_record_index bl_operations_index bl_information_index bl_business_practice {
	sum `var'
	}	
	
**********************************************************************************************************************************
********************************** Part 4: Preparation of Personal Initiative variables ****************************************
**********************************************************************************************************************************

*Creation of personal initiative measures
*Scale
* Personal initiative scale bl
sum bl_q135e bl_q135k bl_q135ac bl_q143j bl_q143q bl_q143u bl_q143y
alpha bl_q135e bl_q135k bl_q135ac bl_q143j bl_q143q bl_q143u bl_q143y, item
egen PI_bl = rowmean (bl_q135e bl_q135k bl_q135ac bl_q143j bl_q143q bl_q143u bl_q143y)
gen PI_bl_miss = (PI_bl==.)
sum PI_bl

* Personal initiative scale fu1
sum fu1_p518a fu1_p5q18b fu1_p5q18d fu1_p5q18f fu1_p5q18h fu1_p5q18j fu1_p5q18l
alpha fu1_p518a fu1_p5q18b fu1_p5q18d fu1_p5q18f fu1_p5q18h fu1_p5q18j fu1_p5q18l, item
egen PI_fu1 = rowmean (fu1_p518a fu1_p5q18b fu1_p5q18d fu1_p5q18f fu1_p5q18h fu1_p5q18j fu1_p5q18l)
sum PI_fu1

* Personal initiative scale fu2
sum fu2_p5q11a fu2_p5q11b fu2_p5q11c fu2_p5q11d fu2_p5q11e fu2_p5q11f fu2_p5q11g 
alpha fu2_p5q11a fu2_p5q11b fu2_p5q11c fu2_p5q11d fu2_p5q11e fu2_p5q11f fu2_p5q11g , item
egen PI_fu2 = rowmean (fu2_p5q11a fu2_p5q11b fu2_p5q11c fu2_p5q11d fu2_p5q11e fu2_p5q11f fu2_p5q11g)
sum PI_fu2

*Personal initiative scale fu3
sum fu3_p5q14a fu3_p5q14b fu3_p5q14d fu3_p5q14f fu3_p5q14h fu3_p5q14j fu3_p5q14l
alpha fu3_p5q14a fu3_p5q14b fu3_p5q14d fu3_p5q14f fu3_p5q14h fu3_p5q14j fu3_p5q14l  , item
egen PI_fu3 = rowmean ( fu3_p5q14a fu3_p5q14b fu3_p5q14d fu3_p5q14f fu3_p5q14h fu3_p5q14j fu3_p5q14l)
sum PI_fu3

*Personal Initiative scale fu4
sum fu4_p4q8a fu4_p4q8b fu4_p4q8d fu4_p4q8f fu4_p4q8h fu4_p4q8j fu4_p4q8l
alpha fu4_p4q8a fu4_p4q8b fu4_p4q8d fu4_p4q8f fu4_p4q8h fu4_p4q8j fu4_p4q8l, item
egen PI_fu4 = rowmean (fu4_p4q8a fu4_p4q8b fu4_p4q8d fu4_p4q8f fu4_p4q8h fu4_p4q8j fu4_p4q8l)
sum PI_fu4
bysort assign_group: sum PI_fu4

*Personal initiative behavior z-Score fu1
sum fu1_pi_quant_p4q10 fu1_pi_qual_p4q10
alpha fu1_pi_quant_p4q10 fu1_pi_qual_p4q10
summarize fu1_pi_quant_p4q10 if assign_group==3
gen z_fu1_pi_quant_p4q10_wb=(fu1_pi_quant_p4q10-r(mean))/r(sd)
			
summarize fu1_pi_qual_p4q10 if assign_group==3
gen z_fu1_pi_qual_p4q10_wb=(fu1_pi_qual_p4q10-r(mean))/r(sd)

egen z_PI_beh_wb_fu1 = rowmean (z_fu1_pi_quant_p4q10_wb z_fu1_pi_qual_p4q10_wb)
sum z_PI_beh_wb_fu1
bysort assign_group: sum z_PI_beh_wb_fu1 z_fu1_pi_quant_p4q10_wb z_fu1_pi_qual_p4q10_wb

*Personal initiative behavior z-score fu2
sum fu2_pi_quant_p4q14 fu2_pi_qual_p4q14
alpha fu2_pi_quant_p4q14 fu2_pi_qual_p4q14

summarize fu2_pi_quant_p4q14 if assign_group==3
gen z_fu2_pi_quant_p4q14_wb=(fu2_pi_quant_p4q14-r(mean))/r(sd)
			
summarize fu2_pi_qual_p4q14 if assign_group==3
gen z_fu2_pi_qual_p4q14_wb=(fu2_pi_qual_p4q14-r(mean))/r(sd)

egen z_PI_beh_wb_fu2 = rowmean (z_fu2_pi_quant_p4q14_wb z_fu2_pi_qual_p4q14_wb)
sum z_PI_beh_wb_fu2
bysort assign_group: sum z_PI_beh_wb_fu2

*Personal initiative behavior z-score fu3
sum fu3_pi_quant_p4q15 fu3_pi_qual_p4q15
alpha fu3_pi_quant_p4q15 fu3_pi_qual_p4q15

summarize fu3_pi_quant_p4q15 if assign_group==3
gen z_fu3_pi_quant_p4q15_wb=(fu3_pi_quant_p4q15-r(mean))/r(sd)
			
summarize fu3_pi_qual_p4q15 if assign_group==3
gen z_fu3_pi_qual_p4q15_wb=(fu3_pi_qual_p4q15-r(mean))/r(sd)

egen z_PI_beh_wb_fu3 = rowmean (z_fu3_pi_quant_p4q15_wb z_fu3_pi_qual_p4q15_wb)
sum z_PI_beh_wb_fu3
bysort assign_group: sum z_PI_beh_wb_fu3

*Personal initiative behavior z-score fu4
ren fu4_PI_quant_fu4 PI_quant_fu4
ren fu4_PI_qual_fu4 PI_qual_fu4
sum PI_quant_fu4 PI_qual_fu4
alpha PI_quant_fu4 PI_qual_fu4

summarize PI_quant_fu4 if assign_group==3
gen z_PI_quant_fu4_wb=(PI_quant_fu4-r(mean))/r(sd)
			
summarize PI_qual_fu4 if assign_group==3
gen z_PI_qual_fu4_wb=(PI_qual_fu4-r(mean))/r(sd)

egen z_PI_beh_wb_fu4 = rowmean (z_PI_quant_fu4_wb z_PI_qual_fu4_wb)
sum z_PI_beh_wb_fu4
bysort assign_group: sum z_PI_beh_wb_fu4

**********************************************************************************************************************************
*********************************** Part 5: Preparation of gender attitudes variables ******************************************
**********************************************************************************************************************************

** Hours not spent on caretaking **
tab1 bl_q188a fu3_p6q7a fu4_p5q6a, m
gen fu4_hrs_not_care = 168 - fu4_p5q6a 
	replace fu4_hrs_not_care = 168 if fu4_p5q6==2
	label var fu4_hrs_not_care "Hours per not spent caring for dependents at fu4"
	
gen fu3_hrs_not_care = 168 - fu3_p6q7a
	replace fu3_hrs_not_care = 168 if fu3_p6q7==2
	label var fu3_hrs_not_care "Hours per week not spent caring for dependents fu3"

gen bl_hrs_not_care = 168 - bl_q188a
	replace bl_hrs_not_care = 168 if bl_q188==2
	label var bl_hrs_not_care "Hours per not spent caring for dependents at bl"

** % of household decisions influenced by women **
gen fu4_no_partner = (fu4_p5q4!=1 & fu4_p5q5!=1)
gen fu4_no_school_children = (fu4_p5q10d==-6)
egen fu4_women_influence_miss = rmiss(fu4_p5q10a fu4_p5q10b fu4_p5q10c fu4_p5q10d fu4_p5q10e fu4_p5q10f)
egen fu4_women_influence_f = anycount(fu4_p5q10a fu4_p5q10b fu4_p5q10c fu4_p5q10d fu4_p5q10e fu4_p5q10f), values (1, 3, 5, 7, 9, 11)
	replace fu4_women_influence_f = . if female==0
egen fu4_women_influence_m = anycount(fu4_p5q10a fu4_p5q10b fu4_p5q10c fu4_p5q10d fu4_p5q10e fu4_p5q10f), values (2, 3, 5, 7, 9, 11)
	replace fu4_women_influence_m = . if female==1
gen fu4_women_influence = fu4_women_influence_f if female==1
	replace fu4_women_influence = fu4_women_influence_m if female==0
	replace fu4_women_influence = . if (fu4_p5q10a==. & fu4_p5q10b==. & fu4_p5q10c==. & fu4_p5q10e==.)
	replace fu4_women_influence = . if fu4_p5q10d==. & fu4_no_school_children==0
	replace fu4_women_influence = . if fu4_p5q10f==. & fu4_no_partner==0
	replace fu4_women_influence = (1/(6-fu4_women_influence_miss)) * fu4_women_influence 
	label var fu4_women_influence "% HH decisions women can influence fu4"
	drop fu4_women_influence_f fu4_women_influence_m

gen fu3_no_school_children=((fu3_p6q2b1 + fu3_p6q2b2)==0)
gen fu3_no_partner=(fu3_p6q3!=1 & fu3_p6q5!=1)
replace fu3_p6q8d = 0 if fu3_p6q8d==. & fu3_p6q8a!=.
replace fu3_p6q8f = 0 if fu3_p6q8f==. & fu3_p6q8a!=.
egen fu3_hhdecisions_miss=rmiss(fu3_p6q8a fu3_p6q8b fu3_p6q8c fu3_p6q8d fu3_p6q8e fu3_p6q8f) 
egen fu3_women_influence_f = anycount(fu3_p6q8a fu3_p6q8b fu3_p6q8c fu3_p6q8d fu3_p6q8e fu3_p6q8f), values (1, 3, 5, 7, 9, 11)
	replace fu3_women_influence_f = . if female==0 
egen fu3_women_influence_m = anycount(fu3_p6q8a fu3_p6q8b fu3_p6q8c fu3_p6q8d fu3_p6q8e fu3_p6q8f), values (2, 3, 5, 7, 9, 11)
	replace fu3_women_influence_m = . if female==1 
gen fu3_women_influence = fu3_women_influence_f if female==1
	replace fu3_women_influence = fu3_women_influence_m if female==0
	replace fu3_women_influence = . if (fu3_p6q8a==. & fu3_p6q8b==. & fu3_p6q8c==. & fu3_p6q8e==.)
	replace fu3_women_influence = . if fu3_p6q8d==. & fu3_no_school_children==0
	replace fu3_women_influence = . if fu3_p6q8f==. & fu3_no_partner==0
	replace fu3_women_influence = (1/(6-fu3_hhdecisions_miss)) * fu3_women_influence
	label var fu3_women_influence "% HH decisions women can influence fu3"

gen bl_no_school_children=((bl_q177_nb_hom_2 + bl_q177_nb_fem_2)==0) 
gen bl_no_partner=(bl_q179!=1 & bl_q179b!=1) 
replace bl_q189d=. if bl_no_school_children==1 & bl_q189d!=.
replace bl_q189f=. if bl_no_partner==1 & bl_q189f!=. 
replace fu3_p6q8d=. if fu3_no_school_children==1 & fu3_p6q8d!=.
replace fu3_p6q8f=. if fu3_no_partner==1 & fu3_p6q8f!=.
egen bl_hhdecisions_miss=rmiss(bl_q189a bl_q189b bl_q189c bl_q189d bl_q189e bl_q189f) 
egen bl_women_decisions_hh_f =anycount(bl_q189a bl_q189b bl_q189c bl_q189d bl_q189e bl_q189f), values (1, 3, 5, 7, 9, 11)
	replace bl_women_decisions_hh_f=. if female==0 
egen bl_women_decisions_hh_m=anycount(bl_q189a bl_q189b bl_q189c bl_q189d bl_q189e bl_q189f), values (2, 3, 5, 7, 9, 11)
	replace bl_women_decisions_hh_m=. if female==1 
gen bl_women_decisions_hh = bl_women_decisions_hh_f if female==1
	replace bl_women_decisions_hh = bl_women_decisions_hh_m if female==0 
	replace bl_women_decisions_hh=. if (bl_q189a==.|bl_q189b==.|bl_q189c==.|bl_q189e==.)
	replace bl_women_decisions_hh=. if bl_q189d==. & bl_no_school_children==0
	replace bl_women_decisions_hh=. if bl_q189f==. & bl_no_partner==0
	replace bl_women_decisions_hh=(1/(6-bl_hhdecisions_miss))*bl_women_decisions_hh
	label var bl_women_decisions_hh "% HH decisions women can influence bl"

** Decision making authority **
replace fu4_p5q11h = 0 if fu4_p5q11h==. & fu4_p5q11a!=.
egen fu4_decision_making = anycount(fu4_p5q11a fu4_p5q11b fu4_p5q11c fu4_p5q11d fu4_p5q11e fu4_p5q11f fu4_p5q11g ///
	fu4_p5q11h fu4_p5q11i), values (2, 3)
replace fu4_decision_making =. if fu4_p5q11a==.| fu4_p5q11b==. | fu4_p5q11c==. | fu4_p5q11d==. | fu4_p5q11e==. | ///
	fu4_p5q11f==. | fu4_p5q11g==. | fu4_p5q11h==. | fu4_p5q11i==.
label var fu4_decision_making "Attitudes about women's decision making authority fu4"
replace fu4_decision_making = fu4_decision_making/10

egen fu3_attitudes_women_decision=anycount(fu3_p6q9a fu3_p6q9b fu3_p6q9c fu3_p6q9d fu3_p6q9e fu3_p6q9f fu3_p6q9g fu3_p6q9h fu3_p6q9i fu3_p6q9j), values (2, 3)
	replace fu3_attitudes_women_decision=. if fu3_p6q9a==.|fu3_p6q9b==.|fu3_p6q9c==.|fu3_p6q9d==.|fu3_p6q9e==.|fu3_p6q9f==.|fu3_p6q9g==.|fu3_p6q9h==.|fu3_p6q9i==.|fu3_p6q9j==.
	replace fu3_attitudes_women_decision = fu3_attitudes_women_decision/10
	label var fu3_attitudes_women_decision "Attitudes about women's decision making authority fu3"
	
egen bl_attitudes_women_decision=anycount(bl_q190a bl_q190b bl_q190c bl_q190d bl_q190e bl_q190f bl_q190g bl_q190h bl_q190i bl_q190j), values (2, 3)
	replace bl_attitudes_women_decision=. if bl_q190a==.|bl_q190b==.|bl_q190c==.|bl_q190d==.|bl_q190e==.|bl_q190f==.|bl_q190g==.|bl_q190h==.|bl_q190i==.|bl_q190j==.
	replace bl_attitudes_women_decision = bl_attitudes_women_decision/10
	label var bl_attitudes_women_decision "Attitudes about women's decision making authority bl"
	
** Autonomy of women **
foreach x in fu4_p5q13a fu4_p5q13b fu4_p5q13c fu4_p5q13d fu4_p5q13e fu4_p5q16a fu4_p5q16b fu4_p5q16c fu4_p5q16d fu4_p5q16e {
	recode `x' (-8=.)
	}
egen fu4_autonomy_women_f = anycount(fu4_p5q13a fu4_p5q13b fu4_p5q13c fu4_p5q13d fu4_p5q13e), values (1) 
	replace fu4_autonomy_women_f = . if fu4_p5q12!=1 & (fu4_p5q13a==. | fu4_p5q13b==. | fu4_p5q13c==. | fu4_p5q13d==. | ///
	fu4_p5q13e==.)
egen fu4_autonomy_women_m = anycount(fu4_p5q16a fu4_p5q16b fu4_p5q16c fu4_p5q16d fu4_p5q16e), values (1) 
	replace fu4_autonomy_women_m = . if fu4_p5q15!=1 & (fu4_p5q16a==. | fu4_p5q16b==. | fu4_p5q16c==. | fu4_p5q16d==. | ///
	fu4_p5q16e==.) 
gen fu4_autonomy_women = fu4_autonomy_women_f if fu4_p5q12==1
	replace fu4_autonomy_women = fu4_autonomy_women_m if fu4_p5q15==1
	replace fu4_autonomy_women = (1/6) * fu4_autonomy_women
	label var fu4_autonomy_women "Autonomy of women at fu4"
	drop fu4_autonomy_women_f fu4_autonomy_women_m
	replace fu4_autonomy_women = 0 if fu4_autonomy_women==. & interviewed_fu4==1

egen fu3_autonomy_women_f=anycount(fu3_p6q11a fu3_p6q11b fu3_p6q11c fu3_p6q11d fu3_p6q11e), values (1) 
	replace fu3_autonomy_women_f=. if fu3_p6q10!=1 & (fu3_p6q11a==.|fu3_p6q11b==.|fu3_p6q11c==.|fu3_p6q11d==.|fu3_p6q11e==.)
	
egen fu3_autonomy_women_m=anycount(fu3_p6q14a fu3_p6q14b fu3_p6q14c fu3_p6q14d fu3_p6q14e), values (1) 
	replace fu3_autonomy_women_m=. if fu3_p6q13!=1 & (fu3_p6q14a==.|fu3_p6q14b==.|fu3_p6q14c==.|fu3_p6q14d==.|fu3_p6q14e==.) 
	
gen fu3_autonomy_women=fu3_autonomy_women_f if fu3_p6q10==1
	replace fu3_autonomy_women=fu3_autonomy_women_m if fu3_p6q13==1
	replace fu3_autonomy_women=(1/6)*fu3_autonomy_women
	label var fu3_autonomy_women "Autonomy of women or of married men's wives fu3"
	drop fu3_autonomy_women_f fu3_autonomy_women_m
	replace fu3_autonomy_women = 0 if fu3_autonomy_women==. & interviewed_fu3==1
	
egen bl_autonomy_women_f=anycount(bl_q191a bl_q191b bl_q191c bl_q191d bl_q191e), values (1) 
	replace bl_autonomy_women_f=. if bl_q191a==.|bl_q191b==.|bl_q191c==.|bl_q191d==.|bl_q191e==.
	
egen bl_autonomy_women_m=anycount(bl_q192a bl_q192b bl_q192c bl_q192d bl_q192e), values (1) 
	replace bl_autonomy_women_m=. if bl_q192a==.|bl_q192b==.|bl_q192c==.|bl_q192d==.|bl_q192e==.
	
gen bl_autonomy_women=bl_autonomy_women_f 
	replace bl_autonomy_women=bl_autonomy_women_m if bl_autonomy_women_f==.
	replace bl_autonomy_women=(1/6)*bl_autonomy_women
	label var bl_autonomy_women "Autonomy of women or of married men's wives fu3"
	drop bl_autonomy_women_f bl_autonomy_women_m

** % of women expected to face sexual harastment concerning their businesses **
recode fu4_p5q18a (-9=0) (-8=0) (37=.) (97=.) (98=.)
rename fu4_p5q18a fu4_exp_sexual_harassment
replace fu4_exp_sexual_harassment = 10 if fu4_exp_sexual_harassment > 10 & fu4_exp_sexual_harassment!=.
replace fu4_exp_sexual_harassment = fu4_exp_sexual_harassment/10
replace fu4_exp_sexual_harassment = . if interviewed_fu4==0
label var fu4_exp_sexual_harassment "% of women expected to face sexual harassment concerning their business fu4"

gen fu3_exp_sexual_harassment=(1/10)*fu3_p6q16a
replace fu3_exp_sexual_harassment=. if fu3_p6q16a>10
label var fu3_exp_sexual_harassment "% of women expected to face sexual harassment concerning their business fu3"

gen bl_exp_sexual_harassment=(1/10)*bl_q193a
replace bl_exp_sexual_harassment=. if bl_q193a>10
label var bl_exp_sexual_harassment "% of women expected to face sexual harassment concerning their business bl"

** % women faced sexual harassment in past 12 months **
gen fu4_sexual_harassment = (fu4_p5q18e==1)
replace fu4_sexual_harassment = . if fu4_p5q18e!=1 & fu4_p5q18e!=2
label var fu4_sexual_harassment "Women were asked for sex in exchange for support of business in the past 12 months"

gen fu3_sexual_harassment=(fu3_p6q16e==1) 
replace fu3_sexual_harassment=. if fu3_p6q16e!=1 & fu3_p6q16e!=2

gen bl_sexual_harassment=(bl_q193d==1)
replace bl_sexual_harassment=. if bl_q193d!=1 & bl_q193d!=2

** Reverse the direction of the harassment variables for the agregate index **
foreach var in bl_exp_sexual_harassment fu3_exp_sexual_harassment fu4_exp_sexual_harassment {
	recode `var' (0=1) (0.1=0.9) (0.2=0.8) (0.3=0.7) (0.4=0.6) (0.6=0.4) (0.7=0.3) (0.8=0.2) (0.9=0.1) (1=0), gen(rev_`var')
	}
foreach var in bl_sexual_harassment fu3_sexual_harassment fu4_sexual_harassment {
	recode `var' (0=1) (1=2), gen(rev_`var')
	}
replace rev_fu3_sexual_harassment = 0 if rev_fu3_sexual_harassment==. & fu3_exp_sexual_harassment!=. 
replace rev_fu4_sexual_harassment = 0 if rev_fu4_sexual_harassment==. & fu4_exp_sexual_harassment!=. 

** Attitudes work women **
egen fu3_attitudes_work_women=anycount(fu3_p5q10a1 fu3_p5q10b1 fu3_p5q10c1 fu3_p5q10d1 fu3_p5q10e1 fu3_p5q10f1), values(1)
	replace fu3_attitudes_work_women=. if fu3_p5q10a1==.|fu3_p5q10b1==.|fu3_p5q10c1==.|fu3_p5q10d1==.|fu3_p5q10e1==.|fu3_p5q10f1==.
	replace fu3_attitudes_work_women=(1/6)*fu3_attitudes_work_women
	label var fu3_attitudes_work_women "Attitudes of acceptable work for women fu3"
	
egen bl_attitudes_work_women=anycount(bl_q139a1 bl_q139b1 bl_q139c1 bl_q139d1 bl_q139e1 bl_q139f1), values (1) 
	replace bl_attitudes_work_women=. if bl_q139a1==.|bl_q139b1==.|bl_q139c1==.|bl_q139d1==.|bl_q139e1==.|bl_q139f1==.
	replace bl_attitudes_work_women=(1/6)*bl_attitudes_work_women
	label var bl_attitudes_work_women "Attitudes of acceptable work for women bl"

** Attitudes work men **
egen fu3_attitudes_work_men=anycount(fu3_p5q10a2 fu3_p5q10b2 fu3_p5q10c2 fu3_p5q10d2 fu3_p5q10e2 fu3_p5q10f2), values(1)
	replace fu3_attitudes_work_men=. if fu3_p5q10a2==.|fu3_p5q10b2==.|fu3_p5q10c2==.|fu3_p5q10d2==.|fu3_p5q10e2==.|fu3_p5q10f2==.
	replace fu3_attitudes_work_men=(1/6)*fu3_attitudes_work_men
	label var fu3_attitudes_work_men "Attitudes of acceptable work for men fu3"

egen bl_attitudes_work_men=anycount(bl_q139a2 bl_q139b2 bl_q139c2 bl_q139d2 bl_q139e2 bl_q139f2), values (1) 
	replace bl_attitudes_work_men=. if bl_q139a2==.|bl_q139b2==.|bl_q139c2==.|bl_q139d2==.|bl_q139e2==.|bl_q139f2==.
	replace bl_attitudes_work_men=(1/6)*bl_attitudes_work_men
	label var bl_attitudes_work_men "Attitudes of acceptable work for men bl"

** Z-scores for attitudes towards women **
foreach var in bl_hrs_not_care fu3_hrs_not_care fu4_hrs_not_care bl_women_decisions_hh fu3_women_influence ///
	fu4_women_influence bl_attitudes_women_decision fu3_attitudes_women_decision fu4_decision_making bl_autonomy_women ///
	fu3_autonomy_women fu4_autonomy_women rev_bl_exp_sexual_harassment rev_fu3_exp_sexual_harassment rev_fu4_exp_sexual_harassment ///
	rev_bl_sexual_harassment rev_fu3_sexual_harassment rev_fu4_sexual_harassment bl_attitudes_work_women ///
	fu3_attitudes_work_women bl_attitudes_work_men fu3_attitudes_work_men {
	summarize `var' if assign_group==3
	gen z_`var'=(`var'-r(mean))/r(sd)
	label var z_`var' "Z-score of `var'"
	}	

** Average Z-scores for attitudes towards women measures **
egen bl_avg_z_hyp_b5 = rowmean(z_bl_hrs_not_care z_bl_women_decisions_hh z_bl_attitudes_women_decision z_bl_autonomy_women ///
	z_rev_bl_sexual_harassment z_rev_bl_exp_sexual_harassment z_bl_attitudes_work_women z_bl_attitudes_work_men)
egen fu3_avg_z_hyp_b5 = rowmean(z_fu3_hrs_not_care z_fu3_women_influence z_fu3_attitudes_women_decision ///
	z_fu3_autonomy_women z_rev_fu3_exp_sexual_harassment z_rev_fu3_sexual_harassment z_fu3_attitudes_work_women ///
	z_fu3_attitudes_work_men)
egen fu4_avg_z_hyp_b5 = rowmean(z_fu4_hrs_not_care z_fu4_women_influence z_fu4_decision_making z_fu4_autonomy ///
	z_rev_fu4_exp_sexual_harass z_rev_fu4_sexual_harassment)

gen bl_avg_z_hyp_b5_miss = (z_bl_hrs_not_care==. & z_bl_women_decisions_hh==. & z_bl_attitudes_women_decision==. & ///
	z_bl_autonomy_women==. & z_rev_bl_sexual_harassment==. & z_rev_bl_exp_sexual_harassment==. & ///
	z_bl_attitudes_work_women==. & z_bl_attitudes_work_men==.)

**********************************************************************************************************************************
************************* Part 4: Preparation of Mechanisms through which Training operates variables ****************************
**********************************************************************************************************************************

******************************
** C-S4a: Firms' Innovation **
******************************

** Introduction of new products or services **
codebook fu4_p3q9 bl_q78 fu3_p4q8 fu2_p4q9 fu1_p4q8 fu2_p4q10
gen fu4_new_products = (fu4_p3q9==1)
replace fu4_new_products =. if fu4_p3q9==. 
label var fu4_new_products "Introduced new products or services fu4"
codebook fu4_p3q10 fu4_p3q11 if fu4_new_products==.

gen bl_new_products=(bl_q78==1)
	replace bl_new_products=. if bl_q78==. 
	label var bl_new_products "Introduced new products or services bl"
	codebook bl_q79 bl_q79a bl_q79b if bl_new_products==.
	replace bl_new_products=1 if bl_q79!=""&bl_new_products==.
	gen bl_new_products_miss = (bl_new_products==.)
gen fu3_new_products=(fu3_p4q8==1)
	replace fu3_new_products=. if fu3_p4q8==. 
	label var fu3_new_products "Introduced new products or services fu3"
	codebook fu3_p4q9 fu3_p4q10 if fu3_new_products==.
gen fu2_new_products=(fu2_p4q9==1)
	replace fu2_new_products=. if fu2_p4q9==.
	replace fu2_new_products=1 if fu2_new_products==.&fu2_p4q10>0&fu2_p4q10<.
	label var fu2_new_products "Introduced new products or services fu2"
	codebook fu2_p4q11 fu2_p4q11a if fu2_new_products==.
gen fu1_new_products=(fu1_p4q8==1)
	replace fu1_new_products=. if fu1_p4q8==.
	replace fu1_new_products=1 if fu1_p4q9!=""&fu1_new_products==.
	label var fu1_new_products "Introduced new products or services fu1"
foreach x in fu1 fu2 fu3 fu4 {
	replace `x'_new_products = 0 if `x'_new_products==. & `x'_has_business==0 
	}

** Number of new products **
ren fu4_p3q10 fu4_num_new_products 
ren fu3_p4q9 fu3_num_new_products 
ren fu2_p4q10 fu2_num_new_products 
forval x=2/4 {
replace fu`x'_num_new_products=0 if fu`x'_new_products==0
sum fu`x'_num_new_products
replace fu`x'_num_new_products=0 if fu`x'_has_business==0
}

** Process innovation **
codebook fu4_p3q17r bl_q120q fu1_p4q12r  fu3_p4q16q
gen fu4_process_innovation = (fu4_p3q17r >= 2)
replace fu4_process_innovation = . if fu4_p3q17r==. 
gen bl_process_innovation=(bl_q120q>=2)
replace bl_process_innovation=. if bl_q120q==.
gen fu1_process_innovation=(fu1_p4q12r>=2)
replace fu1_process_innovation=. if fu1_p4q12r==.
gen fu2_process_innovation=(fu2_p4q16r>=2)
replace fu2_process_innovation=. if fu2_p4q16r==.
gen fu3_process_innovation=(fu3_p4q16q>=2)
replace fu3_process_innovation=. if fu3_p4q16q==.

gen bl_process_innovation_miss = (bl_process_innovation==.)
forval x=1/4 {
replace fu`x'_process_innovation=0 if fu`x'_has_business==0
}

** Degree of innovation **

	** New product was new line **
	codebook bl_q79a fu1_p4q9a
	gen bl_new_line=(bl_q79a==2) 
		replace bl_new_line=. if bl_q79a==.
		label var bl_new_line "Main new product/service was a new product line bl"
	gen fu1_new_line=(fu1_p4q9a==2) 
		replace fu1_new_line=. if fu1_p4q9a==.
		replace fu1_new_line=0 if fu1_has_business==0
		label var fu1_new_line "Main new product/service was a new product line fu1"
	foreach x in bl fu1 {
		replace `x'_new_line=0 if `x'_new_products==0
		}

	** New product was inspired by entrepreneur **
	codebook fu4_p3q12 bl_q79b fu1_p4q9b fu2_p4q11a fu3_p4q11
	gen fu4_own_inspired = (fu4_p3q12==1)
	replace fu4_own_inspired = . if fu4_p3q12==.
	label var fu4_own_inspired "New product or services was inspire by entrepreneur"
	gen bl_own_inspired=(bl_q79b==1| bl_q79b==3) 
	replace bl_own_inspired=. if bl_q79b==.
	label var bl_own_inspired "Main new product/service inspired by the entrepreneurֳ ideas bl"
	gen bl_own_inspired_miss = (bl_own_inspired==.)
	gen fu1_own_inspired=(fu1_p4q9b==1 |fu1_p4q9b==3) 
	replace fu1_own_inspired=. if fu1_p4q9b==.
	label var fu1_own_inspired "Main new product/service inspired by the entrepreneurֳ ideas fu1"
	gen fu3_own_inspired=(fu3_p4q11==1) 
	replace fu3_own_inspired=. if fu3_p4q11==. 
	gen fu2_own_inspired = (fu2_p4q11a==1)
	replace fu2_own_inspired = . if fu2_p4q11a==.
	label var fu2_own_inspired "New product or services was inspire by entrepreneur"
	foreach x in bl fu1 fu2 fu3 fu4 {
		replace `x'_own_inspired=0 if `x'_new_products==0
		}
	foreach x in fu1 fu2 fu3 fu4 {
		replace `x'_own_inspired=0 if `x'_has_business==0&`x'_own_inspired==.
		}
	** New product was new to neighborhood **
	codebook  fu4_p3q13 fu3_p4q12 bl_q80a
	
	rename fu3_p4q12 fu3_neighborhood_new
	recode fu4_p3q13 (2=0)
	rename fu4_p3q13 fu4_neighborhood_new
	recode bl_q80a (2=0)
	ren bl_q80a bl_neighborhood_new
	foreach x in bl fu3 fu4 {
		replace `x'_neighborhood_new=0 if `x'_new_products==0
		}	
	foreach x in fu3 fu4 {
		replace `x'_neighborhood_new=0 if `x'_has_business==0&`x'_neighborhood_new==.
		}
	gen bl_neighborhood_new_miss = (bl_neighborhood_new==.)

	** Innovation variables **
	ren fu2_p4q12 fu2_num_ideas 
	ren fu3_p4q13 fu3_num_ideas
	ren fu4_p3q14 fu4_num_ideas
	
	forval i = 2/4 {
		sum fu`i'_num_ideas
		replace fu`i'_num_ideas=. if fu`i'_num_ideas==9999
		replace fu`i'_num_ideas=0 if fu`i'_has_business==0&fu`i'_num_ideas==.
		}
	
gen bl_new_line_miss = (bl_new_line==.)
label var bl_new_line_miss "Missing observations for bl_new_line at bl"

** Z-scores **
foreach var in bl_new_products bl_process_innovation bl_new_line bl_own_inspired bl_neighborhood_new fu1_new_products ///
	fu1_process_innovation fu1_new_line fu1_own_inspired fu2_new_products fu2_num_new_products fu2_process_innovation ///
	fu2_num_ideas fu2_innovation fu3_new_products fu3_num_new_products fu3_process_innovation fu3_own_inspired fu3_num_ideas ///
	fu2_own_inspired fu3_innovation fu4_new_products fu4_num_new_products fu4_process_innovation fu4_own_inspired ///
	fu3_neighborhood_new fu4_neighborhood_new fu4_num_ideas fu4_innovation {
	summarize `var' if assign_group==3
	gen z_`var'=(`var'-r(mean))/r(sd)
	label var z_`var' "Z-score of `var'"
	}	


** Degree of innovation z-score **
egen z_bl_degree_innovation = rowmean (z_bl_new_line z_bl_own_inspired z_bl_neighborhood_new)
egen z_fu1_degree_innovation = rowmean (z_fu1_new_line z_fu1_own_inspired)
egen z_fu2_degree_innovation = rowmean (z_fu2_num_ideas z_fu2_innovation z_fu2_own_inspired)
egen z_fu3_degree_innovation = rowmean (z_fu3_own_inspired z_fu3_num_ideas z_fu3_innovation z_fu3_neighborhood_new)
egen z_fu4_degree_innovation = rowmean (z_fu4_own_inspired z_fu4_neighborhood_new z_fu4_num_ideas z_fu4_innovation)

** Average Hypothesis CS-4a z-score **
egen bl_avg_z_hyp_cs4a = rowmean(z_bl_new_products z_bl_process_innovation z_bl_degree_innovation)
egen fu1_avg_z_hyp_cs4a = rowmean(z_fu1_new_products z_fu1_process_innovation z_fu1_degree_innovation)
egen fu2_avg_z_hyp_cs4a = rowmean(z_fu2_new_products z_fu2_num_new_products z_fu2_process_innovation z_fu2_degree_innovation)
egen fu3_avg_z_hyp_cs4a = rowmean(z_fu3_new_products z_fu3_num_new_products z_fu3_process_innovation z_fu3_degree_innovation)
egen fu4_avg_z_hyp_cs4a = rowmean(z_fu4_new_products z_fu4_num_new_products z_fu4_process_innovation z_fu4_degree_innovation)
label var bl_avg_z_hyp_cs4a "Average Z-score for hypothesis C-S4a for bl"
label var fu1_avg_z_hyp_cs4a "Average Z-score for hypothesis C-S4a for fu1"
label var fu2_avg_z_hyp_cs4a "Average Z-score for hypothesis C-S4a for fu2"
label var fu3_avg_z_hyp_cs4a "Average Z-score for hypothesis C-S4a for fu3"
label var fu4_avg_z_hyp_cs4a "Average Z-score for hypothesis C-S4a for fu4"
gen bl_avg_z_hyp_cs4a_miss = (bl_avg_z_hyp_cs4a==.)

************************************
** C-S4b: Main sector of activity **
************************************

** Z-scores **
forval i=1/4 {
	foreach var in fu`i'_pri_sector_change fu`i'_sec_sector_change {
		summarize `var' if assign_group==3
		gen z_`var'=(`var'-r(mean))/r(sd)
		label var z_`var' "Z-score of `var'"
		}	
}

** Average Hypothesis CS-4a z-score **
forval i=1/4 {
	egen fu`i'_avg_z_hyp_cs4b = rowmean(z_fu`i'_pri_sector_change z_fu`i'_sec_sector_change)
	label var fu`i'_avg_z_hyp_cs4b "Average Z-score for hypothesis C-S4b for fu`i'"
}

******************************
** C-S4c: Access to finance **
******************************

** Amount they can borrow in two weeks **
codebook fu4_p3q44 fu3_p4q49 fu2_p4q40 bl_q106
ren fu4_p3q44 fu4_amount_borrow
ren fu3_p4q49 fu3_amount_borrow
ren fu2_p4q40 fu2_amount_borrow
ren bl_q106 bl_amount_borrow
gen bl_amount_borrow_miss = (bl_amount_borrow==.) 
forval x=2/4 {
	replace fu`x'_amount_borrow=0 if fu`x'_has_business==0&fu`x'_amount_borrow==.
	}

** Received at least 1 loan from any source **
sum fu4_p3q40a2 fu4_p3q40b2 fu4_p3q40c2 fu4_p3q40d2 fu4_p3q40e2 fu4_p3q40f2 fu4_p3q40g2
foreach x in a b c d e f g {
	replace fu4_p3q40`x'2 = 0 if fu4_p3q40`x'1==0 & fu4_p3q40`x'2==.
	}
egen fu4_loan = rsum(fu4_p3q40a2 fu4_p3q40b2 fu4_p3q40c2 fu4_p3q40d2 fu4_p3q40e2 fu4_p3q40f2 fu4_p3q40g2)
replace fu4_loan =. if fu4_p3q40a2==. & fu4_p3q40b2==. & fu4_p3q40c2==. & fu4_p3q40d2==. & fu4_p3q40e2==. & fu4_p3q40f2==. & ///
	fu4_p3q40g2==.
gen fu4_one_loan = (fu4_loan > 0) 
	replace fu4_one_loan =. if fu4_loan==.
label var fu4_one_loan "Business received at least 1 loan from any source fu4"

sum bl_q94a2 bl_q94b2 bl_q94c2 bl_q94d2 bl_q94e2 bl_q94f2
foreach x in a b c d e f {
	replace bl_q94`x'2 = 0 if bl_q94`x'1==0 & bl_q94`x'2==.
	}
	egen bl_loan=rsum(bl_q94a2 bl_q94b2 bl_q94c2 bl_q94d2 bl_q94e2 bl_q94f2)
	gen bl_one_loan=(bl_loan>0) 
	replace bl_one_loan=. if (bl_q94a2==.|bl_q94b2==.|bl_q94c2==.|bl_q94d2==.|bl_q94e2==.|bl_q94f2==.)
	label var bl_one_loan "Business received at least 1 loan from any source bl"
	gen bl_one_loan_miss = (bl_one_loan==.)

sum fu2_p4q36a2 fu2_p4q36b2 fu2_p4q36c2 fu2_p4q36d2 fu2_p4q36e2 fu2_p4q36f2	
foreach x in a b c d e f {
	replace fu2_p4q36`x'2 = 0 if fu2_p4q36`x'1==0 &fu2_p4q36`x'2==.
	}
	egen fu2_loan=rsum(fu2_p4q36a2 fu2_p4q36b2 fu2_p4q36c2 fu2_p4q36d2 fu2_p4q36e2 fu2_p4q36f2)
	gen fu2_one_loan=(fu2_loan>0) 
	replace fu2_one_loan=. if (fu2_p4q36a2==.|fu2_p4q36b2==.|fu2_p4q36c2==.|fu2_p4q36d2==.|fu2_p4q36e2==.|fu2_p4q36f2==.)
	label var fu2_one_loan "Business received at least 1 loan from any source fu2"
	
sum fu3_p4q45a2 fu3_p4q45b2 fu3_p4q45c2 fu3_p4q45d2 fu3_p4q45e2 fu3_p4q45f2 fu3_p4q45g2	
foreach x in a b c d e f g {
	replace fu3_p4q45`x'2 = 0 if fu3_p4q45`x'1==0 & fu3_p4q45`x'2==.
	}
	egen fu3_loan=rsum(fu3_p4q45a2 fu3_p4q45b2 fu3_p4q45c2 fu3_p4q45d2 fu3_p4q45e2 fu3_p4q45f2 fu3_p4q45g2)
	gen fu3_one_loan=(fu3_loan>0) 
	replace fu3_one_loan=. if (fu3_p4q45a2==.|fu3_p4q45b2==.|fu3_p4q45c2==.|fu3_p4q45d2==.|fu3_p4q45e2==.|fu3_p4q45f2==.|fu3_p4q45g2==.)
	label var fu3_one_loan "Business received at least 1 loan from any source fu3"
	
** Received at least 1 loan from banks or micro finance institutions 
egen fu4_loan_bankmfi = rsum(fu4_p3q40b2 fu4_p3q40e2)
	replace fu4_loan_bank =. if fu4_p3q40b2==. & fu4_p3q40e2
gen fu4_loan_bank = (fu4_loan_bankmfi > 0)
	replace fu4_loan_bank = . if fu4_loan_bankmfi==.
label var fu4_loan_bank "Business received at least 1 loan from a bank or MFI fu4"

	egen bl_loan_bankmfi=rsum(bl_q94b2 bl_q94e2)
	gen bl_loan_bank=(bl_loan_bankmfi>0) 
	replace bl_loan_bank=. if (bl_q94b2==.|bl_q94e2==.)
	label var bl_loan_bank "Business received at least 1 loan from a bank or MFI bl"
	gen bl_loan_bank_miss = (bl_loan_bank==.)
	
	egen fu2_loan_bankmfi=rsum(fu2_p4q36b2 fu2_p4q36e2)
	gen fu2_loan_bank=(fu2_loan_bankmfi>0) 
	replace fu2_loan_bank=. if (fu2_p4q36b2==.|fu2_p4q36e2==.)
	label var fu2_loan_bank "Business received at least 1 loan from a bank or MFI fu2"
	
	egen fu3_loan_bankmfi=rsum(fu3_p4q45b2 fu3_p4q45e2)
	gen fu3_loan_bank=(fu3_loan_bankmfi>0) 
	replace fu3_loan_bank=. if (fu3_p4q45b2==.|fu3_p4q45e2==.)
	label var fu3_loan_bank "Business received at least 1 loan from a bank or MFI fu3"
	
forval i=2/4 {
	replace fu`i'_loan_bank=0 if fu`i'_has_business==0&fu`i'_loan_bank==.
	replace fu`i'_one_loan=0 if fu`i'_one_loan==.&fu`i'_has_business==0
	}

** Total amount most recent loans received from all sources **
foreach x in a b c d e f g {
	replace fu4_p3q40`x'3 = 0 if fu4_p3q40`x'2==0
	sum fu4_p3q40`x'3
	}
egen fu4_tot_recent_loans = rsum(fu4_p3q40a3 fu4_p3q40b3 fu4_p3q40c3 fu4_p3q40d3 fu4_p3q40e3 fu4_p3q40f3 fu4_p3q40g3)
replace fu4_tot_recent_loans = . if fu4_p3q40a3==. & fu4_p3q40b3==. & fu4_p3q40c3==. & fu4_p3q40d3==. & fu4_p3q40e3==. & ///
	fu4_p3q40f3==. & fu4_p3q40g3==. 
label var fu4_tot_recent_loans "Total amount most recent loans received from all sources fu4"

	//replacing amount received as 0 if no loans received from said sources in bl 
	replace bl_q94a5=0 if bl_q94a2==0 
	replace bl_q94b5=0 if bl_q94b2==0 
	replace bl_q94c5=0 if bl_q94c2==0 
	replace bl_q94d5=0 if bl_q94d2==0 
	replace bl_q94e5=0 if bl_q94e2==0
	replace bl_q94f5=0 if bl_q94f2==0
	
	//replacing amount received as 0 if no loans received from said sources in fu2 
	replace fu2_p4q36a3=0 if fu2_p4q36a2==0
	replace fu2_p4q36b3=0 if fu2_p4q36b2==0
	replace fu2_p4q36c3=0 if fu2_p4q36c2==0
	replace fu2_p4q36d3=0 if fu2_p4q36d2==0
	replace fu2_p4q36e3=0 if fu2_p4q36e2==0
	replace fu2_p4q36f3=0 if fu2_p4q36f2==0
	
	//replacing amount received as 0 if no loans received from said sources in fu3
	replace fu3_p4q45a3=0 if fu3_p4q45a2==0
	replace fu3_p4q45b3=0 if fu3_p4q45b2==0
	replace fu3_p4q45c3=0 if fu3_p4q45c2==0
	replace fu3_p4q45d3=0 if fu3_p4q45d2==0
	replace fu3_p4q45e3=0 if fu3_p4q45e2==0
	replace fu3_p4q45f3=0 if fu3_p4q45f2==0
	replace fu3_p4q45g3=0 if fu3_p4q45g2==0
	
	egen bl_tot_recent_loans=rsum(bl_q94a5 bl_q94b5 bl_q94c5 bl_q94d5 bl_q94e5 bl_q94f5)
	replace bl_tot_recent_loans=. if (bl_q94a5==.|bl_q94b5==.|bl_q94c5==.|bl_q94d5==.|bl_q94e5==.|bl_q94f5==.)
	label var bl_tot_recent_loans "Total amount most recent loans received from all sources bl"
	gen bl_tot_recent_loans_miss= (bl_tot_recent_loans==.)
	
	egen fu2_tot_recent_loans=rsum(fu2_p4q36a3 fu2_p4q36b3 fu2_p4q36c3 fu2_p4q36d3 fu2_p4q36e3 fu2_p4q36f3)
	replace fu2_tot_recent_loans=. if (fu2_p4q36a3==.|fu2_p4q36b3==.|fu2_p4q36c3==.|fu2_p4q36d3==.|fu2_p4q36e3==.|fu2_p4q36f3==.)
	label var fu2_tot_recent_loans "Total amount most recent loans received from all sources fu2"
	
	egen fu3_tot_recent_loans=rsum(fu3_p4q45a3 fu3_p4q45b3 fu3_p4q45c3 fu3_p4q45d3 fu3_p4q45e3 fu3_p4q45f3 fu3_p4q45g3)
	replace fu3_tot_recent_loans=. if (fu3_p4q45a3==.|fu3_p4q45b3==.|fu3_p4q45c3==.|fu3_p4q45d3==.|fu3_p4q45e3==.|fu3_p4q45f3==.|fu3_p4q45g3==.) 
	label var fu3_tot_recent_loans "Total amount most recent loans received from all sources fu3"

forval x=2/4 {
	replace fu`x'_tot_recent_loans=0 if fu`x'_tot_recent_loans==.&fu`x'_has_business==0
	}
	
** Has a bank account **
codebook fu4_p3q41 bl_q101 fu3_p4q46 fu2_p4q37
rename fu4_p3q41 fu4_has_account 
	gen bl_has_account=(bl_q101==1) 
	replace bl_has_account=. if bl_q101==. 
	label var bl_has_account "Respondent has an account in a bank or MFI bl"
	gen bl_has_account_miss = (bl_has_account==.)
	ren fu3_p4q46 fu3_has_account 
	ren fu2_p4q37 fu2_has_account

** Recode to 0 for those who no longer have a business **
forval i=2/4{
	foreach var in fu`i'_amount_borrow fu`i'_one_loan fu`i'_loan_bank fu`i'_tot_recent_loans  ///
		fu`i'_has_buss_bank {
		replace `var' = 0 if `var'==. & fu`i'_has_business==0
		}
	}

** Sum of most recent gifts received
foreach x in a b c d e f {
	replace bl_q108`x'2=0 if bl_q108`x'1==0& bl_q108`x'2==.
		}
	egen bl_gifts=rsum(bl_q108a2 bl_q108b2 bl_q108c2 bl_q108d2 bl_q108e2 bl_q108f2)
	replace bl_gifts=. if bl_q108a2==.& bl_q108b2==.& bl_q108c2==.& bl_q108d2==.& bl_q108e2==.& bl_q108f2==.
	label var bl_gifts "Total amount of gifts received for the business"
	gen bl_gifts_miss=(bl_gifts==.)
	
codebook fu3_p4q50 fu3_p4q50a	
	ren fu3_p4q50a fu3_gifts
	replace fu3_gifts=0 if fu3_p4q50==0
	label var fu3_gifts "Total amount of gifts received for the business"
	replace fu3_gifts=0 if fu3_has_business==0&fu3_gifts==.
codebook fu4_p3q45a fu4_p3q45
	ren fu4_p3q45a fu4_gifts
	replace fu4_gifts=0 if fu4_p3q45==2
	label var fu4_gifts "Total amount of gifts received for the business"
	replace fu4_gifts=0 if fu4_has_business==0&fu4_gifts==.	
	
** Z-scores **
foreach var in bl_amount_borrow bl_one_loan bl_loan_bank bl_tot_recent_loans bl_has_account bl_has_buss_bank ///
	fu2_amount_borrow fu2_one_loan fu2_loan_bank fu2_tot_recent_loans fu2_has_account fu2_has_buss_bank fu3_amount_borrow ///
	fu3_one_loan fu3_loan_bank fu3_tot_recent_loans fu3_has_account fu3_has_buss_bank fu4_amount_borrow fu4_one_loan ///
	fu4_loan_bank fu4_tot_recent_loans fu4_has_account fu4_has_buss_bank bl_gifts fu3_gifts fu4_gifts {
	summarize `var' if assign_group==3
	gen z_`var'=(`var'-r(mean))/r(sd)
	label var z_`var' "Z-score of `var'"
	}	
				
** Average Hypothesis CS-4c z-score **
egen bl_avg_z_hyp_cs4c = rowmean(z_bl_amount_borrow z_bl_one_loan z_bl_loan_bank z_bl_tot_recent_loans z_bl_has_account ///
	z_bl_has_buss_bank z_bl_gifts)
gen bl_avg_z_hyp_cs4c_miss = (bl_amount_borrow_miss==1 & bl_one_loan_miss==1 & bl_loan_bank_miss==1 & ///
	bl_tot_recent_loans_miss==1 & bl_has_account_miss==1 & bl_has_buss_bank_miss==1&bl_gifts_miss==1)

forval i=2/2 {
	egen fu`i'_avg_z_hyp_cs4c= rowmean(z_fu`i'_amount_borrow z_fu`i'_one_loan z_fu`i'_loan_bank z_fu`i'_tot_recent_loans ///
		z_fu`i'_has_account z_fu`i'_has_buss_bank)
	label var fu`i'_avg_z_hyp_cs4c "Average Z-score for hypothesis C-S4b for fu`i'"
	}
forval i=3/4 {
	egen fu`i'_avg_z_hyp_cs4c= rowmean(z_fu`i'_amount_borrow z_fu`i'_one_loan z_fu`i'_loan_bank z_fu`i'_tot_recent_loans ///
		z_fu`i'_has_account z_fu`i'_has_buss_bank z_fu`i'_gifts)
	label var fu`i'_avg_z_hyp_cs4c "Average Z-score for hypothesis C-S4b for fu`i'"
	}
*********************************
** C-S4d: Firms' formalization **
*********************************

** Create date variables **
tab1 bl_q111*, m
tab1 fu4_p3q57*, m

gen fu4_ccit_date = mdy(fu4_p3q57ai1, 1, fu4_p3q57ai2)
gen fu4_cfe_date = mdy(fu4_p3q57bi1, 1, fu4_p3q57bi2)
gen fu3_date = mdy(9,1,2015)
gen fu2_date = mdy(1,1,2015)
gen fu1_date = mdy(9,1,2014)
gen bl_date = mdy(12,1,2013)
foreach x in fu4_ccit_date fu4_cfe_date fu3_date fu2_date fu1_date bl_date {
	format `x' %d
	}

** Create dummies for registration **
gen fu4_registered = (fu4_p3q57a==1)
replace fu4_registered = 1 if fu4_p3q57b==1
replace fu4_registered = . if fu4_p3q57a==. & fu4_p3q57b==.

forval i=1/3 {
	gen fu`i'_registered = (fu4_cfe_date <= fu`i'_date & fu4_cfe_date!=.)
	replace fu`i'_registered = 1 if fu4_ccit_date <= fu`i'_date & fu4_ccit_date!=.
	replace fu`i'_registered = 1 if bl_q111==1
	replace fu`i'_registered = . if fu4_p3q57a==. & fu4_p3q57b==. & bl_q111==.
	replace fu`i'_registered = . if interviewed_fu`i'==0
	}

gen bl_registered = (bl_q111==1)
gen bl_registered_miss = (bl_q111==.)

** Recode for closed businesses **
forval i=1/4 {
	replace fu`i'_registered = 0 if fu`i'_registered==. & fu`i'_has_business==0
	}

*******************************
** C-S4e: Ability to network **
*******************************
ds fu2_p4q41*

** Belongs to DOSI **
recode fu4_p3q58 (2=0)
recode bl_q109 (2=0)
sum fu4_p3q58 bl_q109
rename fu4_p3q58 fu4_dosi 
rename bl_q109 bl_dosi
gen bl_dosi_miss = (bl_dosi==.)
label var bl_dosi_miss "Missing observations for dosi at bl"
replace fu4_dosi=0 if fu4_dosi==.&fu4_has_business==0

** Frequency of meetings with other entrepreneurs ** 
tab1 fu4_p3q491c fu4_p3q492c fu4_p3q493c fu4_p3q494c fu4_p3q495c, m
foreach var in fu4_p3q491c fu4_p3q492c fu4_p3q493c fu4_p3q494c fu4_p3q495c {
	gen `var'_meeting_freq = 1 if `var'==3
	replace `var'_meeting_freq = 12 if `var'==2
	replace `var'_meeting_freq = 52 if `var'==1 
	} 

forval i=1/5 {
	gen fu4_p3q49`i'b_annual_freq = fu4_p3q49`i'c_meeting_freq * fu4_p3q49`i'b
	}
egen fu4_total_annual_freq = rsum(fu4_p3q491b_annual_freq fu4_p3q492b_annual_freq fu4_p3q493b_annual_freq ///
	fu4_p3q494b_annual_freq fu4_p3q495b_annual_freq)
	replace fu4_total_annual_freq = . if fu4_meets_entrep==.
	label var fu4_total_annual_freq "Frequency of meeting with other entrepreneurs"
drop fu4_p3q491c_meeting_freq fu4_p3q492c_meeting_freq fu4_p3q493c_meeting_freq fu4_p3q494c_meeting_freq ///
	fu4_p3q495c_meeting_freq fu4_p3q491b_annual_freq fu4_p3q492b_annual_freq fu4_p3q493b_annual_freq fu4_p3q494b_annual_freq ///
	fu4_p3q495b_annual_freq

*integrate answers for those who are no longer entrepreneurs in FU2
codebook fu2_p2q13	
ds fu2_p2q13*
codebook `r(varlist)'	
	//there is only one group for those with no businesses
	replace fu2_p4q411e=fu2_p2q131e if fu2_p4q411e==.&fu2_p2q131e!=.
	replace fu2_p4q411d=fu2_p2q131d if fu2_p4q411d==.&fu2_p2q131d!=.
	replace fu2_p4q411f=fu2_p2q131f if fu2_p4q411f==.&fu2_p2q131f!=.
	
	foreach var in fu2_p4q411e fu2_p4q412e fu2_p4q413e fu2_p4q414e fu2_p4q415e {
		gen `var'_meeting_freq=1 if `var'==3
		replace `var'_meeting_freq=12 if `var'==2
		replace `var'_meeting_freq=52 if `var'==1 
	} 

	gen fu2_p4q411d_annual_freq= fu2_p4q411e_meeting_freq*fu2_p4q411d
	gen fu2_p4q412d_annual_freq= fu2_p4q412e_meeting_freq*fu2_p4q412d
	gen fu2_p4q413d_annual_freq= fu2_p4q413e_meeting_freq*fu2_p4q413d
	gen fu2_p4q414d_annual_freq= fu2_p4q414e_meeting_freq*fu2_p4q414d
	gen fu2_p4q415d_annual_freq= fu2_p4q415e_meeting_freq*fu2_p4q415d
	
	egen fu2_total_annual_freq=rsum(fu2_p4q411d_annual_freq fu2_p4q412d_annual_freq fu2_p4q413d_annual_freq fu2_p4q414d_annual_freq fu2_p4q415d_annual_freq) 
	replace fu2_total_annual_freq=. if fu2_meets_entrep==.
	
	foreach var in fu3_p4q551e fu3_p4q552e fu3_p4q553e fu3_p4q554e fu3_p4q555e {
		gen `var'_meeting_freq=1 if `var'==3
		replace `var'_meeting_freq=12 if `var'==2
		replace `var'_meeting_freq=52 if `var'==1 
	} 

	gen fu3_p4q551d_annual_freq= fu3_p4q551e_meeting_freq*fu3_p4q551d
	gen fu3_p4q552d_annual_freq= fu3_p4q552e_meeting_freq*fu3_p4q552d
	gen fu3_p4q553d_annual_freq= fu3_p4q553e_meeting_freq*fu3_p4q553d
	gen fu3_p4q554d_annual_freq= fu3_p4q554e_meeting_freq*fu3_p4q554d
	gen fu3_p4q555d_annual_freq= fu3_p4q555e_meeting_freq*fu3_p4q555d
	
	egen fu3_total_annual_freq=rsum(fu3_p4q551d_annual_freq fu3_p4q552d_annual_freq fu3_p4q553d_annual_freq fu3_p4q554d_annual_freq fu3_p4q555d_annual_freq) 
	replace fu3_total_annual_freq=. if fu3_meets_entrep==.

** Number of entrepreneurs in their networks **
egen fu4_entrep_network = rsum(fu4_p3q491d fu4_p3q492d fu4_p3q493d fu4_p3q494d fu4_p3q495d) 
	replace fu4_entrep_network = . if fu4_p3q491d==.& fu4_p3q492d==.& fu4_p3q493d==.& fu4_p3q494d==.& fu4_p3q495d==.
	replace fu4_entrep_network = 0 if fu4_entrep_network==. & fu4_meets_entrep==0
	label var fu4_entrep_network "Number of entrepreneurs in respondent's network at fu4"

egen fu2_entrep_network = rsum(fu2_p4q411f fu2_p4q412f fu2_p4q413f fu2_p4q414f fu2_p4q415f) 
	label var fu2_entrep_network "Number of entrepreneurs in respondent's network"
	replace fu2_entrep_network=. if fu2_p4q411f==.& fu2_p4q412f==.& fu2_p4q413f==.& fu2_p4q414f==.& fu2_p4q415f==.
	replace fu2_entrep_network = 0 if fu2_entrep_network==. & fu2_meets_entrep==0

egen fu3_entrep_network = rsum(fu3_p4q551f fu3_p4q552f fu3_p4q553f fu3_p4q554f fu3_p4q555f) 
	label var fu3_entrep_network "Number of entrepreneurs in respondent's network"
	replace fu3_entrep_network=. if fu3_p4q551f==.& fu3_p4q552f==.& fu3_p4q553f==.& fu3_p4q554f==.& fu3_p4q555f==.
	replace fu3_entrep_network = 0 if fu3_entrep_network==. & fu3_meets_entrep==0

** Recode if reported not to meet with other entrep **
forval i=2/4 {
	foreach var in fu`i'_total_annual_freq fu`i'_entrep_network {
		replace `var' = . if fu`i'_meets_entrep==.
		replace `var' = 0 if `var'==. & fu`i'_meets_entrep==0
		replace `var' = 0 if `var'==. & fu`i'_has_business==0
	}
}

** Benefits from networks **
tab1 fu4_p3q50 fu4_p3q51 fu4_p3q52 fu4_p3q53 fu4_p3q54 fu4_p3q55, m
foreach var in fu4_p3q50 fu4_p3q51 fu4_p3q52 fu4_p3q53 fu4_p3q54 fu4_p3q55 {
	recode `var' (2=0)
	}
	
	rename fu4_p3q50 fu4_money_networks
	label var fu4_money_networks "Receive money from networks fu4"
		
	rename fu4_p3q51 fu4_supp_networks 
	label var fu4_supp_networks "Receive suppliers from networks fu4"

	rename fu4_p3q52 fu4_cust_networks
	label var fu4_cust_networks "Receive customers from networks fu4"

	rename fu4_p3q53 fu4_tools_networks
	label var fu4_tools_networks "Shared tools, inputs, equipments or employees with networks fu4"

	rename fu4_p3q54 fu4_stocks_networks
	label var fu4_stocks_networks "Purchased inputs or stocks wholesale with networks fu4"

	rename fu4_p3q55 fu4_changes_networks 
	label var fu4_changes_networks "Made changes from networks fu4"

** Recode if does not meet with other entrepreneurs **
foreach x in fu4_money_networks fu4_supp_networks fu4_cust_networks fu4_tools_networks fu4_stocks_networks fu4_entrep_network ///
	fu4_changes_networks fu4_total_annual_freq  {
	replace `x' = 0 if `x'==. & fu4_meets_entrep==0
	}

** Recode to 0 for those who no longer have a business **
foreach var in fu4_discuss_ideas fu4_discuss_entrep fu4_meets_entrep fu4_total_annual_freq fu4_entrep_network ///
	fu4_money_networks fu4_supp_networks fu4_cust_networks fu4_tools_networks fu4_stocks_networks fu4_changes_networks {
	replace `var' = 0 if `var'==. & fu4_has_business==0
	}

** Z-scores for CS4e variables **
foreach var in fu4_discuss_ideas fu4_discuss_entrep fu4_meets_entrep fu4_total_annual_freq fu4_entrep_network fu4_dosi ///
	fu4_money_networks fu4_supp_networks fu4_cust_networks fu4_tools_networks fu4_stocks_networks fu4_changes_networks  {
	summarize `var' if assign_group==3
	gen z_`var'=(`var'-r(mean))/r(sd)
	label var z_`var' "Z-score of `var'"
	}	

********************************
** Recode fu3 & fu2 variables **
********************************

** Meets with other entrepreneurs **
forval i=2/4 {
	replace fu`i'_meets_entrep = 0 if fu`i'_has_business==0&fu`i'_meets_entrep==.
	}

	codebook fu2_discuss_ideas fu3_discuss_ideas fu2_discuss_entrep fu3_discuss_entrep


	gen fu3_money_networks=(fu3_p4q56==1)
	label var fu3_money_networks "Receive money from networks fu3"
	replace fu3_money_networks=. if fu3_p4q56==.
	
	gen fu2_money_networks=(fu2_p4q42==1)
	label var fu2_money_networks "Receive money from networks fu2"
	replace fu2_money_networks=. if fu2_p4q42==.
	
	gen fu3_supp_networks=(fu3_p4q57==1)
	label var fu3_supp_networks "Receive suppliers from networks fu3"
	replace fu3_supp_networks=. if fu3_p4q57==.

	gen fu2_supp_networks=(fu2_p4q43==1)
	label var fu2_supp_networks "Receive suppliers from networks fu2"
	replace fu2_supp_networks=. if fu2_p4q43==.
	
	gen fu3_cust_networks=(fu3_p4q58==1)
	label var fu3_cust_networks "Receive customers from networks fu3"
	replace fu3_cust_networks=. if fu3_p4q58==.
	
	gen fu2_cust_networks=(fu2_p4q44==1)
	label var fu2_cust_networks "Receive customers from networks fu2"
	replace fu2_cust_networks=. if fu2_p4q44==.
	
	gen fu3_tools_networks=(fu3_p4q59==1)
	label var fu3_tools_networks "Shared tools, inputs, equipments or employees with networks fu3"
	replace fu3_tools_networks=. if fu3_p4q59==.
	
	gen fu2_tools_networks=(fu2_p4q45==1)
	label var fu2_tools_networks "Shared tools, inputs, equipments or employees with networks fu2"
	replace fu2_tools_networks=. if fu2_p4q45==.
	
	gen fu3_stocks_networks=(fu3_p4q60==1)
	label var fu3_stocks_networks "Purchased inputs or stocks wholesale with networks fu3"
	replace fu3_stocks_networks=. if fu3_p4q60==. 
	
	gen fu2_stocks_networks=(fu2_p4q46==1)
	label var fu2_stocks_networks "Purchased inputs or stocks wholesale with networks fu2"
	replace fu2_stocks_networks=. if fu2_p4q46==. 
	
	gen fu3_changes_networks=(fu3_p4q61==1)
	label var fu3_changes_networks "Made changes from networks fu3"
	replace fu3_changes_networks=. if fu3_p4q61==. 
	
	gen fu2_changes_networks=(fu2_p4q47==1)
	label var fu2_changes_networks "Made changes from networks fu2"
	replace fu2_changes_networks=. if fu2_p4q47==. 
	
	forval i=2/3 {
		foreach var in fu`i'_money_networks fu`i'_supp_networks fu`i'_cust_networks fu`i'_tools_networks fu`i'_stocks_networks fu`i'_changes_networks fu`i'_total_annual_freq fu`i'_entrep_network {
			replace `var'=0 if `var'==.&fu`i'_meets_entrep==0
			replace `var'=0 if `var'==.&fu`i'_has_business==0
			}
			}
	
	foreach var in fu3_money_networks fu2_money_networks fu3_supp_networks fu2_supp_networks fu3_cust_networks fu2_cust_networks fu3_tools_networks fu2_tools_networks fu3_stocks_networks fu2_stocks_networks fu3_changes_networks fu2_changes_networks {
				summarize `var' if assign_group==3
				gen z_`var'=(`var'-r(mean))/r(sd)
				label var z_`var' "Z-score of `var'"
				}	
				
	egen fu3_avg_z_benefits_networks=rowmean(z_fu3_money_networks z_fu3_supp_networks z_fu3_cust_networks z_fu3_tools_networks z_fu3_stocks_networks z_fu3_changes_networks)
	egen fu2_avg_z_benefits_networks=rowmean(z_fu2_money_networks z_fu2_supp_networks z_fu2_cust_networks z_fu2_tools_networks z_fu2_stocks_networks z_fu2_changes_networks)

	egen fu3_avg_benefits_networks=rowmean(fu3_money_networks fu3_supp_networks fu3_cust_networks fu3_tools_networks fu3_stocks_networks fu3_changes_networks)
	egen fu2_avg_benefits_networks=rowmean(fu2_money_networks fu2_supp_networks fu2_cust_networks fu2_tools_networks fu2_stocks_networks fu2_changes_networks)

	
	label var fu3_avg_z_benefits_networks "Average Z-score for network benefits in hypothesis C-S4a for fu3"
	label var fu2_avg_z_benefits_networks "Average Z-score for network benefits in hypothesis C-S4a for fu2"

foreach var in fu2_meets_entrep fu3_meets_entrep fu2_total_annual_freq fu3_total_annual_freq fu2_entrep_network ///
	fu3_entrep_network bl_discuss_ideas bl_discuss_entrep bl_dosi fu2_discuss_ideas fu3_discuss_ideas fu2_discuss_entrep fu3_discuss_entrep {
	summarize `var' if assign_group==3
	gen z_`var'=(`var'-r(mean))/r(sd)
	label var z_`var' "Z-score of `var'"
	}	
***********************************
** Z-scores for hypothesis CS-4e **
***********************************

** Average Hypothesis CS-4e z-score **
egen fu4_avg_z_hyp_cs4e = rowmean(z_fu4_discuss_ideas z_fu4_discuss_entrep z_fu4_meets_entrep z_fu4_total_annual_freq ///
	z_fu4_entrep_network z_fu4_money_networks z_fu4_supp_networks z_fu4_cust_networks z_fu4_tools_networks z_fu4_dosi ///
	z_fu4_stocks_networks z_fu4_changes_networks)
egen fu3_avg_z_hyp_cs4e= rowmean(z_fu3_discuss_ideas z_fu3_discuss_entrep z_fu3_meets_entrep z_fu3_total_annual_freq ///
	z_fu3_entrep_network z_fu3_money_networks z_fu3_supp_networks z_fu3_cust_networks z_fu3_tools_networks ///
	z_fu3_stocks_networks z_fu3_changes_networks)
egen fu2_avg_z_hyp_cs4e= rowmean(z_fu2_discuss_ideas z_fu2_discuss_entrep z_fu2_meets_entrep z_fu2_total_annual_freq ///
	z_fu2_entrep_network z_fu2_money_networks z_fu2_supp_networks z_fu2_cust_networks z_fu2_tools_networks ///
	z_fu2_stocks_networks z_fu2_changes_networks)
egen bl_avg_z_hyp_cs4e = rowmean(z_bl_discuss_ideas z_bl_discuss_entrep z_bl_dosi)
	gen bl_avg_z_hyp_cs4e_miss = (bl_discuss_ideas_miss==1 & bl_discuss_entrep_miss==1 & bl_dosi_miss==1)
label var fu4_avg_z_hyp_cs4e "Average Z-score for hypothesis C-S4e for fu4"
label var fu3_avg_z_hyp_cs4e "Average Z-score for hypothesis C-S4e for fu3"
label var fu2_avg_z_hyp_cs4e "Average Z-score for hypothesis C-S4e for fu2"
label var bl_avg_z_hyp_cs4e "Average Z-score for hypothesis C-S4e for bl"
	

*****************************
** Variables for Table S11 **
*****************************

********* Constructing Big Five Scales *********

*Personality fu3
*Extraversion fu3
recode fu3_p5q20e (1=5)(2=4)(3=3)(4=2)(5=1), generate (rec_fu3_p5q20e)
recode fu3_p5q20k(1=5)(2=4)(3=3)(4=2)(5=1), generate (rec_fu3_p5q20k)
recode fu3_p5q20n(1=5)(2=4)(3=3)(4=2)(5=1), generate (rec_fu3_p5q20n)
sum rec_fu3_p5q20e rec_fu3_p5q20k rec_fu3_p5q20n
alpha rec_fu3_p5q20e rec_fu3_p5q20k rec_fu3_p5q20n, item
egen EXT_fu3 = rowmean (rec_fu3_p5q20e rec_fu3_p5q20k rec_fu3_p5q20n)
label var EXT_fu3 "Big 5: Extraversion at FU3"
sum EXT_fu3
bysort assign_group:sum EXT_fu3

*Agreeableness fu3
recode fu3_p5q20b(1=5)(2=4)(3=3)(4=2)(5=1), generate (rec_fu3_p5q20b)
recode fu3_p5q20l(1=5)(2=4)(3=3)(4=2)(5=1), generate (rec_fu3_p5q20l)
recode fu3_p5q20p(1=5)(2=4)(3=3)(4=2)(5=1), generate (rec_fu3_p5q20p)
recode fu3_p5q20t(1=5)(2=4)(3=3)(4=2)(5=1), generate (rec_fu3_p5q20t)
sum rec_fu3_p5q20b rec_fu3_p5q20l rec_fu3_p5q20p rec_fu3_p5q20t
alpha rec_fu3_p5q20b rec_fu3_p5q20l rec_fu3_p5q20p rec_fu3_p5q20t, item
egen AGR_fu3 = rowmean (rec_fu3_p5q20b rec_fu3_p5q20l rec_fu3_p5q20p rec_fu3_p5q20t)
label var AGR_fu3 "Big 5: Agreeableness at FU3"
sum AGR_fu3
bysort assign_group:sum AGR_fu3

*Neuroticism fu3
sum fu3_p5q20c fu3_p5q20g fu3_p5q20i fu3_p5q20r
alpha fu3_p5q20c fu3_p5q20g fu3_p5q20i fu3_p5q20r, item
egen NEU_fu3 = rowmean (fu3_p5q20c fu3_p5q20g fu3_p5q20i fu3_p5q20r)
label var NEU_fu3 "Big 5: Neuroticism at FU3"
sum NEU_fu3
bysort assign_group:sum NEU_fu3

*Conscientiousness fu3
sum fu3_p5q20a fu3_p5q20f fu3_p5q20m fu3_p5q20o fu3_p5q20q
alpha fu3_p5q20a fu3_p5q20f fu3_p5q20m fu3_p5q20o fu3_p5q20q, item
egen CON_fu3 = rowmean (fu3_p5q20a fu3_p5q20f fu3_p5q20m fu3_p5q20o fu3_p5q20q)
label var CON_fu3 "Big 5: Conscientousness at FU3"
sum CON_fu3
bysort assign_group:sum CON_fu3

*Openness fu3
sum fu3_p5q20d fu3_p5q20h fu3_p5q20j fu3_p5q20s
alpha fu3_p5q20d fu3_p5q20h fu3_p5q20j fu3_p5q20s, item
egen OPEN_fu3 = rowmean (fu3_p5q20d fu3_p5q20h fu3_p5q20j fu3_p5q20s)
label var OPEN_fu3 "Big 5: Openness at FU3"
sum OPEN_fu3
bysort assign_group:sum OPEN_fu3


******************** Constructing Entrepreneurial Passion Scales *********************

* Passion for entrepreneurship bl
sum bl_q135g bl_q135m bl_q135s bl_q135z bl_q143c bl_q143e bl_q143l bl_q143p bl_q143w
foreach var in bl_q135g bl_q135m bl_q135s bl_q135z bl_q143c bl_q143e bl_q143l bl_q143p bl_q143w {
	replace `var'=. if `var'==99
	}
alpha bl_q135g bl_q135m bl_q135s bl_q135z bl_q143c bl_q143e bl_q143l bl_q143p bl_q143w, item
egen PFE_bl = rowmean (bl_q135g bl_q135m bl_q135s bl_q135z bl_q143c bl_q143e bl_q143l bl_q143p bl_q143w)
	replace PFE_bl=. if bl_q135g==.& bl_q135m==.& bl_q135s==.& bl_q135z==.& bl_q143c==.& bl_q143e==.& bl_q143l==.& bl_q143p==.& bl_q143w==.
label var PFE_bl "Passion for Entrepreneurship at BL"
sum PFE_bl
bysort assign_group:sum PFE_bl

* Passion for entrepreneurship fu3
sum fu3_p5q12a fu3_p5q12b fu3_p5q12c fu3_p5q12d fu3_p5q12e fu3_p5q12f fu3_p5q12g fu3_p5q12h fu3_p5q12i
alpha fu3_p5q12a fu3_p5q12b fu3_p5q12c fu3_p5q12d fu3_p5q12e fu3_p5q12f fu3_p5q12g fu3_p5q12h fu3_p5q12i, item
egen PFE_fu3 = rowmean (fu3_p5q12a fu3_p5q12b fu3_p5q12c fu3_p5q12d fu3_p5q12e fu3_p5q12f fu3_p5q12g fu3_p5q12h fu3_p5q12i)
label var PFE_fu3 "Passion for Entrepreneurship at FU3"
sum PFE_fu3
bysort assign_group:sum PFE_fu3

*Passion fu4
sum fu4_p4q7a fu4_p4q7b fu4_p4q7c fu4_p4q7d fu4_p4q7e fu4_p4q7f fu4_p4q7g fu4_p4q7h fu4_p4q7i
alpha fu4_p4q7a fu4_p4q7b fu4_p4q7c fu4_p4q7d fu4_p4q7e fu4_p4q7f fu4_p4q7g fu4_p4q7h fu4_p4q7i, item
egen PFE_fu4 = rowmean (fu4_p4q7a fu4_p4q7b fu4_p4q7c fu4_p4q7d fu4_p4q7e fu4_p4q7f fu4_p4q7g fu4_p4q7h fu4_p4q7i)
label var PFE_fu4 "Passion for Entrepreneurship at FU4"
sum PFE_fu4
bysort assign_group: sum PFE_fu4


*** CREATE DUMMIES FOR MISSING VALUES ***

replace bl_q140=. if bl_q140==99

foreach var in bl_q140 PFE_bl win_bl_sales_lm win_bl_profits_lm ihs_bl_profits_lm win_bl_profits_lw {
			gen `var'_miss=(`var'==.)
			label var `var'_miss "Dummy variable taking 1 if `var' is missing"
			replace `var'=0 if `var'==.
			label values `var'_miss dummy
			}
			
		
*Risk taking
ren bl_q140 RT_bl
ren bl_q140_miss RT_bl_miss
ren fu3_p5q11 RT_fu3
ren fu4_p4q6 RT_fu4

**************************************
** Recoding baseline missing values **
**************************************

foreach var in bl_sales_lm bl_sales_lw win_bl_sales_lm bl_profits_lm bl_profits_lw win_bl_profits_lm ihs_bl_profits_lm win_bl_profits_lw ///
	bl_total_profits bl_avg_z_hyp_a1 bl_no_workers ///
	bl_k_stock bl_k_invest bl_stock_value bl_avg_z_hyp_b1 bl_has_buss_bank bl_discuss_ideas bl_discuss_entrep ///
	bl_marketing_index bl_record_index bl_operations_index bl_information_index bl_business_practice PI_bl  ///
	bl_avg_z_hyp_b5 bl_new_products bl_new_line bl_avg_z_hyp_cs4a bl_amount_borrow bl_one_loan bl_loan_bank ///
	bl_tot_recent_loans bl_has_account bl_avg_z_hyp_cs4c bl_registered bl_dosi bl_avg_z_hyp_cs4e bl_hours_open ///
	bl_big_invest bl_process_innovation  {
	label var `var'_miss "Dummy variable taking 1 if `var' is missing"
	replace `var'=0 if `var'_miss==1
	label values `var'_miss dummy
	}
	
foreach var in bl_own_inspired bl_neighborhood_new {
	replace `var'_miss=0 if bl_new_products==0
	}

sort id_ent
saveold "$Master_final", replace
