File size: 153,246 Bytes
395f9a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
*****UK*****
import delimited "U:\How to Save a Democracy\Data\ukmain.tsv", varnames(1) encoding(UTF-16LE) numericcols(15 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85) clear
encode responseid, gen(id)
generate respondentid = id+1
drop if respondentid == .
keep if q4 == "Medium-size or small city" | q4 == "Metropolis"| q4 == "Rural County"
gen country = "UK"
gen resp = respondentid + 10000
drop startdate enddate status progress finished distributionchannel userlanguage fl* responseid id

**Correct reshaping of data into uniquely identifying candidate level (by respondent id x candidate number (1-20)).
*Renaming necessary
rename q17_1 answ_1
rename q17_2 answ_2
rename q18_1 answ_3
rename q18_2 answ_4
rename q19_1 answ_5
rename q19_2 answ_6
rename q20_1 answ_7
rename q20_2 answ_8
rename q21_1 answ_9
rename q21_2 answ_10
rename q22_1 answ_11
rename q22_2 answ_12
rename q23_1 answ_13
rename q23_2 answ_14
rename q24_1 answ_15
rename q24_2 answ_16
rename q25_1 answ_17
rename q25_2 answ_18
rename q26_1 answ_19
rename q26_2 answ_20

*Reshaping
reshape long answ dem age gender background party redi soc eco cor, i(respondentid) j(candidate, string)

*Renaming
rename q3 region
rename q4 urban 
rename q5 genderres
rename q6 ageres
rename q7 edures 
rename q8_1 abortion
rename q8_2 tax
rename q8_3 samesex
rename q8_4 welfare
rename q8_5 unions
rename q8_6 immi
rename q8_7 demfra
rename q9_1 aboprio
rename q9_2 taxprio
rename q9_3 samesexprio
rename q9_4 welprio
rename q9_5 unionprio
rename q9_6 immiprio
rename q10 pid
rename q11_1 conser
rename q11_2 labour
rename q15 mcheck
rename q27 attention
rename q28 device
rename block6_do treat

***Recoding
**Candidate attributes
clonevar canage = age
encode gender, gen(cangender)
encode background, gen(canbackground)
encode party, gen(canparty)
encode redi, gen(canredi)
recode canredi (1 = 0 "Decrease income tax on 10 percent richest") (4 = 1 "Increase income tax on 10 percent richest") (else=.), gen(cantax)
recode canredi (2 = 0 "Decrease power of trade unions") (5 = 1 "Increase power of trade unions") (else=.), gen(canunion)
recode canredi (3 = 0 "Decrease public welfare spending") (6 = 1 "Increase public welfare spending") (else=.), gen(canwel)
encode soc, gen(cansoc)
recode cansoc (1 = 1 "Allow illegal immigrants to apply for citizenship") (2 = 0 "Increase efforts to arrest and eventually deport illegal immigrants") (else=.), gen(canimmi)
recode cansoc (3 = 1 "Make it easier for people of the same sex to marry each other") (5 = 0 "Make it harder for people of the same sex to marry each other") (else=.), gen(canss)
recode cansoc (4 = 1 "Make it easier for women to get an abortion") (6 = 0 "Make it harder for women to get an abortion") (else=.), gen(canabort)
encode dem, gen(candem)
recode candem (1 5 6 7 = 0 "Democratic") (2 3 4 8 = 1 "Undemocratic"), gen(candemmg) //Making one variable where all undemocratic positions are merged
encode eco, gen(canec)
recode canec (1 = 1 "Bad at handling economic matters") (2 = 3 "Good at handling economic matters") (3 = 2 "Neither good nor bad reputation on economic matters"), gen(caneco)
encode cor, gen(canco)
recode canco (1 = 1 "Bad at fighting corruption") (2 = 3 "Good at fighting corruption") (3 = 2 "Neither good nor bad reputation on fighting corruption"), gen(cancor)
gen cancom = (caneco + cancor)-1
label define competence 1 "Very incompetent" 2 "Moderately incompetent" 3 "Neither competent nor incompetent" 4 "Moderately competent" 5 "Very competent"
label values cancom competence

**Respondent attributes
*Background vars
encode region, gen(regionres)
encode urban, gen(urbanres)
recode urbanres (3 = 1 "Rural County") (2 = 3 "Metropolis") (1 = 2 "Medium-size or small city"), gen(urbanr)
drop urbanres
encode genderres, gen(genderr)
encode edures, gen(edur)
recode edur (1 = 2 "High school") (3 = 1 "Less than high school") (2 = 3 "More than high school"), gen(edurr) //approximation
drop edur

**Preference extremity vars
encode abortion, gen(abortionpre)
encode tax, gen(taxpre)
encode samesex, gen(samesexpre)
encode welfare, gen(welfarepre)
encode unions, gen(unionspre)
encode immi, gen(immipre)
encode demfra, gen(demfrapre)
recode abortionpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(abrpre)
recode taxpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(taxrpre)
recode samesexpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(samerpre)
recode welfarepre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(welrpre)
recode unionspre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(uniorpre)
recode immipre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(immirpre)
recode demfrapre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(demfrpre)
drop abortionpre-demfrapre

*"Extremety on candidate-assigned attributes". Matextax is, for example, the respondent's preference on tax IF the candidate was assigned a tax position. Flips abortion, welfare, unions, and immigration so that low values are extreme left and high values are extreme right.
label define extreme 1 "Extreme left" 2 "Moderate Left" 3 "Center" 4 "Moderate Right" 5 "Extreme Right"
recode abrpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremeab)
recode welrpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremewel)
recode immirpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremeimmi)
recode uniorpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremeunion)
clonevar extremetax = taxrpre
clonevar extremess = samerpre
gen matextax = extremetax if cantax != .
gen matexwel = extremewel if canwel != .
gen matexunion = extremeunion if canunion != .
gen matexredi = .
replace matexredi = matextax if matextax != .
replace matexredi = matexwel if matexwel != .
replace matexredi = matexunion if matexunion != .
gen mateximmi = extremeimmi if canimmi != .
gen matexabo = extremeab if canabort != .
gen matexss = extremess if canss != .
gen matexsoc = .
replace matexsoc = mateximmi if mateximmi != .
replace matexsoc = matexabo if matexabo != .
replace matexsoc = matexss if matexss != .
label values matexsoc mateximmi matexredi matextax matexunion matexwel matexabo matexss extremetax extremess extremeab extremewel extremeunion extremeimmi extreme

**Policy distance between candidate and respondent
*Main measure
recode cantax (0 = 4.5) (1 = 1.5), gen(cantaxm)
recode canunion (0 = 4.5) (1 = 1.5), gen(canunionm)
recode canwel (0 = 4.5) (1 = 1.5), gen(canwelm)
gen canredim = .
replace canredim = cantaxm if cantaxm != .
replace canredim = canunionm if canunionm != .
replace canredim = canwelm if canwelm != .

recode canimmi (0 = 4.5) (1 = 1.5), gen(canimmim)
recode canss (0 = 4.5) (1 = 1.5), gen(canssm)
recode canabort (0 = 4.5) (1 = 1.5), gen(canabortm)
gen cansocm = .
replace cansocm = canimmim if canimmim != .
replace cansocm = canssm if canssm != .
replace cansocm = canabortm if canabortm != .

gen distaxm = matextax-cantaxm
gen disunionm = matexunion-canunionm
gen diswelm = matexwel-canwelm 
gen disredim = matexredi-canredim

gen disimmim = mateximmi-canimmim
gen disssm = matexss-canssm
gen disabom = matexabo-canabortm
gen dissocm = matexsoc-cansocm

gen dissumm = sqrt(disredim^2) + sqrt(dissocm^2)
label define distancem 1 "Completely Aligned Positions" 7 "Completely Diverting Positions"
label values dissumm distancem

*Supplementary measures
recode cantax (0 = 5) (1 = 1), gen(cantaxs1)
recode canunion (0 = 5) (1 = 1), gen(canunions1)
recode canwel (0 = 5) (1 = 1), gen(canwels1)
gen canredis1 = .
replace canredis1 = cantaxs1 if cantaxs1 != .
replace canredis1 = canunions1 if canunions1 != .
replace canredis1 = canwels1 if canwels1 != .

recode canimmi (0 = 5) (1 = 1), gen(canimmis1)
recode canss (0 = 5) (1 = 1), gen(cansss1)
recode canabort (0 = 5) (1 = 1), gen(canaborts1)
gen cansocs1 = .
replace cansocs1 = canimmis1 if canimmis1 != .
replace cansocs1 = cansss1 if cansss1 != .
replace cansocs1 = canaborts1 if canaborts1 != .

gen distaxs1 = matextax-cantaxs1
gen disunions1 = matexunion-canunions1
gen diswels1 = matexwel-canwels1 
gen disredis1 = matexredi-canredis1

gen disimmis1 = mateximmi-canimmis1
gen dissss1 = matexss-cansss1
gen disabos1 = matexabo-canaborts1
gen dissocs1 = matexsoc-cansocs1

gen dissums1 = sqrt(disredis1^2) + sqrt(dissocs1^2)
label define distances1 0 "Completely Aligned Positions" 8 "Completely Diverting Positions"
label values dissums1 distances1

recode cantax (0 = 4) (1 = 2), gen(cantaxs2)
recode canunion (0 = 4) (1 = 2), gen(canunions2)
recode canwel (0 = 4) (1 = 2), gen(canwels2)
gen canredis2 = .
replace canredis2 = cantaxs2 if cantaxs2 != .
replace canredis2 = canunions2 if canunions2 != .
replace canredis2 = canwels2 if canwels2 != .

recode canimmi (0 = 4) (1 = 2), gen(canimmis2)
recode canss (0 = 4) (1 = 2), gen(cansss2)
recode canabort (0 = 4) (1 = 2), gen(canaborts2)
gen cansocs2 = .
replace cansocs2 = canimmis2 if canimmis2 != .
replace cansocs2 = cansss2 if cansss2 != .
replace cansocs2 = canaborts2 if canaborts2 != .

gen distaxs2 = matextax-cantaxs2
gen disunions2 = matexunion-canunions2
gen diswels2 = matexwel-canwels2
gen disredis2 = matexredi-canredis2

gen disarms2 = mateximmi-canimmis2
gen dissss2 = matexss-cansss2
gen disabos2 = matexabo-canaborts2
gen dissocs2 = matexsoc-cansocs2

gen dissums2 = sqrt(disredis2^2) + sqrt(dissocs2^2)
label define distances2 0 "Completely Aligned Positions" 6 "Completely Diverting Positions"
label values dissums2 distances2

**Preference intensity vars (respondent)
encode aboprio, gen(abortionpri)
encode taxprio, gen(taxpri)
encode samesexprio, gen(samesexpri)
encode welprio, gen(welfarepri)
encode unionprio, gen(unionspri)
encode immiprio, gen(immipri)
recode abortionpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(abrpri)
recode taxpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(taxrpri)
recode samesexpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(samerpri)
recode welfarepri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(welrpri)
recode unionspri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(uniorpri)
recode immipri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(immirpri)
drop abortionpri-immipri


*"Intensity on candidate-assigned attributes". Matintax is, for example, the respondent's intensity on tax IF the candidate was assigned a tax position
label define intensity 1 "Very Low Intensity" 2 "Low Intensity" 3 "Moderate Intensity" 4 "High Intensity" 5 "Very High Intensity"
gen matintax = taxrpri if cantax != .
gen matinwel = welrpri if canwel != .
gen matinunion = uniorpri if canunion != .
gen matinredi = .
replace matinredi = matintax if matintax != .
replace matinredi = matinwel if matinwel != .
replace matinredi = matinunion if matinunion != .
gen matinimmi = immirpri if canimmi != .
gen matinabo = abrpri if canabort != .
gen matinss = samerpri if canss != .
gen matinsoc = .
replace matinsoc = matinimmi if matinimmi != .
replace matinsoc = matinabo if matinabo != .
replace matinsoc = matinss if matinss != .
label values matintax matinwel matinunion matinredi matinimmi matinabo matinss matinsoc intensity

*Intensity in favor of or against candidate: used for analysis
gen abodir = . 
replace abodir = -1 if extremeab < 3 & canabort == 0
replace abodir = -1 if extremeab > 3 & canabort == 1
replace abodir = -0.5 if extremeab == 3 & canabort !=.
replace abodir = 1 if extremeab < 3 & canabort == 1
replace abodir = 1 if extremeab > 3 & canabort == 0
gen aboint = abodir*abrpri

gen taxdir = . 
replace taxdir = -1 if extremetax < 3 & cantax == 0
replace taxdir = -1 if extremetax > 3 & cantax == 1
replace taxdir = -0.5 if extremetax == 3 & cantax !=.
replace taxdir = 1 if extremetax < 3 & cantax == 1
replace taxdir = 1 if extremetax > 3 & cantax == 0
gen taxint = taxdir*taxrpri

gen ssdir = . 
replace ssdir = -1 if extremess < 3 & canss == 0
replace ssdir = -1 if extremess > 3 & canss == 1
replace ssdir = -0.5 if extremess == 3 & canss !=.
replace ssdir = 1 if extremess < 3 & canss == 1
replace ssdir = 1 if extremess > 3 & canss == 0
gen ssint = ssdir*samerpri

gen weldir = . 
replace weldir = -1 if extremewel < 3 & canwel == 0
replace weldir = -1 if extremewel > 3 & canwel == 1
replace weldir = -0.5 if extremewel == 3 & canwel !=.
replace weldir = 1 if extremewel < 3 & canwel == 1
replace weldir = 1 if extremewel > 3 & canwel == 0
gen welint = weldir*welrpri

gen uniondir = . 
replace uniondir = -1 if extremeunion < 3 & canunion == 0
replace uniondir = -1 if extremeunion > 3 & canunion == 1
replace uniondir = -0.5 if extremeunion == 3 & canunion !=.
replace uniondir = 1 if extremeunion < 3 & canunion == 1
replace uniondir = 1 if extremeunion > 3 & canunion == 0
gen unionint = uniondir*uniorpri

gen immidir = . 
replace immidir = -1 if extremeimmi < 3 & canimmi == 0
replace immidir = -1 if extremeimmi > 3 & canimmi == 1
replace immidir = -0.5 if extremeimmi == 3 & canimmi !=.
replace immidir = 1 if extremeimmi < 3 & canimmi == 1
replace immidir = 1 if extremeimmi > 3 & canimmi == 0
gen immiint = immidir*immirpri

gen rediint =.
replace rediint = unionint if unionint != .
replace rediint = welint if welint != .
replace rediint = taxint if taxint != .

gen socint =.
replace socint = immiint if immiint != .
replace socint = ssint if ssint != .
replace socint = aboint if aboint != .

label define intensityfa -5 "Intense Opinion Against Candidate" -1 "Mild Opinion Against Candidate" 1 "Mild Opinion in Favor of Candidate" 5 "Intense Opinion in Favor of Candidate"
label values aboint taxint ssint rediint welint unionint immiint socint intensityfa


**Party ID
encode pid, gen(partyid)
recode partyid (2 =.)
drop pid
encode labour, gen(LABOx)
encode conser, gen(CONSx)
recode CONSx (1 = 1 "Dislike a great deal") (2 = 2 "Dislike somewhat") (3=.) (4 = 5 "Like a great deal") (5 = 4 "Like somewhat") (6 = 3 "Neither like nor dislike"), gen(CONS)
recode LABOx (1 = 1 "Dislike a great deal") (2 = 2 "Dislike somewhat") (3=.) (4 = 5 "Like a great deal") (5 = 4 "Like somewhat") (6 = 3 "Neither like nor dislike"), gen(LABO)
drop CONSx LABOx
gen partymmain = .
replace partymmain = LABO if canparty == 2
replace partymmain = CONS if canparty == 1
label define conparty 1 "Dislike candidate's party a great deal" 2 "Dislike candidate's party somewhat" 3 "Neither like nor dislike candidate's party" 4 "Like candidate's party somewhat" 5 "Like candidate's party a great deal"
label values partymmain conparty
recode partyid (4 = 0 "No Party ID") (2=.) (1 3 5 6 7 8 = 1 "Any Party ID"), gen(anyparty)
recode partyid (1 6 = 1 "CONS/LABO") (2=.) (3 4 5 7 8 = 0 "Not CONS/LABO"), gen(anyinparty)
gen copartisansplit = .
replace copartisansplit = 0 if anyinparty == 0
replace copartisansplit = 1 if partyid == 1 & canparty == 1
replace copartisansplit = 2 if partyid == 6 & canparty == 2
replace copartisansplit = 3 if partyid == 1 & canparty == 2
replace copartisansplit = 4 if partyid == 6 & canparty == 1
label define copartisansplit 0 "Neither Copartisanship nor Opposing Partisanship" 1 "Copartisanship: CONS" 2 "Copartisanship: LABO" 3 "Voter: CONS, Candidate: LABO" 4 "Voter: LABO, Candidate: CONS"
label values copartisansplit copartisansplit
recode copartisansplit (0 = 0 "Neither Copartisanship nor Opposing Partisanship") (1 2 = 1 "Copartisanship") (3 4 = 2 "Opposing Partisanship"), gen(copartisanmerge)


**Manipulation and attention check
encode mcheck, gen(mcheck1)
recode mcheck1 (1 = 3 "Democracy is neither robust nor vulnerable in the UK") (2 = 4 "Democracy is quite robust in the UK") (3 = 2 "Democracy is quite vulnerable in the UK") (4 = 5 "Democracy is very robust in the UK") (5 = 1 "Democracy is very vulnerable in the UK") (6=.), gen(manipulation)
drop mcheck1
encode attention, gen(atte)
recode atte (1=5 "Don't know") (2 = 4 "I have not been presented for a piece of text about the current state of democracy around the world") (3 = 2 "That many democratic breakdowns will occur during this decade") (4 = 1 "That no or only very few democratic breakdowns will occur during this decade") (5 = 3 "The piece of text did not mention any predictions"), gen(attent) //NB: Numbers may be wrong; check twice when data is in
drop atte

**Outcome
encode answ, gen(answer)
recode answer (1=.) (2 = 3 "Neither likely nor unlikely") (3 = 4 "Somewhat likely") (4 = 2 "Somewhat unlikely") (5 = 5 "Very likely") (6 = 1 "Very unlikely"), gen(support)
drop answer

**Treatment
encode treat, gen(treat1)
recode treat1 (1 = 0 "Robust") (2=1 "Vulnerable"), gen(treatment)
drop treat1
*Did the treatment work (i.e., did it affect perceived democratic vulnerability)? And does it work best with or without providing a democracy definition just before assigning the treatment?
reg manipulation i.treatment, cluster(respondentid) //clustering added
*Were the respondents attentive?
gen correctatte = .
replace correctatte = 0 if attent == 5
replace correctatte = 0 if attent == 4
replace correctatte = 0 if attent == 3
replace correctatte = 0 if attent == 2 & treatment == 0
replace correctatte = 0 if attent == 1 & treatment == 1
replace correctatte = 1 if attent == 1 & treatment == 0
replace correctatte = 1 if attent == 2 & treatment == 1
label define correct 0 "Inattentive" 1 "Attentive"
label values correctatte correct
sum correctatte

*Creating numerical variables identifying task and candidate number
generate task =.
replace task = 1 if candidate == "_1" | candidate == "_2"
replace task = 2 if candidate == "_3" | candidate == "_4"
replace task = 3 if candidate == "_5" | candidate == "_6"
replace task = 4 if candidate == "_7" | candidate == "_8"
replace task = 5 if candidate == "_9" | candidate == "_10"
replace task = 6 if candidate == "_11" | candidate == "_12"
replace task = 7 if candidate == "_13" | candidate == "_14"
replace task = 8 if candidate == "_15" | candidate == "_16"
replace task = 9 if candidate == "_17" | candidate == "_18"
replace task = 10 if candidate == "_19" | candidate == "_20"
generate candid =.
replace candid = 1 if candidate == "_1"
replace candid = 2 if candidate == "_2"
replace candid = 3 if candidate == "_3"
replace candid = 4 if candidate == "_4"
replace candid = 5 if candidate == "_5"
replace candid = 6 if candidate == "_6"
replace candid = 7 if candidate == "_7"
replace candid = 8 if candidate == "_8"
replace candid = 9 if candidate == "_9"
replace candid = 10 if candidate == "_10"
replace candid = 11 if candidate == "_11"
replace candid = 12 if candidate == "_12"
replace candid = 13 if candidate == "_13"
replace candid = 14 if candidate == "_14"
replace candid = 15 if candidate == "_15"
replace candid = 16 if candidate == "_16"
replace candid = 17 if candidate == "_17"
replace candid = 18 if candidate == "_18"
replace candid = 19 if candidate == "_19"
replace candid = 20 if candidate == "_20"

**Drop respondents with missing values on variables used for key tests
reg partymmain dissumm matexredi matexsoc rediint socint support
gen sample1 = e(sample)

*Saving for appending later
save "U:\How to Save a Democracy\Data\ukfinal.dta", replace


*****US*****
import delimited "U:\How to Save a Democracy\Data\usmain.tsv", varnames(1) encoding(UTF-16LE) numericcols(14 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84) clear
encode responseid, gen(id)
generate respondentid = id+1
drop if respondentid == .
keep if q4 == "Medium-size or small city" | q4 == "Metropolis"| q4 == "Rural County"
gen country = "US"
gen resp = respondentid + 20000
drop startdate enddate status progress finished distributionchannel userlanguage fl* responseid id

**Correct reshaping of data into uniquely identifying candidate level (by respondent id x candidate number (1-20)).
*Renaming necessary
rename q17_1 answ_1
rename q17_2 answ_2
rename q18_1 answ_3
rename q18_2 answ_4
rename q19_1 answ_5
rename q19_2 answ_6
rename q20_1 answ_7
rename q20_2 answ_8
rename q21_1 answ_9
rename q21_2 answ_10
rename q22_1 answ_11
rename q22_2 answ_12
rename q23_1 answ_13
rename q23_2 answ_14
rename q24_1 answ_15
rename q24_2 answ_16
rename q25_1 answ_17
rename q25_2 answ_18
rename q26_1 answ_19
rename q26_2 answ_20

*Reshaping
reshape long answ dem age gender background party redi soc eco cor, i(respondentid) j(candidate, string)

*Renaming
rename q3 region
rename q4 urban 
rename q5 genderres
rename q6 ageres
rename q7 edures 
rename q8_1 abortion
rename q8_2 tax
rename q8_3 samesex
rename q8_4 welfare
rename q8_5 unions
rename q8_6 immi
rename q8_7 demfra
rename q9_1 aboprio
rename q9_2 taxprio
rename q9_3 samesexprio
rename q9_4 welprio
rename q9_5 unionprio
rename q9_6 immiprio
rename q10 pid
rename q11_1 demp
rename q11_2 repp
rename q15 mcheck
rename q27 attention
rename q28 device
rename block6_do treat

***Recoding
**Candidate attributes
clonevar canage = age
encode gender, gen(cangender)
encode background, gen(canbackground)
encode party, gen(canparty)
encode redi, gen(canredi)
recode canredi (1 = 0 "Decrease income tax on 10 percent richest") (4 = 1 "Increase income tax on 10 percent richest") (else=.), gen(cantax)
recode canredi (2 = 0 "Decrease power of labor unions") (5 = 1 "Increase power of labor unions") (else=.), gen(canunion)
recode canredi (3 = 0 "Decrease public welfare spending") (6 = 1 "Increase public welfare spending") (else=.), gen(canwel)
encode soc, gen(cansoc)
recode cansoc (1 = 1 "Allow illegal immigrants to apply for citizenship") (2 = 0 "Increase efforts to arrest and eventually deport illegal immigrants") (else=.), gen(canimmi)
recode cansoc (3 = 1 "Make it easier for people of the same sex to marry each other") (5 = 0 "Make it harder for people of the same sex to marry each other") (else=.), gen(canss)
recode cansoc (4 = 1 "Make it easier for women to get an abortion") (6 = 0 "Make it harder for women to get an abortion") (else=.), gen(canabort)
encode dem, gen(candem)
recode candem (1 5 6 7 = 0 "Democratic") (2 3 4 8 = 1 "Undemocratic"), gen(candemmg) //Making one variable where all undemocratic positions are merged
encode eco, gen(canec)
recode canec (1 = 1 "Bad at handling economic matters") (2 = 3 "Good at handling economic matters") (3 = 2 "Neither good nor bad reputation on economic matters"), gen(caneco)
encode cor, gen(canco)
recode canco (1 = 1 "Bad at fighting corruption") (2 = 3 "Good at fighting corruption") (3 = 2 "Neither good nor bad reputation on fighting corruption"), gen(cancor)
gen cancom = (caneco + cancor)-1
label define competence 1 "Very incompetent" 2 "Moderately incompetent" 3 "Neither competent nor incompetent" 4 "Moderately competent" 5 "Very competent"
label values cancom competence

**Respondent attributes
*Background vars
encode region, gen(regionres)
encode urban, gen(urbanres)
recode urbanres (3 = 1 "Rural County") (2 = 3 "Metropolis") (1 = 2 "Medium-size or small city"), gen(urbanr)
drop urbanres
encode genderres, gen(genderr)
encode edures, gen(edur)
recode edur (1 = 2 "High school") (2 = 1 "Less than high school") (3 = 3 "More than high school"), gen(edurr)
drop edur

**Preference extremity vars
encode abortion, gen(abortionpre)
encode tax, gen(taxpre)
encode samesex, gen(samesexpre)
encode welfare, gen(welfarepre)
encode unions, gen(unionspre)
encode immi, gen(immipre)
encode demfra, gen(demfrapre)
recode abortionpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(abrpre)
recode taxpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(taxrpre)
recode samesexpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(samerpre)
recode welfarepre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(welrpre)
recode unionspre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(uniorpre)
recode immipre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(immirpre)
recode demfrapre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(demfrpre)
drop abortionpre-demfrapre

*"Extremety on candidate-assigned attributes". Matextax is, for example, the respondent's preference on tax IF the candidate was assigned a tax position. Flips abortion, welfare, unions, and immigration so that low values are extreme left and high values are extreme right.
label define extreme 1 "Extreme left" 2 "Moderate Left" 3 "Center" 4 "Moderate Right" 5 "Extreme Right"
recode abrpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremeab)
recode welrpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremewel)
recode immirpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremeimmi)
recode uniorpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremeunion)
clonevar extremetax = taxrpre
clonevar extremess = samerpre
gen matextax = extremetax if cantax != .
gen matexwel = extremewel if canwel != .
gen matexunion = extremeunion if canunion != .
gen matexredi = .
replace matexredi = matextax if matextax != .
replace matexredi = matexwel if matexwel != .
replace matexredi = matexunion if matexunion != .
gen mateximmi = extremeimmi if canimmi != .
gen matexabo = extremeab if canabort != .
gen matexss = extremess if canss != .
gen matexsoc = .
replace matexsoc = mateximmi if mateximmi != .
replace matexsoc = matexabo if matexabo != .
replace matexsoc = matexss if matexss != .
label values matexsoc mateximmi matexredi matextax matexunion matexwel matexabo matexss extremetax extremess extremeab extremewel extremeunion extremeimmi extreme

**Policy distance between candidate and respondent
*Main measure
recode cantax (0 = 4.5) (1 = 1.5), gen(cantaxm)
recode canunion (0 = 4.5) (1 = 1.5), gen(canunionm)
recode canwel (0 = 4.5) (1 = 1.5), gen(canwelm)
gen canredim = .
replace canredim = cantaxm if cantaxm != .
replace canredim = canunionm if canunionm != .
replace canredim = canwelm if canwelm != .

recode canimmi (0 = 4.5) (1 = 1.5), gen(canimmim)
recode canss (0 = 4.5) (1 = 1.5), gen(canssm)
recode canabort (0 = 4.5) (1 = 1.5), gen(canabortm)
gen cansocm = .
replace cansocm = canimmim if canimmim != .
replace cansocm = canssm if canssm != .
replace cansocm = canabortm if canabortm != .

gen distaxm = matextax-cantaxm
gen disunionm = matexunion-canunionm
gen diswelm = matexwel-canwelm 
gen disredim = matexredi-canredim

gen disimmim = mateximmi-canimmim
gen disssm = matexss-canssm
gen disabom = matexabo-canabortm
gen dissocm = matexsoc-cansocm

gen dissumm = sqrt(disredim^2) + sqrt(dissocm^2)
label define distancem 1 "Completely Aligned Positions" 7 "Completely Diverting Positions"
label values dissumm distancem

*Supplementary measures
recode cantax (0 = 5) (1 = 1), gen(cantaxs1)
recode canunion (0 = 5) (1 = 1), gen(canunions1)
recode canwel (0 = 5) (1 = 1), gen(canwels1)
gen canredis1 = .
replace canredis1 = cantaxs1 if cantaxs1 != .
replace canredis1 = canunions1 if canunions1 != .
replace canredis1 = canwels1 if canwels1 != .

recode canimmi (0 = 5) (1 = 1), gen(canimmis1)
recode canss (0 = 5) (1 = 1), gen(cansss1)
recode canabort (0 = 5) (1 = 1), gen(canaborts1)
gen cansocs1 = .
replace cansocs1 = canimmis1 if canimmis1 != .
replace cansocs1 = cansss1 if cansss1 != .
replace cansocs1 = canaborts1 if canaborts1 != .

gen distaxs1 = matextax-cantaxs1
gen disunions1 = matexunion-canunions1
gen diswels1 = matexwel-canwels1 
gen disredis1 = matexredi-canredis1

gen disimmis1 = mateximmi-canimmis1
gen dissss1 = matexss-cansss1
gen disabos1 = matexabo-canaborts1
gen dissocs1 = matexsoc-cansocs1

gen dissums1 = sqrt(disredis1^2) + sqrt(dissocs1^2)
label define distances1 0 "Completely Aligned Positions" 8 "Completely Diverting Positions"
label values dissums1 distances1

recode cantax (0 = 4) (1 = 2), gen(cantaxs2)
recode canunion (0 = 4) (1 = 2), gen(canunions2)
recode canwel (0 = 4) (1 = 2), gen(canwels2)
gen canredis2 = .
replace canredis2 = cantaxs2 if cantaxs2 != .
replace canredis2 = canunions2 if canunions2 != .
replace canredis2 = canwels2 if canwels2 != .

recode canimmi (0 = 4) (1 = 2), gen(canimmis2)
recode canss (0 = 4) (1 = 2), gen(cansss2)
recode canabort (0 = 4) (1 = 2), gen(canaborts2)
gen cansocs2 = .
replace cansocs2 = canimmis2 if canimmis2 != .
replace cansocs2 = cansss2 if cansss2 != .
replace cansocs2 = canaborts2 if canaborts2 != .

gen distaxs2 = matextax-cantaxs2
gen disunions2 = matexunion-canunions2
gen diswels2 = matexwel-canwels2
gen disredis2 = matexredi-canredis2

gen disarms2 = mateximmi-canimmis2
gen dissss2 = matexss-cansss2
gen disabos2 = matexabo-canaborts2
gen dissocs2 = matexsoc-cansocs2

gen dissums2 = sqrt(disredis2^2) + sqrt(dissocs2^2)
label define distances2 0 "Completely Aligned Positions" 6 "Completely Diverting Positions"
label values dissums2 distances2

**Preference intensity vars (respondent)
encode aboprio, gen(abortionpri)
encode taxprio, gen(taxpri)
encode samesexprio, gen(samesexpri)
encode welprio, gen(welfarepri)
encode unionprio, gen(unionspri)
encode immiprio, gen(immipri)
recode abortionpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(abrpri)
recode taxpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(taxrpri)
recode samesexpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(samerpri)
recode welfarepri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(welrpri)
recode unionspri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(uniorpri)
recode immipri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(immirpri)
drop abortionpri-immipri


*"Intensity on candidate-assigned attributes". Matintax is, for example, the respondent's intensity on tax IF the candidate was assigned a tax position
label define intensity 1 "Very Low Intensity" 2 "Low Intensity" 3 "Moderate Intensity" 4 "High Intensity" 5 "Very High Intensity"
gen matintax = taxrpri if cantax != .
gen matinwel = welrpri if canwel != .
gen matinunion = uniorpri if canunion != .
gen matinredi = .
replace matinredi = matintax if matintax != .
replace matinredi = matinwel if matinwel != .
replace matinredi = matinunion if matinunion != .
gen matinimmi = immirpri if canimmi != .
gen matinabo = abrpri if canabort != .
gen matinss = samerpri if canss != .
gen matinsoc = .
replace matinsoc = matinimmi if matinimmi != .
replace matinsoc = matinabo if matinabo != .
replace matinsoc = matinss if matinss != .
label values matintax matinwel matinunion matinredi matinimmi matinabo matinss matinsoc intensity

*Intensity in favor of or against candidate: used for analysis
gen abodir = . 
replace abodir = -1 if extremeab < 3 & canabort == 0
replace abodir = -1 if extremeab > 3 & canabort == 1
replace abodir = -0.5 if extremeab == 3 & canabort !=.
replace abodir = 1 if extremeab < 3 & canabort == 1
replace abodir = 1 if extremeab > 3 & canabort == 0
gen aboint = abodir*abrpri

gen taxdir = . 
replace taxdir = -1 if extremetax < 3 & cantax == 0
replace taxdir = -1 if extremetax > 3 & cantax == 1
replace taxdir = -0.5 if extremetax == 3 & cantax !=.
replace taxdir = 1 if extremetax < 3 & cantax == 1
replace taxdir = 1 if extremetax > 3 & cantax == 0
gen taxint = taxdir*taxrpri

gen ssdir = . 
replace ssdir = -1 if extremess < 3 & canss == 0
replace ssdir = -1 if extremess > 3 & canss == 1
replace ssdir = -0.5 if extremess == 3 & canss !=.
replace ssdir = 1 if extremess < 3 & canss == 1
replace ssdir = 1 if extremess > 3 & canss == 0
gen ssint = ssdir*samerpri

gen weldir = . 
replace weldir = -1 if extremewel < 3 & canwel == 0
replace weldir = -1 if extremewel > 3 & canwel == 1
replace weldir = -0.5 if extremewel == 3 & canwel !=.
replace weldir = 1 if extremewel < 3 & canwel == 1
replace weldir = 1 if extremewel > 3 & canwel == 0
gen welint = weldir*welrpri

gen uniondir = . 
replace uniondir = -1 if extremeunion < 3 & canunion == 0
replace uniondir = -1 if extremeunion > 3 & canunion == 1
replace uniondir = -0.5 if extremeunion == 3 & canunion !=.
replace uniondir = 1 if extremeunion < 3 & canunion == 1
replace uniondir = 1 if extremeunion > 3 & canunion == 0
gen unionint = uniondir*uniorpri

gen immidir = . 
replace immidir = -1 if extremeimmi < 3 & canimmi == 0
replace immidir = -1 if extremeimmi > 3 & canimmi == 1
replace immidir = -0.5 if extremeimmi == 3 & canimmi !=.
replace immidir = 1 if extremeimmi < 3 & canimmi == 1
replace immidir = 1 if extremeimmi > 3 & canimmi == 0
gen immiint = immidir*immirpri

gen rediint =.
replace rediint = unionint if unionint != .
replace rediint = welint if welint != .
replace rediint = taxint if taxint != .

gen socint =.
replace socint = immiint if immiint != .
replace socint = ssint if ssint != .
replace socint = aboint if aboint != .

label define intensityfa -5 "Intense Opinion Against Candidate" -1 "Mild Opinion Against Candidate" 1 "Mild Opinion in Favor of Candidate" 5 "Intense Opinion in Favor of Candidate"
label values aboint taxint ssint rediint welint unionint immiint socint intensityfa


**Party ID
encode pid, gen(partyid)
recode partyid (2 =.)
drop pid
encode repp, gen(REPx)
encode demp, gen(DEMx)
recode REPx (1 = 1 "Dislike a great deal") (2 = 2 "Dislike somewhat") (3=.) (4 = 5 "Like a great deal") (5 = 4 "Like somewhat") (6 = 3 "Neither like nor dislike"), gen(REP)
recode DEMx (1 = 1 "Dislike a great deal") (2 = 2 "Dislike somewhat") (3=.) (4 = 5 "Like a great deal") (5 = 4 "Like somewhat") (6 = 3 "Neither like nor dislike"), gen(DEM)
drop REPx-DEMx
gen partymmain = .
replace partymmain = REP if canparty == 2
replace partymmain = DEM if canparty == 1
label define conparty 1 "Dislike candidate's party a great deal" 2 "Dislike candidate's party somewhat" 3 "Neither like nor dislike candidate's party" 4 "Like candidate's party somewhat" 5 "Like candidate's party a great deal"
label values partymmain conparty
recode partyid (3 = 0 "No Party ID") (2=.) (1 4 5 = 1 "Any Party ID"), gen(anyparty)
recode partyid (1 5 = 1 "DEM/REP") (2=.) (3 4 = 0 "Not DEM/REP"), gen(anyinparty)
gen copartisansplit = .
replace copartisansplit = 0 if anyinparty == 0
replace copartisansplit = 1 if partyid == 1 & canparty == 1
replace copartisansplit = 2 if partyid == 5 & canparty == 2
replace copartisansplit = 3 if partyid == 1 & canparty == 2
replace copartisansplit = 4 if partyid == 5 & canparty == 1
label define copartisansplit 0 "Neither Copartisanship nor Opposing Partisanship" 1 "Copartisanship: DEM" 2 "Copartisanship: REP" 3 "Voter: DEM, Candidate: REP" 4 "Voter: REP, Candidate: DEM"
label values copartisansplit copartisansplit
recode copartisansplit (0 = 0 "Neither Copartisanship nor Opposing Partisanship") (1 2 = 1 "Copartisanship") (3 4 = 2 "Opposing Partisanship"), gen(copartisanmerge)


**Manipulation and attention check
encode mcheck, gen(mcheck1)
recode mcheck1 (1 = 3 "Democracy is neither robust nor vulnerable in the United States") (2 = 4 "Democracy is quite robust in the United States") (3 = 2 "Democracy is quite vulnerable in the United States") (4 = 5 "Democracy is very robust in the United States") (5 = 1 "Democracy is very vulnerable in the United States") (6=.), gen(manipulation)
drop mcheck1
encode attention, gen(atte)
recode atte (1=5 "Don't know") (2 = 4 "I have not been presented for a piece of text about the current state of democracy around the world") (3 = 2 "That many democratic breakdowns will occur during this decade") (4 = 1 "That no or only very few democratic breakdowns will occur during this decade") (5 = 3 "The piece of text did not mention any predictions"), gen(attent) //NB: Numbers may be wrong; check twice when data is in
drop atte

**Outcome
encode answ, gen(answer)
recode answer (1=.) (2 = 3 "Neither likely nor unlikely") (3 = 4 "Somewhat likely") (4 = 2 "Somewhat unlikely") (5 = 5 "Very likely") (6 = 1 "Very unlikely"), gen(support)
drop answer

**Treatment
encode treat, gen(treat1)
recode treat1 (1 = 0 "Robust") (2=1 "Vulnerable"), gen(treatment)
drop treat1
*Did the treatment work (i.e., did it affect perceived democratic vulnerability)? And does it work best with or without providing a democracy definition just before assigning the treatment?
reg manipulation i.treatment, cluster(respondentid) //clustering added
*Were the respondents attentive?
gen correctatte = .
replace correctatte = 0 if attent == 5
replace correctatte = 0 if attent == 4
replace correctatte = 0 if attent == 3
replace correctatte = 0 if attent == 2 & treatment == 0
replace correctatte = 0 if attent == 1 & treatment == 1
replace correctatte = 1 if attent == 1 & treatment == 0
replace correctatte = 1 if attent == 2 & treatment == 1
label define correct 0 "Inattentive" 1 "Attentive"
label values correctatte correct
sum correctatte

*Creating numerical variables identifying task and candidate number
generate task =.
replace task = 1 if candidate == "_1" | candidate == "_2"
replace task = 2 if candidate == "_3" | candidate == "_4"
replace task = 3 if candidate == "_5" | candidate == "_6"
replace task = 4 if candidate == "_7" | candidate == "_8"
replace task = 5 if candidate == "_9" | candidate == "_10"
replace task = 6 if candidate == "_11" | candidate == "_12"
replace task = 7 if candidate == "_13" | candidate == "_14"
replace task = 8 if candidate == "_15" | candidate == "_16"
replace task = 9 if candidate == "_17" | candidate == "_18"
replace task = 10 if candidate == "_19" | candidate == "_20"
generate candid =.
replace candid = 1 if candidate == "_1"
replace candid = 2 if candidate == "_2"
replace candid = 3 if candidate == "_3"
replace candid = 4 if candidate == "_4"
replace candid = 5 if candidate == "_5"
replace candid = 6 if candidate == "_6"
replace candid = 7 if candidate == "_7"
replace candid = 8 if candidate == "_8"
replace candid = 9 if candidate == "_9"
replace candid = 10 if candidate == "_10"
replace candid = 11 if candidate == "_11"
replace candid = 12 if candidate == "_12"
replace candid = 13 if candidate == "_13"
replace candid = 14 if candidate == "_14"
replace candid = 15 if candidate == "_15"
replace candid = 16 if candidate == "_16"
replace candid = 17 if candidate == "_17"
replace candid = 18 if candidate == "_18"
replace candid = 19 if candidate == "_19"
replace candid = 20 if candidate == "_20"

**Drop respondents with missing values on variables used for key tests
reg partymmain dissumm matexredi matexsoc rediint socint support
gen sample1 = e(sample)

*Saving for appending later
save "U:\How to Save a Democracy\Data\usfinal.dta", replace



*****MX*****
import delimited "U:\How to Save a Democracy\Data\mxmain.tsv", varnames(1) encoding(UTF-16LE) numericcols(14 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87) clear
encode responseid, gen(id)
generate respondentid = id+1
drop if respondentid == .
keep if q4 == "Ciudad mediana o pequeña" | q4 == "Zona metropolitana"| q4 == "Zona rural"
gen country = "MX"
gen resp = respondentid + 30000
drop startdate enddate status progress finished distributionchannel userlanguage fl* responseid id


**Correct reshaping of data into uniquely identifying candidate level (by respondent id x candidate number (1-20)).
*Renaming necessary
rename q17_1 answ_1
rename q17_2 answ_2
rename q18_1 answ_3
rename q18_2 answ_4
rename q19_1 answ_5
rename q19_2 answ_6
rename q20_1 answ_7
rename q20_2 answ_8
rename q21_1 answ_9
rename q21_2 answ_10
rename q22_1 answ_11
rename q22_2 answ_12
rename q23_1 answ_13
rename q23_2 answ_14
rename q24_1 answ_15
rename q24_2 answ_16
rename q25_1 answ_17
rename q25_2 answ_18
rename q26_1 answ_19
rename q26_2 answ_20

*Reshaping
reshape long answ dem age gender background party redi soc eco cor, i(respondentid) j(candidate, string)

*Renaming
rename q3 region
rename q4 urban 
rename q5 genderres
rename q6 ageres
rename q7 edures 
rename q8_1 abortion
rename q8_2 tax
rename q8_3 samesex
rename q8_4 welfare
rename q8_5 edu
rename q8_6 crime
rename q8_7 demfra
rename q9_1 aboprio
rename q9_2 taxprio
rename q9_3 samesexprio
rename q9_4 welprio
rename q9_5 eduprio
rename q9_6 crimeprio
rename q10 pid
rename q11_1 pri
rename q11_2 prd
rename q11_3 morena
rename q11_4 pan
rename q11_5 ciu
rename q15 mcheck
rename q27 attention
rename q28 device
rename block1_do treat

*Translating variables to English
replace abortion = "Strongly agree" if abortion == "Totalmente de acuerdo"
replace abortion = "Don't know" if abortion == "No sé"
replace abortion = "Somewhat agree" if abortion == "Ligeramente de acuerdo"
replace abortion = "Neither agree nor disagree" if abortion == "Ni de acuerdo ni en desacuerdo"
replace abortion = "Strongly disagree" if abortion == "Totalmente en desacuerdo"
replace abortion = "Somewhat disagree" if abortion == "Ligeramente en desacuerdo"
replace tax = "Strongly agree" if tax == "Totalmente de acuerdo"
replace tax = "Don't know" if tax == "No sé"
replace tax = "Somewhat agree" if tax == "Ligeramente de acuerdo"
replace tax = "Neither agree nor disagree" if tax == "Ni de acuerdo ni en desacuerdo"
replace tax = "Strongly disagree" if tax == "Totalmente en desacuerdo"
replace tax = "Somewhat disagree" if tax == "Ligeramente en desacuerdo"
replace samesex = "Strongly agree" if samesex == "Totalmente de acuerdo"
replace samesex = "Don't know" if samesex == "No sé"
replace samesex = "Somewhat agree" if samesex == "Ligeramente de acuerdo"
replace samesex = "Neither agree nor disagree" if samesex == "Ni de acuerdo ni en desacuerdo"
replace samesex = "Strongly disagree" if samesex == "Totalmente en desacuerdo"
replace samesex = "Somewhat disagree" if samesex == "Ligeramente en desacuerdo"
replace welfare = "Strongly agree" if welfare == "Totalmente de acuerdo"
replace welfare = "Don't know" if welfare == "No sé"
replace welfare = "Somewhat agree" if welfare == "Ligeramente de acuerdo"
replace welfare = "Neither agree nor disagree" if welfare == "Ni de acuerdo ni en desacuerdo"
replace welfare = "Strongly disagree" if welfare == "Totalmente en desacuerdo"
replace welfare = "Somewhat disagree" if welfare == "Ligeramente en desacuerdo"
replace edu = "Strongly agree" if edu == "Totalmente de acuerdo"
replace edu = "Don't know" if edu == "No sé"
replace edu = "Somewhat agree" if edu == "Ligeramente de acuerdo"
replace edu = "Neither agree nor disagree" if edu == "Ni de acuerdo ni en desacuerdo"
replace edu = "Strongly disagree" if edu == "Totalmente en desacuerdo"
replace edu = "Somewhat disagree" if edu == "Ligeramente en desacuerdo"
replace crime = "Strongly agree" if crime == "Totalmente de acuerdo"
replace crime = "Don't know" if crime == "No sé"
replace crime = "Somewhat agree" if crime == "Ligeramente de acuerdo"
replace crime = "Neither agree nor disagree" if crime == "Ni de acuerdo ni en desacuerdo"
replace crime = "Strongly disagree" if crime == "Totalmente en desacuerdo"
replace crime = "Somewhat disagree" if crime == "Ligeramente en desacuerdo"
replace demfra = "Strongly agree" if demfra == "Totalmente de acuerdo"
replace demfra = "Don't know" if demfra == "No sé"
replace demfra = "Somewhat agree" if demfra == "Ligeramente de acuerdo"
replace demfra = "Neither agree nor disagree" if demfra == "Ni de acuerdo ni en desacuerdo"
replace demfra = "Strongly disagree" if demfra == "Totalmente en desacuerdo"
replace demfra = "Somewhat disagree" if demfra == "Ligeramente en desacuerdo"
replace aboprio = "Not at all important" if aboprio == "Nada importante" 
replace aboprio = "Don't know" if aboprio == "No sé"
replace aboprio = "Extremely important" if aboprio == "Sumamente importante"
replace aboprio = "Very important" if aboprio == "Muy importante"
replace aboprio = "Not very important" if aboprio == "No muy importante"
replace aboprio = "Moderately important" if aboprio == "Moderadamente importante"
replace taxprio = "Not at all important" if taxprio == "Nada importante"
replace taxprio = "Don't know" if taxprio == "No sé"
replace taxprio = "Extremely important" if taxprio == "Sumamente importante"
replace taxprio = "Very important" if taxprio == "Muy importante"
replace taxprio = "Not very important" if taxprio == "No muy importante"
replace taxprio = "Moderately important" if taxprio == "Moderadamente importante"
replace samesexprio = "Not at all important" if samesexprio == "Nada importante"
replace samesexprio = "Don't know" if samesexprio == "No sé"
replace samesexprio = "Extremely important" if samesexprio == "Sumamente importante"
replace samesexprio = "Very important" if samesexprio == "Muy importante"
replace samesexprio = "Not very important" if samesexprio == "No muy importante"
replace samesexprio = "Moderately important" if samesexprio == "Moderadamente importante"
replace welprio = "Not at all important" if welprio == "Nada importante"
replace welprio = "Don't know" if welprio == "No sé"
replace welprio = "Extremely important" if welprio == "Sumamente importante"
replace welprio = "Very important" if welprio == "Muy importante"
replace welprio = "Not very important" if welprio == "No muy importante"
replace welprio = "Moderately important" if welprio == "Moderadamente importante"
replace eduprio = "Not at all important" if eduprio == "Nada importante"
replace eduprio = "Don't know" if eduprio == "No sé"
replace eduprio = "Extremely important" if eduprio == "Sumamente importante"
replace eduprio = "Very important" if eduprio == "Muy importante"
replace eduprio = "Not very important" if eduprio == "No muy importante"
replace eduprio = "Moderately important" if eduprio == "Moderadamente importante"
replace crimeprio = "Not at all important" if crimeprio == "Nada importante"
replace crimeprio = "Don't know" if crimeprio == "No sé"
replace crimeprio = "Extremely important" if crimeprio == "Sumamente importante"
replace crimeprio = "Very important" if crimeprio == "Muy importante"
replace crimeprio = "Not very important" if crimeprio == "No muy importante"
replace crimeprio = "Moderately important" if crimeprio == "Moderadamente importante"
replace pid = "I identify with a party not listed here" if pid == "Me identifico con un partido que no está enumerado aquí en la lista"
replace pid = "MORENA" if pid == "MORENA (Movimiento Regeneración Nacional)"
replace pid = "Don't know" if pid == "No sé"
replace pid = "I do not identify with any party" if pid == "No me identifico con ningún partido"
replace pid = "PAN" if pid == "PAN (Partido Acción Nacional)"
replace pid = "PRD" if pid == "PRD (Partido de la Revolución Democrática)"
replace pid = "PRI" if pid == "PRI (Partido Revolucionario Institucional)"
replace pri = "Dislike a great deal" if pri == "Me desagrada mucho"
replace pri = "Like a great deal" if pri == "Me agrada mucho"
replace pri = "Don't know" if pri == "No sé"
replace pri = "Dislike somewhat" if pri == "Me desagrada un poco"
replace pri = "Like somewhat" if pri == "Me agrada un poco"
replace pri = "Neither like nor dislike" if pri == "Ni me agrada ni me desagrada"
replace prd = "Dislike a great deal" if prd == "Me desagrada mucho"
replace prd = "Like a great deal" if prd == "Me agrada mucho"
replace prd = "Don't know" if prd == "No sé"
replace prd = "Dislike somewhat" if prd == "Me desagrada un poco"
replace prd = "Like somewhat" if prd == "Me agrada un poco"
replace prd = "Neither like nor dislike" if prd == "Ni me agrada ni me desagrada"
replace morena = "Dislike a great deal" if morena == "Me desagrada mucho"
replace morena = "Like a great deal" if morena == "Me agrada mucho"
replace morena = "Don't know" if morena == "No sé"
replace morena = "Dislike somewhat" if morena == "Me desagrada un poco"
replace morena = "Like somewhat" if morena == "Me agrada un poco"
replace morena = "Neither like nor dislike" if morena == "Ni me agrada ni me desagrada"
replace pan = "Dislike a great deal" if pan == "Me desagrada mucho"
replace pan = "Like a great deal" if pan == "Me agrada mucho"
replace pan = "Don't know" if pan == "No sé"
replace pan = "Dislike somewhat" if pan == "Me desagrada un poco"
replace pan = "Like somewhat" if pan == "Me agrada un poco"
replace pan = "Neither like nor dislike" if pan == "Ni me agrada ni me desagrada"
replace ciu = "Dislike a great deal" if ciu == "Me desagrada mucho"
replace ciu = "Like a great deal" if ciu == "Me agrada mucho"
replace ciu = "Don't know" if ciu == "No sé"
replace ciu = "Dislike somewhat" if ciu == "Me desagrada un poco"
replace ciu = "Like somewhat" if ciu == "Me agrada un poco"
replace ciu = "Neither like nor dislike" if ciu == "Ni me agrada ni me desagrada"
replace mcheck = "Democracy is neither robust nor vulnerable in Mexico" if mcheck == "La democracia no es ni robusta ni vulnerable en México"
replace mcheck = "Democracy is quite robust in Mexico" if mcheck == "La democracia es bastante robusta en México"
replace mcheck = "Democracy is quite vulnerable in Mexico" if mcheck == "La democracia es bastante vulnerable en México"
replace mcheck = "Democracy is very robust in Mexico" if mcheck == "La democracia es muy robusta en México"
replace mcheck = "Democracy is very vulnerable in Mexico" if mcheck == "La democracia es muy vulnerable en México"
replace mcheck = "Don't know" if mcheck == "No sé"
replace attention = "The piece of text did not mention any predictions" if attention == "El texto mencionó ninguna predicción"
replace attention = "Don't know" if attention == "No sé"
replace attention = "I have not been presented for a piece of text about the current state of democracy around the world" if attention == "No se me mostró un texto acerca del estado actual de la democracia en todo el mundo"
replace attention = "That many democratic breakdowns will occur during this decade" if attention == "Que muchos colapsos democráticos sucederán durante esta década"
replace attention = "That no or only very few democratic breakdowns will occur during this decade" if attention == "Que ninguno o muy pocos colapsos democráticos sucederán durante esta década"
replace device = "Prefer not to answer" if device == "Prefiero no responder"
replace device = "Other" if device == "Otra opción"
replace device = "Smartphone" if device == "Teléfono inteligente"
replace device = "PC or Macbook" if device == "Computadora personal o MacBook"
replace device = "Tablet" if device == "Tableta"
replace answ = "Very unlikely" if answ == "Muy improbable"
replace answ = "Very likely" if answ == "Muy probable"
replace answ = "Don't know" if answ == "No sé"
replace answ = "Somewhat unlikely" if answ == "Ligeramente improbable"
replace answ = "Somewhat likely" if answ == "Ligeramente probable"
replace answ = "Neither likely nor unlikely" if answ == "Ni probable ni improbable"
replace dem = "Said it is unacceptable to harass journalists even though they do not reveal sources" if dem == "Dijo que es inaceptable acosar a los periodistas, incluso si no revelan sus fuentes"
replace dem = "Said it is legitimate to fight political opponents in the streets if one feels provoked" if dem == "Dijo que es legal luchar contra oponentes políticos en las calles si uno(a) se siente provocado(a)"
replace dem = "Said it is unacceptable to fight political opponents in the streets even though one feels provoked" if dem == "Dijo que es inaceptable luchar contra oponentes políticos en las calles si uno(a) se siente provocado(a)"
replace dem = "Said court rulings by judges appointed by opposing parties should be ignored" if dem == "Dijo que deberían ignorarse las sentencias de los jueces nombrados por los partidos de oposición"
replace dem = "Said court rulings by judges appointed by opposing parties should be adhered to" if dem == "Dijo que deberían cumplirse las sentencias de los jueces nombrados por los partidos de oposición"
replace dem = "Supported a proposal to reduce polling stations in areas that support opposing parties" if dem == "Apoyó una propuesta para reducir los centros electorales en áreas que apoyan a los partidos de oposición"
replace dem = "Supported a proposal to preserve existing polling-stations in all areas" if dem == "Apoyó una propuesta para conservar los centros electorales existentes en todas las áreas"
replace dem = "Said it is acceptable to harass journalists that do not reveal sources" if dem == "Dijo que es aceptable acosar a los periodistas que no revelan sus fuentes"
replace gender = "Male" if gender == "Masculino"
replace gender = "Female" if gender == "Femenino"
replace background = "Civil Servant" if background == "Funcionario(a) público(a)"
replace background = "Academic" if background == "Académico(a)"
replace background = "Accountant" if background == "Contador(a)"
replace background = "Journalist" if background == "Periodista"
replace background = "Lawyer" if background == "Abogado(a)"
replace background = "Engineer" if background == "Ingeniero(a)"
replace background = "Self-employed" if background == "Trabajador(a) independiente"
replace background = "Professional Sports" if background == "Deportes profesionales"
replace background = "Business Administration" if background == "Administración de empresas"
replace redi = "Prevent universal access to public colleges" if redi == "Evitar el acceso universal a las universidades públicas"
replace redi = "Provide universal access to public colleges" if redi == "Ofrecer acceso universal a las universidades públicas"
replace redi = "Decrease public welfare spending" if redi == "Disminuir el gasto del bienestar público"
replace redi = "Increase public welfare spending" if redi == "Aumentar el gasto del bienestar público"
replace redi = "Decrease income tax on 10 percent richest" if redi == "Disminuir en un 10 por ciento el impuesto sobre la renta a las personas más acaudaladas"
replace redi = "Increase income tax on 10 percent richest" if redi == "Aumentar en un 10 por ciento el impuesto sobre la renta a las personas más acaudaladas"
replace soc = "Punish all drug-related crime harsher" if soc == "Castigar más estrictamente a los delincuentes que cometan delitos relacionados con las drogas"
replace soc = "Provide amnesty to low-level drug offenders" if soc == "Ofrecer amnistía a los delincuentes que cometan delitos menores relacionados con las drogas"
replace soc = "Make abortion law more strict" if soc == "Endurecer la ley contra el aborto"
replace soc = "Relax abortion law" if soc == "Flexibilizar la ley contra el aborto"
replace soc = "Prohibit same-sex marriage nationally" if soc == "Prohibir el matrimonio entre personas del mismo sexo en todo el país"
replace soc = "Legalize same-sex marriage nationally" if soc == "Legalizar el matrimonio entre personas del mismo sexo en todo el país"
replace eco = "Bad at handling economic matters" if eco == "Gestiona de ineficazmente los asuntos económicos"
replace eco = "Neither good nor bad reputation on economic matters" if eco == "Su reputación en asuntos económicos no es positiva ni negativa"
replace eco = "Good at handling economic matters" if eco == "Gestiona eficazmente los asuntos económicos"
replace cor = "Bad at fighting corruption" if cor == "Es ineficaz en la lucha contra la corrupción"
replace cor = "Neither good nor bad reputation on fighting corruption" if cor == "Su reputación en la lucha contra la corrupción no es positiva ni negativa"
replace cor = "Good at fighting corruption" if cor == "Es eficaz en la lucha contra la corrupción"

***Recoding
**Candidate attributes
clonevar canage = age
encode gender, gen(cangender)
encode background, gen(canbackground)
encode party, gen(canparty)
encode redi, gen(canredi)
recode canredi (1 = 0 "Decrease income tax on 10 percent richest") (3 = 1 "Increase income tax on 10 percent richest") (else=.), gen(cantax)
recode canredi (5 = 0 "Prevent universal access to public colleges") (6 = 1 "Provide universal access to public colleges") (else=.), gen(canedu)
recode canredi (2 = 0 "Decrease public welfare spending") (4 = 1 "Increase public welfare spending") (else=.), gen(canwel)
encode soc, gen(cansoc)
recode cansoc (4 = 1 "Provide amnesty to low-level drug offenders") (5 = 0 "Punish all drug-related crime harsher") (else=.), gen(cancrime)
recode cansoc (1 = 1 "Legalize same-sex marriage nationally") (3 = 0 "Prohibit same-sex marriage nationally") (else=.), gen(canss)
recode cansoc (2 = 0 "Make abortion law more strict") (6 = 1 "Relax abortion law") (else=.), gen(canabort)
encode dem, gen(candem)
recode candem (1 5 6 7 = 0 "Democratic") (2 3 4 8 = 1 "Undemocratic"), gen(candemmg) //Making one variable where all undemocratic positions are merged
encode eco, gen(canec)
recode canec (1 = 1 "Bad at handling economic matters") (2 = 3 "Good at handling economic matters") (3 = 2 "Neither good nor bad reputation on economic matters"), gen(caneco)
encode cor, gen(canco)
recode canco (1 = 1 "Bad at fighting corruption") (2 = 3 "Good at fighting corruption") (3 = 2 "Neither good nor bad reputation on fighting corruption"), gen(cancor)
gen cancom = (caneco + cancor)-1
label define competence 1 "Very incompetent" 2 "Moderately incompetent" 3 "Neither competent nor incompetent" 4 "Moderately competent" 5 "Very competent"
label values cancom competence

**Respondent attributes
*Background vars
encode region, gen(regionres)
encode urban, gen(urbanres)
recode urbanres (3 = 1 "Rural County") (2 = 3 "Metropolis") (1 = 2 "Medium-size or small city"), gen(urbanr)
drop urbanres
encode genderres, gen(genderr)
encode edures, gen(edur)
recode edur (2 3 4 5 6 7 = 1 "Less than high school") (1 = 2 "High school") (8 9 = 3 "More than high school"), gen(edurr) //altered to fit US/UK
drop edur

**Preference extremity vars
encode abortion, gen(abortionpre)
encode tax, gen(taxpre)
encode samesex, gen(samesexpre)
encode welfare, gen(welfarepre)
encode edu, gen(edupre)
encode crime, gen(crimepre)
encode demfra, gen(demfrapre)
recode abortionpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(abrpre)
recode taxpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(taxrpre)
recode samesexpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(samerpre)
recode welfarepre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(welrpre)
recode edupre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(edurpre)
recode crimepre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(crimerpre)
recode demfrapre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(demfrpre)
drop abortionpre-demfrapre

*"Extremety on candidate-assigned attributes". Matextax is, for example, the respondent's preference on tax IF the candidate was assigned a tax position. Flips abortion, welfare, unions, and army so that low values are extreme left and high values are extreme right.
label define extreme 1 "Extreme left" 2 "Moderate Left" 3 "Center" 4 "Moderate Right" 5 "Extreme Right"
recode abrpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremeab)
recode welrpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremewel)
recode edurpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremeedu)
recode crimerpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremecrime)
clonevar extremetax = taxrpre
clonevar extremess = samerpre
gen matextax = extremetax if cantax != .
gen matexwel = extremewel if canwel != .
gen matexedu = extremeedu if canedu != .
gen matexredi = .
replace matexredi = matextax if matextax != .
replace matexredi = matexwel if matexwel != .
replace matexredi = matexedu if matexedu != .
gen matexcrime = extremecrime if cancrime != .
gen matexabo = extremeab if canabort != .
gen matexss = extremess if canss != .
gen matexsoc = .
replace matexsoc = matexcrime if matexcrime != .
replace matexsoc = matexabo if matexabo != .
replace matexsoc = matexss if matexss != .
label values matexsoc matexcrime matexredi matextax matexedu matexwel matexabo matexss extremetax extremess extremeab extremewel extremeedu extremecrime extreme

**Policy distance between candidate and respondent
*Main measure
recode cantax (0 = 4.5) (1 = 1.5), gen(cantaxm)
recode canedu (0 = 4.5) (1 = 1.5), gen(canedum)
recode canwel (0 = 4.5) (1 = 1.5), gen(canwelm)
gen canredim = .
replace canredim = cantaxm if cantaxm != .
replace canredim = canedum if canedum != .
replace canredim = canwelm if canwelm != .

recode cancrime (0 = 4.5) (1 = 1.5), gen(cancrimem)
recode canss (0 = 4.5) (1 = 1.5), gen(canssm)
recode canabort (0 = 4.5) (1 = 1.5), gen(canabortm)
gen cansocm = .
replace cansocm = cancrimem if cancrimem != .
replace cansocm = canssm if canssm != .
replace cansocm = canabortm if canabortm != .

gen distaxm = matextax-cantaxm
gen disedum = matexedu-canedum
gen diswelm = matexwel-canwelm 
gen disredim = matexredi-canredim

gen discrimem = matexcrime-cancrimem
gen disssm = matexss-canssm
gen disabom = matexabo-canabortm
gen dissocm = matexsoc-cansocm

gen dissumm = sqrt(disredim^2) + sqrt(dissocm^2)
label define distancem 1 "Completely Aligned Positions" 7 "Completely Diverting Positions"
label values dissumm distancem

*Supplementary measures
recode cantax (0 = 5) (1 = 1), gen(cantaxs1)
recode canedu (0 = 5) (1 = 1), gen(canedus1)
recode canwel (0 = 5) (1 = 1), gen(canwels1)
gen canredis1 = .
replace canredis1 = cantaxs1 if cantaxs1 != .
replace canredis1 = canedus1 if canedus1 != .
replace canredis1 = canwels1 if canwels1 != .

recode cancrime (0 = 5) (1 = 1), gen(cancrimes1)
recode canss (0 = 5) (1 = 1), gen(cansss1)
recode canabort (0 = 5) (1 = 1), gen(canaborts1)
gen cansocs1 = .
replace cansocs1 = cancrimes1 if cancrimes1 != .
replace cansocs1 = cansss1 if cansss1 != .
replace cansocs1 = canaborts1 if canaborts1 != .

gen distaxs1 = matextax-cantaxs1
gen disedus1 = matexedu-canedus1
gen diswels1 = matexwel-canwels1 
gen disredis1 = matexredi-canredis1

gen discrimes1 = matexcrime-cancrimes1
gen dissss1 = matexss-cansss1
gen disabos1 = matexabo-canaborts1
gen dissocs1 = matexsoc-cansocs1

gen dissums1 = sqrt(disredis1^2) + sqrt(dissocs1^2)
label define distances1 0 "Completely Aligned Positions" 8 "Completely Diverting Positions"
label values dissums1 distances1

recode cantax (0 = 4) (1 = 2), gen(cantaxs2)
recode canedu (0 = 4) (1 = 2), gen(canedus2)
recode canwel (0 = 4) (1 = 2), gen(canwels2)
gen canredis2 = .
replace canredis2 = cantaxs2 if cantaxs2 != .
replace canredis2 = canedus2 if canedus2 != .
replace canredis2 = canwels2 if canwels2 != .

recode cancrime (0 = 4) (1 = 2), gen(cancrimes2)
recode canss (0 = 4) (1 = 2), gen(cansss2)
recode canabort (0 = 4) (1 = 2), gen(canaborts2)
gen cansocs2 = .
replace cansocs2 = cancrimes2 if cancrimes2 != .
replace cansocs2 = cansss2 if cansss2 != .
replace cansocs2 = canaborts2 if canaborts2 != .

gen distaxs2 = matextax-cantaxs2
gen disedus2 = matexedu-canedus2
gen diswels2 = matexwel-canwels2
gen disredis2 = matexredi-canredis2

gen discrimes2 = matexcrime-cancrimes2
gen dissss2 = matexss-cansss2
gen disabos2 = matexabo-canaborts2
gen dissocs2 = matexsoc-cansocs2

gen dissums2 = sqrt(disredis2^2) + sqrt(dissocs2^2)
label define distances2 0 "Completely Aligned Positions" 6 "Completely Diverting Positions"
label values dissums2 distances2

**Preference intensity vars
encode aboprio, gen(abortionpri)
encode taxprio, gen(taxpri)
encode samesexprio, gen(samesexpri)
encode welprio, gen(welfarepri)
encode eduprio, gen(edupri)
encode crimeprio, gen(crimepri)
recode abortionpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(abrpri)
recode taxpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(taxrpri)
recode samesexpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(samerpri)
recode welfarepri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(welrpri)
recode edupri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(edurpri)
recode crimepri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(crimerpri)
drop abortionpri-crimepri


*"Intensity on candidate-assigned attributes". Matintax is, for example, the respondent's intensity on tax IF the candidate was assigned a tax position
label define intensity 1 "Very Low Intensity" 2 "Low Intensity" 3 "Moderate Intensity" 4 "High Intensity" 5 "Very High Intensity"
gen matintax = taxrpri if cantax != .
gen matinwel = welrpri if canwel != .
gen matinedu = edurpri if canedu != .
gen matinredi = .
replace matinredi = matintax if matintax != .
replace matinredi = matinwel if matinwel != .
replace matinredi = matinedu if matinedu != .
gen matincrime = crimerpri if cancrime != .
gen matinabo = abrpri if canabort != .
gen matinss = samerpri if canss != .
gen matinsoc = .
replace matinsoc = matincrime if matincrime != .
replace matinsoc = matinabo if matinabo != .
replace matinsoc = matinss if matinss != .
label values matintax matinwel matinedu matinredi matincrime matinabo matinss matinsoc intensity

*Intensity in favor of or against candidate: used for analysis
gen abodir = . 
replace abodir = -1 if extremeab < 3 & canabort == 0
replace abodir = -1 if extremeab > 3 & canabort == 1
replace abodir = -0.5 if extremeab == 3 & canabort !=.
replace abodir = 1 if extremeab < 3 & canabort == 1
replace abodir = 1 if extremeab > 3 & canabort == 0
gen aboint = abodir*abrpri

gen taxdir = . 
replace taxdir = -1 if extremetax < 3 & cantax == 0
replace taxdir = -1 if extremetax > 3 & cantax == 1
replace taxdir = -0.5 if extremetax == 3 & cantax !=.
replace taxdir = 1 if extremetax < 3 & cantax == 1
replace taxdir = 1 if extremetax > 3 & cantax == 0
gen taxint = taxdir*taxrpri

gen ssdir = . 
replace ssdir = -1 if extremess < 3 & canss == 0
replace ssdir = -1 if extremess > 3 & canss == 1
replace ssdir = -0.5 if extremess == 3 & canss !=.
replace ssdir = 1 if extremess < 3 & canss == 1
replace ssdir = 1 if extremess > 3 & canss == 0
gen ssint = ssdir*samerpri

gen weldir = . 
replace weldir = -1 if extremewel < 3 & canwel == 0
replace weldir = -1 if extremewel > 3 & canwel == 1
replace weldir = -0.5 if extremewel == 3 & canwel !=.
replace weldir = 1 if extremewel < 3 & canwel == 1
replace weldir = 1 if extremewel > 3 & canwel == 0
gen welint = weldir*welrpri

gen edudir = . 
replace edudir = -1 if extremeedu < 3 & canedu == 0
replace edudir = -1 if extremeedu > 3 & canedu == 1
replace edudir = -0.5 if extremeedu == 3 & canedu !=.
replace edudir = 1 if extremeedu < 3 & canedu == 1
replace edudir = 1 if extremeedu > 3 & canedu == 0
gen eduint = edudir*edurpri

gen crimedir = . 
replace crimedir = -1 if extremecrime < 3 & cancrime == 0
replace crimedir = -1 if extremecrime > 3 & cancrime == 1
replace crimedir = -0.5 if extremecrime == 3 & cancrime !=.
replace crimedir = 1 if extremecrime < 3 & cancrime == 1
replace crimedir = 1 if extremecrime > 3 & cancrime == 0
gen crimeint = crimedir*crimerpri

gen rediint =.
replace rediint = eduint if eduint != .
replace rediint = welint if welint != .
replace rediint = taxint if taxint != .

gen socint =.
replace socint = crimeint if crimeint != .
replace socint = ssint if ssint != .
replace socint = aboint if aboint != .

label define intensityfa -5 "Intense Opinion Against Candidate" -1 "Mild Opinion Against Candidate" 1 "Mild Opinion in Favor of Candidate" 5 "Intense Opinion in Favor of Candidate"
label values aboint taxint ssint rediint welint eduint crimeint socint intensityfa


**Party ID
encode pid, gen(partyid)
recode partyid (1 =.)
drop pid
encode pri, gen(PRIx)
encode pan, gen(PANx)
encode prd, gen(PRDx)
encode morena, gen(MORENAx)
encode ciu, gen(CIUx)
replace PRIx = . if canparty != 4
replace PANx = . if canparty != 2
replace PRDx = . if canparty != 3
replace MORENAx = . if canparty != 1
recode PRIx (1 = 1 "Dislike a great deal") (2 = 2 "Dislike somewhat") (3=.) (4 = 5 "Like a great deal") (5 = 4 "Like somewhat") (6 = 3 "Neither like nor dislike"), gen(PRI)
recode PANx (1 = 1 "Dislike a great deal") (2 = 2 "Dislike somewhat") (3=.) (4 = 5 "Like a great deal") (5 = 4 "Like somewhat") (6 = 3 "Neither like nor dislike"), gen(PAN)
recode PRDx (1 = 1 "Dislike a great deal") (2 = 2 "Dislike somewhat") (3=.) (4 = 5 "Like a great deal") (5 = 4 "Like somewhat") (6 = 3 "Neither like nor dislike"), gen(PRD)
recode MORENAx (1 = 1 "Dislike a great deal") (2 = 2 "Dislike somewhat") (3=.) (4 = 5 "Like a great deal") (5 = 4 "Like somewhat") (6 = 3 "Neither like nor dislike"), gen(MORENA)
recode CIUx (1 = 1 "Dislike a great deal") (2 = 2 "Dislike somewhat") (3=.) (4 = 5 "Like a great deal") (5 = 4 "Like somewhat") (6 = 3 "Neither like nor dislike"), gen(CIU)
drop PRIx-CIUx
gen partymmain = .
replace partymmain = PRI if canparty == 4
replace partymmain = PAN if canparty == 2
replace partymmain = PRD if canparty == 3
replace partymmain = MORENA if canparty == 1
label define conparty 1 "Dislike candidate's party a great deal" 2 "Dislike candidate's party somewhat" 3 "Neither like nor dislike candidate's party" 4 "Like candidate's party somewhat" 5 "Like candidate's party a great deal"
label values partymmain conparty
recode partyid (2 = 0 "No Party ID") (1=.) (3 4 5 6 7 8 = 1 "Any Party ID"), gen(anyparty)
recode partyid (4 6 7 8 = 1 "PRI/PRD/PAN/MORENA") (1=.) (2 3 5 = 0 "Not PRI/PRD/PAN/MORENA"), gen(anyinparty) //maybe makes less sense in Mexico - not polarized in two camps as in SK
gen copartisansplit = .
replace copartisansplit = 0 if anyparty == 0 //note other coding than in SK: baseline category with no voter party ID
replace copartisansplit = 1 if partyid == 4 & canparty == 1
replace copartisansplit = 2 if partyid == 6 & canparty == 2
replace copartisansplit = 3 if partyid == 7 & canparty == 3
replace copartisansplit = 4 if partyid == 8 & canparty == 4
replace copartisansplit = 5 if partyid == 4 & canparty == 2
replace copartisansplit = 6 if partyid == 4 & canparty == 3
replace copartisansplit = 7 if partyid == 4 & canparty == 4
replace copartisansplit = 8 if partyid == 6 & canparty == 1
replace copartisansplit = 9 if partyid == 6 & canparty == 3
replace copartisansplit = 10 if partyid == 6 & canparty == 4
replace copartisansplit = 11 if partyid == 7 & canparty == 1
replace copartisansplit = 12 if partyid == 7 & canparty == 2
replace copartisansplit = 13 if partyid == 7 & canparty == 4
replace copartisansplit = 14 if partyid == 8 & canparty == 1
replace copartisansplit = 15 if partyid == 8 & canparty == 2
replace copartisansplit = 16 if partyid == 8 & canparty == 3
replace copartisansplit = 17 if partyid == 3 & canparty == 1
replace copartisansplit = 17 if partyid == 5 & canparty == 1
replace copartisansplit = 18 if partyid == 3 & canparty == 2
replace copartisansplit = 18 if partyid == 5 & canparty == 2
replace copartisansplit = 19 if partyid == 3 & canparty == 3
replace copartisansplit = 19 if partyid == 5 & canparty == 3
replace copartisansplit = 20 if partyid == 3 & canparty == 4
replace copartisansplit = 20 if partyid == 5 & canparty == 4
label define copartisansplit 0 "No Party ID (Voter)" 1 "Copartisanship: MORENA" 2 "Copartisanship: PAN" 3 "Copartisanship: PRD" 4 "Copartisanship: PRI" 5 "Voter: MORENA, Candidate: PAN" 6 "Voter: MORENA, Candidate: PRD" 7 "Voter: MORENA, Candidate: PRI" 8 "Voter: PAN, Candidate: MORENA" 9 "Voter: PAN, Candidate: PRD" 10 "Voter: PAN, Candidate: PRI" 11 "Voter: PRD, Candidate: MORENA" 12 "Voter: PRD, Candidate: PAN" 13 "Voter: PRD, Candidate: PRI" 14 "Voter: PRI, Candidate: MORENA" 15 "Voter: PRI, Candidate: PAN" 16 "Voter: PRI, Candidate: PRD" 17 "Voter: Other, Candidate: MORENA" 18 "Voter: Other, Candidate: PAN" 19 "Voter: Other, Candidate: PRD" 20 "Voter: Other, Candidate: PRI"
label values copartisansplit copartisansplit
recode copartisansplit (0 = 0 "No Party ID (Voter)") (1 2 3 4 = 1 "Copartisanship") (5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 = 2 "Differing Partisanship"), gen(copartisanmerge)

**Manipulation and attention check
encode mcheck, gen(mcheck1)
recode mcheck1 (1 = 3 "Democracy is neither robust nor vulnerable in Mexico") (2 = 4 "Democracy is quite robust in Mexico") (3 = 2 "Democracy is quite vulnerable in Mexico") (4 = 5 "Democracy is very robust in Mexico") (5 = 1 "Democracy is very vulnerable in Mexico") (6=.), gen(manipulation)
drop mcheck1
encode attention, gen(atte)
recode atte (1=5 "Don't know") (2 = 4 "I have not been presented for a piece of text about the current state of democracy around the world") (3 = 2 "That many democratic breakdowns will occur during this decade") (4 = 1 "That no or only very few democratic breakdowns will occur during this decade") (5 = 3 "The piece of text did not mention any predictions"), gen(attent) //NB: Numbers may be wrong; check twice when data is in
drop atte

**Outcome
encode answ, gen(answer)
recode answer (1=.) (2 = 3 "Neither likely nor unlikely") (3 = 4 "Somewhat likely") (4 = 2 "Somewhat unlikely") (5 = 5 "Very likely") (6 = 1 "Very unlikely"), gen(support)
drop answer

**Treatment
encode treat, gen(treat1)
recode treat1 (1 = 0 "Robust") (2=1 "Vulnerable"), gen(treatment)
drop treat1
*Did the treatment work (i.e., did it affect perceived democratic vulnerability?)
reg manipulation i.treatment, cluster(respondentid) //clustering added
*Were the respondents attentive?
gen correctatte = .
replace correctatte = 0 if attent == 5
replace correctatte = 0 if attent == 4
replace correctatte = 0 if attent == 3
replace correctatte = 0 if attent == 2 & treatment == 0
replace correctatte = 0 if attent == 1 & treatment == 1
replace correctatte = 1 if attent == 1 & treatment == 0
replace correctatte = 1 if attent == 2 & treatment == 1
label define correct 0 "Inattentive" 1 "Attentive"
label values correctatte correct
sum correctatte

*Creating numerical variables identifying task and candidate number
generate task =.
replace task = 1 if candidate == "_1" | candidate == "_2"
replace task = 2 if candidate == "_3" | candidate == "_4"
replace task = 3 if candidate == "_5" | candidate == "_6"
replace task = 4 if candidate == "_7" | candidate == "_8"
replace task = 5 if candidate == "_9" | candidate == "_10"
replace task = 6 if candidate == "_11" | candidate == "_12"
replace task = 7 if candidate == "_13" | candidate == "_14"
replace task = 8 if candidate == "_15" | candidate == "_16"
replace task = 9 if candidate == "_17" | candidate == "_18"
replace task = 10 if candidate == "_19" | candidate == "_20"
generate candid =.
replace candid = 1 if candidate == "_1"
replace candid = 2 if candidate == "_2"
replace candid = 3 if candidate == "_3"
replace candid = 4 if candidate == "_4"
replace candid = 5 if candidate == "_5"
replace candid = 6 if candidate == "_6"
replace candid = 7 if candidate == "_7"
replace candid = 8 if candidate == "_8"
replace candid = 9 if candidate == "_9"
replace candid = 10 if candidate == "_10"
replace candid = 11 if candidate == "_11"
replace candid = 12 if candidate == "_12"
replace candid = 13 if candidate == "_13"
replace candid = 14 if candidate == "_14"
replace candid = 15 if candidate == "_15"
replace candid = 16 if candidate == "_16"
replace candid = 17 if candidate == "_17"
replace candid = 18 if candidate == "_18"
replace candid = 19 if candidate == "_19"
replace candid = 20 if candidate == "_20"

**Drop respondents with missing values on variables used for key tests
reg partymmain dissumm matexredi matexsoc rediint socint support
gen sample1 = e(sample)

*Saving for appending later
save "U:\How to Save a Democracy\Data\mxfinal.dta", replace


*****SK*****
import delimited "U:\How to Save a Democracy\Data\skmain.tsv", varnames(1) encoding(UTF-16LE) numericcols(14 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84) clear 
encode responseid, gen(id)
generate respondentid = id+1
keep if q4 == "대도시" | q4 == "시골" | q4 == "중소도시"
gen country = "SK"
gen resp = respondentid + 40000
drop startdate enddate status progress finished distributionchannel userlanguage fl* responseid id


**Correct reshaping of data into uniquely identifying candidate level (by respondent id x candidate number (1-20)).
*Renaming necessary
rename q17_1 answ_1
rename q17_2 answ_2
rename q18_1 answ_3
rename q18_2 answ_4
rename q19_1 answ_5
rename q19_2 answ_6
rename q20_1 answ_7
rename q20_2 answ_8
rename q21_1 answ_9
rename q21_2 answ_10
rename q22_1 answ_11
rename q22_2 answ_12
rename q23_1 answ_13
rename q23_2 answ_14
rename q24_1 answ_15
rename q24_2 answ_16
rename q25_1 answ_17
rename q25_2 answ_18
rename q26_1 answ_19
rename q26_2 answ_20

*Reshaping
reshape long answ dem age gender background party redi soc eco cor, i(respondentid) j(candidate, string)

*Renaming
rename q3 region
rename q4 urban 
rename q5 genderres
rename q6 ageres
rename q7 edures 
rename q8_1 abortion
rename q8_2 tax
rename q8_3 samesex
rename q8_4 welfare
rename q8_5 unions
rename q8_6 army
rename q8_7 demfra
rename q9_1 aboprio
rename q9_2 taxprio
rename q9_3 samesexprio
rename q9_4 welprio
rename q9_5 unionprio
rename q9_6 armyprio
rename q10 pid
rename q11_1 ufp
rename q11_2 dpk
rename q15 mcheck
rename q27 attention
rename q28 device
rename block1_do treat

*Translating variables to English
replace region = "Gangwon" if region == "강원"
replace region = "Gyeonnggi" if region == "경기"
replace region = "Gyeongnam" if region == "경남"
replace region = "Gyeongbuk" if region == "경북"
replace region = "Gwangju" if region == "광주"
replace region = "Daegu" if region == "대구"
replace region = "Daejeon" if region == "대전"
replace region = "Pusan" if region == "부산"
replace region = "Seoul" if region == "서울"
replace region = "Ulsan" if region == "울산"
replace region = "Incheon" if region == "인천"
replace region = "Jeonnam" if region == "전남"
replace region = "Jeonbuk" if region == "전북"
replace region = "Jeju" if region == "제주"
replace region = "Chungnam" if region == "충남"
replace region = "Chungbuk" if region == "충북"
replace urban = "Metropolis" if urban == "대도시"
replace urban = "Rural County" if urban == "시골"
replace urban = "Medium-size or small city" if urban == "중소도시"
replace genderres = "Other" if genderres == "기타"
replace genderres = "Male" if genderres == "남성"
replace genderres = "Prefer not to answer" if genderres == "답변 거부"
replace genderres = "Female" if genderres == "여성"
replace edures = "High School" if edures == "고졸"
replace edures = "College" if edures == "대졸"
replace edures = "Graduate School or above" if edures == "대학원 이상"
replace edures = "Vocational High School" if edures == "전문대"
replace edures = "Middle School or below" if edures == "중졸 이하"
replace abortion = "Strongly agree" if abortion == "매우 동의함"
replace abortion = "Don't know" if abortion == "모름"
replace abortion = "Somewhat agree" if abortion == "어느 정도 동의함"
replace abortion = "Neither agree nor disagree" if abortion == "이도 저도 아님"
replace abortion = "Strongly disagree" if abortion == "전혀 동의하지 않음"
replace abortion = "Somewhat disagree" if abortion == "별로 동의하지 않음"
replace tax = "Strongly agree" if tax == "매우 동의함"
replace tax = "Don't know" if tax == "모름"
replace tax = "Somewhat agree" if tax == "어느 정도 동의함"
replace tax = "Neither agree nor disagree" if tax == "이도 저도 아님"
replace tax = "Strongly disagree" if tax == "전혀 동의하지 않음"
replace tax = "Somewhat disagree" if tax == "별로 동의하지 않음"
replace samesex = "Strongly agree" if samesex == "매우 동의함"
replace samesex = "Don't know" if samesex == "모름"
replace samesex = "Somewhat agree" if samesex == "어느 정도 동의함"
replace samesex = "Neither agree nor disagree" if samesex == "이도 저도 아님"
replace samesex = "Strongly disagree" if samesex == "전혀 동의하지 않음"
replace samesex = "Somewhat disagree" if samesex == "별로 동의하지 않음"
replace welfare = "Strongly agree" if welfare == "매우 동의함"
replace welfare = "Don't know" if welfare == "모름"
replace welfare = "Somewhat agree" if welfare == "어느 정도 동의함"
replace welfare = "Neither agree nor disagree" if welfare == "이도 저도 아님"
replace welfare = "Strongly disagree" if welfare == "전혀 동의하지 않음"
replace welfare = "Somewhat disagree" if welfare == "별로 동의하지 않음"
replace unions = "Strongly agree" if unions == "매우 동의함"
replace unions = "Don't know" if unions == "모름"
replace unions = "Somewhat agree" if unions == "어느 정도 동의함"
replace unions = "Neither agree nor disagree" if unions == "이도 저도 아님"
replace unions = "Strongly disagree" if unions == "전혀 동의하지 않음"
replace unions = "Somewhat disagree" if unions == "별로 동의하지 않음"
replace army = "Strongly agree" if army == "매우 동의함"
replace army = "Don't know" if army == "모름"
replace army = "Somewhat agree" if army == "어느 정도 동의함"
replace army = "Neither agree nor disagree" if army == "이도 저도 아님"
replace army = "Strongly disagree" if army == "전혀 동의하지 않음"
replace army = "Somewhat disagree" if army == "별로 동의하지 않음"
replace demfra = "Strongly agree" if demfra == "매우 동의함"
replace demfra = "Don't know" if demfra == "모름"
replace demfra = "Somewhat agree" if demfra == "어느 정도 동의함"
replace demfra = "Neither agree nor disagree" if demfra == "이도 저도 아님"
replace demfra = "Strongly disagree" if demfra == "전혀 동의하지 않음"
replace demfra = "Somewhat disagree" if demfra == "별로 동의하지 않음"
replace aboprio = "Not at all important" if aboprio == "전혀 중요하지 않음"
replace aboprio = "Don't know" if aboprio == "모름"
replace aboprio = "Extremely important" if aboprio == "지극히 중요함"
replace aboprio = "Very important" if aboprio == "매우 중요함"
replace aboprio = "Not very important" if aboprio == "별로 중요하지 않음"
replace aboprio = "Moderately important" if aboprio == "어느 정도 중요함"
replace taxprio = "Not at all important" if taxprio == "전혀 중요하지 않음"
replace taxprio = "Don't know" if taxprio == "모름"
replace taxprio = "Extremely important" if taxprio == "지극히 중요함"
replace taxprio = "Very important" if taxprio == "매우 중요함"
replace taxprio = "Not very important" if taxprio == "별로 중요하지 않음"
replace taxprio = "Moderately important" if taxprio == "어느 정도 중요함"
replace samesexprio = "Not at all important" if samesexprio == "전혀 중요하지 않음"
replace samesexprio = "Don't know" if samesexprio == "모름"
replace samesexprio = "Extremely important" if samesexprio == "지극히 중요함"
replace samesexprio = "Very important" if samesexprio == "매우 중요함"
replace samesexprio = "Not very important" if samesexprio == "별로 중요하지 않음"
replace samesexprio = "Moderately important" if samesexprio == "어느 정도 중요함"
replace welprio = "Not at all important" if welprio == "전혀 중요하지 않음"
replace welprio = "Don't know" if welprio == "모름"
replace welprio = "Extremely important" if welprio == "지극히 중요함"
replace welprio = "Very important" if welprio == "매우 중요함"
replace welprio = "Not very important" if welprio == "별로 중요하지 않음"
replace welprio = "Moderately important" if welprio == "어느 정도 중요함"
replace unionprio = "Not at all important" if unionprio == "전혀 중요하지 않음"
replace unionprio = "Don't know" if unionprio == "모름"
replace unionprio = "Extremely important" if unionprio == "지극히 중요함"
replace unionprio = "Very important" if unionprio == "매우 중요함"
replace unionprio = "Not very important" if unionprio == "별로 중요하지 않음"
replace unionprio = "Moderately important" if unionprio == "어느 정도 중요함"
replace armyprio = "Not at all important" if armyprio == "전혀 중요하지 않음"
replace armyprio = "Don't know" if armyprio == "모름"
replace armyprio = "Extremely important" if armyprio == "지극히 중요함"
replace armyprio = "Very important" if armyprio == "매우 중요함"
replace armyprio = "Not very important" if armyprio == "별로 중요하지 않음"
replace armyprio = "Moderately important" if armyprio == "어느 정도 중요함"
replace pid = "I identify with a party not listed here" if pid == "다른 정당을 지지함"
replace pid = "Democratic Party of Korea" if pid == "더불어민주당"
replace pid = "Don't know" if pid == "모름"
replace pid = "United Future Party" if pid == "미래통합당"
replace pid = "I do not identify with any party" if pid == "어떤 정당도 지지하지 않음"
replace ufp = "Dislike a great deal" if ufp == "매우 싫어함"
replace ufp = "Like a great deal" if ufp == "매우 좋아함"
replace ufp = "Don't know" if ufp == "모름"
replace ufp = "Dislike somewhat" if ufp == "약간 싫어함"
replace ufp = "Like somewhat" if ufp == "약간 좋아함"
replace ufp = "Neither like nor dislike" if ufp == "좋아하지도 싫어하지도 않음"
replace dpk = "Dislike a great deal" if dpk == "매우 싫어함"
replace dpk = "Like a great deal" if dpk == "매우 좋아함"
replace dpk = "Don't know" if dpk == "모름"
replace dpk = "Dislike somewhat" if dpk == "약간 싫어함"
replace dpk = "Like somewhat" if dpk == "약간 좋아함"
replace dpk = "Neither like nor dislike" if dpk == "좋아하지도 싫어하지도 않음"
replace mcheck = "Democracy is neither robust nor vulnerable in South Korea" if mcheck == "대한민국의 민주주의는 강건하지도 취약하지도 않음"
replace mcheck = "Democracy is quite robust in South Korea" if mcheck == "대한민국의 민주주의는 꽤 강건함"
replace mcheck = "Democracy is quite vulnerable in South Korea" if mcheck == "대한민국의 민주주의는 꽤 취약함"
replace mcheck = "Democracy is very robust in South Korea" if mcheck == "대한민국의 민주주의는 매우 강건함"
replace mcheck = "Democracy is very vulnerable in South Korea" if mcheck == "대한민국의 민주주의는 매우 취약함"
replace mcheck = "Don't know" if mcheck == "모름"
replace attention = "The piece of text did not mention any predictions" if attention == "글은 그 어떤 예상도 다루지 않았음"
replace attention = "Don't know" if attention == "모름"
replace attention = "I have not been presented for a piece of text about the current state of democracy around the world" if attention == "세계 민주주의 상황에 대한 글을 보지 못했음"
replace attention = "That many democratic breakdowns will occur during this decade" if attention == "향후 10년 이내 붕괴할 민주주의의 수가 많을 것"
replace attention = "That no or only very few democratic breakdowns will occur during this decade" if attention == "향후 10년 이내 붕괴할 민주주의의 수는 전혀 없거나 매우 낮을 것"
replace device = "Prefer not to answer" if device == "답변 거부"
replace device = "Other" if device == "기타"
replace device = "Smartphone" if device == "스마트폰"
replace device = "PC or Macbook" if device == "컴퓨터 또는 맥북"
replace device = "Tablet" if device == "태블릿"
replace answ = "Very unlikely" if answ == "매우 낮음"
replace answ = "Very likely" if answ == "매우 높음"
replace answ = "Don't know" if answ == "모름"
replace answ = "Somewhat unlikely" if answ == "약간 낮음"
replace answ = "Somewhat likely" if answ == "약간 높음"
replace answ = "Neither likely nor unlikely" if answ == "높지도 낮지도 않음"
replace dem = "Said it is unacceptable to harass journalists even though they do not reveal sources" if dem == "기자가 정보 출처를 밝히지 않는다고 하더라도 공격 당해서는 안 된다고 주장함"
replace dem = "Said it is legitimate to fight political opponents in the streets if one feels provoked" if dem == "도발당했다고 느낄 경우 길거리에서 정치적으로 반대 성향인 상대와 몸싸움을 벌이는"
replace dem = "Said it is unacceptable to fight political opponents in the streets even though one feels provoked" if dem == "도발당했다고 느낄 경우라도 길거리에서 정치적으로 반대 성향인 상대와 몸싸움을"
replace dem = "Said court rulings by judges appointed by opposing parties should be ignored" if dem == "반대 정당에서 임명한 판사들이 내린 판결은 무시해야 한다고 주장함"
replace dem = "Said court rulings by judges appointed by opposing parties should be adhered to" if dem == "반대 정당에서 임명한 판사들이 내린 판결이라도 따라야 한다고 주장함"
replace dem = "Supported a proposal to reduce polling stations in areas that support opposing parties" if dem == "반대 정당을 지지하는 지역의 투표소 수를 줄이자는 제안을 지지함"
replace dem = "Supported a proposal to preserve existing polling-stations in all areas" if dem == "전 지역에 현존하는 투표소를 유지하자는 제안을 지지함"
replace dem = "Said it is acceptable to harass journalists that do not reveal sources" if dem == "정보 출처를 밝히지 않는 기자는 공격 당해도 된다고 주장함"
replace gender = "Male" if gender == "남성"
replace gender = "Female" if gender == "여성"
replace background = "Civil Servant" if background == "공무원"
replace background = "Professor" if background == "교수"
replace background = "Army General" if background == "군대 참모"
replace background = "Journalist" if background == "기자"
replace background = "Lawyer" if background == "변호사"
replace background = "Engineer" if background == "엔지니어"
replace background = "Self-employed" if background == "자영업자"
replace background = "Political Career" if background == "정치인"
replace background = "Company Director" if background == "회사 임원"
replace party = "Democratic Party of Korea" if party == "더불어민주당"
replace party = "United Future Party" if party == "미래통합당"
replace redi = "Decrease power of labor unions" if redi == "노동조합의 힘 축소"
replace redi = "Increase power of labor unions" if redi == "노동조합의 힘 확대"
replace redi = "Decrease public welfare spending" if redi == "사회복지 지출 감소"
replace redi = "Increase public welfare spending" if redi == "사회복지 지출 증가"
replace redi = "Decrease income tax on 10 percent richest" if redi == "상위 10% 고소득자의 소득세 감소"
replace redi = "Increase income tax on 10 percent richest" if redi == "상위 10% 고소득자의 소득세 증가"
replace soc = "Decrease funds to the army" if soc == "군대 예산 삭감"
replace soc = "Increase funds to the army" if soc == "군대 예산 증가"
replace soc = "Make abortion law more strict" if soc == "낙태법 강화"
replace soc = "Relax abortion law" if soc == "낙태법 완화"
replace soc = "Prohibit same-sex marriage nationally" if soc == "동성 결혼 금지"
replace soc = "Legalize same-sex marriage nationally" if soc == "동성 결혼 합법화"
replace eco = "Bad at handling economic matters" if eco == "경제 문제를 잘 다루지 못함"
replace eco = "Neither good nor bad reputation on economic matters" if eco == "경제 문제를 잘 다루지도 못 다루지도 않음"
replace eco = "Good at handling economic matters" if eco == "경제 문제를 잘 다룸"
replace cor = "Bad at fighting corruption" if cor == "부정부패에 잘 맞서지 못함"
replace cor = "Neither good nor bad reputation on fighting corruption" if cor == "부정부패에 잘 맞서지도 못 맞서지도 않음"
replace cor = "Good at fighting corruption" if cor == "부정부패에 잘 맞섬"

***Recoding
**Candidate attributes
clonevar canage = age
encode gender, gen(cangender)
encode background, gen(canbackground)
encode party, gen(canparty)
encode redi, gen(canredi)
recode canredi (1 = 0 "Decrease income tax on 10 percent richest") (4 = 1 "Increase income tax on 10 percent richest") (else=.), gen(cantax)
recode canredi (2 = 0 "Decrease power of labor unions") (5 = 1 "Increase power of labor unions") (else=.), gen(canunion)
recode canredi (3 = 0 "Decrease public welfare spending") (6 = 1 "Increase public welfare spending") (else=.), gen(canwel)
encode soc, gen(cansoc)
recode cansoc (1 = 1 "Decrease funds to the army") (2 = 0 "Increase funds to the army") (else=.), gen(canarmy)
recode cansoc (3 = 1 "Legalize same-sex marriage nationally") (5 = 0 "Prohibit same-sex marriage nationally") (else=.), gen(canss)
recode cansoc (4 = 0 "Make abortion law more strict") (6 = 1 "Relax abortion law") (else=.), gen(canabort)
encode dem, gen(candem)
recode candem (1 5 6 7 = 0 "Democratic") (2 3 4 8 = 1 "Undemocratic"), gen(candemmg) //Making one variable where all undemocratic positions are merged
encode eco, gen(canec)
recode canec (1 = 1 "Bad at handling economic matters") (2 = 3 "Good at handling economic matters") (3 = 2 "Neither good nor bad reputation on economic matters"), gen(caneco)
encode cor, gen(canco)
recode canco (1 = 1 "Bad at fighting corruption") (2 = 3 "Good at fighting corruption") (3 = 2 "Neither good nor bad reputation on fighting corruption"), gen(cancor)
gen cancom = (caneco + cancor)-1
label define competence 1 "Very incompetent" 2 "Moderately incompetent" 3 "Neither competent nor incompetent" 4 "Moderately competent" 5 "Very competent"
label values cancom competence

**Respondent attributes
*Background vars
encode region, gen(regionres)
encode urban, gen(urbanres)
recode urbanres (3 = 1 "Rural County") (2 = 3 "Metropolis") (1 = 2 "Medium-size or small city"), gen(urbanr)
drop urbanres
encode genderres, gen(genderr)
encode edures, gen(edur)
recode edur (1 2 = 3 "More than high school") (3 5 = 2 "High School") (4 = 1 "Less than high school"), gen(edurr) //altered to fit UK/US
drop edur

**Preference extremity vars
encode abortion, gen(abortionpre)
encode tax, gen(taxpre)
encode samesex, gen(samesexpre)
encode welfare, gen(welfarepre)
encode unions, gen(unionspre)
encode army, gen(armypre)
encode demfra, gen(demfrapre)
recode abortionpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(abrpre)
recode taxpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(taxrpre)
recode samesexpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(samerpre)
recode welfarepre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(welrpre)
recode unionspre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(uniorpre)
recode armypre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(armrpre)
recode demfrapre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(demfrpre)
drop abortionpre-demfrapre

*"Extremety on candidate-assigned attributes". Matextax is, for example, the respondent's preference on tax IF the candidate was assigned a tax position. Flips abortion, welfare, unions, and army so that low values are extreme left and high values are extreme right.
label define extreme 1 "Extreme left" 2 "Moderate Left" 3 "Center" 4 "Moderate Right" 5 "Extreme Right"
recode abrpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremeab)
recode welrpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremewel)
recode armrpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremearm)
recode uniorpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremeunion)
clonevar extremetax = taxrpre
clonevar extremess = samerpre
gen matextax = extremetax if cantax != .
gen matexwel = extremewel if canwel != .
gen matexunion = extremeunion if canunion != .
gen matexredi = .
replace matexredi = matextax if matextax != .
replace matexredi = matexwel if matexwel != .
replace matexredi = matexunion if matexunion != .
gen matexarmy = extremearm if canarmy != .
gen matexabo = extremeab if canabort != .
gen matexss = extremess if canss != .
gen matexsoc = .
replace matexsoc = matexarmy if matexarmy != .
replace matexsoc = matexabo if matexabo != .
replace matexsoc = matexss if matexss != .
label values matexsoc matexarmy matexredi matextax matexunion matexwel matexabo matexss extremetax extremess extremeab extremewel extremeunion extremearm extreme

**Policy distance between candidate and respondent
*Main measure
recode cantax (0 = 4.5) (1 = 1.5), gen(cantaxm)
recode canunion (0 = 4.5) (1 = 1.5), gen(canunionm)
recode canwel (0 = 4.5) (1 = 1.5), gen(canwelm)
gen canredim = .
replace canredim = cantaxm if cantaxm != .
replace canredim = canunionm if canunionm != .
replace canredim = canwelm if canwelm != .

recode canarmy (0 = 4.5) (1 = 1.5), gen(canarmym)
recode canss (0 = 4.5) (1 = 1.5), gen(canssm)
recode canabort (0 = 4.5) (1 = 1.5), gen(canabortm)
gen cansocm = .
replace cansocm = canarmym if canarmym != .
replace cansocm = canssm if canssm != .
replace cansocm = canabortm if canabortm != .

gen distaxm = matextax-cantaxm
gen disunionm = matexunion-canunionm
gen diswelm = matexwel-canwelm 
gen disredim = matexredi-canredim

gen disarmm = matexarmy-canarmym
gen disssm = matexss-canssm
gen disabom = matexabo-canabortm
gen dissocm = matexsoc-cansocm

gen dissumm = sqrt(disredim^2) + sqrt(dissocm^2)
label define distancem 1 "Completely Aligned Positions" 7 "Completely Diverting Positions"
label values dissumm distancem

*Supplementary measures
recode cantax (0 = 5) (1 = 1), gen(cantaxs1)
recode canunion (0 = 5) (1 = 1), gen(canunions1)
recode canwel (0 = 5) (1 = 1), gen(canwels1)
gen canredis1 = .
replace canredis1 = cantaxs1 if cantaxs1 != .
replace canredis1 = canunions1 if canunions1 != .
replace canredis1 = canwels1 if canwels1 != .

recode canarmy (0 = 5) (1 = 1), gen(canarmys1)
recode canss (0 = 5) (1 = 1), gen(cansss1)
recode canabort (0 = 5) (1 = 1), gen(canaborts1)
gen cansocs1 = .
replace cansocs1 = canarmys1 if canarmys1 != .
replace cansocs1 = cansss1 if cansss1 != .
replace cansocs1 = canaborts1 if canaborts1 != .

gen distaxs1 = matextax-cantaxs1
gen disunions1 = matexunion-canunions1
gen diswels1 = matexwel-canwels1 
gen disredis1 = matexredi-canredis1

gen disarms1 = matexarmy-canarmys1
gen dissss1 = matexss-cansss1
gen disabos1 = matexabo-canaborts1
gen dissocs1 = matexsoc-cansocs1

gen dissums1 = sqrt(disredis1^2) + sqrt(dissocs1^2)
label define distances1 0 "Completely Aligned Positions" 8 "Completely Diverting Positions"
label values dissums1 distances1

recode cantax (0 = 4) (1 = 2), gen(cantaxs2)
recode canunion (0 = 4) (1 = 2), gen(canunions2)
recode canwel (0 = 4) (1 = 2), gen(canwels2)
gen canredis2 = .
replace canredis2 = cantaxs2 if cantaxs2 != .
replace canredis2 = canunions2 if canunions2 != .
replace canredis2 = canwels2 if canwels2 != .

recode canarmy (0 = 4) (1 = 2), gen(canarmys2)
recode canss (0 = 4) (1 = 2), gen(cansss2)
recode canabort (0 = 4) (1 = 2), gen(canaborts2)
gen cansocs2 = .
replace cansocs2 = canarmys2 if canarmys2 != .
replace cansocs2 = cansss2 if cansss2 != .
replace cansocs2 = canaborts2 if canaborts2 != .

gen distaxs2 = matextax-cantaxs2
gen disunions2 = matexunion-canunions2
gen diswels2 = matexwel-canwels2
gen disredis2 = matexredi-canredis2

gen disarms2 = matexarmy-canarmys2
gen dissss2 = matexss-cansss2
gen disabos2 = matexabo-canaborts2
gen dissocs2 = matexsoc-cansocs2

gen dissums2 = sqrt(disredis2^2) + sqrt(dissocs2^2)
label define distances2 0 "Completely Aligned Positions" 6 "Completely Diverting Positions"
label values dissums2 distances2

**Preference intensity vars (respondent)
encode aboprio, gen(abortionpri)
encode taxprio, gen(taxpri)
encode samesexprio, gen(samesexpri)
encode welprio, gen(welfarepri)
encode unionprio, gen(unionspri)
encode armyprio, gen(armypri)
recode abortionpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(abrpri)
recode taxpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(taxrpri)
recode samesexpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(samerpri)
recode welfarepri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(welrpri)
recode unionspri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(uniorpri)
recode armypri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(armrpri)
drop abortionpri-armypri


*"Intensity on candidate-assigned attributes". Matintax is, for example, the respondent's intensity on tax IF the candidate was assigned a tax position
label define intensity 1 "Very Low Intensity" 2 "Low Intensity" 3 "Moderate Intensity" 4 "High Intensity" 5 "Very High Intensity"
gen matintax = taxrpri if cantax != .
gen matinwel = welrpri if canwel != .
gen matinunion = uniorpri if canunion != .
gen matinredi = .
replace matinredi = matintax if matintax != .
replace matinredi = matinwel if matinwel != .
replace matinredi = matinunion if matinunion != .
gen matinarmy = armrpri if canarmy != .
gen matinabo = abrpri if canabort != .
gen matinss = samerpri if canss != .
gen matinsoc = .
replace matinsoc = matinarmy if matinarmy != .
replace matinsoc = matinabo if matinabo != .
replace matinsoc = matinss if matinss != .
label values matintax matinwel matinunion matinredi matinarmy matinabo matinss matinsoc intensity

*Intensity in favor of or against candidate: used for analysis
gen abodir = . 
replace abodir = -1 if extremeab < 3 & canabort == 0
replace abodir = -1 if extremeab > 3 & canabort == 1
replace abodir = -0.5 if extremeab == 3 & canabort !=.
replace abodir = 1 if extremeab < 3 & canabort == 1
replace abodir = 1 if extremeab > 3 & canabort == 0
gen aboint = abodir*abrpri

gen taxdir = . 
replace taxdir = -1 if extremetax < 3 & cantax == 0
replace taxdir = -1 if extremetax > 3 & cantax == 1
replace taxdir = -0.5 if extremetax == 3 & cantax !=.
replace taxdir = 1 if extremetax < 3 & cantax == 1
replace taxdir = 1 if extremetax > 3 & cantax == 0
gen taxint = taxdir*taxrpri

gen ssdir = . 
replace ssdir = -1 if extremess < 3 & canss == 0
replace ssdir = -1 if extremess > 3 & canss == 1
replace ssdir = -0.5 if extremess == 3 & canss !=.
replace ssdir = 1 if extremess < 3 & canss == 1
replace ssdir = 1 if extremess > 3 & canss == 0
gen ssint = ssdir*samerpri

gen weldir = . 
replace weldir = -1 if extremewel < 3 & canwel == 0
replace weldir = -1 if extremewel > 3 & canwel == 1
replace weldir = -0.5 if extremewel == 3 & canwel !=.
replace weldir = 1 if extremewel < 3 & canwel == 1
replace weldir = 1 if extremewel > 3 & canwel == 0
gen welint = weldir*welrpri

gen uniondir = . 
replace uniondir = -1 if extremeunion < 3 & canunion == 0
replace uniondir = -1 if extremeunion > 3 & canunion == 1
replace uniondir = -0.5 if extremeunion == 3 & canunion !=.
replace uniondir = 1 if extremeunion < 3 & canunion == 1
replace uniondir = 1 if extremeunion > 3 & canunion == 0
gen unionint = uniondir*uniorpri

gen armdir = . 
replace armdir = -1 if extremearm < 3 & canarmy == 0
replace armdir = -1 if extremearm > 3 & canarmy == 1
replace armdir = -0.5 if extremearm == 3 & canarmy !=.
replace armdir = 1 if extremearm < 3 & canarmy == 1
replace armdir = 1 if extremearm > 3 & canarmy == 0
gen armint = armdir*armrpri

gen rediint =.
replace rediint = unionint if unionint != .
replace rediint = welint if welint != .
replace rediint = taxint if taxint != .

gen socint =.
replace socint = armint if armint != .
replace socint = ssint if ssint != .
replace socint = aboint if aboint != .

label define intensityfa -5 "Intense Opinion Against Candidate" -1 "Mild Opinion Against Candidate" 1 "Mild Opinion in Favor of Candidate" 5 "Intense Opinion in Favor of Candidate"
label values aboint taxint ssint rediint welint unionint armint socint intensityfa


**Party ID
encode pid, gen(partyid)
recode partyid (2 =.)
drop pid
encode ufp, gen(UFPx)
encode dpk, gen(DPKx)
replace UFPx = . if canparty != 2
replace DPKx = . if canparty != 1
recode UFPx (1 = 1 "Dislike a great deal") (2 = 2 "Dislike somewhat") (3=.) (4 = 5 "Like a great deal") (5 = 4 "Like somewhat") (6 = 3 "Neither like nor dislike"), gen(UFP)
recode DPKx (1 = 1 "Dislike a great deal") (2 = 2 "Dislike somewhat") (3=.) (4 = 5 "Like a great deal") (5 = 4 "Like somewhat") (6 = 3 "Neither like nor dislike"), gen(DPK)
drop UFPx-DPKx
gen partymmain = .
replace partymmain = UFP if canparty == 2
replace partymmain = DPK if canparty == 1
label define conparty 1 "Dislike candidate's party a great deal" 2 "Dislike candidate's party somewhat" 3 "Neither like nor dislike candidate's party" 4 "Like candidate's party somewhat" 5 "Like candidate's party a great deal"
label values partymmain conparty
recode partyid (3 = 0 "No Party ID") (2=.) (1 4 5 = 1 "Any Party ID"), gen(anyparty)
recode partyid (1 5 = 1 "DPK/UFP") (2=.) (3 4 = 0 "Not DPK/UFP"), gen(anyinparty)
gen copartisansplit = .
replace copartisansplit = 0 if anyinparty == 0
replace copartisansplit = 1 if partyid == 1 & canparty == 1
replace copartisansplit = 2 if partyid == 5 & canparty == 2
replace copartisansplit = 3 if partyid == 1 & canparty == 2
replace copartisansplit = 4 if partyid == 5 & canparty == 1
label define copartisansplit 0 "Neither Copartisanship nor Opposing Partisanship" 1 "Copartisanship: DPK" 2 "Copartisanship: UFP" 3 "Voter: DPK, Candidate: UFP" 4 "Voter: UFP, Candidate: DPK"
label values copartisansplit copartisansplit
recode copartisansplit (0 = 0 "Neither Copartisanship nor Opposing Partisanship") (1 2 = 1 "Copartisanship") (3 4 = 2 "Opposing Partisanship"), gen(copartisanmerge)


**Manipulation and attention check
encode mcheck, gen(mcheck1)
recode mcheck1 (1 = 3 "Democracy is neither robust nor vulnerable in South Korea") (2 = 4 "Democracy is quite robust in South Korea") (3 = 2 "Democracy is quite vulnerable in South Korea") (4 = 5 "Democracy is very robust in South Korea") (5 = 1 "Democracy is very vulnerable in South Korea") (6=.), gen(manipulation)
drop mcheck1
encode attention, gen(atte)
recode atte (1=5 "Don't know") (2 = 4 "I have not been presented for a piece of text about the current state of democracy around the world") (3 = 2 "That many democratic breakdowns will occur during this decade") (4 = 1 "That no or only very few democratic breakdowns will occur during this decade") (5 = 3 "The piece of text did not mention any predictions"), gen(attent) //NB: Numbers may be wrong; check twice when data is in
drop atte

**Outcome
encode answ, gen(answer)
recode answer (1=.) (2 = 3 "Neither likely nor unlikely") (3 = 4 "Somewhat likely") (4 = 2 "Somewhat unlikely") (5 = 5 "Very likely") (6 = 1 "Very unlikely"), gen(support)
drop answer

**Treatment
encode treat, gen(treat1)
recode treat1 (1 = 0 "Robust") (2=1 "Vulnerable"), gen(treatment)
drop treat1
*Did the treatment work (i.e., did it affect perceived democratic vulnerability?)
reg manipulation i.treatment, cluster(respondentid) //clustering added
*Were the respondents attentive?
gen correctatte = .
replace correctatte = 0 if attent == 5
replace correctatte = 0 if attent == 4
replace correctatte = 0 if attent == 3
replace correctatte = 0 if attent == 2 & treatment == 0
replace correctatte = 0 if attent == 1 & treatment == 1
replace correctatte = 1 if attent == 1 & treatment == 0
replace correctatte = 1 if attent == 2 & treatment == 1
label define correct 0 "Inattentive" 1 "Attentive"
label values correctatte correct
sum correctatte

*Creating numerical variables identifying task and candidate number
generate task =.
replace task = 1 if candidate == "_1" | candidate == "_2"
replace task = 2 if candidate == "_3" | candidate == "_4"
replace task = 3 if candidate == "_5" | candidate == "_6"
replace task = 4 if candidate == "_7" | candidate == "_8"
replace task = 5 if candidate == "_9" | candidate == "_10"
replace task = 6 if candidate == "_11" | candidate == "_12"
replace task = 7 if candidate == "_13" | candidate == "_14"
replace task = 8 if candidate == "_15" | candidate == "_16"
replace task = 9 if candidate == "_17" | candidate == "_18"
replace task = 10 if candidate == "_19" | candidate == "_20"
generate candid =.
replace candid = 1 if candidate == "_1"
replace candid = 2 if candidate == "_2"
replace candid = 3 if candidate == "_3"
replace candid = 4 if candidate == "_4"
replace candid = 5 if candidate == "_5"
replace candid = 6 if candidate == "_6"
replace candid = 7 if candidate == "_7"
replace candid = 8 if candidate == "_8"
replace candid = 9 if candidate == "_9"
replace candid = 10 if candidate == "_10"
replace candid = 11 if candidate == "_11"
replace candid = 12 if candidate == "_12"
replace candid = 13 if candidate == "_13"
replace candid = 14 if candidate == "_14"
replace candid = 15 if candidate == "_15"
replace candid = 16 if candidate == "_16"
replace candid = 17 if candidate == "_17"
replace candid = 18 if candidate == "_18"
replace candid = 19 if candidate == "_19"
replace candid = 20 if candidate == "_20"

**Drop respondents with missing values on variables used for key tests
reg partymmain dissumm matexredi matexsoc rediint socint support
gen sample1 = e(sample)

*Saving for appending later
save "U:\How to Save a Democracy\Data\skfinal.dta", replace


*****CZ*****
import delimited "U:\How to Save a Democracy\Data\czmain.tsv", varnames(1) encoding(UTF-16LE) numericcols(14 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84) clear 
encode responseid, gen(id)
generate respondentid = id+1
drop if respondentid == .
keep if q4 == "Středně velké nebo malé město" | q4 == "Velkoměsto"| q4 == "Venkov"
gen country = "CZ"
gen resp = respondentid + 50000
drop startdate enddate status progress finished distributionchannel userlanguage fl* responseid id

**Correct reshaping of data into uniquely identifying candidate level (by respondent id x candidate number (1-20)).
*Renaming necessary
rename q17_1 answ_1
rename q17_2 answ_2
rename q18_1 answ_3
rename q18_2 answ_4
rename q19_1 answ_5
rename q19_2 answ_6
rename q20_1 answ_7
rename q20_2 answ_8
rename q21_1 answ_9
rename q21_2 answ_10
rename q22_1 answ_11
rename q22_2 answ_12
rename q23_1 answ_13
rename q23_2 answ_14
rename q24_1 answ_15
rename q24_2 answ_16
rename q25_1 answ_17
rename q25_2 answ_18
rename q26_1 answ_19
rename q26_2 answ_20

*Reshaping
reshape long answ dem age gender background party redi soc eco cor, i(respondentid) j(candidate, string)

*Renaming
rename q3 region
rename q4 urban 
rename q5 genderres
rename q6 ageres
rename q7 edures 
rename q8_1 abortion
rename q8_2 tax
rename q8_3 samesex
rename q8_4 welfare
rename q8_5 unions
rename q8_6 immi
rename q8_7 demfra
rename q9_1 aboprio
rename q9_2 taxprio
rename q9_3 samesexprio
rename q9_4 welprio
rename q9_5 unionprio
rename q9_6 immiprio
rename q10 pid
rename q11_1 Čssd
rename q11_2 Ods
rename q11_3 Ano
rename q15 mcheck
rename q27 attention
rename q28 device
rename block5_do treat

*Translating variables to English
replace urban = "Metropolis" if urban == "Velkoměsto"
replace urban = "Rural County" if urban == "Venkov"
replace urban = "Medium-size or small city" if urban == "Středně velké nebo malé město"
replace genderres = "Other" if genderres == "Jiné"
replace genderres = "Male" if genderres == "Muž"
replace genderres = "Prefer not to answer" if genderres == "Nepřeji si odpovědět"
replace genderres = "Female" if genderres == "Žena"
replace edures = "Elementary school or lower" if edures == "Základní škola nebo nižší vzdělání"
replace edures = "Secondary education (general or vocational)" if edures == "Středoškolské vzdělání (všeobecné nebo odborné)"
replace edures = "University or other tertiary education" if edures == "Univerzitní nebo jiné terciární vzdělání"
replace abortion = "Strongly agree" if abortion == "Rozhodně souhlasím"
replace abortion = "Don't know" if abortion == "Nevím"
replace abortion = "Somewhat agree" if abortion == "Spíše souhlasím"
replace abortion = "Neither agree nor disagree" if abortion == "Mám neutrální názor"
replace abortion = "Strongly disagree" if abortion == "Rozhodně nesouhlasím"
replace abortion = "Somewhat disagree" if abortion == "Spíše nesouhlasím"
replace tax = "Strongly agree" if tax == "Rozhodně souhlasím"
replace tax = "Don't know" if tax == "Nevím"
replace tax = "Somewhat agree" if tax == "Spíše souhlasím"
replace tax = "Neither agree nor disagree" if tax == "Mám neutrální názor"
replace tax = "Strongly disagree" if tax == "Rozhodně nesouhlasím"
replace tax = "Somewhat disagree" if tax == "Spíše nesouhlasím"
replace samesex = "Strongly agree" if samesex == "Rozhodně souhlasím"
replace samesex = "Don't know" if samesex == "Nevím"
replace samesex = "Somewhat agree" if samesex == "Spíše souhlasím"
replace samesex = "Neither agree nor disagree" if samesex == "Mám neutrální názor"
replace samesex = "Strongly disagree" if samesex == "Rozhodně nesouhlasím"
replace samesex = "Somewhat disagree" if samesex == "Spíše nesouhlasím"
replace welfare = "Strongly agree" if welfare == "Rozhodně souhlasím"
replace welfare = "Don't know" if welfare == "Nevím"
replace welfare = "Somewhat agree" if welfare == "Spíše souhlasím"
replace welfare = "Neither agree nor disagree" if welfare == "Mám neutrální názor"
replace welfare = "Strongly disagree" if welfare == "Rozhodně nesouhlasím"
replace welfare = "Somewhat disagree" if welfare == "Spíše nesouhlasím"
replace unions = "Strongly agree" if unions == "Rozhodně souhlasím"
replace unions = "Don't know" if unions == "Nevím"
replace unions = "Somewhat agree" if unions == "Spíše souhlasím"
replace unions = "Neither agree nor disagree" if unions == "Mám neutrální názor"
replace unions = "Strongly disagree" if unions == "Rozhodně nesouhlasím"
replace unions = "Somewhat disagree" if unions == "Spíše nesouhlasím"
replace immi = "Strongly agree" if immi == "Rozhodně souhlasím"
replace immi = "Don't know" if immi == "Nevím"
replace immi = "Somewhat agree" if immi == "Spíše souhlasím"
replace immi = "Neither agree nor disagree" if immi == "Mám neutrální názor"
replace immi = "Strongly disagree" if immi == "Rozhodně nesouhlasím"
replace immi = "Somewhat disagree" if immi == "Spíše nesouhlasím"
replace demfra = "Strongly agree" if demfra == "Rozhodně souhlasím"
replace demfra = "Don't know" if demfra == "Nevím"
replace demfra = "Somewhat agree" if demfra == "Spíše souhlasím"
replace demfra = "Neither agree nor disagree" if demfra == "Mám neutrální názor"
replace demfra = "Strongly disagree" if demfra == "Rozhodně nesouhlasím"
replace demfra = "Somewhat disagree" if demfra == "Spíše nesouhlasím"
replace aboprio = "Not at all important" if aboprio == "Zcela nedůležité"
replace aboprio = "Don't know" if aboprio == "Nevím"
replace aboprio = "Extremely important" if aboprio == "Extrémně důležité"
replace aboprio = "Very important" if aboprio == "Velmi důležité"
replace aboprio = "Not very important" if aboprio == "Nepříliš důležité"
replace aboprio = "Moderately important" if aboprio == "Středně důležité"
replace taxprio = "Not at all important" if taxprio == "Zcela nedůležité"
replace taxprio = "Don't know" if taxprio == "Nevím"
replace taxprio = "Extremely important" if taxprio == "Extrémně důležité"
replace taxprio = "Very important" if taxprio == "Velmi důležité"
replace taxprio = "Not very important" if taxprio == "Nepříliš důležité"
replace taxprio = "Moderately important" if taxprio == "Středně důležité"
replace samesexprio = "Not at all important" if samesexprio == "Zcela nedůležité"
replace samesexprio = "Don't know" if samesexprio == "Nevím"
replace samesexprio = "Extremely important" if samesexprio == "Extrémně důležité"
replace samesexprio = "Very important" if samesexprio == "Velmi důležité"
replace samesexprio = "Not very important" if samesexprio == "Nepříliš důležité"
replace samesexprio = "Moderately important" if samesexprio == "Středně důležité"
replace welprio = "Not at all important" if welprio == "Zcela nedůležité"
replace welprio = "Don't know" if welprio == "Nevím"
replace welprio = "Extremely important" if welprio == "Extrémně důležité"
replace welprio = "Very important" if welprio == "Velmi důležité"
replace welprio = "Not very important" if welprio == "Nepříliš důležité"
replace welprio = "Moderately important" if welprio == "Středně důležité"
replace unionprio = "Not at all important" if unionprio == "Zcela nedůležité"
replace unionprio = "Don't know" if unionprio == "Nevím"
replace unionprio = "Extremely important" if unionprio == "Extrémně důležité"
replace unionprio = "Very important" if unionprio == "Velmi důležité"
replace unionprio = "Not very important" if unionprio == "Nepříliš důležité"
replace unionprio = "Moderately important" if unionprio == "Středně důležité"
replace immiprio = "Not at all important" if immiprio == "Zcela nedůležité"
replace immiprio = "Don't know" if immiprio == "Nevím"
replace immiprio = "Extremely important" if immiprio == "Extrémně důležité"
replace immiprio = "Very important" if immiprio == "Velmi důležité"
replace immiprio = "Not very important" if immiprio == "Nepříliš důležité"
replace immiprio = "Moderately important" if immiprio == "Středně důležité"
replace pid = "I identify with a party not listed here" if pid == "Identifikuji se s politickou stranou, která zde není uvedena" 
replace pid = "Don't know" if pid == "Nevím"
replace pid = "I do not identify with any party" if pid == "Neidentifikuji se s žádnou politickou stranou"
replace Čssd = "Dislike a great deal" if Čssd == "Velmi se mi nelíbí"
replace Čssd = "Like a great deal" if Čssd == "Velmi se mi líbí"
replace Čssd = "Don't know" if Čssd == "Nevím"
replace Čssd = "Dislike somewhat" if Čssd == "Trochu se mi nelíbí"
replace Čssd = "Like somewhat" if Čssd == "Trochu se mi líbí"
replace Čssd = "Neither like nor dislike" if Čssd == "Mám neutrální názor"
replace Ods = "Dislike a great deal" if Ods == "Velmi se mi nelíbí"
replace Ods = "Like a great deal" if Ods == "Velmi se mi líbí"
replace Ods = "Don't know" if Ods == "Nevím"
replace Ods = "Dislike somewhat" if Ods == "Trochu se mi nelíbí"
replace Ods = "Like somewhat" if Ods == "Trochu se mi líbí"
replace Ods = "Neither like nor dislike" if Ods == "Mám neutrální názor"
replace Ano = "Dislike a great deal" if Ano == "Velmi se mi nelíbí"
replace Ano = "Like a great deal" if Ano == "Velmi se mi líbí"
replace Ano = "Don't know" if Ano == "Nevím"
replace Ano = "Dislike somewhat" if Ano == "Trochu se mi nelíbí"
replace Ano = "Like somewhat" if Ano == "Trochu se mi líbí"
replace Ano = "Neither like nor dislike" if Ano == "Mám neutrální názor"
replace mcheck = "Democracy is neither robust nor vulnerable in the Czech Republic" if mcheck == "Demokracie v České republice není stabilní ani zranitelná"
replace mcheck = "Democracy is quite robust in the Czech Republic" if mcheck == "Demokracie v České republice je docela stabilní"
replace mcheck = "Democracy is quite vulnerable in the Czech Republic" if mcheck == "Demokracie v České republice je docela zranitelná"
replace mcheck = "Democracy is very robust in the Czech Republic" if mcheck == "Demokracie v České republice je velmi stabilní"
replace mcheck = "Democracy is very vulnerable in the Czech Republic" if mcheck == "Demokracie v České republice je velmi zranitelná"
replace mcheck = "Don't know" if mcheck == "Nevím"
replace attention = "The piece of text did not mention any predictions" if attention == "Text neobsahoval žádné předpovědi"
replace attention = "Don't know" if attention == "Nevím"
replace attention = "I have not been presented for a piece of text about the current state of democracy around the world" if attention == "Žádný text o současném stavu demokracie ve světě mi nebyl předložen"
replace attention = "That many democratic breakdowns will occur during this decade" if attention == "Že se během tohoto desetiletí zhroutí mnoho demokracií"
replace attention = "That no or only very few democratic breakdowns will occur during this decade" if attention == "Že se během tohoto desetiletí nezhroutí žádná demokracie nebo že se jich zhroutí jen velmi málo"
replace device = "Prefer not to answer" if device == "Nepřeji si odpovědět"
replace device = "Other" if device == "Jiné"
replace device = "PC or Macbook" if device == "PC nebo Macbook"
replace answ = "Very unlikely" if answ == "Velmi nepravděpodobné"
replace answ = "Very likely" if answ == "Velmi pravděpodobné"
replace answ = "Don't know" if answ == "Nevím"
replace answ = "Somewhat unlikely" if answ == "Spíše nepravděpodobné"
replace answ = "Somewhat likely" if answ == "Spíše pravděpodobné"
replace answ = "Neither likely nor unlikely" if answ == "Mám neutrální názor"
replace dem = "Said it is unacceptable to harass journalists even though they do not reveal sources" if dem == "Řekl/a, že je nepřijatelné pronásledovat novináře, i když neprozradí své zdroje"
replace dem = "Said it is legitimate to fight political opponents in the streets if one feels provoked" if dem == "Řekl/a, že je přijatelné bojovat s politickými oponenty v ulicích, pokud je člověk vyprovokován"
replace dem = "Said it is unacceptable to fight political opponents in the streets even though one feels provoked" if dem == "Řekl/a, že je nepřijatelné bojovat s politickými oponenty v ulicích, i pokud je člověk  vyprovokován"
replace dem = "Said court rulings by judges appointed by opposing parties should be ignored" if dem == "Řekl/a, že rozsudky soudců jmenovaných opozičními stranami by měly být ignorovány"
replace dem = "Said court rulings by judges appointed by opposing parties should be adhered to" if dem == "Řekl/a, že rozsudky soudců jmenovaných opozičními stranami by měly být dodržovány"
replace dem = "Supported a proposal to reduce polling stations in areas that support opposing parties" if dem == "Podporoval/a návrh na omezení počtu volebních místností v oblastech, které podporují opoziční strany"
replace dem = "Supported a proposal to preserve existing polling-stations in all areas" if dem == "Podporoval/a návrh na zachování existujících volebních místností ve všech oblastech"
replace dem = "Said it is acceptable to harass journalists that do not reveal sources" if dem == "Řekl/a, že je přijatelné pronásledovat novináře, kteří neprozradí své zdroje"
replace gender = "Male" if gender == "Muž"
replace gender = "Female" if gender == "Žena"
replace background = "Actor/actress" if background == "Herec/herečka"
replace background = "Professor" if background == "Profesor/ka"
replace background = "Journalist" if background == "Novinář/ka"
replace background = "Political Career" if background == "Politická kariéra"
replace redi = "Decrease power of labor unions" if redi == "Snížit moc odborů"
replace redi = "Increase power of labor unions" if redi == "Zvýšit moc odborů"
replace redi = "Decrease public welfare spending" if redi == "Snížit výdaje na sociální zabezpečení"
replace redi = "Increase public welfare spending" if redi == "Zvýšit výdaje na sociální zabezpečení"
replace redi = "Decrease income tax on 10 percent richest" if redi == "Snížit daň z příjmu u 10 procent nejbohatších"
replace redi = "Increase income tax on 10 percent richest" if redi == "Zvýšit daň z příjmu u 10 procent nejbohatších"
replace soc = "Allow illegal immigrants to apply for citizenship" if soc == "Umožnit nelegálním přistěhovalcům žádat o české občanství"
replace soc = "Increase efforts to arrest and eventually deport illegal immigrants" if soc == "Zvýšit snahu zatýkat a nakonec deportovat nelegální přistěhovalce"
replace soc = "Make it harder for women to get an abortion" if soc == "Ztížit ženám jít na potrat"
replace soc = "Make it easier for women to get an abortion" if soc == "Usnadnit ženám jít na potrat"
replace soc = "Make it harder for people of the same sex to marry each other" if soc == "Ztížit sňatek lidem stejného pohlaví"
replace soc = "Make it easier for people of the same sex to marry each other" if soc == "Usnadnit sňatek lidem stejného pohlaví"
replace eco = "Bad at handling economic matters" if eco == "Špatně zvládá ekonomické záležitosti"
replace eco = "Neither good nor bad reputation on economic matters" if eco == "Ohledně ekonomických záležitostí nemá dobrou ani špatnou pověst"
replace eco = "Good at handling economic matters" if eco == "Dobře zvládá ekonomické záležitosti"
replace cor = "Bad at fighting corruption" if cor == "Špatně bojuje s korupcí"
replace cor = "Neither good nor bad reputation on fighting corruption" if cor == "Ohledně boje s korupcí nemá ani dobrou ani špatnou pověst"
replace cor = "Good at fighting corruption" if cor == "Dobře bojuje s korupcí"

***Recoding
**Candidate attributes
clonevar canage = age
encode gender, gen(cangender)
encode background, gen(canbackground)
encode party, gen(canparty)
encode redi, gen(canredi)
recode canredi (1 = 0 "Decrease income tax on 10 percent richest") (4 = 1 "Increase income tax on 10 percent richest") (else=.), gen(cantax)
recode canredi (2 = 0 "Decrease power of labor unions") (5 = 1 "Increase power of labor unions") (else=.), gen(canunion)
recode canredi (3 = 0 "Decrease public welfare spending") (6 = 1 "Increase public welfare spending") (else=.), gen(canwel)
encode soc, gen(cansoc)
recode cansoc (1 = 1 "Allow illegal immigrants to apply for citizenship") (2 = 0 "Increase efforts to arrest and eventually deport illegal immigrants") (else=.), gen(canimmi)
recode cansoc (3 = 1 "Make it easier for people of the same sex to marry each other") (5 = 0 "Make it harder for people of the same sex to marry each other") (else=.), gen(canss)
recode cansoc (4 = 1 "Make it easier for women to get an abortion") (6 = 0 "Make it harder for women to get an abortion") (else=.), gen(canabort)
encode dem, gen(candem)
recode candem (1 5 6 7 = 0 "Democratic") (2 3 4 8 = 1 "Undemocratic"), gen(candemmg) //Making one variable where all undemocratic positions are merged
encode eco, gen(canec)
recode canec (1 = 1 "Bad at handling economic matters") (2 = 3 "Good at handling economic matters") (3 = 2 "Neither good nor bad reputation on economic matters"), gen(caneco)
encode cor, gen(canco)
recode canco (1 = 1 "Bad at fighting corruption") (2 = 3 "Good at fighting corruption") (3 = 2 "Neither good nor bad reputation on fighting corruption"), gen(cancor)
gen cancom = (caneco + cancor)-1
label define competence 1 "Very incompetent" 2 "Moderately incompetent" 3 "Neither competent nor incompetent" 4 "Moderately competent" 5 "Very competent"
label values cancom competence

**Respondent attributes
*Background vars
encode region, gen(regionres)
encode urban, gen(urbanres)
recode urbanres (3 = 1 "Rural County") (2 = 3 "Metropolis") (1 = 2 "Medium-size or small city"), gen(urbanr)
drop urbanres
encode genderres, gen(genderr)
encode edures, gen(edur)
recode edur (2 = 2 "High school") (1 = 1 "Less than high school") (3 = 3 "More than high school"), gen(edurr)
drop edur

**Preference extremity vars
encode abortion, gen(abortionpre)
encode tax, gen(taxpre)
encode samesex, gen(samesexpre)
encode welfare, gen(welfarepre)
encode unions, gen(unionspre)
encode immi, gen(immipre)
encode demfra, gen(demfrapre)
recode abortionpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(abrpre)
recode taxpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(taxrpre)
recode samesexpre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(samerpre)
recode welfarepre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(welrpre)
recode unionspre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(uniorpre)
recode immipre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(immirpre)
recode demfrapre (1=.) (2 = 3 "Neither agree nor disagree") (3 = 4 "Somewhat agree") (4 = 2 "Somewhat disagree") (5 = 5 "Strongly agree") (6 = 1 "Strongly disagree"), gen(demfrpre)
drop abortionpre-demfrapre

*"Extremety on candidate-assigned attributes". Matextax is, for example, the respondent's preference on tax IF the candidate was assigned a tax position. Flips abortion, welfare, unions, and immigration so that low values are extreme left and high values are extreme right.
label define extreme 1 "Extreme left" 2 "Moderate Left" 3 "Center" 4 "Moderate Right" 5 "Extreme Right"
recode abrpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremeab)
recode welrpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremewel)
recode immirpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremeimmi)
recode uniorpre (1 = 5) (2 = 4) (3 = 3) (4 = 2) (5 = 1), gen(extremeunion)
clonevar extremetax = taxrpre
clonevar extremess = samerpre
gen matextax = extremetax if cantax != .
gen matexwel = extremewel if canwel != .
gen matexunion = extremeunion if canunion != .
gen matexredi = .
replace matexredi = matextax if matextax != .
replace matexredi = matexwel if matexwel != .
replace matexredi = matexunion if matexunion != .
gen mateximmi = extremeimmi if canimmi != .
gen matexabo = extremeab if canabort != .
gen matexss = extremess if canss != .
gen matexsoc = .
replace matexsoc = mateximmi if mateximmi != .
replace matexsoc = matexabo if matexabo != .
replace matexsoc = matexss if matexss != .
label values matexsoc mateximmi matexredi matextax matexunion matexwel matexabo matexss extremetax extremess extremeab extremewel extremeunion extremeimmi extreme

**Policy distance between candidate and respondent
*Main measure
recode cantax (0 = 4.5) (1 = 1.5), gen(cantaxm)
recode canunion (0 = 4.5) (1 = 1.5), gen(canunionm)
recode canwel (0 = 4.5) (1 = 1.5), gen(canwelm)
gen canredim = .
replace canredim = cantaxm if cantaxm != .
replace canredim = canunionm if canunionm != .
replace canredim = canwelm if canwelm != .

recode canimmi (0 = 4.5) (1 = 1.5), gen(canimmim)
recode canss (0 = 4.5) (1 = 1.5), gen(canssm)
recode canabort (0 = 4.5) (1 = 1.5), gen(canabortm)
gen cansocm = .
replace cansocm = canimmim if canimmim != .
replace cansocm = canssm if canssm != .
replace cansocm = canabortm if canabortm != .

gen distaxm = matextax-cantaxm
gen disunionm = matexunion-canunionm
gen diswelm = matexwel-canwelm 
gen disredim = matexredi-canredim

gen disimmim = mateximmi-canimmim
gen disssm = matexss-canssm
gen disabom = matexabo-canabortm
gen dissocm = matexsoc-cansocm

gen dissumm = sqrt(disredim^2) + sqrt(dissocm^2)
label define distancem 1 "Completely Aligned Positions" 7 "Completely Diverting Positions"
label values dissumm distancem

*Supplementary measures
recode cantax (0 = 5) (1 = 1), gen(cantaxs1)
recode canunion (0 = 5) (1 = 1), gen(canunions1)
recode canwel (0 = 5) (1 = 1), gen(canwels1)
gen canredis1 = .
replace canredis1 = cantaxs1 if cantaxs1 != .
replace canredis1 = canunions1 if canunions1 != .
replace canredis1 = canwels1 if canwels1 != .

recode canimmi (0 = 5) (1 = 1), gen(canimmis1)
recode canss (0 = 5) (1 = 1), gen(cansss1)
recode canabort (0 = 5) (1 = 1), gen(canaborts1)
gen cansocs1 = .
replace cansocs1 = canimmis1 if canimmis1 != .
replace cansocs1 = cansss1 if cansss1 != .
replace cansocs1 = canaborts1 if canaborts1 != .

gen distaxs1 = matextax-cantaxs1
gen disunions1 = matexunion-canunions1
gen diswels1 = matexwel-canwels1 
gen disredis1 = matexredi-canredis1

gen disimmis1 = mateximmi-canimmis1
gen dissss1 = matexss-cansss1
gen disabos1 = matexabo-canaborts1
gen dissocs1 = matexsoc-cansocs1

gen dissums1 = sqrt(disredis1^2) + sqrt(dissocs1^2)
label define distances1 0 "Completely Aligned Positions" 8 "Completely Diverting Positions"
label values dissums1 distances1

recode cantax (0 = 4) (1 = 2), gen(cantaxs2)
recode canunion (0 = 4) (1 = 2), gen(canunions2)
recode canwel (0 = 4) (1 = 2), gen(canwels2)
gen canredis2 = .
replace canredis2 = cantaxs2 if cantaxs2 != .
replace canredis2 = canunions2 if canunions2 != .
replace canredis2 = canwels2 if canwels2 != .

recode canimmi (0 = 4) (1 = 2), gen(canimmis2)
recode canss (0 = 4) (1 = 2), gen(cansss2)
recode canabort (0 = 4) (1 = 2), gen(canaborts2)
gen cansocs2 = .
replace cansocs2 = canimmis2 if canimmis2 != .
replace cansocs2 = cansss2 if cansss2 != .
replace cansocs2 = canaborts2 if canaborts2 != .

gen distaxs2 = matextax-cantaxs2
gen disunions2 = matexunion-canunions2
gen diswels2 = matexwel-canwels2
gen disredis2 = matexredi-canredis2

gen disarms2 = mateximmi-canimmis2
gen dissss2 = matexss-cansss2
gen disabos2 = matexabo-canaborts2
gen dissocs2 = matexsoc-cansocs2

gen dissums2 = sqrt(disredis2^2) + sqrt(dissocs2^2)
label define distances2 0 "Completely Aligned Positions" 6 "Completely Diverting Positions"
label values dissums2 distances2

**Preference intensity vars (respondent)
encode aboprio, gen(abortionpri)
encode taxprio, gen(taxpri)
encode samesexprio, gen(samesexpri)
encode welprio, gen(welfarepri)
encode unionprio, gen(unionspri)
encode immiprio, gen(immipri)
recode abortionpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(abrpri)
recode taxpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(taxrpri)
recode samesexpri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(samerpri)
recode welfarepri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(welrpri)
recode unionspri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(uniorpri)
recode immipri (1=.) (2 = 5 "Extremely important") (3 = 3 "Moderately important") (4 = 1 "Not at all important") (5 = 2 "Not very important") (6 = 4 "Very important"), gen(immirpri)
drop abortionpri-immipri


*"Intensity on candidate-assigned attributes". Matintax is, for example, the respondent's intensity on tax IF the candidate was assigned a tax position
label define intensity 1 "Very Low Intensity" 2 "Low Intensity" 3 "Moderate Intensity" 4 "High Intensity" 5 "Very High Intensity"
gen matintax = taxrpri if cantax != .
gen matinwel = welrpri if canwel != .
gen matinunion = uniorpri if canunion != .
gen matinredi = .
replace matinredi = matintax if matintax != .
replace matinredi = matinwel if matinwel != .
replace matinredi = matinunion if matinunion != .
gen matinimmi = immirpri if canimmi != .
gen matinabo = abrpri if canabort != .
gen matinss = samerpri if canss != .
gen matinsoc = .
replace matinsoc = matinimmi if matinimmi != .
replace matinsoc = matinabo if matinabo != .
replace matinsoc = matinss if matinss != .
label values matintax matinwel matinunion matinredi matinimmi matinabo matinss matinsoc intensity

*Intensity in favor of or against candidate: used for analysis
gen abodir = . 
replace abodir = -1 if extremeab < 3 & canabort == 0
replace abodir = -1 if extremeab > 3 & canabort == 1
replace abodir = -0.5 if extremeab == 3 & canabort !=.
replace abodir = 1 if extremeab < 3 & canabort == 1
replace abodir = 1 if extremeab > 3 & canabort == 0
gen aboint = abodir*abrpri

gen taxdir = . 
replace taxdir = -1 if extremetax < 3 & cantax == 0
replace taxdir = -1 if extremetax > 3 & cantax == 1
replace taxdir = -0.5 if extremetax == 3 & cantax !=.
replace taxdir = 1 if extremetax < 3 & cantax == 1
replace taxdir = 1 if extremetax > 3 & cantax == 0
gen taxint = taxdir*taxrpri

gen ssdir = . 
replace ssdir = -1 if extremess < 3 & canss == 0
replace ssdir = -1 if extremess > 3 & canss == 1
replace ssdir = -0.5 if extremess == 3 & canss !=.
replace ssdir = 1 if extremess < 3 & canss == 1
replace ssdir = 1 if extremess > 3 & canss == 0
gen ssint = ssdir*samerpri

gen weldir = . 
replace weldir = -1 if extremewel < 3 & canwel == 0
replace weldir = -1 if extremewel > 3 & canwel == 1
replace weldir = -0.5 if extremewel == 3 & canwel !=.
replace weldir = 1 if extremewel < 3 & canwel == 1
replace weldir = 1 if extremewel > 3 & canwel == 0
gen welint = weldir*welrpri

gen uniondir = . 
replace uniondir = -1 if extremeunion < 3 & canunion == 0
replace uniondir = -1 if extremeunion > 3 & canunion == 1
replace uniondir = -0.5 if extremeunion == 3 & canunion !=.
replace uniondir = 1 if extremeunion < 3 & canunion == 1
replace uniondir = 1 if extremeunion > 3 & canunion == 0
gen unionint = uniondir*uniorpri

gen immidir = . 
replace immidir = -1 if extremeimmi < 3 & canimmi == 0
replace immidir = -1 if extremeimmi > 3 & canimmi == 1
replace immidir = -0.5 if extremeimmi == 3 & canimmi !=.
replace immidir = 1 if extremeimmi < 3 & canimmi == 1
replace immidir = 1 if extremeimmi > 3 & canimmi == 0
gen immiint = immidir*immirpri

gen rediint =.
replace rediint = unionint if unionint != .
replace rediint = welint if welint != .
replace rediint = taxint if taxint != .

gen socint =.
replace socint = immiint if immiint != .
replace socint = ssint if ssint != .
replace socint = aboint if aboint != .

label define intensityfa -5 "Intense Opinion Against Candidate" -1 "Mild Opinion Against Candidate" 1 "Mild Opinion in Favor of Candidate" 5 "Intense Opinion in Favor of Candidate"
label values aboint taxint ssint rediint welint unionint immiint socint intensityfa


**Party ID
encode pid, gen(partyid)
recode partyid (2 =.)
drop pid
encode Čssd, gen(ČSSDx)
encode Ods, gen(ODSx)
encode Ano, gen(ANOx)
recode ČSSDx (1 = 1 "Dislike a great deal") (2 = 2 "Dislike somewhat") (3=.) (4 = 5 "Like a great deal") (5 = 4 "Like somewhat") (6 = 3 "Neither like nor dislike"), gen(ČSSD)
recode ODSx (1 = 1 "Dislike a great deal") (2 = 2 "Dislike somewhat") (3=.) (4 = 5 "Like a great deal") (5 = 4 "Like somewhat") (6 = 3 "Neither like nor dislike"), gen(ODS)
recode ANOx (1 = 1 "Dislike a great deal") (2 = 2 "Dislike somewhat") (3=.) (4 = 5 "Like a great deal") (5 = 4 "Like somewhat") (6 = 3 "Neither like nor dislike"), gen(ANO)
drop ČSSDx ODSx ANOx
gen partymmain = .
replace partymmain = ČSSD if canparty == 3
replace partymmain = ODS if canparty == 2
replace partymmain = ANO if canparty == 1
label define conparty 1 "Dislike candidate's party a great deal" 2 "Dislike candidate's party somewhat" 3 "Neither like nor dislike candidate's party" 4 "Like candidate's party somewhat" 5 "Like candidate's party a great deal"
label values partymmain conparty
recode partyid (3 = 0 "No Party ID") (2=.) (1 4 5 6 7 8 9 10 11 = 1 "Any Party ID"), gen(anyparty)
recode partyid (1 7 10 = 1 "ČSSD/ODS/ANO") (2=.) (3 4 5 6 8 9 11 = 0 "Not ČSSD/ODS/ANO"), gen(anyinparty)
gen copartisansplit = .
replace copartisansplit = 0 if anyinparty == 0
replace copartisansplit = 1 if partyid == 1 & canparty == 1
replace copartisansplit = 2 if partyid == 7 & canparty == 2
replace copartisansplit = 3 if partyid == 10 & canparty == 3
replace copartisansplit = 4 if partyid == 1 & canparty == 2
replace copartisansplit = 5 if partyid == 7 & canparty == 1
replace copartisansplit = 6 if partyid == 10 & canparty == 1
replace copartisansplit = 7 if partyid == 10 & canparty == 2
replace copartisansplit = 8 if partyid == 1 & canparty == 3
replace copartisansplit = 9 if partyid == 7 & canparty == 3
label define copartisansplit 0 "Neither Copartisanship nor Opposing Partisanship" 1 "Copartisanship: ANO" 2 "Copartisanship: OSD" 3 "Copartisanship: ČSSD" 4 "Voter: ANO, Candidate: OSD" 5 "Voter: OSD, Candidate: ANO" 6 "Voter: ČSSD, Candidate: ANO" 7 "Voter: ČSSD, Candidate: OSD" 8 "Voter: ANO, Candidate: ČSSD" 9 "Voter: OSD, Candidate: ČSSD"
label values copartisansplit copartisansplit
recode copartisansplit (0 = 0 "Neither Copartisanship nor Opposing Partisanship") (1 2 3 = 1 "Copartisanship") (4 5 6 7 8 9 = 2 "Opposing Partisanship"), gen(copartisanmerge)


**Manipulation and attention check
encode mcheck, gen(mcheck1)
recode mcheck1 (1 = 3 "Democracy is neither robust nor vulnerable in the Czech Republic") (2 = 4 "Democracy is quite robust in the Czech Republic") (3 = 2 "Democracy is quite vulnerable in the Czech Republic") (4 = 5 "Democracy is very robust in the Czech Republic") (5 = 1 "Democracy is very vulnerable in the Czech Republic") (6=.), gen(manipulation)
drop mcheck1
encode attention, gen(atte)
recode atte (1=5 "Don't know") (2 = 4 "I have not been presented for a piece of text about the current state of democracy around the world") (3 = 2 "That many democratic breakdowns will occur during this decade") (4 = 1 "That no or only very few democratic breakdowns will occur during this decade") (5 = 3 "The piece of text did not mention any predictions"), gen(attent) //NB: Numbers may be wrong; check twice when data is in
drop atte

**Outcome
encode answ, gen(answer)
recode answer (1=.) (2 = 3 "Neither likely nor unlikely") (3 = 4 "Somewhat likely") (4 = 2 "Somewhat unlikely") (5 = 5 "Very likely") (6 = 1 "Very unlikely"), gen(support)
drop answer

**Treatment
encode treat, gen(treat1)
recode treat1 (1 = 0 "Robust") (2=1 "Vulnerable"), gen(treatment)
drop treat1
*Did the treatment work (i.e., did it affect perceived democratic vulnerability)? And does it work best with or without providing a democracy definition just before assigning the treatment?
reg manipulation i.treatment, cluster(respondentid) //clustering added
*Were the respondents attentive?
gen correctatte = .
replace correctatte = 0 if attent == 5
replace correctatte = 0 if attent == 4
replace correctatte = 0 if attent == 3
replace correctatte = 0 if attent == 2 & treatment == 0
replace correctatte = 0 if attent == 1 & treatment == 1
replace correctatte = 1 if attent == 1 & treatment == 0
replace correctatte = 1 if attent == 2 & treatment == 1
label define correct 0 "Inattentive" 1 "Attentive"
label values correctatte correct
sum correctatte

*Creating numerical variables identifying task and candidate number
generate task =.
replace task = 1 if candidate == "_1" | candidate == "_2"
replace task = 2 if candidate == "_3" | candidate == "_4"
replace task = 3 if candidate == "_5" | candidate == "_6"
replace task = 4 if candidate == "_7" | candidate == "_8"
replace task = 5 if candidate == "_9" | candidate == "_10"
replace task = 6 if candidate == "_11" | candidate == "_12"
replace task = 7 if candidate == "_13" | candidate == "_14"
replace task = 8 if candidate == "_15" | candidate == "_16"
replace task = 9 if candidate == "_17" | candidate == "_18"
replace task = 10 if candidate == "_19" | candidate == "_20"
generate candid =.
replace candid = 1 if candidate == "_1"
replace candid = 2 if candidate == "_2"
replace candid = 3 if candidate == "_3"
replace candid = 4 if candidate == "_4"
replace candid = 5 if candidate == "_5"
replace candid = 6 if candidate == "_6"
replace candid = 7 if candidate == "_7"
replace candid = 8 if candidate == "_8"
replace candid = 9 if candidate == "_9"
replace candid = 10 if candidate == "_10"
replace candid = 11 if candidate == "_11"
replace candid = 12 if candidate == "_12"
replace candid = 13 if candidate == "_13"
replace candid = 14 if candidate == "_14"
replace candid = 15 if candidate == "_15"
replace candid = 16 if candidate == "_16"
replace candid = 17 if candidate == "_17"
replace candid = 18 if candidate == "_18"
replace candid = 19 if candidate == "_19"
replace candid = 20 if candidate == "_20"

**Drop respondents with missing values on variables used for key tests
reg partymmain dissumm matexredi matexsoc rediint socint support
gen sample1 = e(sample)


*****APPENDING*****
append using "U:\How to Save a Democracy\Data\ukfinal.dta"
append using "U:\How to Save a Democracy\Data\usfinal.dta"
append using "U:\How to Save a Democracy\Data\mxfinal.dta"
append using "U:\How to Save a Democracy\Data\skfinal.dta"
**Tie variables

gen start = .
replace start =candemmg[_n+11] if candidate == "_1"
replace start =candemmg[_n-11] if candidate == "_2"
replace start =candemmg[_n+1] if candidate == "_3"
replace start =candemmg[_n-1] if candidate == "_4"
replace start =candemmg[_n+1] if candidate == "_5"
replace start =candemmg[_n-1] if candidate == "_6"
replace start =candemmg[_n+1] if candidate == "_7"
replace start =candemmg[_n-1] if candidate == "_8"
replace start =candemmg[_n-18] if candidate == "_9"
replace start =candemmg[_n+18] if candidate == "_10"
replace start =candemmg[_n+1] if candidate == "_11"
replace start =candemmg[_n-1] if candidate == "_12"
replace start =candemmg[_n+1] if candidate == "_13"
replace start =candemmg[_n-1] if candidate == "_14"
replace start =candemmg[_n+1] if candidate == "_15"
replace start =candemmg[_n-1] if candidate == "_16"
replace start =candemmg[_n+1] if candidate == "_17"
replace start =candemmg[_n-1] if candidate == "_18"
replace start =candemmg[_n+2] if candidate == "_19"
replace start =candemmg[_n-2] if candidate == "_20"

gen tie = .
replace tie = 0 if start == 0 & candemmg == 0
replace tie = 1 if start == 1 & candemmg == 0
replace tie = 1 if start == 0 & candemmg == 1
replace tie = 2 if start == 1 & candemmg == 1
label define tie 0 "D+ vs. D+" 1 "D- vs. D+" 2 "D- vs. D-"
label values tie tie
save "U:\How to Save a Democracy\Data\appendedfinal.dta", replace