REPRO-Bench / 26 /replication_package /doFiles /dataManagementExpB.do
anonymous-submission-acl2025's picture
add 26
dd8d986
clear all
// insheet the data
if 1 {
insheet using "data/raw/expBbatch1.csv", names
drop if _n <= 2 // drop lines added by qualtrics
gen batch = 1
gen id = _n + 1000*batch
destring, replace
rename treatment fined /*DZ: fined=1 designates treated with BLB intervention.*/
drop if _n == 1 // dropping text line that qualtrics adds
destring, replace
gen attrited = finlit3 ~= . & impl111_impl11_1 == .
gen attritedLate = q182 ~= . & impl111_impl11_1 == .
save "data/batch1.dta", replace
clear
insheet using "data/raw/expBbatch2.csv", names
drop if _n <= 2 // drop lines added by qualtrics
gen batch = 2
gen id = _n + 1000*batch
destring, replace
rename treatment fined /*DZ: fined=1 designates treated with BLB intervention.*/
drop if _n == 1 // dropping text line that qualtrics adds
destring, replace
gen attrited = finlit3 ~= . & impl111_impl11_1 == .
gen attritedLate = q182 ~= . & impl111_impl11_1 == .
save "data/batch2.dta", replace
clear
use "data/batch1.dta", replace
append using "data/batch2.dta"
save "data/dataRaw.dta", replace
}
use "data/dataRaw.dta", replace
//
** find switching points
// strategy:
// 1. reshape
// 2. order
// 3. gen variable in order starting from 35, going down
// 4. gen second variable, set to missing if choice was 1, to order otherwise, egen min of these
// 5. gen third variable, set to missing if choice was 2, to order otherwise, egen max of those
// 6. check for single switch by comparing whether max + 1 == min
***************************************************************************************************************
forvalues i = 1/10 {
gen s`i' = 0
}
replace s1 = 1 if test1 == 2
replace s2 = 1 if test2 == 4
replace s3 = 1 if test3 == 4
replace s4 = 1 if test4 == 7
replace s5 = 1 if test5 == 6
replace s6 = 1 if test6 == 4
replace s7 = 1 if test7 == 5
replace s8 = 1 if test8 == 5
replace s9 = 1 if test9 == 5
replace s10 = 1 if test10 == 1
gen score = s1+s2+s3+s4+s5+s6+s7+s8+s9+s10
preserve
/*rename sc0_0 score*/
gen pay_test = payment_for_test <= 25
keep ip id amt_id gender age ethnicity educ marital urban income employed hh_size stocks rule72* calculate line1 line2 amt1 amt2 decision_index pay_test payment_for_test fined finlit* att* help_test test* startdate enddate durationinseconds time* score
save "data/dataNon_MPL.dta", replace
restore
*****************************************************************************************************************8
keep id impl*
forvalues i = 1 / 20 {
rename impl`i'11_impl`i'1_1 impl`i'_1
rename impl`i'11_impl`i'1_2 impl`i'_2
rename impl`i'11_impl`i'1_3 impl`i'_3
rename impl`i'11_impl`i'1_4 impl`i'_4
rename impl`i'11_impl`i'1_5 impl`i'_5
rename impl`i'11_impl`i'1_6 impl`i'_6
rename impl`i'11_impl`i'1_7 impl`i'_7
rename impl`i'11_impl`i'1_8 impl`i'_8
rename impl`i'11_impl`i'1_9 impl`i'_9
rename impl`i'11_impl`i'1_10 impl`i'_10
rename impl`i'11_impl`i'1_11 impl`i'_11
}
keep impl1_* impl2_* impl3_* impl4_* impl5_* impl6_* impl7_* impl8_* impl9_* impl10_* impl11_* impl12_* impl13_* impl14_* impl15_* impl16_* impl17_* impl18_* impl19_* impl20_* id
reshape long impl1_ impl2_ impl3_ impl4_ impl5_ impl6_ impl7_ impl8_ impl9_ impl10_ impl11_ impl12_ impl13_ impl14_ impl15_ impl16_ impl17_ impl18_ impl19_ impl20_, i(id) j(line 1-11)
forvalues i = 1 / 20 {
rename impl`i'_ impl`i'
}
sort id line
gen sum_multi_switch_1 = 0
local varlist impl1
forvalues i=2/20 {
local varlist `varlist' impl`i'
}
** first pricelist
foreach var in `varlist' { /*At this point varlist includes impl1, impl2, ... impl20*/
gen line_left = line
gen line_right = line
replace line_left = . if `var' == 1
replace line_right = . if `var' == 0
by id: egen switch_low = max(line_left)
by id: egen switch_high = min(line_right)
by id: egen mll = max(line_left)
by id: egen mlr = min(line_right)
gen multi_switch_`var' = 1 - (switch_high == 1 + switch_low)
replace multi_switch_`var' = 0 if switch_high == 11 | switch_high == . | switch_low == 1 | switch_low == .
gen value_`var' = switch_high
replace value_`var' = . if multi_switch_`var' == 1
replace value_`var' = 0 if mlr == 1 //case where all right selected
replace value_`var' = 12 if mll == 11 // case where all left selected
replace sum_multi_switch_1 = sum_multi_switch_1 + multi_switch_`var'
drop line_left
drop line_right
drop switch_high
drop switch_low
drop mll
drop mlr
gen value_coarse_`var' = 20 - 2*(value_`var'-1)
}
preserve
drop value_impl*
drop impl*
collapse (mean) value* sum_multi* (max) multi*, by(id)
save "data/data_Coarse.dta", replace
restore
***********************************
*** fine valuations ***************
***********************************
clear all
set more off
use "data/dataRaw.dta"
keep id impl*
forvalues i = 1 / 20 {
rename impl`i'21_impl`i'2_3 impl`i'_1
rename impl`i'21_impl`i'2_4 impl`i'_2
rename impl`i'21_impl`i'2_5 impl`i'_3
rename impl`i'21_impl`i'2_6 impl`i'_4
rename impl`i'21_impl`i'2_7 impl`i'_5
rename impl`i'21_impl`i'2_8 impl`i'_6
rename impl`i'21_impl`i'2_9 impl`i'_7
rename impl`i'21_impl`i'2_10 impl`i'_8
rename impl`i'21_impl`i'2_11 impl`i'_9
rename impl`i'21_impl`i'2_12 impl`i'_10
}
keep impl1_* impl2_* impl3_* impl4_* impl5_* impl6_* impl7_* impl8_* impl9_* impl10_* impl11_* impl12_* impl13_* impl14_* impl15_* impl16_* impl17_* impl18_* impl19_* impl20_* id
reshape long impl1_ impl2_ impl3_ impl4_ impl5_ impl6_ impl7_ impl8_ impl9_ impl10_ impl11_ impl12_ impl13_ impl14_ impl15_ impl16_ impl17_ impl18_ impl19_ impl20_ , i(id) j(line 1-10)
forvalues i = 1 / 20 {
rename impl`i'_ impl`i'
}
sort id line
gen sum_multi_switch_2 = 0
local varlist impl1
forvalues i=2/20 {
local varlist `varlist' impl`i'
}
** second pricelist
foreach var in `varlist' {
gen line_left = line
gen line_right = line
replace line_left = . if `var' == 1
replace line_right = . if `var' == 0
by id: egen switch_low = max(line_left)
by id: egen switch_high = min(line_right)
by id: egen mll = max(line_left)
by id: egen mlr = min(line_right)
gen multi_switch_`var' = 1 - (switch_high == 1 + switch_low)
replace multi_switch_`var' = 0 if (switch_high == 1 & switch_low == .) | (switch_high == . & switch_low == 10)
gen value_`var' = switch_low
replace value_`var' = . if multi_switch_`var' == 1
replace value_`var' = 0 if mlr == 1 //case where all right selected
replace value_`var' = 10 if mll == 10 // case where all left selected
replace sum_multi_switch_2 = sum_multi_switch_2 + multi_switch_`var'
drop line_left
drop line_right
drop switch_high
drop switch_low
drop mll
drop mlr
gen value_fine_`var' = 1.8 - 0.2*value_`var'
replace value_fine_`var' = 0 if value_fine_`var' < 0
}
drop value_impl*
drop impl*
collapse (mean) value* sum_multi* (max) multi*, by(id)
save "data/data_Fine.dta", replace
***********************************
*** merge datasets ***************
***********************************
clear all
use "data/data_Fine.dta"
merge 1:1 id using "data/data_Coarse.dta"
drop _merge
merge 1:1 id using "data/dataNon_MPL.dta"
drop _merge
/*DZ: Slight change in naming of variables.*/
forvalues i = 1/20 {
gen value`i' = value_coarse_impl`i' + value_fine_impl`i'
rename time`i'1_firstclick timeFirstClick`i'
rename time`i'1_lastclick timeLastClick`i'
rename time`i'1_pagesubmit timeSubmit`i'
rename time`i'1_clickcount numClicks`i'
}
***********************************
gen multi = 0
forvalues i = 1 / 20 {
replace multi = 1 if multi_switch_impl`i' == 1
replace multi = 1 if sum_multi_switch_1 == 1 | sum_multi_switch_2 == 1
}
drop multi_*
drop value_*
reshape long value timeFirstClick timeLastClick timeSubmit numClicks, i(id) j(treatment)
gen framed = treatment > 10
gen delay = 72
replace delay = 36 if treatment >=6 & treatment <= 10
replace delay = 36 if treatment == 11 | treatment == 13 | treatment == 15 | treatment == 17 | treatment == 19
gen amount = 20
replace amount = 18 if treatment == 2 | treatment == 7 | treatment == 14 | treatment == 13
replace amount = 16 if treatment == 3 | treatment == 8 | treatment == 16 | treatment == 15
replace amount = 14 if treatment == 4 | treatment == 9 | treatment == 18 | treatment == 17
replace amount = 12 if treatment == 5 | treatment == 10 | treatment == 20 | treatment == 19
gen amount_precise = amount
// rename treatments such that #framed = #unframed + 10
gen tr_new = tr
replace tr_new = 1 if treat == 6
replace tr_new = 2 if treat == 1
replace tr_new = 3 if treat == 7
replace tr_new = 4 if treat == 2
replace tr_new = 5 if treat == 8
replace tr_new = 6 if treat == 3
replace tr_new = 7 if treat == 9
replace tr_new = 8 if treat == 4
replace tr_new = 9 if treat == 10
replace tr_new = 10 if treat == 5
rename treatment tr_old
rename tr_new treatment
replace treatment = treatment - 10 if framed == 1
replace amount_precise = 20.40 if treatment == 11 | treatment == 1
replace amount_precise = 20.47 if treatment == 12 | treatment == 2
replace amount_precise = 18.47 if treatment == 13 | treatment == 3
replace amount_precise = 18.73 if treatment == 14 | treatment == 4
replace amount_precise = 16.29 if treatment == 15 | treatment == 5
replace amount_precise = 16.80 if treatment == 16 | treatment == 6
replace amount_precise = 14.37 if treatment == 17 | treatment == 7
replace amount_precise = 15.16 if treatment == 18 | treatment == 8
replace amount_precise = 11.58 if treatment == 19 | treatment == 9
replace amount_precise = 11.83 if treatment == 20 | treatment == 10
gen id_alt = 1000*id+treatment
sort id_alt
order id_alt delay treatment tr_old
drop tr_old
reshape wide value timeFirstClick timeLastClick timeSubmit numClicks, i(id_alt) j(framed)
rename value0 v_unframed
rename value1 v_framed
rename timeFirstClick0 timeFirstClickUnframed
rename timeFirstClick1 timeFirstClickFramed
rename timeLastClick0 timeLastClickUnframed
rename timeLastClick1 timeLastClickFramed
rename timeSubmit0 timeSubmitUnframed
rename timeSubmit1 timeSubmitFramed
rename numClicks0 numClicksUnframed
rename numClicks1 numClicksFramed
gen difficulty = 0
replace difficulty = 1 if treatment >= 3 & treatment <= 8
replace difficulty = 2 if treatment >= 9
gen start = 10
replace start = 4.5 if treatment == 3 | treatment == 4
replace start = 2 if treatment == 5 | treatment == 6 | treatment == 9 | treatment == 10
replace start = 0.9 if treatment == 7 | treatment == 8
gen r = .
replace r = 0.02 if treatment == 1
replace r = 0.01 if treatment == 2
replace r = 0.04 if treatment == 3
replace r = 0.02 if treatment == 4
replace r = 0.06 if treatment == 5
replace r = 0.03 if treatment == 6
replace r = 0.08 if treatment == 7
replace r = 0.04 if treatment == 8
replace r = 0.05 if treatment == 9
replace r = 0.25 if treatment == 10
gen doublings = 1
replace doublings = 2 if treatment == 3 | treatment == 4
replace doublings = 3 if treatment == 5 | treatment == 6
replace doublings = 4 if treatment == 7 | treatment == 8
replace doublings = 2.5 if treatment == 9 | treatment == 10
replace age = age + 17
forvalues i = 1/10 {
gen t`i' = 0
}
replace t1 = 1 if test1 == 2
replace t2 = 1 if test2 == 4
replace t3 = 1 if test3 == 4
replace t4 = 1 if test4 == 7
replace t5 = 1 if test5 == 6
replace t6 = 1 if test6 == 4
replace t7 = 1 if test7 == 4
replace t8 = 1 if test8 == 5
replace t9 = 1 if test9 == 5
replace t10 = 1 if test10 == 5
gen score_compounding = t1+t2+t3+t4+t5
gen score_indexing = score - score_compounding
gen fl1 = finlit1 == 1
gen fl2 = finlit2 == 1
gen fl3 = finlit3 == 3
gen fl4 = finlit4 == 1
gen fl5 = finlit5 == 2
gen fl_score = (fl1 == 1) * (fl2 == 1) * (fl3 == 1) * (fl4 == 1) * (fl5 == 1)
gen fl_sum = (fl1 == 1) + (fl2 == 1) + (fl3 == 1) + (fl4 == 1) + (fl5 == 1)
gen fl_score_compound = (fl1 == 1) * (fl2 == 1) * (fl3 == 1)
gen fl_sum_compound = (fl1 == 1) + (fl2 == 1) + (fl3 == 1)
gen size_error_simple = .
replace size_error_simple = 3.20 if treatment == 1
replace size_error_simple = 3.27 if treatment == 2
replace size_error_simple = 7.49 if treatment == 3
replace size_error_simple = 7.75 if treatment == 4
replace size_error_simple = 9.97 if treatment == 5
replace size_error_simple = 10.48 if treatment == 6
replace size_error_simple = 10.88 if treatment == 7
replace size_error_simple = 11.66 if treatment == 8
replace size_error_simple = 5.98 if treatment == 9
replace size_error_simple = 6.23 if treatment == 10
// use midpoint of the interval for analysis
replace v_framed = v_framed + 0.1
replace v_unframed = v_unframed + 0.1
replace v_framed = 0 if v_framed <= 0
replace v_unframed = 0 if v_unframed <= 0
************ monotonicity violations
sort id
gen v_u_1_i = v_unframed if amount == 12
gen v_u_2_i = v_unframed if amount == 14
gen v_u_3_i = v_unframed if amount == 16
gen v_u_4_i = v_unframed if amount == 18
gen v_u_5_i = v_unframed if amount == 20
by id: egen v_u_1 = max(v_u_1_i)
by id: egen v_u_2 = max(v_u_2_i)
by id: egen v_u_3 = max(v_u_3_i)
by id: egen v_u_4 = max(v_u_4_i)
by id: egen v_u_5 = max(v_u_5_i)
gen monotonic_u = (v_u_1 <= v_u_2 & v_u_2 <= v_u_3 & v_u_3 <= v_u_4 & v_u_4 <= v_u_5)
gen v_f_1_i = v_framed if amount == 12
gen v_f_2_i = v_framed if amount == 14
gen v_f_3_i = v_framed if amount == 16
gen v_f_4_i = v_framed if amount == 18
gen v_f_5_i = v_framed if amount == 20
by id: egen v_f_1 = max(v_f_1_i)
by id: egen v_f_2 = max(v_f_2_i)
by id: egen v_f_3 = max(v_f_3_i)
by id: egen v_f_4 = max(v_f_4_i)
by id: egen v_f_5 = max(v_f_5_i)
gen monotonic_f = (v_f_1 <= v_f_2 & v_f_2 <= v_f_3 & v_f_3 <= v_f_4 & v_f_4 <= v_f_5)
egen tag_id = tag(id)
gen duration = durationinseconds/60 /* duration in minutes */
gen afram = ethnicity == 1
gen asian = ethnicity == 2
gen caucasian = ethnicity == 3
gen hispanic = ethnicity == 4
gen other = ethnicity == 5
gen lessThanHighSchool = educ <= 2
gen highSchool = educ == 3
gen voc = educ == 4
gen someCollege = educ == 5
gen college = educ == 6
gen graduate = educ >= 7
gen rural = urban == 3
gen urbanSuburban = urban <= 2
gen fullTime = employed == 3
gen partTime = employed == 2
gen hh1 = hh_size == 1
gen hh2 = hh_size == 2
gen hh3 = hh_size == 3
gen hh4 = hh_size >= 4
gen married = marital == 3 | marital == 4
gen widowed = marital == 6
gen divorced = marital == 1
gen never_married = marital == 2 | marital == 5
gen ownStocks = stocks == 1
drop line1 line2 decision_index
drop if test10 == .
save "data/dataExpB.dta", replace