**LB 6/30/2017

clear

cap log close
log using tables.log, replace text

use data

* TREATMENT VARS
local treatvars_panelA t_any
local treatvars_panelB t_anycom t_anyord
local treatvars_panelC t_com_noR t_com_RPri t_com_RPub t_ord_noR t_ord_RPri t_ord_RPub 

preserve
	* replace 0s with missing for sum stats and balance
	replace bl_d_hyper = .m if bl_mi_d_hyper==1
	replace bl_d_hypo = .m if bl_mi_d_hyper==1
	replace bl_totsavcash_099 = .m if bl_mi_totsavcash==1

// TABLE 1 SUM STATS
	* treatment conditions 
	 tabstat `treatvars_panelA' `treatvars_panelB' `treatvars_panelC', statistics(mean sd p10 p50 p90 count) format(%12.3f) columns(statistics)

	* baseline characteristics
 	 tabstat clubsize if tag_club, statistics(mean sd p10 p50 p90 count) format(%12.3f) columns(statistics)

	 #d ;
	 local tabstat_blchars 
				bl_d_female bl_d_married bl_age_099 bl_eduyrs_099 bl_hhnum_099
				bl_asset_pca_199 bl_livest_pca_199 
				bl_acre_adj_099 bl_salecrop_099 bl_inpexp_099

				bl_d_anyformalacc bl_savcash_099 bl_savform_099
				bl_d_hyper bl_d_hypo
				bl_transNet_199
				bl_mi_totsavcash bl_mi_d_hyper 	
		;
	#d cr	 	 
	 
	 tabstat `tabstat_blchars', statistics(mean sd p10 p50 p90 count) format(%12.3f) columns(statistics)

	* transactions with partner institutions
	 local tabstat_transvars trans_d_any trans_dep_ord_PRE trans_dep_splan_PRE trans_dep_oth_PRE trans_dep_total_PRE trans_with_total_PRE net_total_PRE net_total_NOVDEC09 net_total_JANAPR10 has_anyActive_o22
	 tabstat `tabstat_transvars', statistics(mean sd p10 p50 p90 count) format(%12.3f) columns(statistics)
	  
	* endline survey outcomes
	 local tabstat_elsvy el_landcult_099 el_input_val_099 el_maizetobasale_099 el_mainoutput_099 el_farmprofit_199 el_exp30_099 el_hhsize el_tr_made el_tr_received el_tr_net el_tobacloan el_d_fixeddep d_elineattrit1
	 tabstat `tabstat_elsvy' , statistics(mean sd p10 p50 p90 count) format(%12.3f) columns(statistics)
	
// TABLE 2
	tab treatment tag_club

	
* BASELINE CONTROLS
#d ;
local svyRHScontr 
	bl_d_female bl_d_married bl_age_099 bl_eduyrs_099 bl_hhnum_099
	bl_asset_pca_199 bl_livest_pca_199 
	bl_acre_adj_099
	bl_salecrop_099 bl_inpexp_099
	bl_d_anyformalacc bl_totsavcash_099
	bl_d_hyper bl_d_hypo
	bl_transNet_199
	bl_mi_totsavcash bl_mi_d_hyper 	
	;
#d cr


// TABLE 3 (BALANCE)

	foreach y of varlist `svyRHScontr' {
		* PANEL A
		 reg `y' t_any d_strat*, cluster(club_id) 
		* PANEL B
		 reg `y' t_anycom t_anyord d_strat*, cluster(club_id) 
		 test t_anycom=t_anyord 
		 
	}
	//
	
	* replace missing with 0s for joint test
	 replace bl_d_hyper = 0 if bl_d_hyper==.m
	 replace bl_d_hypo = 0 if bl_d_hypo==.m
	 replace bl_totsavcash_099 = 0 if bl_totsavcash_099==.m 
	
	 reg t_anycom `svyRHScontr', cluster(club_id) 
	 testparm `svyRHScontr' 
	 reg t_anyord `svyRHScontr', cluster(club_id) 		 
	 testparm `svyRHScontr' 
	 
restore

// TABLES 4 to 7
	 local table4 trans_d_any trans_dep_total_PRE trans_dep_ord_PRE trans_dep_splan_PRE trans_dep_oth_PRE trans_with_total_PRE 
	 local table5 bal_total_o22 bal_ordkasup_o22 bal_splan_o22 bal_oth_o22
	 local table6 el_landcult_099 el_input_val_099 el_maizetobasale_099 el_mainoutput_099 el_farmprofit_199 el_exp30_099
	 local table7 el_hhsize el_tobacloan el_tr_made el_tr_received el_tr_net el_d_fixeddep
	 
	 foreach table in table4 table5 table6 table7 {
		foreach y of varlist ``table'' {
			* PANEL A
			 reg `y' t_any `svyRHScontr' d_strat*, cluster(club_id) 
			* PANEL B
			 reg `y' t_anycom t_anyord `svyRHScontr' d_strat*, cluster(club_id) 
			 test t_anycom=t_anyord 
		}
		//
	 }
	 //

// TABLE APPENDIX 1
	 local y d_elineattrit1
	 
	* PANEL A
	 reg `y' `treatvars_panelA' `svyRHScontr' d_strat*, cluster(club_id) 
	* PANEL B
	 reg `y' `treatvars_panelB' `svyRHScontr' d_strat*, cluster(club_id) 
	 test t_anycom=t_anyord 
	* PANEL C
	 reg `y' `treatvars_panelC' `svyRHScontr' d_strat*, cluster(club_id) 

// TABLE APPENDIX 2
preserve
	replace bl_d_hyper = .m if bl_mi_d_hyper==1
	replace bl_d_hypo = .m if bl_mi_d_hyper==1
	replace bl_totsavcash_099 = .m if bl_mi_totsavcash==1

	foreach y of varlist `svyRHScontr' {
		* PANEL C
		 reg `y' `treatvars_panelC' d_strat*, cluster(club_id) 
	}
	//
restore

// TABLE APPENDIX 3 - 6 
	 local table_apx_3 `table4' 
	 local table_apx_4 `table5' 
	 local table_apx_5 `table6' 
	 local table_apx_6 `table7' 
	 
	 local list_of_apx_tables table_apx_3 table_apx_4 table_apx_5 table_apx_6

	 foreach table of local list_of_apx_tables {
		foreach y of varlist ``table'' {
			* PANEL C
			 reg `y' `treatvars_panelC' `svyRHScontr' d_strat*, cluster(club_id) 
		}
		//
	 }
	 //

// TABLE APPENDIX 7 --- TAKE-UP 

* divide by 10,000 for easy of display
 foreach v of varlist bl_totsavcash_099 bl_transNet_199 bl_inpexp_099 bl_salecrop_099 {
	replace `v' = `v'/10000
 }
 // 
 
#d ;
local x_takeup 
	bl_d_female
	bl_d_married
	bl_age_099
	bl_eduyrs_099
	bl_hhnum_099
	bl_asset_pca_199
	bl_livest_pca_199 
	bl_acre_adj_099
	bl_d_anyformalacc	
	bl_totsavcash_099
	bl_d_hyper
	bl_d_hypo
	bl_inpexp_099
	bl_salecrop_099 
	bl_transNet_199
	bl_mi_totsavcash 
	bl_mi_d_hyper 	
	;
#d cr 
 
* regressions
 foreach y of varlist has_anyActive_o22 trans_d_any {  
	 reg `y' `x_takeup' d_strat* if inlist(treatment,1,2,3,4,5,6), cluster(club_id)
	 reg `y' `x_takeup' d_strat* if inlist(treatment,4,5,6), cluster(club_id)
 }
// 

log close

exit

 
