********************************************************************************
*
*							GENERAL INFORMATION
*
********************************************************************************
*
*Data_analysis_202101.do  Stata 14.2 - January, 2021
*
*Fabio Galeotti, Maria Montero and Anders Poulsen 2021. 
*The Attraction and Compromise Effects in Bargaining: Experimental Evidence
* 
*Requires the following additional ado files:
*  - estout
*
* To install and ado file type: ssc install NAME_OF_FILE
*
* inputs:
*  - experiment1.dta
*  - experiment2.dta
*  - chat_coding_data.dta
*
* The structure of the do-file follows approximately the structure of the paper  
*
*
********************************************************************************
*
*							DEFINE WORKING FOLDERS
*
********************************************************************************

* Define path of working directory here:
global PATH "C:\Users\galeotti\ownCloud\GATE-Travail\Projects\GaleottiMonteroPoulsen_AE_CE\Data\Replication_files"

		
*** Set the current directory:
cd "$PATH"
	
*** Declare working folders:
global Do 			"$PATH\Do"
global Data 		"$PATH\Data"
global Results 		"$PATH\Results"


********************************************************************************
*
*								DATA ANALYSIS
*
********************************************************************************

********************************************************************************
*							MAIN PAPER: EXPERIMENT 1
********************************************************************************


use "$Data\experiment1.dta", clear


**********4.2 Experimental Design and Procedures

preserve
collapse (mean) session, by(subject_index)
di _N //Total n. of subjects
tab session //sessions and subjects x session
restore

*****Effect of the labels on behavior
preserve
collapse (mean) Profit, by( Role session)
reshape wide Profit, i( session_n) j(Role)
signrank Profit1= Profit2
restore

preserve
keep if first_chat==1
gen Person1 = Role==1
collapse (mean) Person1, by(session_n)
gen Person2 = 1-Person1
signrank Person1=Person2
signrank Person1=0.5
restore

preserve
keep if first_prop==1
gen Person1 = Role==1
collapse (mean) Person1, by(session_n)
gen Person2 = 1-Person1
signrank Person1=Person2
signrank Person1=0.5
restore

**********6 Findings of Experiment 1

*****6.1 Overview

***Table 2
preserve
collapse (first) contract1 contract2 contract3 (mean) disagreement agreement_contract1 agreement_contract2 agreement_contract3 agreement_time, by(Game)
// G1 and G10 are symmetric:
replace agreement_contract1 = agreement_contract1/2 if Game==1
replace agreement_contract2 = agreement_contract1 if Game==1
replace agreement_contract1 = agreement_contract1/2 if Game==10
replace agreement_contract3 = agreement_contract1 if Game==10

format disagreement agreement_contract1 agreement_contract2 agreement_contract3 agreement_time %9.4g

label variable contract1 "Contract A"
label variable contract2 "Contract B"
label variable contract3 "Contract C"
label variable agreement_contract1 "Agree on A"
label variable agreement_contract2 "Agree on B"
label variable agreement_contract3 "Agree on C"
label variable disagreement "Disagree"
label variable agreement_time "Time to (in sec.)"

export delimited using Results\Table2.csv, nolabel replace datafmt
restore

***Figure 5

//See Results\Figure5.xlsx

***Non-parametric tests

preserve
collapse (mean) disagreement agreement_contract1 agreement_contract2 agreement_contract3 agreement_time, by(session_n Game)
// G1 and G10 are symmetric:
replace agreement_contract1 = agreement_contract1/2 if Game==1
replace agreement_contract2 = agreement_contract1 if Game==1
replace agreement_contract1 = agreement_contract1/2 if Game==10
replace agreement_contract3 = agreement_contract1 if Game==10

rename (agreement_contract*) =_

reshape wide agreement_contract1_ agreement_contract2_ agreement_contract3_ disagreement agreement_time, i( session_n) j(Game)


gen attraction_effect = ((agreement_contract2_3 - agreement_contract2_1) + ///
						 (agreement_contract1_6 - agreement_contract1_4) + ///
						 (agreement_contract1_13 - agreement_contract1_7) + ///
						 (agreement_contract2_14 - agreement_contract2_7) + ///
						 (agreement_contract2_19 - agreement_contract2_16) + ///
						 (agreement_contract2_20 - agreement_contract2_16) + ///
						 (agreement_contract1_21 - agreement_contract1_16))/7

gen compromise_effect = ((agreement_contract2_2 - agreement_contract2_1) + ///
						 (agreement_contract1_5 - agreement_contract1_4) + ///
						 (agreement_contract1_8 - agreement_contract1_7) + ///
						 (agreement_contract1_9 - agreement_contract1_7) + ///
						 (agreement_contract2_10 - agreement_contract2_7) + ///
						 (agreement_contract2_11 - agreement_contract2_7) + ///
						 (agreement_contract2_12 - agreement_contract2_7) + ///
						 (agreement_contract1_17 - agreement_contract1_16) + ///
						 (agreement_contract2_18- agreement_contract2_16))/9
				 
sum attraction_effect compromise_effect

quietly signrank attraction_effect=0
di normprob(-abs(r(z))) //one-sided p-value
quietly signrank compromise_effect=0
di normprob(-abs(r(z))) //one-sided p-value

quietly signrank agreement_contract2_20=agreement_contract2_16
di normprob(-abs(r(z))) //G20 vs. BG16
quietly signrank agreement_contract2_2=agreement_contract2_1
di normprob(-abs(r(z))) //G2 vs. BG1
quietly signrank agreement_contract2_18=agreement_contract2_16
di normprob(-abs(r(z))) //G18 vs. BG16

*****6.2 Games with an Equal Payoff Contract

gen attraction_effect_equal = ((agreement_contract1_6 - agreement_contract1_4) + ///
							  (agreement_contract1_13 - agreement_contract1_7) + ///
							  (agreement_contract2_14 - agreement_contract2_7))/3


gen compromise_effect_equal = ((agreement_contract1_5 - agreement_contract1_4) + ///
							  (agreement_contract1_8 - agreement_contract1_7) + ///
							  (agreement_contract1_9 - agreement_contract1_7) + ///
							  (agreement_contract2_10 - agreement_contract2_7) + ///
							  (agreement_contract2_11 - agreement_contract2_7) + ///
							  (agreement_contract2_12 - agreement_contract2_7))/6

sum attraction_effect_equal compromise_effect_equal
quietly signrank attraction_effect_equal=0
di normprob(-abs(r(z))) //all games with equal payoffs (attraction)
quietly signrank compromise_effect_equal=0
di normprob(-abs(r(z))) //all games with equal payoffs (compromise)

quietly signrank agreement_contract1_5 = agreement_contract1_4
di normprob(-abs(r(z))) //G5 vs. BG4 (A)
quietly signrank agreement_contract1_6 = agreement_contract1_4
di normprob(-abs(r(z))) //G6 vs. BG4 (A)
quietly signrank agreement_contract2_5 = agreement_contract2_4
di normprob(-abs(r(z))) //G5 vs. BG4 (B)
quietly signrank agreement_contract2_6 = agreement_contract2_4
di normprob(-abs(r(z))) //G6 vs. BG4 (B)

quietly signrank agreement_contract2_4 = agreement_contract2_7
di 2*normprob(-abs(r(z))) //BG4 vs. BG7 (B, two_sided)

quietly signrank agreement_contract1_8 = agreement_contract1_7
di normprob(-abs(r(z))) //G8 vs. BG7 (A)
quietly signrank agreement_contract1_13 = agreement_contract1_7
di normprob(-abs(r(z))) //G13 vs. BG7 (A)
quietly signrank agreement_contract1_9 = agreement_contract1_7
di normprob(-abs(r(z))) //G9 vs. BG7 (A)

quietly signrank agreement_contract2_8 = agreement_contract2_7
di normprob(-abs(r(z))) //G8 vs. BG7 (B)
quietly signrank agreement_contract2_13 = agreement_contract2_7
di normprob(-abs(r(z))) //G13 vs. BG7 (B)
quietly signrank agreement_contract2_9 = agreement_contract2_7
di normprob(-abs(r(z))) //G9 vs. BG7 (B)

quietly signrank agreement_contract2_10 = agreement_contract2_7
di normprob(-abs(r(z))) //G10 vs. BG7 (B)
quietly signrank agreement_contract2_11 = agreement_contract2_7
di normprob(-abs(r(z))) //G11 vs. BG7 (B)
quietly signrank agreement_contract2_12 = agreement_contract2_7
di normprob(-abs(r(z))) //G12 vs. BG7 (B)
quietly signrank agreement_contract2_14 = agreement_contract2_7
di normprob(-abs(r(z))) //G14 vs. BG7 (B)

quietly signrank agreement_contract1_10 = agreement_contract1_7
di normprob(-abs(r(z))) //G10 vs. BG7 (A)
quietly signrank agreement_contract1_11 = agreement_contract1_7
di normprob(-abs(r(z))) //G11 vs. BG7 (A)
quietly signrank agreement_contract1_12 = agreement_contract1_7
di normprob(-abs(r(z))) //G12 vs. BG7 (A)
quietly signrank agreement_contract1_14 = agreement_contract1_7
di normprob(-abs(r(z))) //G14 vs. BG7 (A)

*****6.3 Games without an Equal Payoff Contract

***6.3.1 Two Symmetrically Unequal Payoff Contracts

quietly signrank agreement_contract2_2 = agreement_contract2_1
di normprob(-abs(r(z))) //G2 vs. BG1 (B)
quietly signrank agreement_contract2_3 = agreement_contract2_1
di normprob(-abs(r(z))) //G3 vs. BG1 (B)
quietly signrank agreement_contract1_3 = agreement_contract1_1
di normprob(-abs(r(z))) //G3 vs. BG1 (A)

***6.3.2 The Case of a Nearly Equal Payoff Contract

quietly signrank agreement_contract1_7 = agreement_contract1_16
di 2*normprob(-abs(r(z))) //BG7 vs. BG16 (A, two-sided)
quietly signrank agreement_contract2_7 = agreement_contract2_16
di 2*normprob(-abs(r(z))) //BG7 vs. BG16 (B, two-sided)

gen attraction_effect_near_equal = ((agreement_contract2_19 - agreement_contract2_16) + ///
								   (agreement_contract2_20 - agreement_contract2_16) + ///
								   (agreement_contract1_21 - agreement_contract1_16))/3

gen compromise_effect_near_equal = ((agreement_contract1_17 - agreement_contract1_16) + ///
								   (agreement_contract2_18- agreement_contract2_16))/2

sum attraction_effect_near_equal compromise_effect_near_equal

quietly signrank attraction_effect_near_equal=0
di normprob(-abs(r(z))) //all games with nearly equal payoffs (attraction)
quietly signrank compromise_effect_near_equal=0
di normprob(-abs(r(z))) //all games with nearly equal payoffs (compromise)

quietly signrank agreement_contract2_18=agreement_contract2_16
di normprob(-abs(r(z))) //G18 vs. BG16 (B)
quietly signrank agreement_contract2_20=agreement_contract2_16
di normprob(-abs(r(z))) //G20 vs. BG16 (B)

quietly signrank agreement_contract1_17=agreement_contract1_16
di normprob(-abs(r(z))) //G17 vs. BG16 (A)
quietly signrank agreement_contract2_17=agreement_contract2_16
di normprob(-abs(r(z))) //G17 vs. BG16 (B)

quietly signrank agreement_contract1_21=agreement_contract1_16
di normprob(-abs(r(z))) //G21 vs. BG16 (A)
quietly signrank agreement_contract2_21=agreement_contract2_16
di normprob(-abs(r(z))) //G21 vs. BG16 (B)

***6.4 Decoy Properties

quietly signrank agreement_contract2_19=agreement_contract2_16
di 2*normprob(-abs(r(z))) //G19 vs. BG16 (B)

quietly signrank agreement_contract2_20=agreement_contract2_16
di normprob(-abs(r(z))) //G20 vs. BG16 (B)
quietly signrank agreement_contract1_20=agreement_contract1_16
di normprob(-abs(r(z))) //G20 vs. BG16 (A)

quietly signrank agreement_contract2_22=agreement_contract2_16
di 2*normprob(-abs(r(z))) //G22 vs. BG16 (B)
quietly signrank agreement_contract1_22=agreement_contract1_16
di 2*normprob(-abs(r(z))) //G22 vs. BG16 (A)

quietly signrank agreement_contract2_15=agreement_contract2_7
di 2*normprob(-abs(r(z))) //G15 vs. BG7 (B)
quietly signrank agreement_contract1_15=agreement_contract1_7
di 2*normprob(-abs(r(z))) //G15 vs. BG7 (A)

restore

***6.5 Agreement Times

drop if Game==15 | Game==22

collapse (mean) agreement_time Game session_n Agreement, by(group_index)

gen compromise_effect = inlist(Game, 1, 2, 4, 5, 7, 8, 9, 10, 11, 12, 16, 17, 18)
gen attraction_effect = inlist(Game, 1, 3, 4, 6, 7, 13, 14, 16, 19, 20, 21)
gen base = inlist(Game, 1, 4, 7, 16)
replace compromise_effect = . if base==0 & attraction_effect==1
replace attraction_effect = . if base==0 & compromise_effect ==1

table base if compromise_effect==1, c(mean agreement_time)
table base if attraction_effect ==1, c(mean agreement_time)

di (56.52024-64.78818)/64.78818
di (58.65016-64.78818)/64.78818

preserve
 
egen time_compr_base = mean(agreement_time) if compromise_effect==1 & base==1, by(session_n)
egen time_compr_nobase = mean(agreement_time) if compromise_effect==1 & base==0, by(session_n)

egen time_attr_base = mean(agreement_time) if attraction_effect==1 & base==1, by(session_n)
egen time_attr_nobase = mean(agreement_time) if attraction_effect==1 & base==0, by(session_n)

collapse (mean) time_compr_base time_compr_nobase time_attr_base time_attr_nobase, by(session_n)

quietly signrank time_compr_base=time_compr_nobase
di 2*normprob(-abs(r(z))) //Base vs. CE
quietly signrank time_attr_base=time_attr_nobase
di 2*normprob(-abs(r(z))) //Base vs. AE

restore

*Setting agreement time to 120 if no agreement
preserve
replace agreement_time=120 if Agreement==0

table base if compromise_effect==1, c(mean agreement_time)
table base if attraction_effect ==1, c(mean agreement_time)

di (58.69847-67.02101)/67.02101
di (60.58345-67.02101)/67.02101
 
egen time_compr_base = mean(agreement_time) if compromise_effect==1 & base==1, by(session_n)
egen time_compr_nobase = mean(agreement_time) if compromise_effect==1 & base==0, by(session_n)

egen time_attr_base = mean(agreement_time) if attraction_effect==1 & base==1, by(session_n)
egen time_attr_nobase = mean(agreement_time) if attraction_effect==1 & base==0, by(session_n)

collapse (mean) time_compr_base time_compr_nobase time_attr_base time_attr_nobase, by(session_n)

quietly signrank time_compr_base=time_compr_nobase
di 2*normprob(-abs(r(z))) //Base vs. CE
quietly signrank time_attr_base=time_attr_nobase
di 2*normprob(-abs(r(z))) //Base vs. AE

restore

********************************************************************************
*							MAIN PAPER: EXPERIMENT 2
********************************************************************************

**********8 Findings from Experiment 2

use "$Data\experiment2.dta", clear


***Table 4
preserve

collapse (first) contract1 contract2 contract3 Game (mean) disagreement agreement_contract1 agreement_contract2 agreement_contract3 agreement_time, by(group_index)

collapse (count) Obs=group_index (first) contract1 contract2 contract3 (mean) disagreement agreement_contract1 agreement_contract2 agreement_contract3 agreement_time, by(Game)
// G1, G4, G7, G18, G20 are symmetric:
replace agreement_contract1 = agreement_contract1/2 if Game==1
replace agreement_contract2 = agreement_contract1 if Game==1
replace agreement_contract1 = agreement_contract1/2 if Game==4
replace agreement_contract2 = agreement_contract1 if Game==4
replace agreement_contract1 = agreement_contract1/2 if Game==7
replace agreement_contract2 = agreement_contract1 if Game==7
replace agreement_contract1 = agreement_contract1/2 if Game==18
replace agreement_contract3 = agreement_contract1 if Game==18
replace agreement_contract1 = agreement_contract1/2 if Game==20
replace agreement_contract3 = agreement_contract1 if Game==20

format disagreement agreement_contract1 agreement_contract2 agreement_contract3 agreement_time %9.4g

label variable contract1 "Contract A"
label variable contract2 "Contract B"
label variable contract3 "Contract C"
label variable agreement_contract1 "Agree on A"
label variable agreement_contract2 "Agree on B"
label variable agreement_contract3 "Agree on C"
label variable disagreement "Disagree"
label variable agreement_time "Time to (in sec.)"

export delimited using Results\Table4.csv, nolabel replace datafmt
restore

***Figure 7

//See Results\Figure7.xlsx

***Non-parametric tests

preserve
collapse (mean) disagreement agreement_contract1 agreement_contract2 agreement_contract3 agreement_time, by(session_n Game)
// G1, G4, G7, G18, G20 are symmetric:
replace agreement_contract1 = agreement_contract1/2 if Game==1
replace agreement_contract2 = agreement_contract1 if Game==1
replace agreement_contract1 = agreement_contract1/2 if Game==4
replace agreement_contract2 = agreement_contract1 if Game==4
replace agreement_contract1 = agreement_contract1/2 if Game==7
replace agreement_contract2 = agreement_contract1 if Game==7
replace agreement_contract1 = agreement_contract1/2 if Game==18
replace agreement_contract3 = agreement_contract1 if Game==18
replace agreement_contract1 = agreement_contract1/2 if Game==20
replace agreement_contract3 = agreement_contract1 if Game==20

rename (agreement_contract*) =_

reshape wide agreement_contract1_ agreement_contract2_ agreement_contract3_ disagreement agreement_time, i(session_n) j(Game)

gen compromise_effect = ((agreement_contract2_2 - agreement_contract2_1) + ///
						(agreement_contract2_5 - agreement_contract2_4) + ///
						(agreement_contract2_8 - agreement_contract2_7) + ///
						(agreement_contract2_11 - agreement_contract2_10) + ///
						(agreement_contract2_14 - agreement_contract2_13) + ///
						(agreement_contract2_18 - agreement_contract2_17) + ///
						(agreement_contract2_20 - agreement_contract2_19) + ///
						(agreement_contract2_21 - agreement_contract2_1) + ///
						(agreement_contract2_22 - agreement_contract2_10))/9 ///
						if session_n>5 & session_n!=10 & session_n!=11 & session_n!=12

replace compromise_effect = ((agreement_contract2_2 - agreement_contract2_1) + ///
							(agreement_contract2_8 - agreement_contract2_7) + ///
							(agreement_contract2_11 - agreement_contract2_10) + ///
							(agreement_contract2_14 - agreement_contract2_13) + ///
							(agreement_contract2_18 - agreement_contract2_17) + ///
							(agreement_contract2_20 - agreement_contract2_19) + ///
							(agreement_contract2_21 - agreement_contract2_1) + ///
							(agreement_contract2_22 - agreement_contract2_10))/8 ///
							if session_n<=5 | session_n==10 | session_n==11 | session_n==12
					
gen attraction_effect = ((agreement_contract2_3 - agreement_contract2_1) + ///
						(agreement_contract2_6 - agreement_contract2_4) + ///
						(agreement_contract2_9 - agreement_contract2_7) + ///
						(agreement_contract2_12 - agreement_contract2_10) + ///
						(agreement_contract2_15 - agreement_contract2_13) + ///
						(agreement_contract2_16 - agreement_contract2_13) )/6 ///
						if session_n>5 & session_n!=10 & session_n!=11 & session_n!=12

replace attraction_effect = ((agreement_contract2_3 - agreement_contract2_1) + ///
							(agreement_contract2_9 - agreement_contract2_7) + ///
							(agreement_contract2_12 - agreement_contract2_10) + ///
							(agreement_contract2_15 - agreement_contract2_13) + ///
							(agreement_contract2_16 - agreement_contract2_13) )/5 ///
							if session_n<=5 | session_n==10 | session_n==11 | session_n==12


sum attraction_effect compromise_effect

quietly signrank attraction_effect=0
di normprob(-abs(r(z))) //one-sided p-value

quietly signrank compromise_effect=0
di normprob(-abs(r(z))) //one-sided p-value

quietly signrank agreement_contract2_2 = agreement_contract2_1
di normprob(-abs(r(z))) //G2 vs. BG1 (B)
quietly signrank agreement_contract2_5 = agreement_contract2_4
di normprob(-abs(r(z))) //G5 vs. BG4 (B)
quietly signrank agreement_contract2_8 = agreement_contract2_7
di normprob(-abs(r(z))) //G8 vs. BG7 (B)
quietly signrank agreement_contract2_11 = agreement_contract2_10
di normprob(-abs(r(z))) //G11 vs. BG10 (B)
quietly signrank agreement_contract2_14 = agreement_contract2_13
di normprob(-abs(r(z))) //G14 vs. BG13 (B)
quietly signrank agreement_contract2_18 = agreement_contract2_17
di normprob(-abs(r(z))) //G18 vs. BG17 (B)
quietly signrank agreement_contract2_20 = agreement_contract2_19
di normprob(-abs(r(z))) //G20 vs. BG19 (B)
quietly signrank agreement_contract2_21 = agreement_contract2_1
di normprob(-abs(r(z))) //G21 vs. BG1 (B)
quietly signrank agreement_contract2_22 = agreement_contract2_10
di normprob(-abs(r(z))) //G22 vs. BG10 (B)

quietly signrank agreement_contract2_3 = agreement_contract2_1
di normprob(-abs(r(z))) //G3 vs. BG1 (B)
quietly signrank agreement_contract2_6 = agreement_contract2_4
di normprob(-abs(r(z))) //G6 vs. BG4 (B)
quietly signrank agreement_contract2_9 = agreement_contract2_7
di normprob(-abs(r(z))) //G9 vs. BG7 (B)
quietly signrank agreement_contract2_12 = agreement_contract2_10
di normprob(-abs(r(z))) //G12 vs. BG10 (B)
quietly signrank agreement_contract2_15 = agreement_contract2_13
di normprob(-abs(r(z))) //G15 vs. BG13 (B)
quietly signrank agreement_contract2_16 = agreement_contract2_13
di normprob(-abs(r(z))) //G16 vs. BG13 (B)

*****8.1 Games with an Equal Payoff Contract

quietly signrank agreement_contract2_18 = agreement_contract2_17
di normprob(-abs(r(z))) //G18 vs. BG17 (B)

quietly signrank agreement_contract2_19 = agreement_contract2_17
di 2*normprob(-abs(r(z))) //BG19 vs. BG17 (B)

quietly signrank agreement_contract2_20 = agreement_contract2_19
di normprob(-abs(r(z))) //G20 vs. BG19 (B)

*****8.2 Games with Two Symmetrically Unequal Payoff Contracts

gen compromise_effect_symmetry = ((agreement_contract2_2 - agreement_contract2_1) + ///
								 (agreement_contract2_5 - agreement_contract2_4) + ///
								 (agreement_contract2_8 - agreement_contract2_7) + ///
								 (agreement_contract2_21 - agreement_contract2_1))/4 ///
								 if session_n>5 & session_n!=10 & session_n!=11 & session_n!=12

replace compromise_effect_symmetry = ((agreement_contract2_2 - agreement_contract2_1) + ///
									 (agreement_contract2_8 - agreement_contract2_7) + ///
									 (agreement_contract2_21 - agreement_contract2_1))/3 ///
									 if session_n<=5 | session_n==10 | session_n==11 | session_n==12
					
gen attraction_effect_symmetry = ((agreement_contract2_3 - agreement_contract2_1) + ///
								 (agreement_contract2_6 - agreement_contract2_4) + ///
								 (agreement_contract2_9 - agreement_contract2_7))/3 ///
								 if session_n>5 & session_n!=10 & session_n!=11 & session_n!=12

replace attraction_effect_symmetry = ((agreement_contract2_3 - agreement_contract2_1) + ///
									 (agreement_contract2_9 - agreement_contract2_7))/2 ///
									 if session_n<=5 | session_n==10 | session_n==11 | session_n==12
								 									 
quietly signrank compromise_effect_symmetry=0
di normprob(-abs(r(z))) //one-sided p-value

quietly signrank attraction_effect_symmetry=0
di normprob(-abs(r(z))) //one-sided p-value

quietly signrank agreement_contract2_2 = agreement_contract2_1
di normprob(-abs(r(z))) //G2 vs. BG1 (B)
quietly signrank agreement_contract2_3 = agreement_contract2_1
di normprob(-abs(r(z))) //G3 vs. BG1 (B)

quietly signrank agreement_contract2_5 = agreement_contract2_4
di normprob(-abs(r(z))) //G5 vs. BG4 (B)
quietly signrank agreement_contract2_8 = agreement_contract2_7
di normprob(-abs(r(z))) //G8 vs. BG7 (B)

quietly signrank agreement_contract1_8 = agreement_contract1_7
di normprob(-abs(r(z))) //G8 vs. BG7 (A)
quietly signrank disagreement8 = disagreement7
di 2*normprob(-abs(r(z))) //G8 vs. BG7 (Disagreement)

quietly signrank agreement_contract2_6 = agreement_contract2_4
di normprob(-abs(r(z))) //G6 vs. BG4 (B)
quietly signrank agreement_contract2_9 = agreement_contract2_7
di normprob(-abs(r(z))) //G9 vs. BG7 (B)

*****8.3 Games with Two Asymmetrically Unequal Payoff Contracts

gen compromise_effect_asymm = ((agreement_contract2_11 - agreement_contract2_10) + ///
							  (agreement_contract2_14 - agreement_contract2_13) + ///
							  (agreement_contract2_22 - agreement_contract2_10))/3
					
gen attraction_effect_asymm = ((agreement_contract2_12 - agreement_contract2_10) + ///
							  (agreement_contract2_15 - agreement_contract2_13) + ///
							  (agreement_contract2_16 - agreement_contract2_13))/3

quietly signrank compromise_effect_asymm=0
di normprob(-abs(r(z))) //one-sided p-value

quietly signrank attraction_effect_asymm=0
di normprob(-abs(r(z))) //one-sided p-value

quietly signrank agreement_contract2_10 = agreement_contract2_17
di 2*normprob(-abs(r(z))) //BG10 vs. BG17 (B)

quietly signrank agreement_contract2_11 = agreement_contract2_10
di normprob(-abs(r(z))) //G11 vs. BG10 (B)
quietly signrank agreement_contract2_12 = agreement_contract2_10
di normprob(-abs(r(z))) //G12 vs. BG10 (B)

quietly signrank agreement_contract2_14 = agreement_contract2_13
di normprob(-abs(r(z))) //G14 vs. BG13 (B)
quietly signrank agreement_contract2_15 = agreement_contract2_13
di normprob(-abs(r(z))) //G15 vs. BG13 (B)
quietly signrank agreement_contract2_16 = agreement_contract2_13
di normprob(-abs(r(z))) //G16 vs. BG13 (B)

*****8.4 Games with Extreme Decoys

gen compromise_effect_extreme = ((agreement_contract2_21 - agreement_contract2_1) + ///
								(agreement_contract2_22 - agreement_contract2_10))/2

signrank compromise_effect_extreme=0
di normprob(-abs(r(z))) //one-sided p-value

quietly signrank agreement_contract2_21 = agreement_contract2_1
di normprob(-abs(r(z))) //G21 vs. BG1 (B)
quietly signrank agreement_contract2_22 = agreement_contract2_10
di normprob(-abs(r(z))) //G22 vs. BG10 (B)

quietly signrank agreement_contract2_21 = agreement_contract2_2
di 2*normprob(-abs(r(z))) //G21 vs. G2 (B)
quietly signrank agreement_contract2_22 = agreement_contract2_11
di 2*normprob(-abs(r(z))) //G22 vs. G11 (B)

restore

*****Footnote 33
preserve

collapse (first) session_n contract1 contract2 contract3 Game (mean) disagreement agreement_contract1 agreement_contract2 agreement_contract3 agreement_time, by(group_index)

gen block = 1 if Game<4
replace block = 2 if block==. & Game<7
replace block = 3 if block==. & Game<10
drop if block==.

table block, c(mean disagreement mean agreement_time)

collapse (mean) disagreement agreement_time, by(session_n block)

reshape wide disagreement agreement_time, i(session_n) j(block)

signrank disagreement1=disagreement2
signrank disagreement1=disagreement3
signrank disagreement2=disagreement3

signrank agreement_time1=agreement_time2
signrank agreement_time1=agreement_time3
signrank agreement_time2=agreement_time3

restore

*****Footnote 31

preserve

append using "$Data\experiment1.dta", gen(experiment1)

keep if Game==1 | Game==3

egen session_n_merged = group(session_n experiment1)
egen group_index_merged = group(group_index experiment1)

collapse (first) session_n_merged experiment1 (mean) Game disagreement agreement_contract1 agreement_contract2 agreement_contract3 agreement_time, by(group_index_merged)

collapse (mean) disagreement agreement_contract1 agreement_contract2 agreement_contract3 agreement_time, by(session_n_merged Game)

replace agreement_contract1 = agreement_contract1/2 if Game==1
replace agreement_contract2 = agreement_contract1 if Game==1

rename (agreement_contract*) =_

reshape wide agreement_contract1_ agreement_contract2_ agreement_contract3_ disagreement agreement_time, i(session_n_merged) j(Game)


quietly signrank agreement_contract2_3 = agreement_contract2_1
di normprob(-abs(r(z))) //G3 vs. BG1 (B, pooled experiments)

restore

*****8.5 Agreement Times

***Exp 1 vs. Exp 2
preserve

append using "$Data\experiment1.dta", gen(experiment1)

egen session_n_merged = group(session_n experiment1)
egen group_index_merged = group(group_index experiment1)

keep if (inlist(Game, 1, 2, 3, 16, 18, 20, 7, 10) & experiment1==1) | (inlist(Game, 1, 2, 3, 10, 11, 12, 17, 18) & experiment1==0)

drop if Agreement==0

collapse (first) session_n_merged experiment1 (mean) Game agreement_time, by(group_index_merged)

table experiment1, c(mean agreement_time)

di 69.74643-55.72598

collapse (mean) agreement_time experiment1, by(session_n_merged)

ranksum agreement_time, by(experiment1)

restore

***Exp 2

collapse (mean) agreement_time Game session_n Agreement, by(group_index)

gen compromise_effect = inlist(Game, 1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 17, 18, 19, 20, 21, 22)
gen attraction_effect = inlist(Game, 1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16)
gen base = inlist(Game, 1, 4, 7, 10, 13, 17, 19)
replace compromise_effect = . if base==0 & attraction_effect==1
replace attraction_effect = . if base==0 & compromise_effect ==1
replace attraction_effect = . if Game==17 | Game==19

table base if compromise_effect==1, c(mean agreement_time)
table base if attraction_effect ==1, c(mean agreement_time)

di (57.65739-62.50556)/62.50556
di (62.94781-70.48549)/70.48549     

preserve
 
egen time_compr_base = mean(agreement_time) if compromise_effect==1 & base==1, by(session_n)
egen time_compr_nobase = mean(agreement_time) if compromise_effect==1 & base==0, by(session_n)

egen time_attr_base = mean(agreement_time) if attraction_effect==1 & base==1, by(session_n)
egen time_attr_nobase = mean(agreement_time) if attraction_effect==1 & base==0, by(session_n)

collapse (mean) time_compr_base time_compr_nobase time_attr_base time_attr_nobase, by(session_n)

quietly signrank time_compr_base=time_compr_nobase
di 2*normprob(-abs(r(z))) //Base vs. CE
quietly signrank time_attr_base=time_attr_nobase
di 2*normprob(-abs(r(z))) //Base vs. AE

restore

*Setting agreement time to 120 if no agreement
preserve
replace agreement_time=120 if Agreement==0

table base if compromise_effect==1, c(mean agreement_time)
table base if attraction_effect ==1, c(mean agreement_time)

di (62.13916-66.55718)/66.55718
di (65.55219-74.67637)/74.67637
 
egen time_compr_base = mean(agreement_time) if compromise_effect==1 & base==1, by(session_n)
egen time_compr_nobase = mean(agreement_time) if compromise_effect==1 & base==0, by(session_n)

egen time_attr_base = mean(agreement_time) if attraction_effect==1 & base==1, by(session_n)
egen time_attr_nobase = mean(agreement_time) if attraction_effect==1 & base==0, by(session_n)

collapse (mean) time_compr_base time_compr_nobase time_attr_base time_attr_nobase, by(session_n)

quietly signrank time_compr_base=time_compr_nobase
di 2*normprob(-abs(r(z))) //Base vs. CE
quietly signrank time_attr_base=time_attr_nobase
di 2*normprob(-abs(r(z))) //Base vs. AE

restore

********************************************************************************
*								APPENDIX
********************************************************************************

********** C Analysis of Chat Conversations

use "$Data\chat_coding_data.dta", clear

*****Table C1

gen compromise = 1 if game==2 | game==5 | game==8 | game==9 | game==10 | game==11 | game == 12 | game==17 | game==18
gen attraction = 1 if game==3 | game==6 | game==13 | game==14 | game==19 | game==20 | game==21
gen base = 1 if game==1 | game==4 | game==7 | game==16

matrix TableC1 = J(13,9,.)

local myvars compr bboff possdisagr rps fairness standoff costbenefit sumearnings pastfut impoor begenerous offtopic
local i = 1
foreach x of newlist `myvars' {
	kap `x'1 `x'2
	matrix TableC1[`i',1] = round(r(kappa),.001)
	sum avg_`x'
	matrix TableC1[`i',2] = round(r(mean),.001)
	sum avg_`x' if no_chat==0
	matrix TableC1[`i',3] = round(r(mean),.001)
	sum avg_`x' if base==1
	matrix TableC1[`i',4] = round(r(mean),.001)
	sum avg_`x' if no_chat==0 & base==1
	matrix TableC1[`i',5] = round(r(mean),.001)
	sum avg_`x' if compromise==1
	matrix TableC1[`i',6] = round(r(mean),.001)
	sum avg_`x' if no_chat==0 & compromise==1
	matrix TableC1[`i',7] = round(r(mean),.001)
	sum avg_`x' if attraction==1
	matrix TableC1[`i',8] = round(r(mean),.001)
	sum avg_`x' if no_chat==0 & attraction==1
	matrix TableC1[`i',9] = round(r(mean),.001)
	local i = `i'+1
}

sum no_chat
matrix TableC1[13,2] = round(r(mean),.001)
sum no_chat if base==1
matrix TableC1[13,4] = round(r(mean),.001)
sum no_chat if compromise==1
matrix TableC1[13,6] = round(r(mean),.001)
sum no_chat if attraction==1
matrix TableC1[13,8] = round(r(mean),.001)

matrix rownames TableC1 = "COMPR" "BBOFF" "POSSDISAGR" "RPS" "FAIRNESS" "STANDOFF" "COSTBENEFIT" "SUMEARNINGS" "PASTFUT" "I'M POOR" "BE GENEROUS" "OFF TOPIC" "NO CHAT"

mat list TableC1

putexcel set $Results\TableC1.csv, sheet("TableC1") replace
putexcel A1=matrix(TableC1), names

*****Table C2

preserve
collapse (mean) avg_compr avg_bboff avg_possdisagr avg_rps avg_fairness avg_standoff ///
				avg_costbenefit avg_sumearnings avg_pastfut avg_impoor avg_begenerous avg_offtopic no_chat, by(game)

mkmat avg_compr avg_bboff avg_possdisagr avg_rps avg_fairness avg_standoff avg_costbenefit ///
	  avg_sumearnings avg_pastfut avg_impoor avg_begenerous avg_offtopic no_chat, matrix(temp)

mat TableC2	= temp'  
putexcel set $Results\TableC2.csv, sheet("TableC2") replace
putexcel A1=matrix(TableC2), names
restore

*****Table C3

gen game_type = 1 if base==1
replace game_type = 2 if compromise==1
replace game_type = 3 if attraction==1
replace game_type = 4 if game_type==.

label define game_typel 1 "Base" 2 "Compromise" 3 "Attraction" 4 "Strict dominance" 
label values game_type game_typel 

egen session_n = group(session)
xtset session_n

***At least one coder
local myvars compr bboff possdisagr rps fairness standoff costbenefit sumearnings pastfut impoor begenerous offtopic
foreach x of newlist `myvars' {
	quietly xtlogit avg_`x' c.period b1.game_type
	margins, dydx(*) post
	estimates store `x', title(`x')
}

xtlogit no_chat c.period b1.game_type
margins, dydx(*) post
estimates store nochat, title(nochat)

esttab compr bboff possdisagr rps fairness standoff costbenefit sumearnings pastfut impoor begenerous offtopic nochat using "$Results\TableC3.rtf", b(%9.3f) se(%9.3f)  legend label varlabels(_cons Constant) starlevels(* 0.10 ** 0.05 *** 0.01) nobaselevels replace noobs

***Assistant who coded all sessions
local myvars compr bboff possdisagr rps fairness standoff costbenefit sumearnings pastfut impoor begenerous offtopic
foreach x of newlist `myvars' {
	quietly xtlogit `x'2 c.period b1.game_type
	margins, dydx(*) post
	estimates store `x', title(`x')
}

xtlogit no_chat c.period b1.game_type
margins, dydx(*) post
estimates store nochat, title(nochat)

esttab compr bboff possdisagr rps fairness standoff costbenefit sumearnings pastfut impoor begenerous offtopic using "$Results\TableC3.rtf", b(%9.3f) se(%9.3f)  legend label varlabels(_cons Constant) starlevels(* 0.10 ** 0.05 *** 0.01) nobaselevels append noobs

***Only if both coders agree
gen y = .

local myvars compr bboff possdisagr rps fairness standoff costbenefit sumearnings pastfut impoor begenerous offtopic
foreach x of newlist `myvars' {
	replace y = avg_`x'
	replace y = 0 if y<1
	quietly xtlogit y c.period b1.game_type
	margins, dydx(*) post
	estimates store `x', title(`x')
}

esttab compr bboff possdisagr rps fairness standoff costbenefit sumearnings pastfut impoor begenerous offtopic using "$Results\TableC3.rtf", b(%9.3f) se(%9.3f)  legend label varlabels(_cons Constant) starlevels(* 0.10 ** 0.05 *** 0.01) nobaselevels append noobs

***Sequential logit
local myvars compr bboff possdisagr rps fairness costbenefit sumearnings pastfut impoor begenerous offtopic
foreach x of newlist `myvars' {
	quietly xtlogit avg_`x' c.period b1.game_type if no_chat==0
	margins, dydx(*) post
	estimates store `x', title(`x')
}

esttab compr bboff possdisagr rps fairness standoff costbenefit sumearnings pastfut impoor begenerous offtopic using "$Results\TableC3.rtf", b(%9.3f) se(%9.3f)  legend label varlabels(_cons Constant) starlevels(* 0.10 ** 0.05 *** 0.01) nobaselevels append noobs

*****Table C4

gen agreement_on_target = 1 						if agreement_contract2==1 & (game==2 | game==3 | game==10 | ///
													   game==11 | game==12 | game==14 | ///
													   game==15 | game==18 | game==19 | game==20  | game==22)

replace agreement_on_target = 0 					if agreement_contract1==1 & (game==2 | game==3 | game==10 | ///
													   game==11 | game==12 | game==14 | ///
													   game==15 | game==18 | game==19 | game==20  | game==22)

replace agreement_on_target = 1					 	if agreement_contract1==1 & (game==5 | game==6 | game==8 | ///
													   game==9 | game==13 | game==17 | ///
													   game==21)

replace agreement_on_target = 0					 	if agreement_contract2==1 & (game==5 | game==6 | game==8 | ///
													   game==9 | game==13 | game==17 | ///
													   game==21)										  									   
													   
matrix TableC4 = J(13,5,.)

local myvars compr bboff possdisagr rps fairness standoff costbenefit sumearnings pastfut impoor begenerous offtopic
local i = 1
foreach x of newlist `myvars' {
	sum avg_`x' if disagreement==1
	matrix TableC4[`i',1] = round(r(mean),.001)
	sum avg_`x' if compromise==1 & agreement_on_target==1
	matrix TableC4[`i',2] = round(r(mean),.001)
	sum avg_`x' if compromise==1 & agreement_on_target==0
	matrix TableC4[`i',3] = round(r(mean),.001)
	sum avg_`x' if attraction==1 & agreement_on_target==1
	matrix TableC4[`i',4] = round(r(mean),.001)
	sum avg_`x' if attraction==1 & agreement_on_target==0
	matrix TableC4[`i',5] = round(r(mean),.001)
	local i = `i'+1
}

sum no_chat if disagreement==1
matrix TableC4[13,1] = round(r(mean),.001)
sum no_chat if compromise==1 & agreement_on_target==1
matrix TableC4[13,2] = round(r(mean),.001)
sum no_chat if compromise==1 & agreement_on_target==0
matrix TableC4[13,3] = round(r(mean),.001)
sum no_chat if attraction==1 & agreement_on_target==1
matrix TableC4[13,4] = round(r(mean),.001)
sum no_chat if attraction==1 & agreement_on_target==0
matrix TableC4[13,5] = round(r(mean),.001)

local myvars compr bboff possdisagr rps fairness standoff costbenefit sumearnings pastfut impoor begenerous offtopic no_chat
tokenize `myvars' 
matrix rownames TableC4 = `myvars'
matrix colnames TableC4 = Disagreement TargetCompr NoTargetCompr TargetAttr NoTargetAttr 
matlist TableC4

preserve
clear
svmat TableC4, names(col)
export delimited using Results\TableC4.csv, nolabel replace datafmt
restore

*****Table C5

matrix TableC5 = J(13,36,.)

local myvars compr bboff possdisagr rps fairness standoff costbenefit sumearnings pastfut impoor begenerous offtopic
local i = 1
foreach x of newlist `myvars' {
	local z = 1
	foreach j of numlist 2 3 5 6 8(1)15 17(1)22{
		sum avg_`x' if game==`j' & agreement_on_target==1
		matrix TableC5[`i',`z'] = round(r(mean),.0001)
		sum avg_`x' if game==`j' & agreement_on_target==0
		matrix TableC5[`i',`z'+1] = round(r(mean),.0001)
		local z = `z'+2
	}
	local i = `i'+1
}

local z = 1
foreach j of numlist 2 3 5 6 8(1)15 17(1)22{
	sum no_chat if game==`j' & agreement_on_target==1
	matrix TableC5[13,`z'] = round(r(mean),.0001)
	sum no_chat if game==`j' & agreement_on_target==0
	matrix TableC5[13,`z'+1] = round(r(mean),.0001)
	local z = `z'+2
}


local myvars compr bboff possdisagr rps fairness standoff costbenefit sumearnings pastfut impoor begenerous offtopic nochat
tokenize `myvars' 
matrix rownames TableC5 = `myvars'
matlist TableC5

preserve
clear
svmat TableC5, names(col)
export delimited using Results\TableC5.csv, nolabel replace datafmt
restore

*****Footnote 8 of Appendix C

gen no_chat_when_agree_on_A = no_chat if agreement_contract1==1
gen no_chat_when_agree_on_B =  no_chat if agreement_contract2==1

collapse (mean) no_chat_when_agree_on_A no_chat_when_agree_on_B, by(game session)

replace no_chat_when_agree_on_A = no_chat_when_agree_on_A /2 if game==1
replace no_chat_when_agree_on_B = no_chat_when_agree_on_A if game==1

reshape wide no_chat_when_agree_on_A no_chat_when_agree_on_B, i( session) j(game)

gen attraction_effect = 0

forvalue i=1(1)`=_N'{


	local mylist no_chat_when_agree_on_B3[`i']-no_chat_when_agree_on_B1[`i'] no_chat_when_agree_on_A6[`i']-no_chat_when_agree_on_A4[`i'] no_chat_when_agree_on_A13[`i']-no_chat_when_agree_on_A7[`i'] no_chat_when_agree_on_B14[`i']-no_chat_when_agree_on_B7[`i'] no_chat_when_agree_on_B19[`i']-no_chat_when_agree_on_B16[`i'] no_chat_when_agree_on_B20[`i']-no_chat_when_agree_on_B16[`i'] no_chat_when_agree_on_A21[`i']-no_chat_when_agree_on_A16[`i']

	local obs = 0

	foreach x of local mylist{

		if (`x'!= .){
			local obs = `obs' + 1
			replace attraction_effect = attraction_effect[`i'] + `x' in `i'
		}

	}

	replace attraction_effect = attraction_effect[`i']/`obs' in `i'

}

sum attraction_effect
signrank attraction_effect=0

gen compromise_effect = 0

forvalue i=1(1)`=_N'{


	local mylist no_chat_when_agree_on_B2[`i']-no_chat_when_agree_on_B1[`i'] no_chat_when_agree_on_A5[`i']-no_chat_when_agree_on_A4[`i'] no_chat_when_agree_on_A8[`i']-no_chat_when_agree_on_A7[`i'] no_chat_when_agree_on_A9[`i']-no_chat_when_agree_on_A7[`i'] no_chat_when_agree_on_B10[`i']-no_chat_when_agree_on_B7[`i'] no_chat_when_agree_on_B11[`i']-no_chat_when_agree_on_B7[`i'] no_chat_when_agree_on_B12[`i']-no_chat_when_agree_on_B7[`i'] no_chat_when_agree_on_A17[`i']-no_chat_when_agree_on_A16[`i'] no_chat_when_agree_on_B18[`i']-no_chat_when_agree_on_B16[`i']

	local obs = 0

	foreach x of local mylist{

		if (`x'!= .){
			local obs = `obs' + 1
			replace compromise_effect = compromise_effect[`i'] + `x' in `i'
		}

	}

	replace compromise_effect = compromise_effect[`i']/`obs' in `i'

}

sum compromise_effect
signrank compromise_effect=0

********** F Learning Effects

*****Figures F1 and F2

***Experiment 1

use "$Data\experiment1.dta", clear

collapse (mean) disagreement agreement_contract1 agreement_contract2 agreement_contract3 agreement_time Game Period session_n, by(group_index)

gen f_target = agreement_contract2 if inlist(Game, 2, 3, 10, 11, 12, 14, 15, 18, 19, 20, 22)
replace f_target = agreement_contract1 if inlist(Game, 5, 6, 8, 9, 13, 17, 21)

gen f_contract1_base = agreement_contract1 if inlist(Game, 1, 4, 7, 16)
gen f_contract2_base = agreement_contract2 if inlist(Game, 4, 7, 16)

replace f_contract1_base = f_contract1_base/2 if Game==1

gen Period2 = floor((Period-1)/2)+1

label define periodlabel 1 "1,2" 2 "3,4" 3 "5,6" 4 "7,8" 5 "9,10" 6 "11,12" 7 "13,14" 8 "15,16" 9 "17,18" 10 "19,20" 11 "21,22"
label values Period2 periodlabel
  
preserve
collapse (mean) f_target f_contract1_base f_contract2_base , by(Period2 Game)
sort Game Period

forvalue i=1(1)22{
	capture noisily spearman f_target Period2 if Game==`i' 
}

twoway connected f_target f_contract1_base f_contract2_base Period2, by(Game, note("") graphregion(color(white))) graphregion(color(white)) ///
legend(label(1 "Agreements on target") label(2 "Agreements on A (base games)") label(3 "Agreements on B (base games)") size(small)) xtitle("Rounds") ///
xlabel(1(2)11, valuelabel angle(45))
graph export Results\FigureF1a.png, replace

restore

preserve
collapse (mean) disagreement, by(Period)
sort Period

twoway connected disagreement Period, color(black) graphregion(color(white)) title("Rate of disagreement") xtitle("Rounds") ylabel(0(0.02)0.2) xlabel(1(3)22)
graph export Results\FigureF2a.png, replace

restore

***Experiment 2

use "$Data\experiment2.dta", clear

collapse (mean) disagreement agreement_contract1 agreement_contract2 agreement_contract3 agreement_time Game Period session_n, by(group_index)

gen f_target = agreement_contract2 if inlist(Game, 2, 3, 5, 6, 8, 9, 11, 12, 14, 15, 16, 18, 20, 21, 22)

gen f_contract1_base = agreement_contract1 if inlist(Game, 1, 4, 7, 10, 13, 17, 19)
gen f_contract2_base = agreement_contract2 if inlist(Game, 10, 13, 17, 19)

replace f_contract1_base = f_contract1_base/2 if inlist(Game, 1, 4, 7)

gen Period2 = floor((Period-1)/2)+1

label define periodlabel 1 "1,2" 2 "3,4" 3 "5,6" 4 "7,8" 5 "9,10" 6 "11,12" 7 "13,14" 8 "15,16" 9 "17,18" 10 "19,20" 11 "21,22"
label values Period2 periodlabel
  
preserve
collapse (mean) f_target f_contract1_base f_contract2_base , by(Period2 Game)
sort Game Period

forvalue i=1(1)22{
	capture noisily spearman f_target Period2 if Game==`i' 
}

twoway connected f_target f_contract1_base f_contract2_base Period2, by(Game, note("") graphregion(color(white))) graphregion(color(white)) ///
legend(label(1 "Agreements on target") label(2 "Agreements on A (base games)") label(3 "Agreements on B (base games)") size(small)) xtitle("Rounds") ///
xlabel(1(2)11, valuelabel angle(45))
graph export Results\FigureF1b.png, replace

restore

preserve
collapse (mean) disagreement, by(Period)
sort Period

twoway connected disagreement Period, color(black) graphregion(color(white)) title("Rate of disagreement") xtitle("Rounds") ylabel(0(0.02)0.2)  xlabel(1(3)22)
graph export Results\FigureF2b.png, replace

restore

********** G Agreement Times

*****G.1 Experiment 1

use "$Data\experiment1.dta", clear

collapse (mean) agreement_time Game session_n disagreement Agreement, by(group_index)

table Game if Agreement==1, c(mean agreement_time)

preserve
collapse (mean) agreement_time, by(session_n Game)

reshape wide agreement_time, i(session_n) j(Game)

signrank agreement_time4=agreement_time7
signrank agreement_time16=agreement_time7
signrank agreement_time1=agreement_time4
signrank agreement_time1=agreement_time7
signrank agreement_time1=agreement_time16

signrank agreement_time4=agreement_time5
signrank agreement_time4=agreement_time6
signrank agreement_time1=agreement_time2
signrank agreement_time1=agreement_time3
restore

preserve
gen Games_8_15 = Game>=8 & Game<=15
keep if Games_8_15==1 | Game==7
collapse (mean) agreement_time disagreement, by(session_n Games_8_15)
reshape wide agreement_time disagreement, i(session_n) j(Games_8_15)
signrank agreement_time0=agreement_time1
signrank disagreement0=disagreement1
restore

preserve
gen Games_17_22 = Game>=17 & Game<=22
keep if Games_17_22==1 | Game==16
collapse (mean) agreement_time disagreement, by(session_n Games_17_22)
reshape wide agreement_time disagreement, i(session_n) j(Games_17_22)
signrank agreement_time0=agreement_time1
signrank disagreement0=disagreement1
restore

drop if Game==15 | Game==22

gen compromise_effect = inlist(Game, 1, 2, 4, 5, 7, 8, 9, 10, 11, 12, 16, 17, 18)
gen attraction_effect = inlist(Game, 1, 3, 4, 6, 7, 13, 14, 16, 19, 20, 21)
gen base = inlist(Game, 1, 4, 7, 16)
replace compromise_effect = . if base==0 & attraction_effect==1
replace attraction_effect = . if base==0 & compromise_effect ==1

table base if compromise_effect==1, c(mean agreement_time)
table base if attraction_effect ==1, c(mean agreement_time)

di (56.52024-64.78818)/64.78818
di (58.65016-64.78818)/64.78818

preserve
 
egen time_compr_base = mean(agreement_time) if compromise_effect==1 & base==1, by(session_n)
egen time_compr_nobase = mean(agreement_time) if compromise_effect==1 & base==0, by(session_n)

egen time_attr_base = mean(agreement_time) if attraction_effect==1 & base==1, by(session_n)
egen time_attr_nobase = mean(agreement_time) if attraction_effect==1 & base==0, by(session_n)

collapse (mean) time_compr_base time_compr_nobase time_attr_base time_attr_nobase, by(session_n)

quietly signrank time_compr_base=time_compr_nobase
di 2*normprob(-abs(r(z))) //Base vs. CE
quietly signrank time_attr_base=time_attr_nobase
di 2*normprob(-abs(r(z))) //Base vs. AE

restore

*Setting agreement time to 120 if no agreement
preserve
replace agreement_time=120 if Agreement==0

table base if compromise_effect==1, c(mean agreement_time)
table base if attraction_effect ==1, c(mean agreement_time)

di (58.69847-67.02101)/67.02101
di (60.58345-67.02101)/67.02101
 
egen time_compr_base = mean(agreement_time) if compromise_effect==1 & base==1, by(session_n)
egen time_compr_nobase = mean(agreement_time) if compromise_effect==1 & base==0, by(session_n)

egen time_attr_base = mean(agreement_time) if attraction_effect==1 & base==1, by(session_n)
egen time_attr_nobase = mean(agreement_time) if attraction_effect==1 & base==0, by(session_n)

collapse (mean) time_compr_base time_compr_nobase time_attr_base time_attr_nobase, by(session_n)

quietly signrank time_compr_base=time_compr_nobase
di 2*normprob(-abs(r(z))) //Base vs. CE
quietly signrank time_attr_base=time_attr_nobase
di 2*normprob(-abs(r(z))) //Base vs. AE

restore

*****G.2 Experiment 2

use "$Data\experiment2.dta", clear

***Exp 1 vs. Exp 2
preserve

append using "$Data\experiment1.dta", gen(experiment1)

egen session_n_merged = group(session_n experiment1)
egen group_index_merged = group(group_index experiment1)

keep if (inlist(Game, 1, 2, 3, 16, 18, 20, 7, 10) & experiment1==1) | (inlist(Game, 1, 2, 3, 10, 11, 12, 17, 18) & experiment1==0)

drop if Agreement==0

collapse (first) session_n_merged experiment1 (mean) Game agreement_time, by(group_index_merged)

table experiment1, c(mean agreement_time)

di 69.74643-55.72598

collapse (mean) agreement_time experiment1, by(session_n_merged)

ranksum agreement_time, by(experiment1)

restore

***Exp 2

collapse (mean) agreement_time Game session_n disagreement Agreement, by(group_index)

table Game if Agreement==1, c(mean agreement_time)

preserve
collapse (mean) agreement_time, by(session_n Game)

reshape wide agreement_time, i(session_n) j(Game)

signrank agreement_time10=agreement_time17
signrank agreement_time10=agreement_time1
signrank agreement_time17=agreement_time1
signrank agreement_time1=agreement_time2
signrank agreement_time1=agreement_time3
signrank agreement_time10=agreement_time11
signrank agreement_time10=agreement_time12
signrank agreement_time17=agreement_time18

signrank agreement_time1=agreement_time4
signrank agreement_time1=agreement_time7
signrank agreement_time13=agreement_time10
signrank agreement_time19=agreement_time17

signrank agreement_time4=agreement_time5
signrank agreement_time4=agreement_time6

signrank agreement_time7=agreement_time8
signrank agreement_time7=agreement_time9
signrank agreement_time19=agreement_time20

signrank agreement_time13=agreement_time14
signrank agreement_time13=agreement_time15
signrank agreement_time13=agreement_time16

signrank agreement_time1=agreement_time21
signrank agreement_time10=agreement_time22

restore

gen compromise_effect = inlist(Game, 1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 17, 18, 19, 20, 21, 22)
gen attraction_effect = inlist(Game, 1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16)
gen base = inlist(Game, 1, 4, 7, 10, 13, 17, 19)
replace compromise_effect = . if base==0 & attraction_effect==1
replace attraction_effect = . if base==0 & compromise_effect ==1
replace attraction_effect = . if Game==17 | Game==19

table base if compromise_effect==1, c(mean agreement_time)
table base if attraction_effect ==1, c(mean agreement_time)

di (57.65739-62.50556)/62.50556
di (62.94781-70.48549)/70.48549     

preserve
 
egen time_compr_base = mean(agreement_time) if compromise_effect==1 & base==1, by(session_n)
egen time_compr_nobase = mean(agreement_time) if compromise_effect==1 & base==0, by(session_n)

egen time_attr_base = mean(agreement_time) if attraction_effect==1 & base==1, by(session_n)
egen time_attr_nobase = mean(agreement_time) if attraction_effect==1 & base==0, by(session_n)

collapse (mean) time_compr_base time_compr_nobase time_attr_base time_attr_nobase, by(session_n)

quietly signrank time_compr_base=time_compr_nobase
di 2*normprob(-abs(r(z))) //Base vs. CE
quietly signrank time_attr_base=time_attr_nobase
di 2*normprob(-abs(r(z))) //Base vs. AE

restore

*Setting agreement time to 120 if no agreement
preserve
replace agreement_time=120 if Agreement==0

table base if compromise_effect==1, c(mean agreement_time)
table base if attraction_effect ==1, c(mean agreement_time)

di (62.13916-66.55718)/66.55718
di (65.55219-74.67637)/74.67637
 
egen time_compr_base = mean(agreement_time) if compromise_effect==1 & base==1, by(session_n)
egen time_compr_nobase = mean(agreement_time) if compromise_effect==1 & base==0, by(session_n)

egen time_attr_base = mean(agreement_time) if attraction_effect==1 & base==1, by(session_n)
egen time_attr_nobase = mean(agreement_time) if attraction_effect==1 & base==0, by(session_n)

collapse (mean) time_compr_base time_compr_nobase time_attr_base time_attr_nobase, by(session_n)

quietly signrank time_compr_base=time_compr_nobase
di 2*normprob(-abs(r(z))) //Base vs. CE
quietly signrank time_attr_base=time_attr_nobase
di 2*normprob(-abs(r(z))) //Base vs. AE

restore

********** H Econometric Analysis

*****Table H1
use "$Data\experiment2.dta", clear

gen Experiment=2

append using "$Data\Experiment1.dta"

replace Experiment=1 if Experiment==.

egen session = group(session_n Experiment)

egen group_index2 = group(group_index Experiment)

collapse (mean) agreement_contract1 agreement_contract2 agreement_contract3 Game session Experiment, by(group_index2)

preserve

collapse (mean) agreement_contract1 agreement_contract2 agreement_contract3, by(session Game Experiment)

// G1 and G10 in Exp1 are symmetric:
replace agreement_contract1 = agreement_contract1/2 if Game==1 & Experiment==1
replace agreement_contract2 = agreement_contract1 if Game==1 & Experiment==1
replace agreement_contract1 = agreement_contract1/2 if Game==10 & Experiment==1
replace agreement_contract3 = agreement_contract1 if Game==10 & Experiment==1

// G1, G4, G7, G18, G20 in Exp 2 are symmetric:
replace agreement_contract1 = agreement_contract1/2 if Game==1 &  Experiment==2
replace agreement_contract2 = agreement_contract1 if Game==1 &  Experiment==2
replace agreement_contract1 = agreement_contract1/2 if Game==4 &  Experiment==2
replace agreement_contract2 = agreement_contract1 if Game==4 &  Experiment==2
replace agreement_contract1 = agreement_contract1/2 if Game==7 &  Experiment==2
replace agreement_contract2 = agreement_contract1 if Game==7 &  Experiment==2
replace agreement_contract1 = agreement_contract1/2 if Game==18 &  Experiment==2
replace agreement_contract3 = agreement_contract1 if Game==18 &  Experiment==2
replace agreement_contract1 = agreement_contract1/2 if Game==20 &  Experiment==2
replace agreement_contract3 = agreement_contract1 if Game==20 &  Experiment==2

rename (agreement_contract*) =_

reshape wide agreement_contract1_ agreement_contract2_ agreement_contract3_, i( session) j(Game)

gen effect2 = (agreement_contract2_2 - agreement_contract2_1) if Experiment==1
gen effect3 = (agreement_contract2_3 - agreement_contract2_1) if Experiment==1
gen effect5 = (agreement_contract1_5 - agreement_contract1_4) if Experiment==1
gen effect6 = (agreement_contract1_6 - agreement_contract1_4) if Experiment==1
gen effect8 = (agreement_contract1_8 - agreement_contract1_7) if Experiment==1
gen effect9 = (agreement_contract1_9 - agreement_contract1_7) if Experiment==1
gen effect10 = (agreement_contract2_10 - agreement_contract2_7) if Experiment==1
gen effect11 = (agreement_contract2_11 - agreement_contract2_7) if Experiment==1
gen effect12 = (agreement_contract2_12 - agreement_contract2_7) if Experiment==1
gen effect13 = (agreement_contract1_13 - agreement_contract1_7) if Experiment==1
gen effect14 = (agreement_contract2_14 - agreement_contract2_7) if Experiment==1
gen effect17 = (agreement_contract1_17 - agreement_contract1_16) if Experiment==1
gen effect18 = (agreement_contract2_18- agreement_contract2_16) if Experiment==1
gen effect19 = (agreement_contract2_19 - agreement_contract2_16) if Experiment==1
gen effect20 = (agreement_contract2_20 - agreement_contract2_16) if Experiment==1
gen effect21 = (agreement_contract1_21 - agreement_contract1_16) if Experiment==1

replace effect2 = (agreement_contract2_2 - agreement_contract2_1) if Experiment==2
replace effect3 = (agreement_contract2_3 - agreement_contract2_1) if Experiment==2
replace effect5 = (agreement_contract2_5 - agreement_contract2_4) if Experiment==2
replace effect6 = (agreement_contract2_6 - agreement_contract2_4) if Experiment==2
replace effect8 = (agreement_contract2_8 - agreement_contract2_7) if Experiment==2
replace effect9 = (agreement_contract2_9 - agreement_contract2_7) if Experiment==2
replace effect11 = (agreement_contract2_11 - agreement_contract2_10) if Experiment==2
replace effect12 = (agreement_contract2_12 - agreement_contract2_10) if Experiment==2
replace effect14 = (agreement_contract2_14 - agreement_contract2_13) if Experiment==2
gen effect15 = (agreement_contract2_15 - agreement_contract2_13) if Experiment==2
gen effect16 = (agreement_contract2_16 - agreement_contract2_13) if Experiment==2
replace effect18 = (agreement_contract2_18 - agreement_contract2_17) if Experiment==2
replace effect20 = (agreement_contract2_20 - agreement_contract2_19) if Experiment==2
replace effect21 = (agreement_contract2_21 - agreement_contract2_1) if Experiment==2
gen effect22 = (agreement_contract2_22 - agreement_contract2_10) if Experiment==2

drop agreement_contract*

reshape long effect, i(session) j(Game)

gen attraction = (Game==3 | Game==6 | Game==13 | Game==14 | Game==19 | Game==20 | Game==21) if Experiment==1
gen target_equality = (Game==10 | Game==11 | Game==12 | Game==14) if Experiment==1
gen non_target_equality = (Game==5 | Game==6 | Game==8 | Game==9 | Game==13) if Experiment==1
gen target_more_unequality = (Game==17 | Game==21) if Experiment==1

replace attraction = (Game==3 | Game==6 | Game==9 | Game==12 | Game==15 | Game==16) if Experiment==2
gen target_equality_more_foc = (Game==18) if Experiment==2
gen target_equality_less_foc = (Game==20) if Experiment==2
gen extremeness = (Game==21 | Game==22) if Experiment==2

replace target_equality_more_foc = (Game==10 | Game==11 | Game==12 | Game==14) if Experiment==1
replace non_target_equality=0 if Experiment==2
replace target_more_unequality =0 if Experiment==2
replace extremeness =0 if Experiment==1
replace target_equality_less_foc =0 if Experiment==1

gen conflict = (Game==8 | Game==9) & Experiment==2

label variable attraction  "AE" 
label variable target_equality_more_foc "Target gives equal payoffs"
label variable non_target_equality "Other base contract gives equal payoffs"
label variable target_more_unequality "Target gives the most unequal payoffs"
label variable extremeness "Extreme decoy"
label variable conflict "High conflict"
label variable target_equality_less_foc "Target gives equal but smaller payoffs"

quietly eststo clear
quietly eststo, title("Model 1"): reg effect i.attraction if Experiment==1, cluster(session) cformat(%9.3f) pformat(%5.3f) sformat(%8.3f)
quietly test _cons + 1.attraction = 0
di r(p)/2
quietly eststo, title("Model 2"): reg effect i.attraction##i.target_equality_more_foc i.attraction##i.non_target_equality i.attraction##i.target_more_unequality if Experiment==1, cluster(session) cformat(%9.3f) pformat(%5.3f) sformat(%8.3f)
quietly test _cons + 1.attraction = 0
di r(p)/2
quietly eststo, title("Model 3"): reg effect i.attraction if Experiment==2, cluster(session) cformat(%9.3f) pformat(%5.3f) sformat(%8.3f)
quietly test _cons + 1.attraction = 0
di r(p)/2
quietly eststo, title("Model 4"): reg effect i.attraction i.target_equality_more_foc i.target_equality_less_foc extremeness conflict if Exp==2, cluster(session) cformat(%9.3f) pformat(%5.3f) sformat(%8.3f)
quietly test _cons + 1.attraction = 0
di r(p)/2
quietly eststo, title("Model 5"): reg effect i.attraction, cluster(session) cformat(%9.3f) pformat(%5.3f) sformat(%8.3f)
quietly test _cons + 1.attraction = 0
di r(p)/2
quietly eststo, title("Model 6"): reg effect i.attraction##i.target_equality_more_foc i.target_equality_less_foc i.attraction##i.non_target_equality ///
i.attraction##i.target_more_unequality extremeness conflict, cluster(session) cformat(%9.3f) pformat(%5.3f) sformat(%8.3f)
quietly test _cons + 1.attraction = 0
di r(p)/2


esttab, 							se starlevels(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(3)) se(par fmt(3))) ///
									stats(r2 N, fmt(3 0) labels("R-squared" "Obs")) legend label varlabels(_cons "Constant (CE)") ///
									replace nobaselevels interaction(" $\times$ ") mlabels(none) mgroups("Experiment 1" ///
									"Experiment 2" "Both Experiments", pattern(1 0 1 0 1 0) ///
									prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))



esttab using "Results\TableH1.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(3)) se(par fmt(3))) ///
									stats(r2 N, fmt(3 0) labels("R-squared" "Obs")) legend label varlabels(_cons "Constant (CE)") ///
									replace nobaselevels interaction(" $\times$ ") mlabels(none) mgroups("Experiment 1" ///
									"Experiment 2" "Both Experiments", pattern(1 0 1 0 1 0) ///
									prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

***p-values and joint test
quietly reg effect i.attraction##i.target_equality_more_foc i.attraction##i.non_target_equality i.attraction##i.target_more_unequality if Experiment==1, cluster(session) cformat(%9.3f) pformat(%5.3f) sformat(%8.3f)
test _cons=0
test 1.target_equality_more_foc=0
test 1.target_equality_more_foc+_cons=0
test 1.non_target_equality=0
test 1.non_target_equality+_cons=0
test 1.target_more_unequality=0
test 1.target_more_unequality+_cons=0

quietly reg effect i.attraction i.target_equality_more_foc i.target_equality_less_foc extremeness conflict if Exp==2, cluster(session) cformat(%9.3f) pformat(%5.3f) sformat(%8.3f)
test _cons=0
test conflict=0
test conflict+_cons=0
test 1.target_equality_less_foc=0
test 1.target_equality_less_foc+_cons=0
test 1.target_equality_more_foc=0
test 1.target_equality_more_foc+_cons=0
test extremeness=0
test extremeness+_cons=0

restore
