File size: 56,225 Bytes
b6c95bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
*** PARAMETER ESTIMATES FOR Carrera, Royer, Stehr, Sydnor, and Taubinsky (2021)
*******************************************************************************

*** Initial set-up ***
clear
set more off

*** Set directories for data and output ***
cd "$main/Output"
/* Note: outputs to the working directory. Uses a program from 

   master_do_file_for_analysis.do */


*** Load and clean experimental data ******************************************

*** Load dataset ***
use "$main/Data/cleaned_commitment_study_data", clear

*** Variable Creation & Cleaning Steps ***
*** Create an ID variable for use when reshaping long 
gen id = _n

*** Generate info treatment indicators
gen first_info = type_of_info=="1-onlygraph" 
gen new_info = type_of_info=="2-graphplus" 
gen control_info = (new_info == 0 & first_info == 0) 

*** Generate wave indicators
gen wave1 = (wave == "fall") 
gen wave2 = (wave == "winter")
gen wave3 = (wave == "spring")

*** Define anticommitment/commitment variables for each threshold
gen anticommit8 = q170 ==2 if q170<.
gen commit8 = q169 ==2 if q169<.
gen anticommit12 = chose_anticommit11
gen commit12 = chose_commit12
gen anticommit16 = q296==2 if q296<.
gen commit16 = q295 ==2 if q295<.

*** Generate additional variables ***
/*** These variables are the amounts, per attendance, by which a person 

"overpays" for the increase in incentive. Second-order approximation */
gen delta1=(wtp1) - (days_1+days_0)/2
gen delta2 = (wtp2-wtp1) - (days_2+days_1)/2
gen delta3=(wtp3-wtp2) - (days_3+days_2)/2
gen delta5=(wtp5-wtp3)/(5-3) - (days_5+days_3)/2
gen delta7=(wtp7-wtp5)/(7-5) - (days_7+days_5)/2
gen delta12=(wtp12-wtp7)/(12-7) - (days_12+days_7)/2

gen avg_delta = (delta1 + delta2+delta3 + delta5 + delta7 + delta12)/6
gen avg_delta_ex1 = (delta2+delta3 + delta5 + delta7 + delta12)/5

*** Change in days by incentive
gen diffa1=(days_1-days_0)
gen diffa2=(days_2-days_1)
gen diffa3=(days_3-days_2)
gen diffa5=(days_5-days_3)/2
gen diffa7=(days_7-days_5)/2
gen diffa12=(days_12-days_7)/5
gen avg_diffa=(diffa1+diffa2+diffa3+diffa5+diffa7+diffa12)/6
gen avg_diffa_ex1=(diffa2+diffa3+diffa5+diffa7+diffa12)/5

*** Indicator for rejecting 12+ visits contract
gen nocommit12 = !commit12

*** Generate estimates for graphing below ***
foreach k in 0 1 2 3 5 7 12{

	foreach cdtn in "" "&commit12==1" "&first_info!=1" "&commit12==1&first_info!=1"{
	
		if "`cdtn'" == "" loc n ""
		else if "`cdtn'" == "&commit12==1" loc n "_c12"
		else if "`cdtn'" == "&first_info!=1" loc n "_inf"
		else loc n "_infc12"

		ci means days_`k' if flag_exclude_exog==0&flag_low_wtp==0 `cdtn'
		* Store estimates in unique variables
		local mean = r(mean)
		local ub = r(ub)
		local lb = r(lb)
		gen mean_days`n'_`k' = `mean'
		gen ub_days`n'_`k' = `ub'
		gen lb_days`n'_`k' = `lb'
		

		if `k' != 1 & `k' != 3 & `k' != 12{
			ci means visits if incentive == `k' &flag_exclude_exog==0& ///
				flag_low_wtp==0 `cdtn'
			* Store estimates in unique variables
			local mean = r(mean)
			local ub = r(ub)
			local lb = r(lb)
			gen mean_visits`n'_`k' = `mean'
			gen ub_visits`n'_`k' = `ub'
			gen lb_visits`n'_`k' = `lb'
			
			if "`n'" == "_inf"{
				* Store number of observations
				if `k' == 0 loc num "zero"
				else if `k' == 2 loc num "two"
				else if `k' == 5 loc num "five"
				else loc num "seven"
				latex_write incentive`num'infobs `r(N)' numbers
				}
			}
		}
	}
	
*For heterogeneity analysis
sum commit12 if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.
loc totalobs = r(N)
sum commit12 if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&(control_info==1|new_info==1)
loc obs : di %5.0fc `r(N)'
latex_write minfoavgobspe `obs' numbers
loc obs : di %5.0fc `totalobs'-`r(N)'
latex_write infodropobs `obs' numbers
sum commit12 if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&(control_info==1|new_info==1)&flag_confusion!=1
loc obs : di %5.0fc `r(N)'
latex_write minfoavgnoconfusedobspe `obs' numbers

*** Reshape data and generate additional variables ***
preserve
reshape long days_ mean_days_ ub_days_ lb_days_ ///
	mean_visits_ ub_visits_ lb_visits_ ///
	mean_days_c12_ ub_days_c12_ lb_days_c12_ ///
	mean_visits_c12_ ub_visits_c12_ lb_visits_c12_ ///
	mean_days_inf_ ub_days_inf_ lb_days_inf_ ///
	mean_visits_inf_ ub_visits_inf_ lb_visits_inf_ ///
	mean_days_infc12_ ub_days_infc12_ lb_days_infc12_ ///
	mean_visits_infc12_ ub_visits_infc12_ lb_visits_infc12_, i(id) j(prize)
rename days_ days
gen prize2=prize^2
gen incentivesq=incentive^2

gen visits12=visits>=12
gen getcommit=treatment=="threshold80_12"

** Create programs to write to latex file **
** NOTE: these are specific to the commands run below **
cap program drop latex_write_gmm latex_write_nlcom 

program define latex_write_gmm
loc obs : di %5.0fc `e(N_clust)'
latex_write `1'obspe `obs' `2'
loc k = 1 // lambda is in the first position
foreach param in lambda betatilde b beta {
	if `k' == 1 loc fig : di %4.3f [`param']_cons
	else loc fig : di %4.2f [`param']_cons // store estimate
	latex_write `param'`1' `fig' `2'
	matrix temp = e(V)
	loc lb : di %4.2f [`param']_cons - invnormal(0.975)*sqrt(el(temp,`k',`k'))
	loc ub : di %4.2f [`param']_cons + invnormal(0.975)*sqrt(el(temp,`k',`k'))
	loc ci : di "(`lb', `ub')"
	latex_write `param'`1'CI "`ci'" `2'
	loc ++k
	}
end

program define latex_write_nlcom
	matrix tempb = r(b)
	matrix tempv = r(V)
	loc fig : di %4.2f tempb[1,1]
	loc lb : di %4.2f tempb[1,1] - invnormal(0.975)*sqrt(tempv[1,1])
	loc ub : di %4.2f tempb[1,1] + invnormal(0.975)*sqrt(tempv[1,1])
	loc ci : di "(`lb', `ub')"
	latex_write `1' `fig' `2'
	latex_write `1'CI "`ci'" `2'
end


********** Structural estimates ***********************************************

foreach v in "" "+5" "-10" "+0"{ // minimal cost draws of 0, -5, and 10

*declare locals for naming different versions & storing results
if "`v'" == ""{
	loc o ""
	loc lx "numbers_struct"
	}
else if "`v'" == "+5"{
	loc o "V"
	loc lx "numbers_struct_appx"
	}
else if "`v'" == "-10"{
	loc o "X"
	loc lx "numbers_struct_appx"
	}
else{
	loc o "noconfused"
	loc lx "numbers_struct_appx"
	drop if flag_confusion==1 // dropping those flagged for possible confusion
	}

********* Overall estimates ***************************************************
gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
if flag_low_wtp==0&flag_exclude_exog==0&incentive!=., ///
instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
latex_write_gmm all`o' `lx' // store estimates

*actual internality:
nlcom (1-[beta]_cons)*[b]_cons
latex_write_nlcom aintall`o' `lx' // store estimates

*naivete statistic:
nlcom (1-[betatilde]_cons)/(1-[beta]_cons)
latex_write_nlcom naiveall`o' `lx' // store estimates

*expected cost
nlcom 1/[lambda]_cons
latex_write_nlcom expcostall`o' `lx' // store estimate


if "`v'" == ""{ // only for baseline
*compute approx. error in behavior change premium from assumptions
foreach p in 1 2 3 5 7{ // baseline incentive level

	*increase in incentive
	if `p' == 1 | `p' == 2 loc delta = 1
	else if `p' == 3 | `p' == 5 loc delta = 2
	else loc delta = 5
	
	* compute error numerator
	loc error_numerator = ///
		`delta' - ( ( exp(-[lambda]_cons*[betatilde]_cons*([b]_cons + `p')) / ([lambda]_cons*[betatilde]_cons) ) * (1 - exp(-[lambda]_cons*[betatilde]_cons*`delta')) ) - ///
		( `delta' * ( 1 - ( exp(-[lambda]_cons*[betatilde]_cons*([b]_cons + `p')) * ( (1 + exp(-[lambda]_cons*[betatilde]_cons*`delta')) / 2 ) ) ) )
		
	* compute error denominator
	loc error_denominator = ///
		( (1 - [betatilde]_cons) * ( [b]_cons*exp(-[lambda]_cons*[betatilde]_cons*([b]_cons + `p')) ) * (1 - exp(-[lambda]_cons*[betatilde]_cons*`delta')) ) + ///
		( (1 - [betatilde]_cons) * exp(-[lambda]_cons*[betatilde]_cons*[b]_cons) * ( `p' + ( (1/([lambda]_cons*[betatilde]_cons)) * (1 - (1 + ([lambda]_cons*[betatilde]_cons*`delta'))*exp(-[lambda]_cons*[betatilde]_cons*`delta') ) ) ) )
		
	*compute the error in percentage terms
	loc error : di %4.2f abs(`error_numerator'/`error_denominator')*100
	
	* export error
	if `p' == 1 & `delta' == 1 loc errorname "poneDone"
	else if `p' == 2 & `delta' == 1 loc errorname "ptwoDone"
	else if `p' == 3 & `delta' == 2 loc errorname "pthreeDtwo"
	else if `p' == 5 & `delta' == 2 loc errorname "pfiveDtwo"
	else loc errorname "psevenDfive"
	latex_write `errorname'error `error' numbers_struct 
	
	}
}

*generate 95% CIs for model values 
if "`v'" == ""{ // generate plotting variable in the first loop only
	global obs = _N
	loc num = _N+241
	set obs `num'
	gen plot_incentive = .
	forval i = 0(.05)12.05{
		qui replace plot_incentive = `i' if _n == $obs + (`i'*20) + 1
		}
	}
if "`v'" != "+0"{
	predictnl mean_days_pred`o' = 28*(1-exp(-[lambda]_cons*([betatilde]_cons*([b]_cons+plot_incentive)`v'))) ///
		if _n > $obs, ci(lb_days_pred`o' ub_days_pred`o') level(95)
	predictnl mean_visits_pred`o' = 28*(1-exp(-[lambda]_cons*([beta]_cons*([b]_cons+plot_incentive)`v'))) ///
		if _n > $obs, ci(lb_visits_pred`o' ub_visits_pred`o') level(95)

	*plot model with actual data
	twoway (conn mean_days_pred`o' plot_incentive, lcolor(black) m(none)) ///
		(conn ub_days_pred`o' plot_incentive, lc(black) lp(shortdash) m(none)) ///
		(conn lb_days_pred`o' plot_incentive, lc(black) lp(shortdash) m(none)) ///
		(sc mean_days_ prize, msize(small) color(black)) ///
		(rcap ub_days_ lb_days_ prize, lcolor(black) lwidth(medium) lpattern(dash)) ///
		(conn mean_visits_pred`o' plot_incentive, lcolor(red) m(none)) ///
		(conn ub_visits_pred`o' plot_incentive, lc(red) lp(shortdash) m(none)) ///
		(conn lb_visits_pred`o' plot_incentive, lc(red) lp(shortdash) m(none)) ///
		(sc mean_visits_ prize, m(square) msize(small) color(red)) ///
		(rcap ub_visits_ lb_visits_ prize, lcolor(red) lwidth(medium) lpattern(dash)), ///
		xlab(0(1)12) ylabel(0(5)22, angle(0)) ///
		xtitle("Per-visit incentive ($)", height(6)) ytitle("Visits", height(6)) ///
		graphregion(color(white)) plotregion(margin(sides)) ///
		legend(order(1 2 6 7 4 9) label(1 "Predicted expected visits") label(2 "Prediction 95% CI") label(4 "Average expected visits") label(6 "Predicted realized visits") label(7 "Prediction 95% CI") label(9 "Average realized visits")) legend(rows(3))	
	graph export overconfidence_estimates`o'.pdf, replace
	}


********* Waves exclusions ****************************************************
if "`v'" == ""{ // only for baseline

	foreach i in 1 3{ // loop through wave number to be excluded
	
		if `i' == 1 loc wname "wtwothree"
		else loc wname "wonetwo"
	
		gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
		(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
		(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
		(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
		(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
		(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
		(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
		if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&wave`i'==0, ///
		instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
		from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
		latex_write_gmm `wname' `lx' // store estimates

		*actual internality:
		nlcom (1-[beta]_cons)*[b]_cons
		latex_write_nlcom aint`wname' `lx' // store estimates

		*naivete statistic:
		nlcom (1-[betatilde]_cons)/(1-[beta]_cons)
		latex_write_nlcom naive`wname' `lx' // store estimates

		*expected cost
		nlcom 1/[lambda]_cons
		latex_write_nlcom expcost`wname' `lx' // store estimate
		
		}
	}

	
********** Information ********************************************************
* information control group
gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&control_info==1, ///
instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
latex_write_gmm control`o' `lx'

*actual internality:
nlcom (1-[beta]_cons)*[b]_cons
latex_write_nlcom aintcontrol`o' `lx'

*naivete statistic:
nlcom (1-[betatilde]_cons)/(1-[beta]_cons)
latex_write_nlcom naivecontrol`o' `lx'

*expected cost
nlcom 1/[lambda]_cons
latex_write_nlcom expcostcontrol`o' `lx' // store estimate

* enhanced information treatment group
gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&new_info==1, ///
instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
latex_write_gmm treat`o' `lx'

*actual internality:
nlcom (1-[beta]_cons)*[b]_cons
latex_write_nlcom ainttreat`o' `lx'

*naivete statistic:
nlcom (1-[betatilde]_cons)/(1-[beta]_cons)
latex_write_nlcom naivetreat`o' `lx'

*expected cost
nlcom 1/[lambda]_cons
latex_write_nlcom expcosttreat`o' `lx'


********** Past attendance ****************************************************
if "`v'" == ""{ // generate in first loop only
sum past4 if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.,d
loc q1past4=r(p25)
loc medpast4=r(p50)
loc q3past4=r(p75)
gen abovemedpast4=past4>=`medpast4'
gen belowmedpast4=past4<`medpast4'
gen qpast4=1 if past4<`q1past4'
replace qpast4=2 if past4>=`q1past4'&past4<`medpast4'
replace qpast4=3 if past4>=`medpast4'&past4<`q3past4'
replace qpast4=4 if past4>=`q3past4'
}

*by median
foreach r in "0" "1"{

if "`r'"=="0" loc name "bm"
else loc name "am"

gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&abovemedpast4==`r', ///
instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
latex_write_gmm `name'`o' `lx'

*actual internality:
nlcom (1-[beta]_cons)*[b]_cons
latex_write_nlcom aint`name'`o' `lx'

*naivete statistic:
nlcom (1-[betatilde]_cons)/(1-[beta]_cons)
latex_write_nlcom naive`name'`o' `lx'

*expected cost
nlcom 1/[lambda]_cons
latex_write_nlcom expcost`name'`o' `lx'

}	


*by median, info treatment, and take-up of 12+ contract - averages with CIs
loc name "het`o'"

*share in each group
sum commit12 if first_info!=1&flag_low_wtp==0&flag_exclude_exog==0&incentive!=. 
loc propcommit12het = r(mean)
sum abovemedpast4 if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit12==1
loc meanam = r(mean)
sum control_info if first_info!=1&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit12==1&abovemedpast4==1
loc propamctrlcommit`o' = `meanam'*r(mean)*`propcommit12het'
loc propaminfocommit`o' = `meanam'*(1 - r(mean))*`propcommit12het'
sum control_info if first_info!=1&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit12==1&abovemedpast4==0
loc propbmctrlcommit`o' = (1 - `meanam')*r(mean)*`propcommit12het'
loc propbminfocommit`o' = (1 - `meanam')*(1 - r(mean))*`propcommit12het'
sum abovemedpast4 if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit12==0
loc meanam = r(mean)
sum control_info if first_info!=1&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit12==0&abovemedpast4==1
loc propamctrlnocommit`o' = `meanam'*r(mean)*(1 - `propcommit12het')
loc propaminfonocommit`o' = `meanam'*(1 - r(mean))*(1 - `propcommit12het')
sum control_info if first_info!=1&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit12==0&abovemedpast4==0
loc propbmctrlnocommit`o' = (1 - `meanam')*r(mean)*(1 - `propcommit12het')
loc propbminfonocommit`o' = (1 - `meanam')*(1 - r(mean))*(1 - `propcommit12het')

gmm (eq1:28*(1-exp(-{lambda0}*({betatilde0}*({b0}+prize)`v')))*control_info*abovemedpast4*commit12-days*control_info*abovemedpast4*commit12) ///
(eq2: 28*(1-exp(-{lambda0}*({beta0}*({b0}+incentive)`v')))*control_info*abovemedpast4*commit12-visits*control_info*abovemedpast4*commit12) ///
(eq3: (1-{betatilde0})*diffa2*({b0}+(1+2)/2)*control_info*abovemedpast4*commit12-delta2*control_info*abovemedpast4*commit12) ///
(eq4: (1-{betatilde0})*diffa3*({b0}+(2+3)/2)*control_info*abovemedpast4*commit12-delta3*control_info*abovemedpast4*commit12) ///
(eq5: (1-{betatilde0})*diffa5*({b0}+(3+5)/2)*control_info*abovemedpast4*commit12-delta5*control_info*abovemedpast4*commit12) ///
(eq6: (1-{betatilde0})*diffa7*({b0}+(5+7)/2)*control_info*abovemedpast4*commit12-delta7*control_info*abovemedpast4*commit12) ///
(eq7: (1-{betatilde0})*diffa12*({b0}+(7+12)/2)*control_info*abovemedpast4*commit12-delta12*control_info*abovemedpast4*commit12) ///
(eq1b:28*(1-exp(-{lambda1}*({betatilde1}*({b1}+prize)`v')))*new_info*abovemedpast4*commit12-days*new_info*abovemedpast4*commit12) ///
(eq2b: 28*(1-exp(-{lambda1}*({beta1}*({b1}+incentive)`v')))*new_info*abovemedpast4*commit12-visits*new_info*abovemedpast4*commit12) ///
(eq3b: (1-{betatilde1})*diffa2*({b1}+(1+2)/2)*new_info*abovemedpast4*commit12-delta2*new_info*abovemedpast4*commit12) ///
(eq4b: (1-{betatilde1})*diffa3*({b1}+(2+3)/2)*new_info*abovemedpast4*commit12-delta3*new_info*abovemedpast4*commit12) ///
(eq5b: (1-{betatilde1})*diffa5*({b1}+(3+5)/2)*new_info*abovemedpast4*commit12-delta5*new_info*abovemedpast4*commit12) ///
(eq6b: (1-{betatilde1})*diffa7*({b1}+(5+7)/2)*new_info*abovemedpast4*commit12-delta7*new_info*abovemedpast4*commit12) ///
(eq7b: (1-{betatilde1})*diffa12*({b1}+(7+12)/2)*new_info*abovemedpast4*commit12-delta12*new_info*abovemedpast4*commit12) ///
(eq1c:28*(1-exp(-{lambda2}*({betatilde2}*({b2}+prize)`v')))*control_info*belowmedpast4*commit12-days*control_info*belowmedpast4*commit12) ///
(eq2c: 28*(1-exp(-{lambda2}*({beta2}*({b2}+incentive)`v')))*control_info*belowmedpast4*commit12-visits*control_info*belowmedpast4*commit12) ///
(eq3c: (1-{betatilde2})*diffa2*({b2}+(1+2)/2)*control_info*belowmedpast4*commit12-delta2*control_info*belowmedpast4*commit12) ///
(eq4c: (1-{betatilde2})*diffa3*({b2}+(2+3)/2)*control_info*belowmedpast4*commit12-delta3*control_info*belowmedpast4*commit12) ///
(eq5c: (1-{betatilde2})*diffa5*({b2}+(3+5)/2)*control_info*belowmedpast4*commit12-delta5*control_info*belowmedpast4*commit12) ///
(eq6c: (1-{betatilde2})*diffa7*({b2}+(5+7)/2)*control_info*belowmedpast4*commit12-delta7*control_info*belowmedpast4*commit12) ///
(eq7c: (1-{betatilde2})*diffa12*({b2}+(7+12)/2)*control_info*belowmedpast4*commit12-delta12*control_info*belowmedpast4*commit12) ///
(eq1d:28*(1-exp(-{lambda3}*({betatilde3}*({b3}+prize)`v')))*new_info*belowmedpast4*commit12-days*new_info*belowmedpast4*commit12) ///
(eq2d: 28*(1-exp(-{lambda3}*({beta3}*({b3}+incentive)`v')))*new_info*belowmedpast4*commit12-visits*new_info*belowmedpast4*commit12) ///
(eq3d: (1-{betatilde3})*diffa2*({b3}+(1+2)/2)*new_info*belowmedpast4*commit12-delta2*new_info*belowmedpast4*commit12) ///
(eq4d: (1-{betatilde3})*diffa3*({b3}+(2+3)/2)*new_info*belowmedpast4*commit12-delta3*new_info*belowmedpast4*commit12) ///
(eq5d: (1-{betatilde3})*diffa5*({b3}+(3+5)/2)*new_info*belowmedpast4*commit12-delta5*new_info*belowmedpast4*commit12) ///
(eq6d: (1-{betatilde3})*diffa7*({b3}+(5+7)/2)*new_info*belowmedpast4*commit12-delta7*new_info*belowmedpast4*commit12) ///
(eq7d: (1-{betatilde3})*diffa12*({b3}+(7+12)/2)*new_info*belowmedpast4*commit12-delta12*new_info*belowmedpast4*commit12) ///
(eq1e:28*(1-exp(-{lambda4}*({betatilde4}*({b4}+prize)`v')))*control_info*abovemedpast4*nocommit12-days*control_info*abovemedpast4*nocommit12) ///
(eq2e: 28*(1-exp(-{lambda4}*({beta4}*({b4}+incentive)`v')))*control_info*abovemedpast4*nocommit12-visits*control_info*abovemedpast4*nocommit12) ///
(eq3e: (1-{betatilde4})*diffa2*({b4}+(1+2)/2)*control_info*abovemedpast4*nocommit12-delta2*control_info*abovemedpast4*nocommit12) ///
(eq4e: (1-{betatilde4})*diffa3*({b4}+(2+3)/2)*control_info*abovemedpast4*nocommit12-delta3*control_info*abovemedpast4*nocommit12) ///
(eq5e: (1-{betatilde4})*diffa5*({b4}+(3+5)/2)*control_info*abovemedpast4*nocommit12-delta5*control_info*abovemedpast4*nocommit12) ///
(eq6e: (1-{betatilde4})*diffa7*({b4}+(5+7)/2)*control_info*abovemedpast4*nocommit12-delta7*control_info*abovemedpast4*nocommit12) ///
(eq7e: (1-{betatilde4})*diffa12*({b4}+(7+12)/2)*control_info*abovemedpast4*nocommit12-delta12*control_info*abovemedpast4*nocommit12) ///
(eq1f:28*(1-exp(-{lambda5}*({betatilde5}*({b5}+prize)`v')))*new_info*abovemedpast4*nocommit12-days*new_info*abovemedpast4*nocommit12) ///
(eq2f: 28*(1-exp(-{lambda5}*({beta5}*({b5}+incentive)`v')))*new_info*abovemedpast4*nocommit12-visits*new_info*abovemedpast4*nocommit12) ///
(eq3f: (1-{betatilde5})*diffa2*({b5}+(1+2)/2)*new_info*abovemedpast4*nocommit12-delta2*new_info*abovemedpast4*nocommit12) ///
(eq4f: (1-{betatilde5})*diffa3*({b5}+(2+3)/2)*new_info*abovemedpast4*nocommit12-delta3*new_info*abovemedpast4*nocommit12) ///
(eq5f: (1-{betatilde5})*diffa5*({b5}+(3+5)/2)*new_info*abovemedpast4*nocommit12-delta5*new_info*abovemedpast4*nocommit12) ///
(eq6f: (1-{betatilde5})*diffa7*({b5}+(5+7)/2)*new_info*abovemedpast4*nocommit12-delta7*new_info*abovemedpast4*nocommit12) ///
(eq7f: (1-{betatilde5})*diffa12*({b5}+(7+12)/2)*new_info*abovemedpast4*nocommit12-delta12*new_info*abovemedpast4*nocommit12) ///
(eq1g:28*(1-exp(-{lambda6}*({betatilde6}*({b6}+prize)`v')))*control_info*belowmedpast4*nocommit12-days*control_info*belowmedpast4*nocommit12) ///
(eq2g: 28*(1-exp(-{lambda6}*({beta6}*({b6}+incentive)`v')))*control_info*belowmedpast4*nocommit12-visits*control_info*belowmedpast4*nocommit12) ///
(eq3g: (1-{betatilde6})*diffa2*({b6}+(1+2)/2)*control_info*belowmedpast4*nocommit12-delta2*control_info*belowmedpast4*nocommit12) ///
(eq4g: (1-{betatilde6})*diffa3*({b6}+(2+3)/2)*control_info*belowmedpast4*nocommit12-delta3*control_info*belowmedpast4*nocommit12) ///
(eq5g: (1-{betatilde6})*diffa5*({b6}+(3+5)/2)*control_info*belowmedpast4*nocommit12-delta5*control_info*belowmedpast4*nocommit12) ///
(eq6g: (1-{betatilde6})*diffa7*({b6}+(5+7)/2)*control_info*belowmedpast4*nocommit12-delta7*control_info*belowmedpast4*nocommit12) ///
(eq7g: (1-{betatilde6})*diffa12*({b6}+(7+12)/2)*control_info*belowmedpast4*nocommit12-delta12*control_info*belowmedpast4*nocommit12) ///
(eq1h:28*(1-exp(-{lambda7}*({betatilde7}*({b7}+prize)`v')))*new_info*belowmedpast4*nocommit12-days*new_info*belowmedpast4*nocommit12) ///
(eq2h: 28*(1-exp(-{lambda7}*({beta7}*({b7}+incentive)`v')))*new_info*belowmedpast4*nocommit12-visits*new_info*belowmedpast4*nocommit12) ///
(eq3h: (1-{betatilde7})*diffa2*({b7}+(1+2)/2)*new_info*belowmedpast4*nocommit12-delta2*new_info*belowmedpast4*nocommit12) ///
(eq4h: (1-{betatilde7})*diffa3*({b7}+(2+3)/2)*new_info*belowmedpast4*nocommit12-delta3*new_info*belowmedpast4*nocommit12) ///
(eq5h: (1-{betatilde7})*diffa5*({b7}+(3+5)/2)*new_info*belowmedpast4*nocommit12-delta5*new_info*belowmedpast4*nocommit12) ///
(eq6h: (1-{betatilde7})*diffa7*({b7}+(5+7)/2)*new_info*belowmedpast4*nocommit12-delta7*new_info*belowmedpast4*nocommit12) ///
(eq7h: (1-{betatilde7})*diffa12*({b7}+(7+12)/2)*new_info*belowmedpast4*nocommit12-delta12*new_info*belowmedpast4*nocommit12) ///
if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&(control_info==1|new_info==1), ///
instruments(eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
instruments(eq1b: prize prize2) instruments(eq2b:incentive incentivesq) ///
instruments(eq1c: prize prize2) instruments(eq2c:incentive incentivesq) ///
instruments(eq1d: prize prize2) instruments(eq2d:incentive incentivesq) ///
instruments(eq1e: prize prize2) instruments(eq2e:incentive incentivesq) ///
instruments(eq1f: prize prize2) instruments(eq2f:incentive incentivesq) ///
instruments(eq1g: prize prize2) instruments(eq2g:incentive incentivesq) ///
instruments(eq1h: prize prize2) instruments(eq2h:incentive incentivesq) ///
from (b7 8 b6 8 b5 8 b4 8 b3 8 b2 8 b1 8 b0 8 lambda7 0.06 lambda6 0.06 lambda5 0.06 lambda4 0.06 lambda3 0.06 lambda2 0.06 lambda1 0.06 lambda0 0.06 beta7 0.5 beta6 0.5 beta5 0.5 beta4 0.5 beta3 0.5 beta2 0.5 beta1 0.5 beta0 0.5 betatilde7 0.8 betatilde6 0.8 betatilde5 0.8 betatilde4 0.8 betatilde3 0.8 betatilde2 0.8 betatilde1 0.8 betatilde0 0.8) ///
 vce(cluster id) winitial(identity)
foreach p in b lambda beta betatilde{
	nlcom [`p'0]_cons*`propamctrlcommit`o'' + ///
		[`p'1]_cons*`propaminfocommit`o'' + ///
		[`p'2]_cons*`propbmctrlcommit`o'' + ///
		[`p'3]_cons*`propbminfocommit`o'' + ///
		[`p'4]_cons*`propamctrlnocommit`o'' + ///
		[`p'5]_cons*`propaminfonocommit`o'' + ///
		[`p'6]_cons*`propbmctrlnocommit`o'' + ///
		[`p'7]_cons*`propbminfonocommit`o''
	latex_write_nlcom `p'minfoavg`name' `lx'
	}

*actual internality:
nlcom (1-[beta0]_cons)*[b0]_cons*`propamctrlcommit`o'' + ///
	(1-[beta1]_cons)*[b1]_cons*`propaminfocommit`o'' + ///
	(1-[beta2]_cons)*[b2]_cons*`propbmctrlcommit`o'' + ///
	(1-[beta3]_cons)*[b3]_cons*`propbminfocommit`o'' + ///
	(1-[beta4]_cons)*[b4]_cons*`propamctrlnocommit`o'' + ///
	(1-[beta5]_cons)*[b5]_cons*`propaminfonocommit`o'' + ///
	(1-[beta6]_cons)*[b6]_cons*`propbmctrlnocommit`o'' + ///
	(1-[beta7]_cons)*[b7]_cons*`propbminfonocommit`o''
latex_write_nlcom aintminfoavg`name' `lx'

*naivete statistic:
nlcom (1-[betatilde0]_cons)/(1-[beta0]_cons)*`propamctrlcommit`o'' + ///
	(1-[betatilde1]_cons)/(1-[beta1]_cons)*`propaminfocommit`o'' + ///
	(1-[betatilde2]_cons)/(1-[beta2]_cons)*`propbmctrlcommit`o'' + ///
	(1-[betatilde3]_cons)/(1-[beta3]_cons)*`propbminfocommit`o'' + ///
	(1-[betatilde4]_cons)/(1-[beta4]_cons)*`propamctrlnocommit`o'' + ///
	(1-[betatilde5]_cons)/(1-[beta5]_cons)*`propaminfonocommit`o'' + ///
	(1-[betatilde6]_cons)/(1-[beta6]_cons)*`propbmctrlnocommit`o'' + ///
	(1-[betatilde7]_cons)/(1-[beta7]_cons)*`propbminfonocommit`o''
latex_write_nlcom naiveminfoavg`name' `lx'

*expected cost
nlcom (1/[lambda0]_cons)*`propamctrlcommit`o'' + ///
	(1/[lambda1]_cons)*`propaminfocommit`o'' + ///
	(1/[lambda2]_cons)*`propbmctrlcommit`o'' + ///
	(1/[lambda3]_cons)*`propbminfocommit`o'' + ///
	(1/[lambda4]_cons)*`propamctrlnocommit`o'' + ///
	(1/[lambda5]_cons)*`propaminfonocommit`o'' + ///
	(1/[lambda6]_cons)*`propbmctrlnocommit`o'' + ///
	(1/[lambda7]_cons)*`propbminfonocommit`o''
latex_write_nlcom expcostminfoavg`name' `lx'

if "`v'" != "+0"{
	*generate 95% CIs for model values
	predictnl mean_days_minfo`name'_pred = ///
		28*((1-exp(-[lambda0]_cons*([betatilde0]_cons*([b0]_cons+plot_incentive)`v')))*`propamctrlcommit`o'' + ///
			(1-exp(-[lambda1]_cons*([betatilde1]_cons*([b1]_cons+plot_incentive)`v')))*`propaminfocommit`o'' + ///
			(1-exp(-[lambda2]_cons*([betatilde2]_cons*([b2]_cons+plot_incentive)`v')))*`propbmctrlcommit`o'' + ///
			(1-exp(-[lambda3]_cons*([betatilde3]_cons*([b3]_cons+plot_incentive)`v')))*`propbminfocommit`o'' + ///
			(1-exp(-[lambda4]_cons*([betatilde4]_cons*([b4]_cons+plot_incentive)`v')))*`propamctrlnocommit`o'' + ///
			(1-exp(-[lambda5]_cons*([betatilde5]_cons*([b5]_cons+plot_incentive)`v')))*`propaminfonocommit`o'' + ///
			(1-exp(-[lambda6]_cons*([betatilde6]_cons*([b6]_cons+plot_incentive)`v')))*`propbmctrlnocommit`o'' + ///
			(1-exp(-[lambda7]_cons*([betatilde7]_cons*([b7]_cons+plot_incentive)`v')))*`propbminfonocommit`o'') ///
		if _n > $obs, ci(lb_days_minfo`name'_pred ub_days_minfo`name'_pred) level(95)
	predictnl mean_visits_minfo`name'_pred = ///
		28*((1-exp(-[lambda0]_cons*([beta0]_cons*([b0]_cons+plot_incentive)`v')))*`propamctrlcommit`o'' + ///
			(1-exp(-[lambda1]_cons*([beta1]_cons*([b1]_cons+plot_incentive)`v')))*`propaminfocommit`o'' + ///
			(1-exp(-[lambda2]_cons*([beta2]_cons*([b2]_cons+plot_incentive)`v')))*`propbmctrlcommit`o'' + ///
			(1-exp(-[lambda3]_cons*([beta3]_cons*([b3]_cons+plot_incentive)`v')))*`propbminfocommit`o'' + ///
			(1-exp(-[lambda4]_cons*([beta4]_cons*([b4]_cons+plot_incentive)`v')))*`propamctrlnocommit`o'' + ///
			(1-exp(-[lambda5]_cons*([beta5]_cons*([b5]_cons+plot_incentive)`v')))*`propaminfonocommit`o'' + ///
			(1-exp(-[lambda6]_cons*([beta6]_cons*([b6]_cons+plot_incentive)`v')))*`propbmctrlnocommit`o'' + ///
			(1-exp(-[lambda7]_cons*([beta7]_cons*([b7]_cons+plot_incentive)`v')))*`propbminfonocommit`o'')	///
		if _n > $obs, ci(lb_visits_minfo`name'_pred ub_visits_minfo`name'_pred) level(95)

	*plot model with actual data
	twoway (conn mean_days_minfo`name'_pred plot_incentive, lcolor(black) m(none)) ///
		(conn ub_days_minfo`name'_pred plot_incentive, lc(black) lp(shortdash) m(none)) ///
		(conn lb_days_minfo`name'_pred plot_incentive, lc(black) lp(shortdash) m(none)) ///
		(sc mean_days_inf_ prize, msize(small) color(black)) ///
		(rcap ub_days_inf_ lb_days_inf_ prize, lcolor(black) lwidth(medium) lpattern(dash)) ///
		(conn mean_visits_minfo`name'_pred plot_incentive, lcolor(red) m(none)) ///
		(conn ub_visits_minfo`name'_pred plot_incentive, lc(red) lp(shortdash) m(none)) ///
		(conn lb_visits_minfo`name'_pred plot_incentive, lc(red) lp(shortdash) m(none)) ///
		(sc mean_visits_inf_ prize, m(square) msize(small) color(red)) ///
		(rcap ub_visits_inf_ lb_visits_inf_ prize, lcolor(red) lwidth(medium) lpattern(dash)), ///
		xlab(0(1)12) ylabel(0(5)22, angle(0)) ///
		xtitle("Per-visit incentive ($)", height(6)) ytitle("Visits", height(6)) ///
		graphregion(color(white)) plotregion(margin(sides)) ///
		legend(order(1 2 6 7 4 9) label(1 "Predicted expected visits") label(2 "Prediction 95% CI") label(4 "Average expected visits") label(6 "Predicted realized visits") label(7 "Prediction 95% CI") label(9 "Average realized visits")) legend(rows(3))		
	graph export overconfidence_estimates_past4_info_`name'.pdf, replace

	*by median and take-up of commitment contract
	forval j = 8(4)16{

		if `j' == 8 loc x "e"
		else if `j' == 12 loc x ""
		else loc x "s"

		foreach r in "0&commit`j'==1" "1&commit`j'==1" "0&commit`j'==0" "1&commit`j'==0"{

		if "`r'"=="0&commit`j'==1" loc name "bmcommit`x'`o'"
		else if "`r'"=="1&commit`j'==1" loc name "amcommit`x'`o'"
		else if "`r'"=="0&commit`j'==0" loc name "bmnocommit`x'`o'"
		else loc name "amnocommit`x'`o'"

		gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
		(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
		(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
		(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
		(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
		(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
		(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
		if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&abovemedpast4==`r', ///
		instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
		from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
		foreach p in b lambda beta betatilde{
			loc `p'`name' = [`p']_cons
			}
		}

		*share in each group
		sum abovemedpast4 if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==1
		loc propamcommit`x'`o' = r(mean)
		loc propbmcommit`x'`o' = 1 - r(mean)
		loc propmavgcommit`x'`o' = 1
		sum abovemedpast4 if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==0
		loc propamnocommit`x'`o' = r(mean)
		loc propbmnocommit`x'`o' = 1 - r(mean)

	}

	*by quartile of past attendance and take-up of commitment contract (for export)
	forval j = 8(4)16{

		if `j' == 8 loc x "e"
		else if `j' == 12 loc x ""
		else loc x "s"

		foreach r in "1&commit`j'==1" "2&commit`j'==1" "3&commit`j'==1" "4&commit`j'==1" "1&commit`j'==0" "2&commit`j'==0" "3&commit`j'==0" "4&commit`j'==0"{

		if "`r'"=="1&commit`j'==1" loc name "qfstcommit`x'`o'"
		else if "`r'"=="2&commit`j'==1" loc name "qsndcommit`x'`o'"
		else if "`r'"=="3&commit`j'==1" loc name "qthdcommit`x'`o'"
		else if "`r'"=="4&commit`j'==1" loc name "qfthcommit`x'`o'"
		else if "`r'"=="1&commit`j'==0" loc name "qfstnocommit`x'`o'"
		else if "`r'"=="2&commit`j'==0" loc name "qsndnocommit`x'`o'"
		else if "`r'"=="3&commit`j'==0" loc name "qthdnocommit`x'`o'"
		else loc name "qfthnocommit`x'`o'"

		gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
		(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
		(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
		(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
		(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
		(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
		(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
		if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&qpast4==`r', ///
		instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
		from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
		foreach p in b lambda beta betatilde{
			loc `p'`name' = [`p']_cons
			}
		}

		*share in each group
		sum qpast4 if abovemedpast4==0&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==1
		loc propqfstcommit`x'`o' = (2 - r(mean))*`propbmcommit`x'`o''
		loc propqsndcommit`x'`o' = (1 - (2 - r(mean)))*`propbmcommit`x'`o''
		sum qpast4 if abovemedpast4==1&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==1
		loc propqthdcommit`x'`o' = (4 - r(mean))*`propamcommit`x'`o''
		loc propqfthcommit`x'`o' = (1 - (4 - r(mean)))*`propamcommit`x'`o''
		sum qpast4 if abovemedpast4==0&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==0
		loc propqfstnocommit`x'`o' = (2 - r(mean))*`propbmnocommit`x'`o''
		loc propqsndnocommit`x'`o' = (1 - (2 - r(mean)))*`propbmnocommit`x'`o''
		sum qpast4 if abovemedpast4==1&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==0
		loc propqthdnocommit`x'`o' = (4 - r(mean))*`propamnocommit`x'`o''
		loc propqfthnocommit`x'`o' = (1 - (4 - r(mean)))*`propamnocommit`x'`o''
		
	}

	*by median, info treatment, & take-up of each commitment contract
	forval j = 8(4)16{

		if `j' == 8 loc x "e"
		else if `j' == 12 loc x ""
		else loc x "s"
		
		foreach r in "0&control_info==1&commit`j'==1" "0&new_info==1&commit`j'==1" "1&control_info==1&commit`j'==1" "1&new_info==1&commit`j'==1" "0&control_info==1&commit`j'==0" "0&new_info==1&commit`j'==0" "1&control_info==1&commit`j'==0" "1&new_info==1&commit`j'==0" {

		if "`r'"=="0&control_info==1&commit`j'==1" loc name "bmctrlcommit`x'`o'"
		else if "`r'"=="0&new_info==1&commit`j'==1" loc name "bminfocommit`x'`o'"
		else if "`r'"=="1&control_info==1&commit`j'==1" loc name "amctrlcommit`x'`o'"
		else if "`r'"=="1&new_info==1&commit`j'==1" loc name "aminfocommit`x'`o'"
		else if "`r'"=="0&control_info==1&commit`j'==0" loc name "bmctrlnocommit`x'`o'"
		else if "`r'"=="0&new_info==1&commit`j'==0" loc name "bminfonocommit`x'`o'"
		else if "`r'"=="1&control_info==1&commit`j'==0" loc name "amctrlnocommit`x'`o'"
		else loc name "aminfonocommit`x'`o'"

		gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
		(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
		(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
		(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
		(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
		(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
		(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
		if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&abovemedpast4==`r', ///
		instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
		from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
		foreach p in b lambda beta betatilde{
			loc `p'`name' = [`p']_cons
			}
		}

		*share in each group
		sum commit`j' if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.
		loc propcommit
		sum abovemedpast4 if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==1
		loc meanam = r(mean)
		sum control_info if first_info!=1&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==1&abovemedpast4==1
		loc propamctrlcommit`x'`o' = `meanam'*r(mean)
		loc propaminfocommit`x'`o' = `meanam'*(1 - r(mean))
		sum control_info if first_info!=1&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==1&abovemedpast4==0
		loc propbmctrlcommit`x'`o' = (1 - `meanam')*r(mean)
		loc propbminfocommit`x'`o' = (1 - `meanam')*(1 - r(mean))
		sum abovemedpast4 if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==0
		loc meanam = r(mean)
		sum control_info if first_info!=1&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==0&abovemedpast4==1
		loc propamctrlnocommit`x'`o' = `meanam'*r(mean)
		loc propaminfonocommit`x'`o' = `meanam'*(1 - r(mean))
		sum control_info if first_info!=1&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==0&abovemedpast4==0	
		loc propbmctrlnocommit`x'`o' = (1 - `meanam')*r(mean)
		loc propbminfonocommit`x'`o' = (1 - `meanam')*(1 - r(mean))
		
		}
		
	*by quartile, info treatment, & take-up of 12 visit commitment contract	
	loc j = 12 // for 12+ visits contract only
	loc x ""
	foreach r in "1&commit`j'==1&control_info==1" "2&commit`j'==1&control_info==1" "3&commit`j'==1&control_info==1" "4&commit`j'==1&control_info==1" "1&commit`j'==1&new_info==1" "2&commit`j'==1&new_info==1" "3&commit`j'==1&new_info==1" "4&commit`j'==1&new_info==1" {

		if "`r'"=="1&commit`j'==1&control_info==1" loc name "qfstctrlcommit`x'`o'"
		else if "`r'"=="2&commit`j'==1&control_info==1" loc name "qsndctrlcommit`x'`o'"
		else if "`r'"=="3&commit`j'==1&control_info==1" loc name "qthdctrlcommit`x'`o'"
		else if "`r'"=="4&commit`j'==1&control_info==1" loc name "qfthctrlcommit`x'`o'"
		else if "`r'"=="1&commit`j'==0&control_info==1" loc name "qfstctrlnocommit`x'`o'"
		else if "`r'"=="2&commit`j'==0&control_info==1" loc name "qsndctrlnocommit`x'`o'"
		else if "`r'"=="3&commit`j'==0&control_info==1" loc name "qthdctrlnocommit`x'`o'"
		else if "`r'"=="4&commit`j'==0&control_info==1" loc name "qfthctrlnocommit`x'`o'"
		else if "`r'"=="1&commit`j'==1&new_info==1" loc name "qfstinfocommit`x'`o'"
		else if "`r'"=="2&commit`j'==1&new_info==1" loc name "qsndinfocommit`x'`o'"
		else if "`r'"=="3&commit`j'==1&new_info==1" loc name "qthdinfocommit`x'`o'"
		else if "`r'"=="4&commit`j'==1&new_info==1" loc name "qfthinfocommit`x'`o'"
		else if "`r'"=="1&commit`j'==0&new_info==1" loc name "qfstinfonocommit`x'`o'"
		else if "`r'"=="2&commit`j'==0&new_info==1" loc name "qsndinfonocommit`x'`o'"
		else if "`r'"=="3&commit`j'==0&new_info==1" loc name "qthdinfonocommit`x'`o'"
		else loc name "qfthinfonocommit`x'`o'"

		gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
		(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
		(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
		(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
		(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
		(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
		(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
		if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&qpast4==`r', ///
		instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
		from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
		foreach p in b lambda beta betatilde{
			loc `p'`name' = [`p']_cons
			}
		}

	*share in each group
	forval k = 1/4{
		sum control_info if first_info!=1&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==0&qpast4==`k'
		loc propctrlq`k' = r(mean)
		}
	sum qpast4 if abovemedpast4==0&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==1
	loc propqfstctrlcommit`x'`o' = (2 - r(mean))*`propbmcommit`x'`o''*`propctrlq1'
	loc propqfstinfocommit`x'`o' = (2 - r(mean))*`propbmcommit`x'`o''*(1 - `propctrlq1')
	loc propqsndctrlcommit`x'`o' = (1 - (2 - r(mean)))*`propbmcommit`x'`o''*`propctrlq2'
	loc propqsndinfocommit`x'`o' = (1 - (2 - r(mean)))*`propbmcommit`x'`o''*(1 - `propctrlq2')
	sum qpast4 if abovemedpast4==1&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==1
	loc propqthdctrlcommit`x'`o' = (4 - r(mean))*`propamcommit`x'`o''*`propctrlq3'
	loc propqthdinfocommit`x'`o' = (4 - r(mean))*`propamcommit`x'`o''*(1 - `propctrlq3')
	loc propqfthctrlcommit`x'`o' = (1 - (4 - r(mean)))*`propamcommit`x'`o''*`propctrlq4'
	loc propqfthinfocommit`x'`o' = (1 - (4 - r(mean)))*`propamcommit`x'`o''*(1 - `propctrlq4')
	sum qpast4 if abovemedpast4==0&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==0
	loc propqfstctrlnocommit`x'`o' = (2 - r(mean))*`propbmnocommit`x'`o''*`propctrlq1'
	loc propqfstinfonocommit`x'`o' = (2 - r(mean))*`propbmnocommit`x'`o''*(1 - `propctrlq1')
	loc propqsndctrlnocommit`x'`o' = (1 - (2 - r(mean)))*`propbmnocommit`x'`o''*`propctrlq2'
	loc propqsndinfonocommit`x'`o' = (1 - (2 - r(mean)))*`propbmnocommit`x'`o''*(1 - `propctrlq2')
	sum qpast4 if abovemedpast4==1&flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit`j'==0
	loc propqthdctrlnocommit`x'`o' = (4 - r(mean))*`propamnocommit`x'`o''*`propctrlq3'
	loc propqthdinfonocommit`x'`o' = (4 - r(mean))*`propamnocommit`x'`o''*(1 - `propctrlq3')
	loc propqfthctrlnocommit`x'`o' = (1 - (4 - r(mean)))*`propamnocommit`x'`o''*`propctrlq4'
	loc propqfthinfonocommit`x'`o' = (1 - (4 - r(mean)))*`propamnocommit`x'`o''*(1 - `propctrlq4')

	}


********** Commitment contract - 12 visits ************************************

gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit12==1, ///
instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
latex_write_gmm twelve`o' `lx'

*for export
foreach param in lambda betatilde b beta {
	loc `param'commit12`o' = [`param']_cons
	}

*actual internality:
nlcom (1-[beta]_cons)*[b]_cons
latex_write_nlcom ainttwelve`o' `lx'

*naivete statistic:
nlcom (1-[betatilde]_cons)/(1-[beta]_cons)
latex_write_nlcom naivetwelve`o' `lx'

*expected cost
nlcom 1/[lambda]_cons
latex_write_nlcom expcosttwelve`o' `lx'

*take-up rate
sum commit12 if flag_low_wtp==0&flag_exclude_exog==0&incentive!=. 
loc propcommit12`o' = r(mean)
loc propnocommit12`o' = 1 - r(mean) 

if "`v'" == ""{ // baseline only

	*generate 95% CIs for model values
	predictnl mean_days_c12_pred = ///
		28*(1-exp(-[lambda]_cons*[betatilde]_cons*([b]_cons+plot_incentive))) ///
		if _n > $obs, ci(lb_days_c12_pred ub_days_c12_pred) level(95)
	predictnl mean_visits_c12_pred = ///
		28*(1-exp(-[lambda]_cons*[beta]_cons*([b]_cons+plot_incentive))) ///
		if _n > $obs, ci(lb_visits_c12_pred ub_visits_c12_pred) level(95)

	*plot model with actual data
	twoway (conn mean_days_c12_pred plot_incentive, lcolor(black) m(none)) ///
		(conn ub_days_c12_pred plot_incentive, lc(black) lp(shortdash) m(none)) ///
		(conn lb_days_c12_pred plot_incentive, lc(black) lp(shortdash) m(none)) ///
		(sc mean_days_c12_ prize, msize(small) color(black)) ///
		(rcap ub_days_c12_ lb_days_c12_ prize, lcolor(black) lwidth(medium) lpattern(dash)) ///
		(conn mean_visits_c12_pred plot_incentive, lcolor(red) m(none)) ///
		(conn ub_visits_c12_pred plot_incentive, lc(red) lp(shortdash) m(none)) ///
		(conn lb_visits_c12_pred plot_incentive, lc(red) lp(shortdash) m(none)) ///
		(sc mean_visits_c12_ prize, m(square) msize(small) color(red)) ///
		(rcap ub_visits_c12_ lb_visits_c12_ prize, lcolor(red) lwidth(medium) lpattern(dash)), ///
		xlab(0(1)12) ylabel(0(5)22, angle(0)) ///
		xtitle("Per-visit incentive ($)", height(6)) ytitle("Visits", height(6)) ///
		graphregion(color(white)) plotregion(margin(sides)) ///
		legend(order(1 2 6 7 4 9) label(1 "Predicted expected visits") label(2 "Prediction 95% CI") label(4 "Average expected visits") label(6 "Predicted realized visits") label(7 "Prediction 95% CI") label(9 "Average realized visits")) legend(rows(3))	
	graph export overconfidence_estimates_commit12.pdf, replace

	**lower bound on how bad commitment contracts are:
	loc internalityC12=(1-[beta]_cons)*[b]_cons
	* impact on visits
	reg visits getcommit if wave3==1&(getcommit==1|incentive==0)&commit12==1
	loc internalityBenefit=_b[getcommit]*`internalityC12'
	di `internalityBenefit'
	* financial loss
	qui sum visits12 if commit12==1&getcommit==1
	loc lose=1-r(mean)
	loc dollarslost=`lose'*80
	di `dollarslost'
	* net loss:
	di `dollarslost'-`internalityBenefit'

}

*rejected contract
if "`v'" != "+0"{
	gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
	(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
	(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
	(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
	(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
	(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
	(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
	if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit12==0, ///
	instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
	from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
	if "`v'" == "" latex_write_gmm notwelve `lx' // baseline only

	*for export
	foreach param in lambda betatilde b beta {
		loc `param'nocommit12`o' = [`param']_cons
		}

	if "`v'" == ""{ // baseline only
		*actual internality:
		nlcom (1-[beta]_cons)*[b]_cons
		latex_write_nlcom aintnotwelve `lx'

		*naivete statistic:
		nlcom (1-[betatilde]_cons)/(1-[beta]_cons)
		latex_write_nlcom naivenotwelve `lx'

		*expected cost
		nlcom 1/[lambda]_cons
		latex_write_nlcom expcostnotwelve `lx'
		}
	}


********** Commitment contract - 8 visits *************************************

gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit8==1, ///
instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
latex_write_gmm eight`o' `lx'

*for export
foreach param in lambda betatilde b beta {
	loc `param'commit8`o' = [`param']_cons
	}

*actual internality:
nlcom (1-[beta]_cons)*[b]_cons
latex_write_nlcom ainteight`o' `lx'

*naivete statistic:
nlcom (1-[betatilde]_cons)/(1-[beta]_cons)
latex_write_nlcom naiveeight`o' `lx'

*expected cost
nlcom 1/[lambda]_cons
latex_write_nlcom expcosteight`o' `lx'

*take-up rate
sum commit8 if flag_low_wtp==0&flag_exclude_exog==0&incentive!=. 
loc propcommit8`o' = r(mean)
loc propnocommit8`o' = 1 -r(mean)


* rejected contract
if "`v'" != "+0"{
	gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
	(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
	(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
	(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
	(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
	(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
	(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
	if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit8==0, ///
	instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
	from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
	if "`v'" == "" latex_write_gmm noeight `lx' // baseline only

	*for export
	foreach param in lambda betatilde b beta {
		loc `param'nocommit8`o' = [`param']_cons
		}

	if "`v'" == ""{ // baseline only
		*actual internality:
		nlcom (1-[beta]_cons)*[b]_cons
		latex_write_nlcom aintnoeight `lx'

		*naivete statistic:
		nlcom (1-[betatilde]_cons)/(1-[beta]_cons)
		latex_write_nlcom naivenoeight `lx'

		*expected cost
		nlcom 1/[lambda]_cons
		latex_write_nlcom expcostnoeight `lx'
		}
	}


********** Commitment contract - 16 visits ************************************

gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit16==1, ///
instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
latex_write_gmm sixteen`o' `lx'

*for export
foreach param in lambda betatilde b beta {
	loc `param'commit16`o' = [`param']_cons
	}

*actual internality:
nlcom (1-[beta]_cons)*[b]_cons
latex_write_nlcom aintsixteen`o' `lx'

*naivete statistic:
nlcom (1-[betatilde]_cons)/(1-[beta]_cons)
latex_write_nlcom naivesixteen`o' `lx'

*expected cost
nlcom 1/[lambda]_cons
latex_write_nlcom expcostsixteen`o' `lx'

*take-up rate
sum commit16 if flag_low_wtp==0&flag_exclude_exog==0&incentive!=. 
loc propcommit16`o' = r(mean)
loc propnocommit16`o' = 1 -r(mean)


* rejected contract
if "`v'" != "+0"{
	gmm (eq1:28*(1-exp(-{lambda}*({betatilde}*({b}+prize)`v')))-days) ///
	(eq2: 28*(1-exp(-{lambda}*({beta}*({b}+incentive)`v')))-visits) ///
	(eq3: (1-{betatilde})*diffa2*({b}+(1+2)/2)-delta2) ///
	(eq4: (1-{betatilde})*diffa3*({b}+(2+3)/2)-delta3) ///
	(eq5: (1-{betatilde})*diffa5*({b}+(3+5)/2)-delta5) ///
	(eq6: (1-{betatilde})*diffa7*({b}+(5+7)/2)-delta7) ///
	(eq7: (1-{betatilde})*diffa12*({b}+(7+12)/2)-delta12) ///
	if flag_low_wtp==0&flag_exclude_exog==0&incentive!=.&commit16==0, ///
	instruments (eq1: prize prize2) instruments(eq2:incentive incentivesq) ///
	from (b 8 lambda 0.06 beta 0.5 betatilde 0.8) vce(cluster id) winitial(identity) nolog
	if "`v'" == "" latex_write_gmm nosixteen `lx' // baseline only

	*for export
	foreach param in lambda betatilde b beta {
		loc `param'nocommit16`o' = [`param']_cons
		}

	if "`v'" == ""{ // baseline only
		*actual internality:
		nlcom (1-[beta]_cons)*[b]_cons
		latex_write_nlcom aintnosixteen `lx'

		*naivete statistic:
		nlcom (1-[betatilde]_cons)/(1-[beta]_cons)
		latex_write_nlcom naivenosixteen `lx'

		*expected cost
		nlcom 1/[lambda]_cons
		latex_write_nlcom expcostnosixteen `lx'
		}
	}

}
	
restore


********** Export estimates from each subsample to a file *********************

foreach o in "" "V" "X"{

	foreach f in bmcommit`o' amcommit`o' bmnocommit`o' amnocommit`o' ///
		bmcommite`o' amcommite`o' bmnocommite`o' amnocommite`o' ///
		bmcommits`o' amcommits`o' bmnocommits`o' amnocommits`o' ///
		qfstcommit`o' qsndcommit`o' qthdcommit`o' qfthcommit`o' ///
		qfstnocommit`o' qsndnocommit`o' qthdnocommit`o' qfthnocommit`o' ///
		qfstcommite`o' qsndcommite`o' qthdcommite`o' qfthcommite`o' ///
		qfstnocommite`o' qsndnocommite`o' qthdnocommite`o' qfthnocommite`o' ///
		qfstcommits`o' qsndcommits`o' qthdcommits`o' qfthcommits`o' ///
		qfstnocommits`o' qsndnocommits`o' qthdnocommits`o' qfthnocommits`o' ///
		qfstctrlcommit`o' qsndctrlcommit`o' qthdctrlcommit`o' qfthctrlcommit`o' ///
		qfstinfocommit`o' qsndinfocommit`o' qthdinfocommit`o' qfthinfocommit`o' ///
		bmctrlcommit`o' bminfocommit`o' amctrlcommit`o' aminfocommit`o' ///
		bmctrlnocommit`o' bminfonocommit`o' amctrlnocommit`o' aminfonocommit`o' ///
		bmctrlcommite`o' bminfocommite`o' amctrlcommite`o' aminfocommite`o' ///
		bmctrlnocommite`o' bminfonocommite`o' amctrlnocommite`o' aminfonocommite`o' ///
		bmctrlcommits`o' bminfocommits`o' amctrlcommits`o' aminfocommits`o' ///
		bmctrlnocommits`o' bminfonocommits`o' amctrlnocommits`o' aminfonocommits`o' ///
		commit12`o' nocommit12`o' commit8`o' nocommit8`o' commit16`o' nocommit16`o'{

		preserve
		clear
		set obs 1
		foreach p in lambda beta betatilde b prop{
			gen `p' = ``p'`f''
			}
		outsheet using "parameter_estimates/`f'.csv", comma replace
		restore
		}
		
	}
	
	
********** Empirical moments **************************************************

preserve
* restrict sample
keep if flag_low_wtp==0&flag_exclude_exog==0

*generate variables
gen got_contract = 1 if treatment == "threshold80_12"
replace got_contract = 0 if treatment == "control"
gen success = visits >= 12

*change in attendance due to contract
reg visits got_contract wave? if commit12==1
matrix temp = r(table)'
loc b : di %4.2f temp[1,1]
loc lb : di %4.2f temp[1,5]
loc ub : di %4.2f temp[1,6]
loc ci : di "(`lb', `ub')"
latex_write empirDaC `b' numbers
latex_write empirDaCCI "`ci'" numbers

*probability of meeting threshold (with and w/out the contract)
reg success wave? if commit12==1&treatment=="control"
matrix temp = r(table)'
loc b : di %4.2f temp[4,1]
loc lb : di %4.2f temp[4,5]
loc ub : di %4.2f temp[4,6]
loc ci : di "(`lb', `ub')"
latex_write empirctrlPmeet `b' numbers
latex_write empirctrlPmeetCI "`ci'" numbers

reg success if commit12==1&treatment=="threshold80_12"
matrix temp = r(table)'
loc b : di %4.2f temp[1,1]
loc lb : di %4.2f temp[1,5]
loc ub : di %4.2f temp[1,6]
loc ci : di "(`lb', `ub')"
latex_write empirtreatPmeet `b' numbers
latex_write empirtreatPmeetCI "`ci'" numbers

*change in probability of meeting threshold
reg success got_contract wave? if commit12==1
matrix temp = r(table)'
loc b : di %4.2f temp[1,1]
loc lb : di %4.2f temp[1,5]
loc ub : di %4.2f temp[1,6]
loc ci : di "(`lb', `ub')"
latex_write empirDmeet `b' numbers
latex_write empirDmeetCI "`ci'" numbers
restore