***** Voting on the Threat of Exclusion in a Public Goods Experiment 
*****    (by A. Dannenberg, C. Haita-Falah, S. Zitzelsberger)
*****Corresponding Word Document: MainText.rtf 
*****Do-File Author: Sonja Zitzelsberger

version 14.1
clear all
macro drop all
set more off
set linesize 80

capture log close

global root "C:\Users\Zitzelsberger\Documents\Experiments\Posted\Experimental Economics\Data etc"
*Insert the directory where you saved the data files
cd "$root"
use "$root\dataprep.dta", clear
log using MainPart, replace text

*Declare panel 
xtset id_unique round

*Use only endogenous treatments for first part
preserve 
drop if exog == 1

*******************************************************************************
*******************Voting Behavior and Game Choice**************************
*******************************************************************************
////////////////////////////////////
**Figure 2- Voting Behavior by treatment 
*(Figure constracted in Word, underlying data generated here)
tab game treatment if subject==1 & rounddummy==1, col chi exact
tab voted_b treatment if rounddummy==1 , col chi exact
forvalues p = 1/4 {
	display "Phase `p'"
	tab game treatment if subject==1 & rounddummy==1 & phase==`p', col chi exact
	tab voted_b treatment if rounddummy==1  & phase==`p', col chi exact
	}

///////////////////////////////////////
*Voting Patterns
*Begin A
bysort treatment: count if votegame_p1 == 1 & round==1
quietly count if ((votegame_p1==1 & votegame_p2 == 1 & votegame_p3 == 1  ///
	& votegame_p4 == 1) | (votegame_p1==1 & votegame_p2 == 2 & votegame_p3 == 2  ///
	& votegame_p4 == 2) | (votegame_p1==1 & votegame_p2 == 1 & votegame_p3 == 2  ///
	& votegame_p4 == 2) | (votegame_p1==1 & votegame_p2 == 1 & votegame_p3 == 1  ///
	& votegame_p4 == 2) ) & round==1 & treatment==1
display "Start A, <= 1 switch - B10"
display r(N)/72
quietly count if ((votegame_p1==1 & votegame_p2 == 1 & votegame_p3 == 1  ///
	& votegame_p4 == 1) | (votegame_p1==1 & votegame_p2 == 2 & votegame_p3 == 2  ///
	& votegame_p4 == 2) | (votegame_p1==1 & votegame_p2 == 1 & votegame_p3 == 2  ///
	& votegame_p4 == 2) | (votegame_p1==1 & votegame_p2 == 1 & votegame_p3 == 1  ///
	& votegame_p4 == 2) ) & round==1 & treatment==2
display "Start A, <= 1 switch - B8"
display r(N)/97

*Begin B, never switch
bysort treatment: count if votegame_p1 == 2 & round==1
quietly count if (votegame_p1==2 & votegame_p2 == 2 & votegame_p3 == 2  ///
	& votegame_p4 == 2) & round==1 & treatment==1
display "Start B, never switch - B10"
display r(N)/43
quietly count if (votegame_p1==2 & votegame_p2 == 2 & votegame_p3 == 2  ///
	& votegame_p4 == 2) & round==1 & treatment==2
display "Start B, never switch - B8"
display r(N)/18

*Game Patterns 
bysort treatment: count if game_p1 == 1 & round==1
quietly count if ((game_p1==1 & game_p2 == 1 & game_p3 == 1  ///
	& game_p4 == 1) | (game_p1==1 & game_p2 == 2 & game_p3 == 2  ///
	& game_p4 == 2) | (game_p1==1 & game_p2 == 1 & game_p3 == 2  ///
	& game_p4 == 2) | (game_p1==1 & game_p2 == 1 & game_p3 == 1  ///
	& game_p4 == 2) ) & round==1 & treatment==1
display "Start A, <= 1 switch - B10"
display r(N)/80
quietly count if ((game_p1==1 & game_p2 == 1 & game_p3 == 1  ///
	& game_p4 == 1) | (game_p1==1 & game_p2 == 2 & game_p3 == 2  ///
	& game_p4 == 2) | (game_p1==1 & game_p2 == 1 & game_p3 == 2  ///
	& game_p4 == 2) | (game_p1==1 & game_p2 == 1 & game_p3 == 1  ///
	& game_p4 == 2) ) & round==1 & treatment==2
display "Start A, <= 1 switch - B8"
display r(N)/110

*Begin B, never switch
bysort treatment: count if game_p1 == 2 & round==1
quietly count if (game_p1==2 & game_p2 == 2 & game_p3 == 2  ///
	& game_p4 == 2) & round==1 & treatment==1
display "Start B, never switch - B10"
display r(N)/35
quietly count if (game_p1==2 & game_p2 == 2 & game_p3 == 2  ///
	& game_p4 == 2) & round==1 & treatment==2
display "Start B, never switch - B8"
display r(N)/5

////////////////////////////////////////////////
//TABLE 1: Probability of voting for game B
#delimit ;
local notes "Marginal effects of random effects probit estimation results with 
standard errors in parentheses. 
Standard errors clustered by group. 
Level of significance: * p<0.10, ** p<0.05, *** p<0.01" ;
local tabopt "cells(b(star fmt(4)) se(par fmt(4))) nobaselevels noconst onecell 
compress starlevels(* 0.10 ** 0.05 *** 0.01) label" ;
#delimit cr

eststo clear
xtprobit voted_b i.voted_b_lag mean_profit_phase_lag ///
	mean_cont_perc_phase_lag i.phase ///
	if cat==1&game_lag==1&r1inphase==1, re vce(cluster groupid_unique)
eststo: margins, dydx(*) post	
probit voted_b i.voted_b_lag c.mean_profit_phase_lag##i.ostracized_phase_lag ///
	c.mean_cont_perc_phase_lag##i.ostracized_phase_lag i.phase ///
	if cat==1&game_lag==2&r1inphase==1, vce(cluster groupid_unique)
eststo: margins, dydx(*) post
xtprobit voted_b i.voted_b_lag mean_profit_phase_lag ///
	mean_cont_perc_phase_lag i.phase ///
	if cat==2&game_lag==1&r1inphase==1, re vce(cluster groupid_unique)
eststo: margins, dydx(*) post		
xtprobit voted_b i.voted_b_lag c.mean_profit_phase_lag##i.ostracized_phase_lag ///
	c.mean_cont_perc_phase_lag##i.ostracized_phase_lag i.phase ///
	if cat==2&game_lag==2&r1inphase==1, re vce(cluster groupid_unique)
eststo: margins, dydx(*) post		
esttab using MainText.rtf, replace `tabopt' ///
		mtitle("B10 Game A" "B10 Game B" "B8 Game A" "B8 Game B") addn(`notes') ///
		order(1.voted_b_lag mean_profit_phase_lag mean_cont_perc_group_lag 1.ostracized_phase_lag) ///
		ti("Table 1: Probability of voting for game B")

probit voted_b i.voted_b_lag c.mean_profit_phase_lag##i.ostracized_phase_lag ///
	c.mean_cont_perc_phase_lag##i.ostracized_phase_lag i.phase ///
	if cat==1&game_lag==2&r1inphase==1, vce(cluster groupid_unique)
margins, dydx(mean_profit_phase_lag) at(ostracized_phase_lag= (0 1))
margins, dydx(mean_cont_perc_phase_lag) at(ostracized_phase_lag= (0 1))

xtprobit voted_b i.voted_b_lag c.mean_profit_phase_lag##i.ostracized_phase_lag ///
	c.mean_cont_perc_phase_lag##i.ostracized_phase_lag i.phase ///
	if cat==2&game_lag==2&r1inphase==1, re vce(cluster groupid_unique)
margins, dydx(mean_profit_phase_lag) at(ostracized_phase_lag= (0 1))
margins, dydx(mean_cont_perc_phase_lag) at(ostracized_phase_lag= (0 1))

*******************************************************************************
*******************Contributions**************************
*******************************************************************************
restore
******************************
////////Table 2 - Average contributions and payoffs by treatment, phase, and game
*****************************
format mean_cont_perc_group_phase mean_cont_perc_group_totalA mean_cont_perc_group_totalB %9.4f
format mean_groupsize_phase_totalB mean_profit_phase_group_insider mean_profit_phase_group mean_groupsize_phase %9.1f

*Total Groupisze
bysort treatment exog: sum mean_groupsize_phase_totalB if subject==1 & round == 1, format
bysort treatment: ranksum mean_groupsize_phase_totalB if subject == 1 & round == 1, by(exog)

*Total contribution	
bysort treatment exog: sum mean_cont_perc_group_totalA mean_cont_perc_group_totalB ///
	  if subject==1&round==1, format
bysort treatment exog: signrank mean_cont_perc_group_totalA = mean_cont_perc_group_totalB if subject==1&round==1
forvalues i = 1/2 {
	display "Treamtment `i'"
	ranksum mean_cont_perc_group_totalA if subject == 1 & round == 1 & treatment ==`i', by(exog)
	ranksum mean_cont_perc_group_totalB if subject == 1 & round == 1 & treatment ==`i', by(exog)
	}

*Total Payoff (mean_profit_phase_group_A mean_profit_phase_group_B)
bysort treatment exog: sum mean_profit_phase_group_A mean_profit_phase_group_B ///
	if subject==1&round==1, format
bysort treatment exog: signrank mean_profit_phase_group_A = mean_profit_phase_group_B if subject==1&round==1
forvalues i = 1/2 {
	display "Treamtment `i'"
	ranksum mean_profit_phase_group_A if subject == 1 & round == 1 & treatment ==`i', by(exog)
	ranksum mean_profit_phase_group_B if subject == 1 & round == 1 & treatment ==`i', by(exog)
	}

*Total Payoff Insider(mean_profit_phase_group_in_A mean_profit_phase_group_in_B)	
bysort treatment exog: sum mean_profit_phase_group_in_A mean_profit_phase_group_in_B ///
	if subject==1&round==1
bysort treatment exog: signrank mean_profit_phase_group_in_A = mean_profit_phase_group_in_B if subject==1&round==1
forvalues i = 1/2 {
	display "Treamtment `i'"
	ranksum mean_profit_phase_group_in_A if subject == 1 & round == 1 & treatment ==`i', by(exog)
	ranksum mean_profit_phase_group_in_B if subject == 1 & round == 1 & treatment ==`i', by(exog)
	}


forvalues i = 1/2 {
	display "Treatment `i'"
	forvalues p = 1/4 {
		display "Phase `p'"
		forvalues e = 0/1 {
			display "Treatment `i' Phase `p' Exog `e'"
			bysort game: sum mean_groupsize_phase mean_cont_perc_group_phase mean_profit_phase_group_insider ///
				mean_profit_phase_group if subject==1&rounddummy==1&treatment==`i'&phase==`p'&exog==`e', format
			display "Contribution Game A vs B in Treatment `i' Phase `p' Exog `e'"	
			cap noisily ranksum mean_cont_perc_group_phase if subject==1&rounddummy==1 ///
				&treatment==`i'&phase==`p'&exog==`e', by(game)
			display "Profit Insider Game A vs B in Treatment `i' Phase `p' Exog `e'"	
			cap noisily ranksum mean_profit_phase_group_insider if subject==1&rounddummy==1 ///
				&treatment==`i'&phase==`p'&exog==`e', by(game)
			display "Profit All Game A vs B in Treatment `i' Phase `p' Exog `e'"	
			cap noisily ranksum mean_profit_phase_group if subject==1&rounddummy==1 ///
				&treatment==`i'&phase==`p'&exog==`e', by(game)
			forvalues g = 1/2 {
				display "Contribution Exog vs. Endog in Treatment `i' Phase `p' Game `g'"	
				cap noisily ranksum mean_cont_perc_group_phase if subject==1&rounddummy==1 ///
					&treatment==`i'&phase==`p'&game==`g', by(exog)
				display "Profit Insider Exog vs. Endog in Treatment `i' Phase `p' Game `g'"	
				cap noisily ranksum mean_profit_phase_group_insider if subject==1&rounddummy==1 ///
					&treatment==`i'&phase==`p'&game==`g', by(exog)
				display "Profit All Exog vs. Endog in Treatment `i' Phase `p' Game `g'"	
				cap noisily ranksum mean_profit_phase_group if subject==1&rounddummy==1 ///
					&treatment==`i'&phase==`p'&game==`g', by(exog)
				}
			}
		}
	}

forvalues i = 1/2 {
	forvalues p = 1/4 {
		display "Contribution Exog vs. Endog in Treatment `i' Phase `p' Game `g'"	
		cap noisily ranksum mean_groupsize_phase if subject==1&rounddummy==1 ///
			&treatment==`i'&phase==`p'&game==2, by(exog)
		}
	}

***************************	
////// Figure 3 - Average contribution over time
****************************
bysort cat game round: egen mean_treat_cont_perc2 = mean(mean_contr_group_perc)
replace mean_treat_cont_perc2 = mean_treat_cont_perc2*100
bysort cat game round: egen mean_treat_groupsize2 = mean(groupsize)
bysort cat game round: egen count_group = count(subject) if subject==1

local gameA "game==1"
local gameB "game==2"
local phase1 "phase==1"
local phase2 "phase==2"
local phase3 "phase==3"
local phase4 "phase==4"
local colorA "sort mcolor(blue) lcolor(blue)"
local colorB "sort mcolor(red) lcolor(red)"
local colorA1 "sort mcolor(blue) lcolor(blue) lpattern(shortdash)"
local colorB1 "sort mcolor(red) lcolor(red) lpattern(shortdash)"
local colorBar "fcolor(gs14) lcolor(gs13)"

twoway (bar mean_treat_groupsize2 round if `phase1' & `gameB', `colorBar' yaxis(2)) ///
(bar mean_treat_groupsize2 round if `phase2' & `gameB', `colorBar' yaxis(2)) ///
(bar mean_treat_groupsize2 round if `phase3' & `gameB', `colorBar' yaxis(2)) ///
(bar mean_treat_groupsize2 round if `phase4' & `gameB', `colorBar' yaxis(2)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase1' &count_group>=5, `colorA' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase2'&count_group>=5, `colorA' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase3'&count_group>=5, `colorA' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase4'&count_group>=5, `colorA' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase1'&count_group>=5, `colorB' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase2'&count_group>=5, `colorB' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase3'&count_group>=5, `colorB' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase4'&count_group>=5, `colorB' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase1', `colorA1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase2', `colorA1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase3', `colorA1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase4', `colorA1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase1', `colorB1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase2', `colorB1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase3', `colorB1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase4', `colorB1' yaxis(1)) ///
if subject==1&exog==0, xtitle(Round) by(treatment, legend(off) ///
 note("") col(1)) xlabel(1(5)16) ///
ytitle(Group size) ytitle(Group size, axis(2)) yscale(range(2(1)5) axis(2)) 
graph save Figure3, replace
//label axis (Average contribution (%)

//Footnote 16, Size of Groups only Cooperators
cap drop hvar*
bysort groupid_unique phase: egen hvar = count(lowest_con_phase) if lowest_con_phase!=1 & rounddummy==1 & game==1
bysort groupid_unique phase: egen hvar2 = max(hvar)
bysort exog: tab hvar2 if rounddummy==1 & game==1 & subject==1 &exog==0
bysort exog game: sum hvar2 endgroupsize if rounddummy==1 &  subject==1 & exog ==0


*******************************************************************************
******************** Difference between A-and B-voters**********************
********************************************************************************
format contribution_perc_voters mean_cont_perc_phase_voters %9.4f

*First Time Game B
bysort treatment voted_b: sum contribution_perc_voters mean_cont_perc_phase_voters ///
	if exog==0 & rounddummy==1 & first_gameb == 1 & rank_id==1, format

*************
**Table 3 - First round contributions in game B 
#delimit ;
local notes "OLS estimation results with standard errors in parentheses. 
Standard errors clustered by group. 
Level of significance: * p<0.10, ** p<0.05, *** p<0.01" ;
local tabopt "cells(b(star fmt(4)) se(par fmt(4))) nobaselevels noconst onecell 
compress starlevels(* 0.10 ** 0.05 *** 0.01) label" ;
local mt `""B10" "B10" "B8" "B8""' ;
#delimit cr

	eststo clear
	eststo: reg contribution_perc  ///
		i.voted_b i.phase if game==2 & ///
		r1inphase==1 & first_gameb == 1&cat==1, vce(cluster groupid_unique)
	eststo: reg contribution_perc mean_cont_perc_phase_lag  ///
		i.voted_b i.phase if  game==2 & ///
		r1inphase==1 & first_gameb == 1&cat==1, vce(cluster groupid_unique)
	eststo: reg contribution_perc  ///
		i.voted_b i.phase if game==2 & ///
		r1inphase==1 & first_gameb == 1&cat==2, vce(cluster groupid_unique)
	eststo: reg contribution_perc mean_cont_perc_phase_lag  ///
		i.voted_b i.phase if  game==2 & ///
		r1inphase==1 & first_gameb == 1&cat==2, vce(cluster groupid_unique)
	esttab using MainText.rtf, append `tabopt' ///
		mtitle(`mt') addn(`notes') order(1.voted_b mean_cont_perc_phase_lag) ///
		ti("Table 3A-Average individual contribution (%) in Round 1 if game B is played 1st time")

	eststo clear
	eststo: xtreg contribution_perc   ///
		i.voted_b  i.phase if cat==1 & game==2 & ///
		r1inphase==1&first_gameb!=1, re vce(cluster groupid_unique)
	eststo: xtreg contribution_perc mean_cont_perc_phase_lag  ///
		i.voted_b i.game_b_lag i.phase if cat==1 & game==2 & ///
		r1inphase==1&first_gameb!=1, re vce(cluster groupid_unique)
	eststo: xtreg contribution_perc   ///
		i.voted_b i.phase if cat==2 & game==2 & ///
		r1inphase==1&first_gameb!=1, re vce(cluster groupid_unique)
	eststo: xtreg contribution_perc mean_cont_perc_phase_lag  ///
		i.voted_b i.game_b_lag i.phase if cat==2 & game==2 & ///
		r1inphase==1&first_gameb!=1, re vce(cluster groupid_unique)
	esttab using MainText.rtf, append `tabopt' ///
		mtitle(`mt') order(1.voted_b mean_cont_perc_phase_lag 1.game_b_lag) addn(`notes')  ///
	ti("Table 3B-Average individual contribution (%) in Round 1 of each Phase (2-4) if game B is not first time") 
	
* First Time Game A
bysort treatment voted_b: sum contribution_perc_voters mean_cont_perc_phase_voters ///
	if exog==0 & rounddummy==1 & first_gamea == 1 & rank_id==1, format

*******************************************************************************
**********************  Group size and exclusion of player ******************
*******************************************************************************
********Groupsize
bysort cat: sum endgroupsize if subject==1&rounddummy==1&game==2
bysort cat: tab endgroupsize if rounddummy==1 & subject==1 & game==2


***********EXCLUSION
*Received exclusion vote
bysort cat: tab received_excl_vote_total if round==1 & ever_gameb==1
*bysort exog: ranksum received_excl_vote_total if round==1 & ever_gameb==1, by(treatment)
*bysort treatment:  ranksum received_excl_vote_total if round==1 & ever_gameb==1, by(exog)
bysort cat: tab ever_ostracized if round==1 & ever_gameb==1
*bysort exog: ranksum ever_ostracized if round==1 & ever_gameb==1, by(treatment)
*bysort treatment:  ranksum ever_ostracized if round==1 & ever_gameb==1, by(exog)

cap drop hvar*
bysort groupid_unique round: egen hvar1 = min(contribution) if game==2 &ostracized!=1
gen hvar2 = 1 if contribution==hvar1 & game==2 &ostracized!=1
replace hvar2 = 0 if contribution!=hvar1 & game==2 &ostracized!=1
bysort cat: tab contribution_rank hvar2 if received_excl_vote==1 //sum rank 1 to 2.5 (lowest or second lowest contributor)
//B10 170/193 = 88%    
//B8 76/95 = 80%        
//B10-Exog (188-15+10+7)= 190  190/220= 86%
//B8-Exog   (91-1+8+6)=104		104/111=94%
bysort cat: tab contribution_rank hvar2 if ostracized_v2==1
drop hvar*
	
*Number of exclusions 
bysort cat: tab ever_ostracized if ever_gameb==1&round==1
bysort exog: ranksum ever_ostracized if round==1 & ever_gameb==1, by(treatment)
bysort treatment:  ranksum ever_ostracized if round==1 & ever_gameb==1, by(exog)
bysort cat: tab total_num_ost if round==1 & ever_gameb==1
bysort exog: ranksum total_num_ost if round==1 & ever_gameb==1, by(treatment)
bysort treatment:  ranksum total_num_ost if round==1 & ever_gameb==1, by(exog)

*Contributions by groups that did not exclude
bysort cat: sum mean_cont_perc_group_phase if endgroupsize == 5 & game == 2 & subject== 1 & rounddummy == 1
bysort cat: sum mean_cont_perc_group_phase if endgroupsize != 5 & game == 2 & subject== 1 & rounddummy == 1	
	

********************************************************************************
***********Comparison between endog and exog***************************************
**********************************************************************
////// Figure 4 - Average contribution over time
cap drop mean_treat_cont_perc2 mean_treat_groupsize2 count_group
bysort cat game round: egen mean_treat_cont_perc2 = mean(mean_contr_group_perc)
 replace mean_treat_cont_perc2 = mean_treat_cont_perc2*100
bysort cat game round: egen mean_treat_groupsize2 = mean(groupsize)
bysort cat game round: egen count_group = count(subject) if subject==1

local gameA "game==1"
local gameB "game==2"
local phase1 "phase==1"
local phase2 "phase==2"
local phase3 "phase==3"
local phase4 "phase==4"
local colorA "sort mcolor(blue) lcolor(blue)"
local colorB "sort mcolor(red) lcolor(red)"
local colorA1 "sort mcolor(blue) lcolor(blue) lpattern(shortdash)"
local colorB1 "sort mcolor(red) lcolor(red) lpattern(shortdash)"
local colorExA "sort mcolor(blue) lcolor(blue) msymbol(T)"
local colorExB "sort mcolor(red) lcolor(red) msymbol(T)"
local colorExA1 "sort mcolor(blue) lcolor(blue) lpattern(shortdash) msymbol(T)"
local colorExB1 "sort mcolor(red) lcolor(red) lpattern(shortdash) msymbol(T)"
local colorExBar "fcolor(gs14) lcolor(gs13)"
local colorBar " fcolor(none) lcolor(lavender)"

twoway (bar mean_treat_groupsize2 round if `phase1' & `gameB' & exog==1, `colorExBar' yaxis(2)) ///
(bar mean_treat_groupsize2 round if `phase2' & `gameB' & exog==1, `colorExBar' yaxis(2)) ///
(bar mean_treat_groupsize2 round if `phase3' & `gameB' & exog==1, `colorExBar' yaxis(2)) ///
(bar mean_treat_groupsize2 round if `phase4' & `gameB' & exog==1, `colorExBar' yaxis(2)) ///
(bar mean_treat_groupsize2 round if `phase1' & `gameB' & exog==0, `colorBar' yaxis(2)) ///
(bar mean_treat_groupsize2 round if `phase2' & `gameB' & exog==0, `colorBar' yaxis(2)) ///
(bar mean_treat_groupsize2 round if `phase3' & `gameB' & exog==0, `colorBar' yaxis(2)) ///
(bar mean_treat_groupsize2 round if `phase4' & `gameB' & exog==0, `colorBar' yaxis(2)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase1' & exog==0 &count_group>=5, `colorA' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase2' & exog==0 &count_group>=5, `colorA' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase3' & exog==0 &count_group>=5, `colorA' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase4' & exog==0 &count_group>=5, `colorA' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase1' & exog==0 &count_group>=5, `colorB' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase2' & exog==0 &count_group>=5, `colorB' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase3' & exog==0 &count_group>=5, `colorB' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase4' & exog==0 &count_group>=5, `colorB' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase1' & exog==0, `colorA1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase2' & exog==0, `colorA1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase3' & exog==0, `colorA1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase4' & exog==0, `colorA1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase1' & exog==0, `colorB1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase2' & exog==0, `colorB1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase3' & exog==0, `colorB1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase4' & exog==0, `colorB1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase1' & exog==1 &count_group>=5, `colorExA' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase2' & exog==1 &count_group>=5, `colorExA' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase3' & exog==1 &count_group>=5, `colorExA' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase4' & exog==1 &count_group>=5, `colorExA' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase1' & exog==1 &count_group>=5, `colorExB' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase2' & exog==1 &count_group>=5, `colorExB' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase3' & exog==1 &count_group>=5, `colorExB' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase4' & exog==1 &count_group>=5, `colorExB' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase1' & exog==1, `colorExA1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase2' & exog==1, `colorExA1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase3' & exog==1, `colorExA1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameA' & `phase4' & exog==1, `colorExA1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase1' & exog==1, `colorExB1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase2' & exog==1, `colorExB1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase3' & exog==1, `colorExB1' yaxis(1)) ///
(connected mean_treat_cont_perc2 round if `gameB' & `phase4' & exog==1, `colorExB1' yaxis(1)) ///
if subject==1, xtitle(Round) by(treatment, legend(off) ///
 note("") col(1)) xlabel(1(5)16) ///
ytitle(Group size) ytitle(Group size, axis(2)) yscale(range(2(1)5) axis(2)) 
//label axis (Average contribution (%) 
graph save Figure4, replace

log close 
exit
