File size: 17,307 Bytes
dd8d986 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
clear all
******* bring Qualtrics data into stata format
insheet using "data/raw/expAbatch1.csv", names
gen id = _n
drop if id == 1
replace id = id - 1 + 1000
destring, replace
rename treatment fined
save "data/raw_1.dta", replace
clear
insheet using "data/raw/expAbatch2.csv", names
gen id = _n
drop if id == 1
replace id = id - 1 + 2000
drop excluded
destring, replace
rename treatment fined
save "data/raw_2.dta", replace
clear
insheet using "data/raw/expAbatch3.csv", names
gen id = _n
drop if id == 1
replace id = id - 1 + 3000
destring, replace
drop excluded
rename treatment fined
replace fined = 2 if fined == 1 // 2 is substance only
replace fined = 3 if fined == 0 // 3 is rhetoric only
save "data/raw_3.dta", replace
clear
insheet using "data/raw/expAbatch4.csv", names
gen id = _n
drop if id == 1
replace id = id - 1 + 4000
destring, replace
drop excluded
rename treatment fined
save "data/raw_4.dta", replace
clear
insheet using "data/raw/expAbatch5.csv", names
gen id = _n
drop if id == 1
replace id = id - 1 + 5000
destring, replace
drop excluded
rename treatment fined
save "data/raw_5.dta", replace
clear
insheet using "data/raw/expAbatch6.csv", names
gen id = _n
drop if id == 1
replace id = id - 1 + 6000
destring, replace
drop excluded
rename treatment fined
replace fined = 2 if fined == 1 // 2 is substance only
replace fined = 3 if fined == 0 // 3 is rhetoric only
save "data/raw_6.dta", replace
clear
insheet using "data/raw/expAbatch7.csv", names
gen id = _n
drop if id == 1
replace id = id - 1 + 7000
destring, replace
drop excluded
rename treatment fined
replace fined = 2 if fined == 1 // 2 is substance only
replace fined = 3 if fined == 0 // 3 is rhetoric only
save "data/raw_7.dta", replace
clear
insheet using "data/raw/expAbatch8.csv", names
gen id = _n
drop if id == 1
replace id = id - 1 + 8000
destring, replace
drop excluded
rename treatment fined
replace fined = 2 if fined == 1 // 2 is substance only
replace fined = 3 if fined == 0 // 3 is rhetoric only
drop codewt
drop codetreat
save "data/raw_8.dta", replace
clear
use "data/raw_1.dta"
append using "data/raw_2.dta"
append using "data/raw_3.dta"
append using "data/raw_4.dta"
append using "data/raw_5.dta"
append using "data/raw_6.dta"
append using "data/raw_7.dta"
append using "data/raw_8.dta"
rename v6 ip
rename v8 startDate
rename v9 endDate
***** attrition
gen attrited = help_test == .
gen attrition_before_video = q120 == .
gen started_video = (q124 == 1 | q125 == 1)
preserve
keep id attrited attrition_before_video started_video fined
save "data/attrition.dta", replace
restore
drop if help_test == .
drop attrited attrition_before_video started_video
save "data/raw_all.dta", replace
** find switching points
// strategy:
// 1. reshape
// 2. order
// 3. generate variable in order starting from 35, going down
// 4. generate second variable, set to missing if choice was 1, to order otherwise, egen min of these
// 5. generate 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
preserve
rename sc0_0 score
gen pay_test = payment_for_test <= 25
keep id ip 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 score fined finlit* att* help_test test* startDate endDate time*
save "data/non_MPL.dta", replace
restore
keep id impl*
forvalues i = 1 / 20 {
rename impl`i'_1_11 impl`i'_1
rename impl`i'_1_21 impl`i'_2
rename impl`i'_1_31 impl`i'_3
rename impl`i'_1_41 impl`i'_4
rename impl`i'_1_51 impl`i'_5
rename impl`i'_1_61 impl`i'_6
rename impl`i'_1_71 impl`i'_7
rename impl`i'_1_81 impl`i'_8
rename impl`i'_1_91 impl`i'_9
rename impl`i'_1_101 impl`i'_10
rename impl`i'_1_111 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 for each delayed reward
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 == 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
// second pricelist for each delayed reward
clear all
set more off
use "data/raw_all.dta"
keep id impl*
forvalues i = 1 / 20 {
rename impl`i'_2_31 impl`i'_1
rename impl`i'_2_41 impl`i'_2
rename impl`i'_2_51 impl`i'_3
rename impl`i'_2_61 impl`i'_4
rename impl`i'_2_71 impl`i'_5
rename impl`i'_2_81 impl`i'_6
rename impl`i'_2_91 impl`i'_7
rename impl`i'_2_101 impl`i'_8
rename impl`i'_2_111 impl`i'_9
rename impl`i'_2_121 impl`i'_10
drop impl`i'_1_*
}
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'
}
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/non_MPL.dta"
drop _merge
forvalues i = 1/20 {
gen value`i' = value_coarse_impl`i' + value_fine_impl`i'
rename time`i'1_1 timeFirstClick`i'
rename time`i'1_2 timeLastClick`i'
rename time`i'1_3 timeSubmit`i'
rename time`i'1_4 numClicks`i'
}
// Label variables conveniently
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_* 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 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 == 3
replace t7 = 1 if test7 == 4
replace t8 = 1 if test8 == 2
replace t9 = 1 if test9 == 3
replace t10 = 1 if test10 == 3
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
merge m:1 id using "data/attrition.dta"
gen double startTime = clock(startDate, "YMDhms")
gen double endTime = clock(endDate, "YMDhms")
gen double duration = endTime - startTime
replace duration = duration / (1000*60) // duration in minutes
drop line1 line2 decision_index
gen fl_high = fl_score_compound == 1
gen discount_unframed = v_unframed/amount * 100
gen discount_framed = v_framed/amount_precise * 100
gen discount_framed_72 = v_framed/amount * 100
sort id delay
by id delay: egen min_discount_unframed = min(discount_unframed)
by id delay: egen max_discount_unframed = max(discount_unframed)
gen diff = discount_framed - discount_unframed
gen diff72 = discount_framed - discount_unframed
gen min_diff = discount_framed - min_discount_unframed
gen max_diff = discount_framed - max_discount_unframed
gen abs_diff = - abs(diff)
gen sq_diff = - (diff/100)^2*100
gen sq_diff72 = - (diff72/100)^2*100
gen sq_diff_up = - (diff/100)^2*100
gen sq_diff_down = - (diff/100)^2*100
replace sq_diff_up = 0 if diff > 0
replace sq_diff_down = 0 if diff < 0
sort id
by id: egen mean_diff = mean(diff)
gen sq_mean_diff = - (mean_diff/100)^2*100
gen sq_mean_diff_up = - (mean_diff/100)^2*100
gen sq_mean_diff_down = - (mean_diff/100)^2*100
replace sq_mean_diff_up = 0 if mean_diff > 0
replace sq_mean_diff_down = 0 if mean_diff < 0
gen sqrt_diff = - sqrt(abs(diff)/100)*100
gen abs_min_diff = - abs(min_diff)
gen abs_max_diff = - abs(max_diff)
gen sq_min_diff = -(min_diff/100)^2*100
gen sq_max_diff = -(max_diff/100)^2*100
gen CVa = min(sq_min_diff, sq_max_diff)
gen CVb = max(sq_min_diff, sq_max_diff)
replace CVb = 0 if discount_framed <= max_discount_unframed & discount_framed >= min_discount_unframed
gen asy_diff_up = diff
replace asy_diff_up = 0 if diff > 0
gen asy_diff_down = - diff
replace asy_diff_down = 0 if diff < 0
sort id delay
by id delay: egen mean_disc = mean(discount_unframed)
gen r72 = rule72 == 1
gen r72inv = rule72_inv == 1
// generate treatment dummies
gen Control = fined == 0 // Control
gen Full = fined == 1 // Full
gen Rule72 = fined == 2 // Substance Only
gen Rhetoric = fined == 3 // Rhetoric Only
label define treatment 0 "Control" 1 "Full Treatment" 2 "Only Rule of 72" 3 "Only Rhetoric"
label values fined treatment
// measures of noise and inattention
sort id delay
by id delay: egen sdV = sd(v_framed)
by id: egen mean_sdV = mean(sdV)
gen slope_unframed = .
gen slope_framed = .
gen corr_unframed_framed = .
gen r2_unframed_framed = .
drop if id == -1
egen id3 = group(id)
su id3
local max = r(max)
forvalues i = 1/`max' {
capture: reg discount_unframed amount if id3 == `i'
capture: replace slope_unframed = _b[amount] if id3 == `i'
capture: reg discount_framed amount_precise if id3 == `i'
capture: replace slope_framed = _b[amount_precise] if id3 == `i'
capture: reg discount_framed discount_unframed if id3 == `i'
capture: replace corr_unframed_framed = _b[discount_unframed] if id3 == `i'
capture: replace r2_unframed_framed = e(r2) if id3 == `i'
}
su slope_unframed, d
gen lowSlope25 = slope_unframed <= r(p25)
gen lowSlope50 = slope_unframed <= r(p50)
gen lowSlope75 = slope_unframed <= r(p75)
***** Demographic variables
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
gen fl_high_remaining = fl4 == 1 & fl5 == 1
gen was_married = widowed == 1 | divorced == 1
gen highSchoolOrLess = highSchool == 1 | lessThanHighSchool == 1
gen vocOrSomeCollege = voc == 1 | someCollege == 1
gen hh3to5 = hh_size >= 2 & hh_size <= 5
gen hhGeq6 = hh_size >= 6
replace income = income / 1000
egen tag = tag(id)
save "data/dataExpA.dta", replace
|