File size: 65,570 Bytes
f81d4f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/*******************************************************************************



This file contains the code to replicate the tables and figures in the paper.



	Contents:

	0. Generate or import final dataset

	Figure 1: The Season in 1841

	Figure 2: Pressure  marry young.

	Figure 3: Attendees at royal parties, by type of event.

	Figure 4: Synthetic probability to marry during the Season's interruption (1861-63).

	Table  1: Marriage market before, during, and after the Season's interruption.

	Figure 5: The interruption of the Season and distance between spouses' seats.

	Table  2: The Season's interruption and marriage outcomes, probit and OLS estimation.

	Figure 6: Placebo tests. Dependent variable: married a commoner.

	Figure 7: Peer-commoner intermarriage, Probit estimation with age dummies.

	Table  3: The Season's interruption and marriage outcomes, IV estimation.

	Table  4: Contingency tables

	Table  5: The interruption and sorting by title, non-parametric estimates.

	Figure 8: Sorting by landholdings, non-parametric estimation.

	Table  6: Women's marriages to commoners and her family's political power, IV estimation.

	Table  7: Determinants of investments in state education, IV estimation.

		

The file "3 Replication package\programs00_setup.do" installs the required ado 

packages sets. It also sets the path to all directories. If you want to run this 

do file individually, after installing the required packages unnmark and specify 

location of parent directory here:



	*global dirroot = "SPECIFY\LOCATION\OF\PARENT\DIRECTORY\HERE"



and then run the following lines for the secondary directories (specified as 

downloaded in replication package):



	global dirdata = "${dirroot}\data"

	global dirdta  = "${dirroot}\programs\01_dataprep\dta-temp-files"

	global dirresu = "${dirroot}\programs\results"



*******************************************************************************/


* Set-up:

	do "${dirroot}\programs\00_setup.do"


* ==============================================================================
* 0. GENERATE OR IMPORT FINAL DATASET:
* ------------------------------------------------------------------------------
clear all
set more off
set matsize 10000

* To generate the final dataset run the following line:

	do "${dirroot}\programs\01_dataprep\master-dataprep.do"

* Alternatively, you can import the final dataset data directly by writting
* use "${dirdata}\final-data.dta", clear

* ==============================================================================



* ==============================================================================
* FIGURE 1: 
* The Season in 1841.
* ------------------------------------------------------------------------------

* Import Sheppard (1977)'s data on 4,000 movements into and out of London of 
* families participating in the Season of 1841, as reported in The Morning Post.
import delimited "${dirdata}\sheppard.txt", clear
label var week "Week"
label var arrivals "Arrivals to London of members of Fashionable World"
label var departures "Departures from London of members of Fashionable World"
label var cumulative "Cumulative members of Fashionable World in London"


* Figure 1:
twoway	(bar arrivals week, fcolor(dknavy) fintensity(inten50) lcolor(dknavy) barw(1)) 		///
		(bar departures week, fcolor(maroon) fintensity(inten50) lcolor(maroon) barw(1)) 	///
		(line cumulative week, lcolor(black))			///
		(scatter cumulative week if week==4 | week==15 | week==20 | week==32),	///
		ytitle("Number of families") xtitle("") 			///
		legend(col(3) on order(1 "Arrivals" 2 "Departures" 3 "Cummulative")) graphregion(color(white))	///
		xlabel(1 "Jan" 5 "Feb" 9 "Mar" 13 "Apr" 17 "May" 22 "Jun" 26 "Jul" 31 "Ago" 35 "Sep" 39 "Oct" 44 "Nov" 48 "Dec") ///
		text(310 4  "Opening of Parliament", place(e) size(small))	///
		text(440 17 "Queen arrives to London", place(s) size(small))	///
		text(850 20 "Royal ball", place(n) size(small))	///
		text(420 32 "End of the Season", place(e) size(small))
graph export "${dirresu}\Figure1.pdf", as(pdf) replace



* ==============================================================================
* FIGURE 2: 
* Pressure  marry young.
* ------------------------------------------------------------------------------

* Import final dataset
use "${dirdata}\final-data.dta", clear


* Sample: all 796 peers' daughters first marrying in 1851-75
keep if wom==1 & nthismarriage==1 & myear>=1851 & myear<=1875 & mage!=.


* Variables for Figure
gen agegroup = .					// age groups in figure
forvalues i=18(3)35{
replace agegroup = `i' if mage>=`i' & mage<=`i'+2
}
replace agegroup = 30 if mage>=30
keep if agegroup!=. & agegroup<=30
gen duk = (rankspo==5) 				// marrying a dukes' heir


* Figure 2, first panel
preserve
collapse (mean) duk (sd) sd_duk=duk (count) n_duk=duk, by(agegroup)
gen hi_duk = duk + invttail(n_duk-1,0.025)*(sd_duk / sqrt(n_duk))
gen lo_duk = duk - invttail(n_duk-1,0.025)*(sd_duk / sqrt(n_duk))
label var agegroup "Age at marriage"
label var duk "% marrying duke, marquis, earl heir"
label var hi_duk "CI high, % marrying duke, marquis, earl heir"
label var lo_duk "CI low, % marrying duke, marquis, earl heir"
twoway 	(scatter duk agegroup, lcolor(dknavy) mcolor(black) msymbol(circle)) 					///
		(rcap hi_duk lo_duk agegroup, lcolor(black)),											///
		xlabel(18 "18-20" 21 "21-23" 24 "24-26" 27 "27-29" 30 "{&ge}30", labsize(medlarge) angle(45))  	///
		ylabel(0 "0" 0.1 "10" 0.2 "20" 0.3 "30", labsize(medlarge)) 	///
		legend(on order(1 "All peers' daughters") ring(0) position(1) nobox region(lstyle(none))) ///
		ytitle("% marrying duke, marquis, earl heir", size(medlarge)) ///
		xtitle("Age at marriage", size(medlarge)) ///
		name(fig2panela, replace) graphregion(color(white))
restore


* Figure 2, second panel
preserve
collapse (mean) duk (sd) sd_duk=duk (count) n_duk=duk, by(agegroup prank)
gen hi_duk = duk + invttail(n_duk-1,0.025)*(sd_duk / sqrt(n_duk))
gen lo_duk = duk - invttail(n_duk-1,0.025)*(sd_duk / sqrt(n_duk))
replace lo_duk = 0 if lo_duk<0	// restrict lower bound of c.i. to zero for visual purposes  
label var duk "% marrying duke, marquis, earl heir"
label var hi_duk "CI high, % marrying duke, marquis, earl heir"
label var lo_duk "CI low, % marrying duke, marquis, earl heir"
gen agegroup1 = agegroup-0.3	// separate estimates for the two groups for visibility
gen agegroup0 = agegroup+0.3
label var agegroup "Age at marriage"
label var agegroup0 "Age at marriage"
label var agegroup1 "Age at marriage"
twoway 	(rcap hi_duk lo_duk agegroup1 if prank==5, lcolor(blue))			///
		(rcap hi_duk lo_duk agegroup0 if prank==4, lcolor(red))				///
		(scatter duk agegroup1 if prank==5, lcolor(blue) mcolor(blue) msymbol(diamond))			/// 
		(scatter duk agegroup0 if prank==4, lcolor(red) msymbol(diamond) mlc(red) mfc(white)),	/// 
		ylabel(0 "0" 0.1 "10" 0.2 "20" 0.3 "30" 0.4 "40", labsize(medlarge))				///
		xlabel(18 "18-20" 21 "21-23" 24 "24-26" 27 "27-29" 30 "{&ge}30", labsize(medlarge) angle(45))  		///
		legend(on order(3 "Dukes', Marquis', Earls' daughters" 4 "Barons', Viscounts' daughters") rows(2) ring(0) position(1) nobox region(lstyle(none))) ///
		ytitle(" ", size(medlarge)) ///
		xtitle("Age at marriage", size(medlarge)) ///
		name(fig2panelb, replace) graphregion(color(white))
restore


* Figure 2, combined panels
graph combine fig2panela fig2panelb, graphregion(color(white))
graph export "${dirresu}\Figure2.pdf", replace
graph drop fig2panela fig2panelb



* ==============================================================================
* FIGURE 3: 
* Attendees at royal parties, by type of event.
* ------------------------------------------------------------------------------

* Import data with the invitations to royal parties, the number of attendees 
* at each party, and the numbers presented at court in the Seasons of 1851-75.
import delimited "${dirdata}\seasonattend.txt", clear


* Calculate attendance to royal parties, by type of event  
gen str15 partytype2 = partytype
replace partytype2 = "Concert and Evening party" if partytype=="Concert" | partytype=="Evening Party"
replace partytype2 = "Breakfast and Afternoon party" if partytype=="Breakfast" | partytype=="Afternoon"
replace partytype2 = "Children's Ball" if partytype2=="Child's Ball"
local j = 1
foreach x in "Ball" "Concert and Evening party" "Breakfast and Afternoon party" "Children's Ball" "Court"{
bysort year: egen tattend`j' = sum(attended) if partytype2=="`x'"
gsort year -tattend`j'
by year: replace tattend`j' = tattend`j'[1] if tattend`j'==.
replace tattend`j' = 0 if tattend`j'==.
local j = `j'+1
}
gen tAttend2 = tattend1+tattend2
gen tAttend3 = tAttend2+tattend3
gen tAttend4 = tAttend3+tattend4
gen tAttend5 = tAttend4+tattend5
collapse tattend1 tAttend2 tAttend3  tAttend4  tAttend5 court, by(year)


* Figure 3
twoway 																			///
	(bar tattend1 year, barw(0.7) bcolor(dknavy) yaxis(1)) 						///
	(rbar tattend1 tAttend2 year, bcolor(orange) barw(0.7) yaxis(1))			///
	(rbar tAttend2 tAttend3 year, bcolor(forest_green) barw(0.7) yaxis(1))		///
	(rbar tAttend3 tAttend4 year, bcolor(maroon) barw(0.7) yaxis(1))			///
	(rbar tAttend4 tAttend5 year, bcolor(teal) barw(0.7) yaxis(1))				///
	(line court year, yaxis(2) lcolor(black)),									///
	ytitle("attendees", axis(1)) ytitle("debutantes", axis(2)) 					///
	legend(on order(1 "Ball" 2 "Concert and Evening party" 3 "Children's Ball"	/// 
	4 "Breakfast and Afternoon party" 5 "Court reception" 6 "Debutantes presented at court (Ellenberger 1990)") size(small) nobox region(lstyle(none)))	///
	xtitle("") xlabel(1851(1)1875, angle(90)) graphregion(color(white))
graph export "${dirresu}\Figure3.pdf", replace



* ==============================================================================
* FIGURE 4: 
* Synthetic probability to marry during the Season's interruption (1861-63).
* ------------------------------------------------------------------------------

* Import final dataset
use "${dirdata}\final-data.dta", clear


* Figure 4
keep if age1861>=15 & age1861<=35
collapse syntheticT, by(age1861)
twoway 	(connect syntheticT age1861, sort lcolor(dknavy) mcolor(dknavy) msymbol(diamond)),	///
		ytitle("synthetic probability to marry in 1861-63 (%)") xtitle("age in 1861") 	///
		legend(off) graphregion(color(white))
graph export "${dirresu}\Figure4.pdf", replace



* ==============================================================================
* TABLE 1: 
* Marriage market before, during, and after the Season's interruption.
* ------------------------------------------------------------------------------

* Import final dataset
clear all
use "${dirdata}\final-data.dta", clear


* Sample and labels
keep if wom==1 & nthismarriage==1 & myear>=1858 & myear<=1866
xtile fATot_tab1 = fatotal, nq(100) // percentiles for Table 1's sample
gen normal = 1-mourn // to have Interruption - Normal
global balancelist mage dage biorder pr4 hengpee fATot_tab1


* Results
mat define tab1 = (.,.,.,.,.,.,.,.,.,.\.,.,.,.,.,.,.,.,.,.\.,.,.,.,.,.,.,.,.,.\.,.,.,.,.,.,.,.,.,.\.,.,.,.,.,.,.,.,.,.\.,.,.,.,.,.,.,.,.,.\.,.,.,.,.,.,.,.,.,.)
* Panel A, mean
qui estpost sum $balancelist if normal==0
qui matrix mu=e(mean)
forvalues j=1/7{
    mat tab1[`j',1] = mu[1,`j']
}
mat drop mu
qui estpost sum $balancelist if normal==1 & myear<=1863
qui matrix mu=e(mean)
forvalues j=1/7{
    mat tab1[`j',3] = mu[1,`j']
}
mat drop mu
qui estpost sum $balancelist if normal==1 & myear>1863
qui matrix mu=e(mean)
forvalues j=1/7{
    mat tab1[`j',7] = mu[1,`j']
}
mat drop mu
* Panel A, ttest
eststo tstbef: qui estpost ttest $balancelist if myear<=1863, by(normal)
qui matrix di1=e(b)
qui matrix di2=e(se)
forvalues j=1/7{
    mat tab1[`j',5] = di1[1,`j']
    mat tab1[`j',6] = di2[1,`j']
}
mat drop di1 di2
eststo tstaft: qui estpost ttest $balancelist if myear>=1861, by(normal)
qui matrix di1=e(b)
qui matrix di2=e(se)
forvalues j=1/7{
    mat tab1[`j',9] = di1[1,`j']
    mat tab1[`j',10] = di2[1,`j']
}
mat drop di1 di2
* Panel A, se of means
local j = 1
foreach x in mage dage biorder pr4 hengpee fATot_tab1{
qui ttest `x' if myear<=1863, by(normal)
local se1 = `r(sd_1)'/sqrt(`r(N_1)')
local se2 = `r(sd_2)'/sqrt(`r(N_2)')
mat tab1[`j',2] = `se1'
mat tab1[`j',4] = `se2'
qui ttest `x' if myear>=1861, by(normal)
local se2 = `r(sd_2)'/sqrt(`r(N_2)')
mat tab1[`j',8] = `se2'
local j = `j'+1
}
* Panel B, mean
collapse wrisk mourn normal, by(myear)
qui estpost sum wrisk if normal==0
qui matrix mu=e(mean)
mat tab1[7,1] = mu[1,1]
mat drop mu
qui estpost sum wrisk if normal==1 & myear<=1863
qui matrix mu=e(mean)
mat tab1[7,3] = mu[1,1]
mat drop mu
qui estpost sum wrisk if normal==1 & myear>1863
qui matrix mu=e(mean)
mat tab1[7,7] = mu[1,1]
mat drop mu
* Panel B, ttest
eststo tstbef: qui estpost ttest wrisk if myear<=1863, by(normal)
qui matrix di1=e(b)
qui matrix di2=e(se)
mat tab1[7,5] = di1[1,1]
mat tab1[7,6] = di2[1,1]
mat drop di1 di2
eststo tstaft: qui estpost ttest wrisk if myear>=1861, by(normal)
qui matrix di1=e(b)
qui matrix di2=e(se)
mat tab1[7,9]  = di1[1,1]
mat tab1[7,10] = di2[1,1]
mat drop di1 di2
* Panel B, se of means
qui ttest wrisk if myear<=1863, by(normal)
local se1 = `r(sd_1)'/sqrt(`r(N_1)')
local se2 = `r(sd_2)'/sqrt(`r(N_2)')
mat tab1[7,2] = `se1'
mat tab1[7,4] = `se2'
qui ttest wrisk if myear>=1861, by(normal)
local se2 = `r(sd_2)'/sqrt(`r(N_2)')
mat tab1[7,8] = `se2'


* Table 1
mat list tab1
mat colnames tab1 = "Int:mean" "Int:se" "Bef:mean" "Bef:se" "Diff:mean" "Diff:se" "Aft:mean" "Aft:se" "Diff:mean" "Diff:se"
mat rownames tab1 = "Panel A: Age at first marriage" "Panel A: Life expectancy" "Panel A: Birth order (excl heirs)" "Panel A: Duke/Earl/Marquis daughter" "Panel A: Peerage of England" "Panel A: Family acreage (percentile)" "Panel B: Female cohort size"
esttab matrix(tab1, fmt(1 1 1 1 1 1 1)) using "${dirresu}\Table1.tex", ///
	mlabel("Table 1") replace
	

	
* ==============================================================================
* FIGURE 5: 
* The interruption of the Season and distance between spouses' seats.
* ------------------------------------------------------------------------------

* Import final dataset
use "${dirdata}\final-data.dta", clear


* Figure 5
keep if wom==1 & nthismarriage<2 & myear>=1858 & myear<=1866
collapse (mean) dist (mean) attendLC, by(myear)
twoway 	(bar attendLC myear, barw(0.3) yaxis(2) color(sand) xlabel(1858(1)1866))	///
		(connect dist myear, yaxis(1) mcolor(black) lcolor(black) msymbol(diamond)),	///
		ytitle("miles", axis(1)) ytitle("attendees", axis(2)) xtitle("year") ///
		legend(on order(1 "Royal parties" 2 "Distance between spouses' seats")) ///
		graphregion(color(white))
graph export "${dirresu}\Figure5.pdf", replace
	

	
* ==============================================================================
* TABLE 2: 
* The Season's interruption and marriage outcomes, probit and OLS estimation.
* ------------------------------------------------------------------------------

* Table 2, columns [1] to [5]

use "${dirdata}\final-data.dta", clear
keep if base_sample==1

	/* Note: Baseline sample is 644 peers' daughters aged 15-35 in 1861 who ever 

	married, excluding second-marriages, women married to foreigners, and 

	members of the royal family.  */

global controls pr4 biorder hengpee
label var distlondon "Distance"
local j = 1
foreach x in "" distlondon{
local panel "A"
if `j'==2{
local panel "B"
}
qui probit cOut syntheticT $controls `x', cluster(byear)
	qui estat classification
	local pcp1 = round(r(P_corr),1)
	qui summ cOut if e(sample)==1
	local mdepvar = round(r(mean),0.01)
	qui margins, dydx(*) predict(pr) post
	outreg2 using "${dirresu}\Table2_`panel'", keep(syntheticT distlondon) nocons nor2 ///
	label dec(4) coefastr ctitle("M common") ///
	addtext(% correct, `pcp1', Mean of Dep Var, `mdepvar', Controls, YES) ///
	tex replace
qui probit mheir syntheticT $controls `x', cluster(byear)
	qui estat classification
	local pcp1 = round(r(P_corr),1)
	qui summ mheir if e(sample)==1
	local mdepvar = round(r(mean),0.01)
	qui margins, dydx(*) predict(pr) post
	outreg2 using "${dirresu}\Table2_`panel'", keep(syntheticT distlondon) nocons nor2 ///
	label dec(4) coefastr ctitle("M heir") ///
	addtext(% correct, `pcp1', Mean of Dep Var, `mdepvar', Controls, YES) ///
	tex
qui reg fmissmatch syntheticT $controls `x', cluster(byear)
	qui summ fmissmatch if e(sample)==1
	local mdepvar = round(r(mean),1)
	outreg2 using "${dirresu}\Table2_`panel'", keep(syntheticT distlondon) nocons nor2 ///
	label dec(3) coefastr ctitle("Diff abs") ///
	addtext(% correct, . , Mean of Dep Var, `mdepvar', Controls, YES) ///
	tex
qui reg fmissmatch2 syntheticT $controls `x', cluster(byear)
	qui summ fmissmatch2 if e(sample)==1
	local mdepvar = round(r(mean),1)
	outreg2 using "${dirresu}\Table2_`panel'", keep(syntheticT distlondon) nocons nor2 ///
	label dec(3) coefastr ctitle("Diff h-w") ///
	addtext(% correct, . , Mean of Dep Var, `mdepvar', Controls, YES) ///
	tex
qui probit fdown syntheticT $controls `x', cluster(byear)
	qui estat classification
	local pcp1 = round(r(P_corr),1)
	qui summ fdown if e(sample)==1
	local mdepvar = round(r(mean),0.01)
	qui margins, dydx(*) predict(pr) post
	outreg2 using "${dirresu}\Table2_`panel'", keep(syntheticT distlondon) nocons nor2 ///
	label dec(4) coefastr ctitle("M down") ///
	addtext(% correct, `pcp1', Mean of Dep Var, `mdepvar', Controls, YES) ///
	tex
local j = `j'+1
}


* Table 2, column [6]

use "${dirdata}\final-data.dta", clear
keep if marital_rates_sample==1
label var distlondon "Distance"

	/*  Note: To examine marital rates, I consider women aged 15-35 in 1861,

	whether they married or not. To avoid counting women who died at an early 

	age as celibate, I exclude those dying before age 35 (see p.20).  */

local j = 1
foreach x in "" distlondon{
local panel "A"
if `j'==2{
local panel "B"
}
qui probit celibacy syntheticT $controls `x', cluster(byear)
	qui estat classification
	local pcp1 = round(r(P_corr),1)
	qui summ celibacy if e(sample)==1
	local mdepvar = round(r(mean),0.01)
	qui margins, dydx(*) predict(pr) post
	outreg2 using "${dirresu}\Table2_`panel'", keep(syntheticT distlondon) nocons nor2 ///
	label dec(4) coefastr ctitle("never M") ///
	addtext(% correct, `pcp1', Mean of Dep Var, `mdepvar', Controls, YES) ///
	tex
local j = `j'+1
}


* Small cluster correction (bootstrap-t procedure of Cameron, Gelbach and Miller, 2008)

	/*  Note: Results stored in log file in the following location:

	3 Replication package\results\Table2_smallcluster.log.  */

clear all
use "${dirdata}\final-data.dta", clear
gsort surname title -nthismarr 	// to get stable results
do "${dirauxp}\cgmreg.do"		// if not run in setup
capture log close				// save results in log file
cd "${dirresu}"
log using Table2_smallcluster.log, replace
keep if wom==1 & nthismarriage<2 & age1861>=15 & age1861<=35	// sample
preserve
keep if nthismarr==1 & myear!=.	// married
foreach x in "" distlondon{
qui probit cOut syntheticT $controls `x', cluster(byear)
keep if e(sample)==1	// keep sample of non-missing variables
clustse probit cOut syntheticT $controls `x', cluster(byear) method(pairs) reps(5000)
clustse probit mheir syntheticT $controls `x', cluster(byear) method(pairs) reps(5000)
cgmwildboot fmissmatch syntheticT $controls `x', cluster(byear) bootcluster(byear) reps(5000)
cgmwildboot fmissmatch2 syntheticT $controls `x', cluster(byear) bootcluster(byear) reps(5000)
clustse probit fdown syntheticT $controls `x', cluster(byear) method(pairs) reps(5000)
}
restore
keep if dage>35 & dyear>byear+1 & prank>1 // married and unmarried women
foreach x in "" distlondon{
qui probit celibacy syntheticT $controls `x', cluster(byear)
keep if e(sample)==1	// keep sample of non-missing variables
clustse probit celibacy syntheticT $controls `x', cluster(byear) method(pairs) reps(5000)
}
log close


* ==============================================================================
* FIGURE 6: 
* Placebo tests. Dependent variable: married a commoner.
* ------------------------------------------------------------------------------

* Import placebo dataset
use "${dirdata}\placebo-data.dta", clear
graph drop _all

* Estimates for baseline sample
global controls pr4 biorder hengpee
qui probit cOut syntheticT $controls distlondon if nthismarr==1 & base_sample==1, cluster(byearclst)
qui margins, dydx(*) post
estimates store baseEST

* Placebo estimates
sort refno sample01 	// drop observations in both baseline and placebo samples
by refno: gen dup=_N
by refno: drop if sample0[1]!= sample0[2] & dup>1
keep if nthismarr==1
drop syntheticT	// just for label purposes
gen syntheticT = synthetic_plac
forvalues i=1811/1851{
qui probit cOut syntheticT $controls distlondon if sample01==`i' & sample0=="placebo", cluster(byearclst)
qui margins, dydx(*) post
estimates store pE`i'
}

* Figure
graph drop _all
coefplot (baseEST, msymbol(circle)) (baseEST, mcolor(white) noci) (pE1851, pstyle(p2)) (pE1850, pstyle(p2))	///
		 (pE1849, pstyle(p2)) (pE1848, pstyle(p2)) (pE1847, pstyle(p2))	///
		 (pE1846, pstyle(p2)) (pE1845, pstyle(p2)) (pE1844, pstyle(p2))	///
		 (pE1843, pstyle(p2)) (pE1842, pstyle(p2)) (pE1841, pstyle(p2))	///
		 (pE1840, pstyle(p2)) (pE1839, pstyle(p2)) (pE1838, pstyle(p2))	///
		 (pE1837, pstyle(p2)) (pE1836, pstyle(p2)) (pE1835, pstyle(p2))	///
		 (pE1834, pstyle(p2)) (pE1833, pstyle(p2)) (pE1832, pstyle(p2))	///
		 (pE1831, pstyle(p2)) (pE1830, pstyle(p2)) (pE1829, pstyle(p2))	///
		 (pE1828, pstyle(p2)) (pE1827, pstyle(p2)) (pE1826, pstyle(p2))	///
		 (pE1825, pstyle(p2)) (pE1824, pstyle(p2)) (pE1823, pstyle(p2))	///
		 (pE1822, pstyle(p2)) (pE1821, pstyle(p2)) (pE1820, pstyle(p2))	///
		 (pE1819, pstyle(p2)) (pE1818, pstyle(p2)) (pE1817, pstyle(p2))	///
		 (pE1816, pstyle(p2)) (pE1815, pstyle(p2)) (pE1814, pstyle(p2))	///
		 (pE1813, pstyle(p2)) (pE1812, pstyle(p2)) (pE1811, pstyle(p2)), 	///	
		 drop(biorder hengpee pr4 pr_3 ̇_cons distlondon) ///
		 msymbol(d) mfcolor(white) levels(95 90) graphregion(color(white)) ///
		 title("Dep. Var: Married a commoner", color(black)) ytitle("mg. effect of T (synthetic prob.)") xtitle("years of placebo interruption") ///
		 ylabel(-0.015(0.005)0.015, nogrid) legend(on order(3 "Baseline (1861-63)" 9 "Placebo") rows(2) ring(0) position(5) bmargin(large)) ///
		 xlabel(0.568 "1851-53" 0.6816 "1846-48" 0.7955 "1841-43" 0.909 "1836-38" 1.023 "1831-33" 1.1366 "1826-28" 1.24939 "1821-23" 1.36392 "1816-18" 1.4775 "1811-13", angle(45)) ///
		 yline(0) lpattern(dash) baselevels vert ///
		 xline(0.568, lpattern(dot) lcolor(gray)) ///
		 xline(0.6816, lpattern(dot) lcolor(gray)) ///
		 xline(0.7955, lpattern(dot) lcolor(gray)) ///
		 xline(0.909, lpattern(dot) lcolor(gray)) ///
		 xline(1.023, lpattern(dot) lcolor(gray)) ///
		 xline(1.1366, lpattern(dot) lcolor(gray)) ///
		 xline(1.24939, lpattern(dot) lcolor(gray)) ///
		 xline(1.36392, lpattern(dot) lcolor(gray)) ///
		 xline(1.4775, lpattern(dot) lcolor(gray)) ///
	text(0.00539529 0.57037 ".037", size(vsmall) orientation(vertical)) ///
	text(0.00539529 0.59037 ".06", size(vsmall) orientation(vertical)) ///
	text(0.00250475 0.613635 ".01", size(vsmall) orientation(vertical)) ///
	text(0.00276912 0.636005 ".01", size(vsmall) orientation(vertical)) ///
	text(0.0012222 0.658375 ".00", size(vsmall) orientation(vertical)) ///
text(0.00079789 0.6816  ".00", size(vsmall) orientation(vertical) box bcolor(white) fcolor(white) lcolor(white)) ///
	text(0.00076157 0.70397 ".00", size(vsmall) orientation(vertical)) ///
	text(0.00128846 0.727235 ".00", size(vsmall) orientation(vertical)) ///
	text(0.00131826 0.749605 ".00", size(vsmall) orientation(vertical)) ///
	text(0.00379514 0.771975 ".02", size(vsmall) orientation(vertical)) ///
text(0.00402036 0.7955  ".02", size(vsmall) orientation(vertical) box bcolor(white) fcolor(white) lcolor(white)) ///
	text(0.00382393 0.81761 ".01", size(vsmall) orientation(vertical)) ///
	text(0.00283652 0.840875 ".01", size(vsmall) orientation(vertical)) ///
	text(0.00210621 0.86414 ".00", size(vsmall) orientation(vertical)) ///
	text(0.00346859 0.88651 ".01", size(vsmall) orientation(vertical)) ///
text(0.00176394 0.909  ".00", size(vsmall) orientation(vertical) box bcolor(white) fcolor(white) lcolor(white)) ///
	text(0.0017114 0.932145 ".00", size(vsmall) orientation(vertical)) ///
	text(0.00205746 0.954515 ".01", size(vsmall) orientation(vertical)) ///
	text(0.00234219 0.97778 ".01", size(vsmall) orientation(vertical)) ///
	text(0.00537774 1.00015 ".12", size(vsmall) orientation(vertical)) ///
text(0.0057546 1.023  ".14", size(vsmall) orientation(vertical) box bcolor(white) fcolor(white) lcolor(white)) ///
	text(0.00787327 1.04579 ".41", size(vsmall) orientation(vertical)) ///
	text(0.00696466 1.06816 ".23", size(vsmall) orientation(vertical)) ///
	text(0.00774832 1.09142 ".25", size(vsmall) orientation(vertical)) ///
	text(0.00742015 1.11379 ".20", size(vsmall) orientation(vertical)) ///
text(0.008436 1.1366  ".31", size(vsmall) orientation(vertical) box bcolor(white) fcolor(white) lcolor(white)) ///
	text(0.00712933 1.15943 ".22", size(vsmall) orientation(vertical)) ///
	text(0.00506362 1.1818 ".08", size(vsmall) orientation(vertical)) ///
	text(0.00545438 1.20506 ".10", size(vsmall) orientation(vertical)) ///
	text(0.00608598 1.22743 ".12", size(vsmall) orientation(vertical)) ///
text(0.00530855 1.24939  ".13", size(vsmall) orientation(vertical) box bcolor(white) fcolor(white) lcolor(white)) ///
	text(0.00537472 1.27307 ".17", size(vsmall) orientation(vertical)) ///
	text(0.00442368 1.29454 ".08", size(vsmall) orientation(vertical)) ///
	text(0.0031978 1.3187 ".03", size(vsmall) orientation(vertical)) ///
	text(0.00497223 1.34107 ".09", size(vsmall) orientation(vertical)) ///
text(0.00586515 1.36392  ".16", size(vsmall) orientation(vertical) box bcolor(white) fcolor(white) lcolor(white)) ///
	text(0.00497563 1.38671 ".11", size(vsmall) orientation(vertical)) ///
	text(0.00487153 1.40908 ".10", size(vsmall) orientation(vertical)) ///
	text(0.00658739 1.43145 ".21", size(vsmall) orientation(vertical)) ///
	text(0.00614651 1.45471 ".17", size(vsmall) orientation(vertical)) ///
text(0.00672715 1.4775  ".19", size(vsmall) orientation(vertical) box bcolor(white) fcolor(white) lcolor(white))
graph export "${dirresu}\Figure6.pdf", replace


* Tests equality of coefficients

	/* Note: the following tests for the equality of coefficients report all the 

	p-values displayed in the Figure above */
	
use "${dirdata}\placebo-data.dta", clear
keep if nthismarr==1
gen syntheticT0 = syntheticT // just for label purposes
replace syntheticT0 = synthetic_plac if synthetic_plac!=.
qui probit cOut syntheticT0 $controls distlondon if sample0=="baseline"
estimates store myreg0
sort refno sample01 	// drop observations in both baseline and placebo samples
by refno: gen dup=_N
by refno: drop if sample0[1]!= sample0[2] & dup>1
	*local count10 = 0
	*local count5 = 0
	*local count1 = 0
forvalues i=1851(-1)1811{
qui probit cOut syntheticT0 $controls distlondon if sample01==`i' & sample0=="placebo"
estimates store myreg`i'
* tests
qui suest myreg0 myreg`i', cluster(byearclst)
display "---- `i' ----"
test [myreg0_cOut]syntheticT0=[myreg`i'_cOut]syntheticT0
local pval = round(`r(p)',0.001)
di `pval'
}



* ==============================================================================
* FIGURE 7: 
* Peer-commoner intermarriage, Probit estimation with age dummies.
* ------------------------------------------------------------------------------

* Import placebo dataset
use "${dirdata}\placebo-data.dta", clear
global controls pr4 biorder hengpee


* Panel A: baseline sample
fvset base 16 age1861
qui probit cOut i.age1861 $controls if base_sample==1, cluster(byearclst)
qui margins, dydx(*) predict(pr) post
estimates store BASE
fvset base 0 age1861
qui reg syntheticT i.age1861 if base_sample==1, nocons
estimates store BASEsynth
coefplot (BASE, label("cohort-level effect (left axis)") ylabel(-0.2(0.1)0.5)) ///
		 (BASEsynth, label("synthetic prob. of marrying at interruption (right axis)") axis(2) ylabel(5(5)25, axis(2)) offset(-0.05) recast(line) symbol(none)), ///
		 drop(biorder hengpee pr4 ̇_cons 0.age1861 15.age1861 27.age1861 28.age1861 29.age1861 30.age1861 31.age1861 32.age1861 33.age1861 34.age1861 35.age1861) ///
		 msymbol(d) mfcolor(white) levels(99 95 90) graphregion(color(white)) ///
		 title("Baseline", color(black)) xtitle(age in 1861) ytitle("prob. of marrying a commoner") ///
		 legend(on rows(2) region(lstyle(none))) ///
		 xlabel(1 "16" 2 "17" 3 "18" 4 "19" 5 "20" 6 "21" 7 "22" 8 "23" 9 "24" 10 "25" 11 "26") ///
		 yline(0) ylabel(-0.2(0.1)0.6) lpattern(dash) name(base, replace) vert baselevels


* Panel B: placebo
sort refno sample01 	// drop observations in both baseline and placebo samples
by refno: gen dup=_N
by refno: drop if sample0[1]!= sample0[2] & dup>1
keep if nthismarr==1
drop age1861	// just for labelling purposes
rename age1861_plac age1861
fvset base 16 age1861
qui probit cOut i.age1861 $controls i.sample01 if sample0=="placebo", cluster(byearclst)
qui margins, dydx(*) predict(pr) post
estimates store PLAC
coefplot (PLAC, label("cohort-level effect (left axis)") ylabel(-0.2(0.1)0.5)) ///
		 (BASEsynth, label("synthetic prob. of marrying at interruption (right axis)") axis(2) ylabel(5(5)25, axis(2)) offset(-0.05) recast(line) symbol(none)), ///
		 keep(16.age1861 17.age1861 18.age1861 19.age1861 20.age1861 21.age1861 22.age1861 23.age1861 24.age1861 25.age1861 26.age1861) ///
		 msymbol(d) mfcolor(white) levels(99 95 90) graphregion(color(white)) ///
 		 title("Placebo", color(black)) xtitle(age in 1861-X) graphregion(color(white)) ///
		 legend(on rows(2) region(lstyle(none))) ///
		 xlabel(1 "16" 2 "17" 3 "18" 4 "19" 5 "20" 6 "21" 7 "22" 8 "23" 9 "24" 10 "25" 11 "26") ///
		 yline(0) ylabel(-0.2(0.1)0.6) lpattern(dash) name(placebo, replace) vert baselevels


* Figure:
grc1leg base placebo, legendfrom(base) graphregion(color(white))
graph export "${dirresu}\Figure7.pdf", replace
graph drop _all
erase "${dirdata}\placebo-data.dta"


* ==============================================================================
* TABLE 3: 
* The Season's interruption and marriage outcomes, IV estimation.
* ------------------------------------------------------------------------------

* Import data and keep baseline sample
use "${dirdata}\final-data.dta", clear
keep if base_sample==1


* IV regressions
global controls pr4 biorder hengpee

* [1]
qui summ cOut
	local mdepvar = round(`r(mean)',0.01)
qui reg mourn syntheticT $controls, cluster(byear)
	local F1 = round(e(F),0.1)
qui cmp (cOut = mourn $controls) (mourn = syntheticT $controls), ind(4 1) cluster(byear) quietly
	qui margins, dydx(*) predict(pr) post
	outreg2 using "${dirresu}\Table3_A", keep(mourn) nocons label dec(2) coefastr ctitle("M common") addtext(Weak iv p-val, ., Mean DV, `mdepvar') tex replace
qui cmp (cOut = mourn $controls) (mourn = syntheticT $controls), ind(4 1) cluster(byear) quietly
	qui margins, dydx(*) predict(eq(#2)) post
	outreg2 using "${dirresu}\Table3_B", keep(syntheticT) nocons label dec(2) coefastr ctitle("M interr") addtext(F-stat, `F1') tex replace

* [2]
qui summ cOut if distlondon!=.
	local mdepvar = round(`r(mean)',0.01)
qui reg mourn syntheticT $controls distlondon, cluster(byear)
	local F1 = round(e(F),0.1)
qui cmp (cOut = mourn $controls distlondon) (mourn = syntheticT $controls distlondon), ind(4 1) cluster(byear) quietly
	qui margins, dydx(*) predict(pr) post
	outreg2 using "${dirresu}\Table3_A", keep(mourn) nocons label dec(2) coefastr ctitle("M common") addtext(Weak iv p-val, ., Mean DV, `mdepvar') tex
qui cmp (cOut = mourn $controls distlondon) (mourn = syntheticT $controls distlondon), ind(4 1) cluster(byear) quietly
	qui margins, dydx(*) predict(eq(#2)) post
	outreg2 using "${dirresu}\Table3_B", keep(syntheticT) nocons label dec(2) coefastr ctitle("M interr") addtext(F-stat, `F1') tex
* [3] and [4]
foreach x in "" distlondon{
qui reg mheir syntheticT $controls `x', cluster(byear)
	qui summ mheir if e(sample)==1
	local mdepvar = round(`r(mean)',0.01)
qui reg mourn syntheticT $controls `x', cluster(byear)
	local F1 = round(e(F),0.1)
qui cmp (mheir = mourn $controls `x') (mourn = syntheticT $controls `x'), ind(4 1) cluster(byear) quietly
	qui margins, dydx(*) predict(pr) post
	outreg2 using "${dirresu}\Table3_A", keep(mourn) nocons label dec(2) coefastr ctitle("M heir") addtext(Weak iv p-val, ., Mean DV, `mdepvar') tex
qui cmp (mheir = mourn $controls `x') (mourn = syntheticT $controls `x'), ind(4 1) cluster(byear) quietly
	qui margins, dydx(*) predict(eq(#2)) post
	outreg2 using "${dirresu}\Table3_B", keep(syntheticT) nocons label dec(2) coefastr ctitle("M interr") addtext(F-stat, `F1') tex
}
* [5] and [6]
foreach x in "" distlondon{
qui reg fmissmatch syntheticT $controls `x', cluster(byear)
	qui summ fmissmatch if e(sample)==1
	local mdepvar = round(`r(mean)',1)
qui ivregress liml fmissmatch (mourn = syntheticT) $controls `x', cluster(byear) first
	qui weakiv, null(0) small
	local wivpv = round(e(ar_p), 0.01)
qui reg mourn syntheticT $controls `x' if fmissmatch!=., cluster(byear)
	local F1 = round(e(F),0.1)
qui ivregress liml fmissmatch (mourn = syntheticT) $controls `x', cluster(byear)
	outreg2 using "${dirresu}\Table3_A", keep(mourn) nocons label dec(1) coefastr ctitle("Diff abs") addtext(Weak iv p-val, `wivpv', Mean DV, `mdepvar') tex
qui cmp (fmissmatch = mourn $controls `x') (mourn = syntheticT $controls `x') if fmissmatch!=., ind(1 1) cluster(byear) quietly
	qui margins, dydx(*) predict(eq(#2)) post
	outreg2 using "${dirresu}\Table3_B", keep(syntheticT) nocons label dec(2) coefastr ctitle("M interr") addtext(F-stat, `F1') tex
}
* [7] and [8]
foreach x in "" distlondon{
qui reg fmissmatch2 syntheticT $controls `x', cluster(byear)
	qui summ fmissmatch2 if e(sample)==1
	local mdepvar = round(`r(mean)',1)
qui ivregress liml fmissmatch2 (mourn = syntheticT) $controls `x', cluster(byear) first
	qui weakiv, null(0) small
	local wivpv = round(e(ar_p), 0.01)
qui reg mourn syntheticT $controls `x' if fmissmatch2!=., cluster(byear)
	local F1 = round(e(F),0.1)
qui ivregress liml fmissmatch2 (mourn = syntheticT) $controls `x', cluster(byear)
	qui margins, dydx(*) post
	outreg2 using "${dirresu}\Table3_A", keep(mourn) nocons label dec(1) coefastr ctitle("Diff h-w") addtext(Weak iv p-val, `wivpv', Mean DV, `mdepvar') tex
qui cmp (fmissmatch2 = mourn $controls `x') (mourn = syntheticT $controls `x') if fmissmatch2!=., ind(1 1) cluster(byear) quietly
	qui margins, dydx(*) predict(eq(#2)) post
	outreg2 using "${dirresu}\Table3_B", keep(syntheticT) nocons label dec(2) coefastr ctitle("M interr") addtext(F-stat, `F1') tex
}
* [9] and [10]
foreach x in "" distlondon{
qui reg fdown syntheticT $controls `x', cluster(byear)
	qui summ fdown if e(sample)==1
	local mdepvar = round(`r(mean)',0.01)
qui ivregress liml fdown (mourn = syntheticT) $controls `x', cluster(byear)
	qui weakiv, null(0) small
	local wivpv = round(e(ar_p), 0.01)
qui reg mourn syntheticT $controls `x' if fdown!=., cluster(byear)
	local F1 = round(e(F),0.1)
qui cmp (fdown = mourn $controls `x') (mourn = syntheticT $controls `x') if fdown!=., ind(4 1) cluster(byear) quietly
	qui margins, dydx(*) predict(pr) post
	outreg2 using "${dirresu}\Table3_A", keep(mourn) nocons label dec(2) coefastr ctitle("M down") addtext(Weak iv p-val, `wivpv', Mean DV, `mdepvar') tex
qui cmp (fdown = mourn $controls `x') (mourn = syntheticT $controls `x') if fdown!=., ind(4 1) cluster(byear) quietly
	qui margins, dydx(*) predict(eq(#2)) post
	outreg2 using "${dirresu}\Table3_B", keep(syntheticT) nocons label dec(2) coefastr ctitle("M interr") addtext(F-stat, `F1') tex
}



* ==============================================================================
* TABLE 4: 
* Contingency tables.
* ------------------------------------------------------------------------------

* Import data and keep baseline sample
use "${dirdata}\final-data.dta", clear
keep if base_sample==1


* Treatment indicator for non-parametric analysis
_pctile syntheticT, nq(100)
gen treatment = (syntheticT > r(r80))

	/* Note: For the non-parametric estimation, I compare a high- vs. a low-treatment

	cohort. The high-treatment cohort are women with a synthetic probability to

	marry during the interruption above 20 percent. This corresponds to the top

	quintile; the 20% of women with the highest synthetic probability to marry in

	1861-63. Conversely, the low-treatment cohort are women below the top quintile. */


* Contingency tables
label var grank "Wife"
capture log close				// save results in log file
cd "${dirresu}"
log using Table4.log, replace

*  Panel A: Low-Treatment cohorts (T < 80th percentile)
tab grank grankspo if treatment==0, expected matcell(ofreqa)

*  Panel B: High-Treatment cohorts (T >= 80th percentile)
tab grank grankspo if treatment==1, expected matcell(ofreqa)
log close



* ==============================================================================
* TABLE 5: 
* The interruption and sorting by title, non-parametric estimates.
* ------------------------------------------------------------------------------

* Import data and keep baseline sample
use "${dirdata}\final-data.dta", clear
keep if base_sample==1


* Treatment indicator for non-parametric analysis
_pctile syntheticT, nq(100)
gen treatment = (syntheticT > r(r80))


* Non-parametric stats
forvalues i=0/1{
tab grank grankspo if treatment==`i', chi2 lrchi2
local chi2_`i' = r(chi2)
local chi2LR_`i' = r(chi2_lr)
local chi2p_`i' = r(p)
local chi2LRp_`i' = r(p_lr)
local df_`i' = e(df_r)
local N`i' = r(N)
ktau grank grankspo if treatment==`i', stats(taub)
local taub_`i' = r(tau_b)
local taubp_`i' = r(p)
}


* Add results to matrix tab5
mat define tab5 = (.,.,.\.,.,.\.,.,.\.,.,.\.,.,.\.,.,.\.,.,.)
forvalues j =0/1{
local col = `j'+1
mat tab5[1,`col'] = `chi2_`j''
mat tab5[2,`col'] = `chi2p_`j''
mat tab5[3,`col'] = `chi2LR_`j''
mat tab5[4,`col'] = `chi2LRp_`j''
mat tab5[5,`col'] = `taub_`j''
mat tab5[6,`col'] = `taubp_`j''
mat tab5[7,`col'] = `N`j''
}
mat tab5[5,3] = `taub_0'-`taub_1'
mat tab5[7,3] = `N0'+`N1'


* Difference chi-squared and LR-chi2
local chi2_diff = `chi2_0'-`chi2_1'
local chi2_diffp = chi2tail(3,`chi2_diff')
local chi2LR_diff = `chi2LR_0'-`chi2LR_1'
local chi2LR_diffp = chi2tail(3,`chi2LR_diff')
mat tab5[1,3] = `chi2_diff'
mat tab5[2,3] = `chi2_diffp'
mat tab5[3,3] = `chi2LR_diff'
mat tab5[4,3] = `chi2LR_diffp'


* Difference tau-b
qui ktau grank grankspo if treatment==0
local convtaub_0 = sin(3.141592654*`r(tau_b)'*0.5)
qui ktau grank grankspo if treatment==1
local convtaub_1 = sin(3.141592654*`r(tau_b)'*0.5)
cortesti `convtaub_0' `N0' `convtaub_1' `N1'
mat tab5[6,3] = 0.1637


* Table 5
mat colnames tab5 = "Low-treat" "High-treat" "Diff"
mat rownames tab5 = "Pearson chi-squared" "  p-val" "Likelihood ratio" "  p-val" "Kendall rank correlation" "  p-val" "N"
mat list tab5
esttab matrix(tab5, fmt(3 3)) using "${dirresu}\Table5.tex", mlabel("Table 5") replace



* ==============================================================================
* FIGURE 8: 
* Sorting by landholdings, non-parametric estimation.
* ------------------------------------------------------------------------------

* Import data and keep baseline sample
use "${dirdata}\final-data.dta", clear
keep if base_sample==1


* Treatment indicator for non-parametric analysis
_pctile syntheticT, nq(100)
gen treatment = (syntheticT > r(r80))
count if fmissmatch!=.	// sample (N=324)
count if fmissmatch!=. & treatment==0	// Low-treatment (N=256)
count if fmissmatch!=. & treatment==0 & age1861<22	// Low-treatment, younger (N=64)
count if fmissmatch!=. & treatment==0 & age1861>22	// Low-treatment, older (N=192)


* Kolmogorov-Smirnov tests
gen treat2`x' = treatment // for High vs. younger comparison
replace treat2 = . if treatment==0 & age1861>22
gen treat3 = treatment // for High vs. older comparison
replace treat3 = . if treatment==0 & age1861<22
foreach x in "" 2{
sort fmissmatch`x' age1861
qui ksmirnov fmissmatch`x', by(treatment) exact
local KS1`x' = round(`r(D)',0.01)
local pval1`x' = round(`r(p_exact)',0.001)
ksmirnov fmissmatch`x', by(treat2) exact
local KS2`x' = round(`r(D)',0.01)
local pval2`x' = round(`r(p_exact)',0.001)
ksmirnov fmissmatch`x', by(treat3) exact
local KS3`x' = round(`r(D)',0.01)
local pval3`x' = round(`r(p_exact)',0.001)
}


* Figure, Panel A
preserve
sort fmissmatch age1861
cumul fmissmatch if treatment>0, gen(cumTREAT)
cumul fmissmatch if treatment==0, gen(cumCONTROL)
cumul fmissmatch if treatment==0 & age1861>22, gen(cumCONTROLold)
cumul fmissmatch if treatment==0 & age1861<22, gen(cumCONTROLyoung)
twoway 	(line cumTREAT fmissmatch, c(J) lwidth(thick) lcolor(red)) ///
		(line cumCONTROL fmissmatch, c(J) lwidth(thin) lcolor(blue)) ///
		(line cumCONTROLold fmissmatch, c(J) lwidth(thin) lpattern(dash) lcolor(emidblue)) ///
		(line cumCONTROLyoung fmissmatch, c(J) lwidth(thin) lpattern(solid) lcolor(emidblue)), ///
		xtitle("|wife's percentile rank of acres - husband's percentile rank of acres|", size(med))	///
		ytitle("cumulative", size(med))	///
		legend(on order(1 "High-Treatment (T{&ge}80p)" 2 "Low-Treatment (T<80p)" 3 "older" 4 "younger") rows(4) ring(0) position(5) bmargin(large) region(lstyle(none))) ///
		graphregion(color(white)) ///
		note("High vs low: KS = `KS1' (`pval1'); High vs younger: KS = `KS2' (`pval2'); High vs older: KS = `KS3' (`pval3')")
graph export "${dirresu}\Figure8_A.pdf", as(pdf) replace
restore


* Figure, Panel B
preserve
sort fmissmatch2 age1861
cumul fmissmatch2 if treatment>0, gen(cumTREAT)
cumul fmissmatch2 if treatment==0, gen(cumCONTROL)
cumul fmissmatch2 if treatment==0 & age1861>22, gen(cumCONTROLold)
cumul fmissmatch2 if treatment==0 & age1861<22, gen(cumCONTROLyoung)
twoway 	(line cumTREAT fmissmatch2, c(J) lwidth(thick) lcolor(red)) ///
		(line cumCONTROL fmissmatch2, c(J) lwidth(thin) lcolor(blue)) ///
		(line cumCONTROLold fmissmatch2, c(J) lwidth(thin) lpattern(dash) lcolor(emidblue)) ///
		(line cumCONTROLyoung fmissmatch2, c(J) lwidth(thin) lpattern(solid) lcolor(emidblue)) ///
		(pcarrowi 0.95 -40 0.95 -60 "Marrying down", color(black)), ///
		xtitle("difference in acres' precentile rank (husband-wife)", size(med))	///
		xline(0, lcolor(black) lwidth(thick)) ytitle("cumulative", size(med))	///
		legend(on order(1 "High-Treat (T{&ge}80p.)" 2 "Low-Treat (T<80p.)" 3 "older" 4 "younger") rows(4) ring(0) position(5) bmargin(large) region(lstyle(none))) ///
		graphregion(color(white)) ///
		note("High vs low: KS = `KS12' (`pval12'); High vs younger: KS = `KS22' (`pval22'); High vs older: KS = `KS32' (`pval32')")
graph export "${dirresu}\Figure8_B.pdf", as(pdf) replace
restore



* ==============================================================================
* TABLE 6: 
* Women's marriages to commoners and her family's political power, IV estimation.
* ------------------------------------------------------------------------------

* Import data
use "${dirdata}/final-data-sec4.dta", clear


* Control variables:
gen nsib2 = nsib^2 											// Number of siblings squared
global controlsb distlondon i.prank nsib nsib2				// controls for regressions with brothers
global controlsh distlondon i.prank							// controls for regressions with family heads
global hechter propman100 logincome propcon propnonc relig	// county controls from Hechter


* Collapse data such that a woman (and her family) is the unit of observation
encode fbio1, gen(nfam) // clusters at the family level
collapse cOut syntheticT byear nfam d_MPb_aft d_MPf_bef MPb_years_aft MPf_years_bef d_MPb_locaft2 d_MPf_local2 MPb_years_locaft MPf_years_locbef d_MPh_aft d_MPh_bef MPh_years_aft MPh_years_bef ///
		 biorder distlondon prank nsib nsib2 $hechter, by(refno)
label var cOut "W married a commoner"


* Col [1]: Any brother is MP after woman's marriage

global polit d_MPb_aft
global polbefore d_MPf_bef
* CLR p-values
qui ivprobit $polit (cOut = syntheticT biorder) $hechter $controlsb $polbefore, first twostep
	weakiv, null(0) small
	local CLR1 = round(e(clr_p), 0.001)
* CLR p-values clustered by family
qui ivregress liml $polit (cOut = syntheticT biorder) $hechter $controlsb $polbefore, first vce(cluster nfam)
	local Nbobs = `e(N)'	// just so that N appears after CLR p-values in table
	weakiv, null(0) small
	local CLR2 = round(e(clr_p), 0.001)
	summ $polit if e(sample)==1
	local mdepvar = round(r(mean),0.01)
* Second stage coefficients
qui cmp ($polit = cOut $hechter $controlsb $polbefore) (cOut = syntheticT biorder $hechter $controlsb $polbefore), ind(4 1) quietly cluster(byear)
	qui margins, dydx(*) predict(pr) post
	outreg2 using "${dirresu}\Table6_A", keep(cOut) nocons label nose dec(2) noas noobs	///
	ctitle("MP (b)") addtext(CLR-pval, `CLR1', CLR-pval 2, `CLR2', Mean DP, `mdepvar', Nb observations, `Nbobs') tex replace
* First stage coefs in Panel B
qui reg cOut syntheticT biorder $hechter $controlsb $polbefore
	local F1 = round(e(F),0.1)
	outreg2 using "${dirresu}\Table6_B", keep(syntheticT) nocons label noas nor2 dec(3) coefastr ctitle("M common") addtext(F-stat, `F1') tex replace


* Col [2]: Years MP after woman's marriage (brothers)

global polit MPb_years_aft
global polbefore MPf_years_bef
* CLR p-values
qui ivregress liml $polit (cOut = syntheticT biorder) $hechter $controlsb $polbefore, first
	qui weakiv, null(0) small
	local CLR1 = round(e(clr_p), 0.001)
* CLR p-values clustered by family
qui ivregress liml $polit (cOut = syntheticT biorder) $hechter $controlsb $polbefore, first vce(cluster nfam)
	local Nbobs = `e(N)'	// just so that N appears after CLR p-values in table
	qui weakiv, null(0) small
	local CLR2 = round(e(clr_p), 0.001)
	summ $polit if e(sample)==1
	local mdepvar = round(r(mean),0.01)
* Second stage coefficients
qui cmp ($polit = cOut $hechter $controlsb $polbefore) (cOut = syntheticT biorder $hechter $controlsb $polbefore), ind(1 1) quietly cluster(byear)
	qui margins, dydx(*) post
	outreg2 using "${dirresu}\Table6_A", keep(cOut) nocons label nose dec(2) noas noobs	///
	ctitle("Years (b)") addtext(CLR-pval, `CLR1', CLR-pval 2, `CLR2', Mean DP, `mdepvar', Nb observations, `Nbobs') tex
* First stage coefs in Panel B
qui reg cOut syntheticT biorder $hechter $controlsb $polbefore
	local F1 = round(e(F),0.1)
	outreg2 using "${dirresu}\Table6_B", keep(syntheticT) nocons label noas nor2 dec(3) coefastr ctitle("M common") addtext(F-stat, `F1') tex

	
* Col [3]: Any brother is local MP after woman's marriage

global polit d_MPb_locaft2
global polbefore d_MPf_local2
* CLR p-values
qui ivprobit $polit (cOut = syntheticT biorder) $hechter $controlsb $polbefore, first twostep
	qui weakiv, null(0) small
	local CLR1 = round(e(clr_p), 0.001)
* CLR p-values clustered by family
qui ivregress liml $polit (cOut = syntheticT biorder) $hechter $controlsb $polbefore, first vce(cluster nfam)
	local Nbobs = `e(N)'	// just so that N appears after CLR p-values in table
	qui weakiv, null(0) small
	local CLR2 = round(e(clr_p), 0.001)
	summ $polit if e(sample)==1
	local mdepvar = round(r(mean),0.01)
* Second stage coefficients
qui cmp ($polit = cOut $hechter $controlsb $polbefore) (cOut = syntheticT biorder $hechter $controlsb $polbefore), ind(4 1) quietly cluster(byear)
	qui margins, dydx(*) predict(pr) post
	outreg2 using "${dirresu}\Table6_A", keep(cOut) nocons label nose dec(2) noas noobs	///
	ctitle("local MP (b)") addtext(CLR-pval, `CLR1', CLR-pval 2, `CLR2', Mean DP, `mdepvar', Nb observations, `Nbobs') tex
* First stage coefs in Panel B
qui reg cOut syntheticT biorder $hechter $controlsb $polbefore
	local F1 = round(e(F),0.1)
	outreg2 using "${dirresu}\Table6_B", keep(syntheticT) nocons label noas nor2 dec(3) coefastr ctitle("M common") addtext(F-stat, `F1') tex
	

* Col [4]: Years local MP after woman's marriage (brothers)

global polit MPb_years_locaft
global polbefore MPf_years_locbef
* CLR p-values
qui ivregress liml $polit (cOut = syntheticT biorder) $hechter $controlsb $polbefore, first
	qui weakiv, null(0) small
	local CLR1 = round(e(clr_p), 0.001)
* CLR p-values clustered by family
qui ivregress liml $polit (cOut = syntheticT biorder) $hechter $controlsb $polbefore, vce(cluster nfam)
	local Nbobs = `e(N)'	// just so that N appears after CLR p-values in table
	qui weakiv, null(0) small
	local CLR2 = round(e(clr_p), 0.001)
	summ $polit if e(sample)==1
	local mdepvar = round(r(mean),0.01)
* Second stage coefficients
qui cmp ($polit = cOut $hechter $controlsb $polbefore) (cOut = syntheticT biorder $hechter $controlsb $polbefore), ind(1 1) quietly cluster(byear)
	qui margins, dydx(*) post
	outreg2 using "${dirresu}\Table6_A", keep(cOut) nocons label nose dec(3) noas noobs	///
	ctitle("lyears (b)") addtext(CLR-pval, `CLR1', CLR-pval 2, `CLR2', Mean DP, `mdepvar', Nb observations, `Nbobs') tex
* First stage coefs in Panel B
qui reg cOut syntheticT biorder $hechter $controlsb $polbefore
	local F1 = round(e(F),0.1)
	outreg2 using "${dirresu}\Table6_B", keep(syntheticT) nocons label noas nor2 dec(3) coefastr ctitle("M common") addtext(F-stat, `F1') tex


* Col [5]: Family head is MP after woman's marriage

global polit d_MPh_aft
global polbefore d_MPh_bef
* CLR p-values
qui ivprobit $polit (cOut = syntheticT biorder) $hechter $controlsh $polbefore, first twostep
	qui weakiv, null(0) small
	local CLR1 = round(e(clr_p), 0.001)
* CLR p-values clustered by family
qui ivregress liml $polit (cOut = syntheticT biorder) $hechter $controlsh $polbefore, vce(cluster nfam)
	local Nbobs = `e(N)'	// just so that N appears after CLR p-values in table
	qui weakiv, null(0) small
	local CLR2 = round(e(clr_p), 0.001)
	summ $polit if e(sample)==1
	local mdepvar = round(r(mean),0.01)
* Second stage coefficients
qui cmp ($polit = cOut $hechter $controlsh $polbefore) (cOut = syntheticT biorder $hechter $controlsh $polbefore), ind(4 1) quietly cluster(byear)
	qui margins, dydx(*) predict(pr) post
	outreg2 using "${dirresu}\Table6_A", keep(cOut) nocons label nose dec(2) noas noobs	///
	ctitle("MP (h)") addtext(CLR-pval, `CLR1', CLR-pval 2, `CLR2', Mean DP, `mdepvar', Nb observations, `Nbobs') tex
* First stage coefs in Panel B
qui reg cOut syntheticT biorder $hechter $controlsh $polbefore
	local F1 = round(e(F),0.1)
	outreg2 using "${dirresu}\Table6_B", keep(syntheticT) nocons label noas nor2 dec(3) coefastr ctitle("M common") addtext(F-stat, `F1') tex


* Col [6]: Years MP after woman's marriage (family head)

global polit MPh_years_aft
global polbefore MPh_years_bef
* CLR p-values
qui ivregress liml $polit (cOut = syntheticT biorder) $hechter $controlsh $polbefore, first 	//
	qui weakiv, null(0) small
	local CLR1 = round(e(clr_p), 0.001)
* CLR p-values clustered by family
qui ivregress liml $polit (cOut = syntheticT biorder) $hechter $controlsh $polbefore, vce(cluster nfam)
	local Nbobs = `e(N)'	// just so that N appears after CLR p-values in table
	qui weakiv, null(0) small
	local CLR2 = round(e(clr_p), 0.001)
	summ $polit if e(sample)==1
	local mdepvar = round(r(mean),0.01)
* Second stage coefficients
qui cmp ($polit = cOut $hechter $controlsb $polbefore) (cOut = syntheticT biorder $hechter $controlsb $polbefore), ind(1 1) quietly cluster(byear)
	qui margins, dydx(*) post
	outreg2 using "${dirresu}\Table6_A", keep(cOut) nocons label nose dec(2) noas noobs	///
	ctitle("Years (h)") addtext(CLR-pval, `CLR1', CLR-pval 2, `CLR2', Mean DP, `mdepvar', Nb observations, `Nbobs') tex
* First stage coefs in Panel B
qui reg cOut syntheticT biorder $hechter $controlsh $polbefore
	local F1 = round(e(F),0.1)
	outreg2 using "${dirresu}\Table6_B", keep(syntheticT) nocons label noas nor2 dec(3) coefastr ctitle("M common") addtext(F-stat, `F1') tex



* ==============================================================================
* TABLE 7: 
* Determinants of investments in state education, IV estimation.
* ------------------------------------------------------------------------------

* Import data
use "${dirdata}/final-data-sec4.dta", clear


* Control variables:
gen nsib2 = nsib^2 											// Number of siblings squared
global controlsrf distlondon i.prank						// controls for reduced-form effect
global controlsb  distlondon i.prank nsib nsib2				// controls for regressions with brothers
global controlsh  distlondon i.prank							// controls for regressions with family heads
global hechter propman100 logincome propcon propnonc relig	// county controls from Hechter
encode fbio1, gen(nfam) 									// clusters at the family level
label var cOut "W married a commoner"

	/* Note: Panel B results for p-values (parenthesis) and CLR p-values 

	adjusted for weak instruments [brackets] are in one column in the paper,

	in two columns in the table produced by this code.  */

* Col [1]: Reduced-form effect

* CLR p-values
qui ivregress liml rateperpou (cOut = syntheticT biorder) $hechter $controlsrf , first
	qui weakiv, null(0) small
	local CLR1 = round(e(clr_p), 0.001)
* CLR p-values clustered by family
qui ivregress liml rateperpou (cOut = syntheticT biorder) $hechter $controlsrf , first vce(cluster nfam)
	local Nbobs = `e(N)'	// just so that N appears after CLR p-values in table
	weakiv, null(0) small
	local CLR2 = round(e(clr_p), 0.001)
* Second-stage coefficients
qui ivregress liml rateperpou (cOut = syntheticT biorder) $hechter $controlsrf , first
	outreg2 using "${dirresu}\Table7_A", keep(cOut) stats(coef) nocons label noobs dec(2) noas ///
	ctitle("tax rate") addtext(CLR-pval, `CLR1', CLR-pval 2, `CLR2', Nb observations, `Nbobs') tex replace	
* First stage coefs in Panel B
qui reg cOut syntheticT biorder $hechter $controlsrf
	local F1 = round(e(F),0.01)
qui ivreg2 rateperpound (cOut = syntheticT biorder) $hechter $controlsrf , first savefirst
	est restore _ivreg2_cOut
	outreg2 using "${dirresu}\Table7_B", keep(syntheticT) replace tex ctitle("M common") label dec(3) noaster nocons nor2 stats(coef pval) addtext(F-stat, `F1', cluster, .)
qui ivreg2 rateperpound (cOut = syntheticT biorder) $hechter $controlsrf , first cluster(nfam) savefirst
	est restore _ivreg2_cOut
	outreg2 using "${dirresu}\Table7_B", keep(syntheticT) tex ctitle("M common") label dec(3) noaster nocons nor2 stats(coef pval) bracket addtext(F-stat, `F1', cluster, family)

		
* Col [2]: Any brother is MP after marriage

global polit d_MPb_aft
global polbefore d_MPf_bef
* CLR p-values
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first
	qui weakiv, null(0) small
	local CLR1 = round(e(clr_p), 0.001)
* CLR p-values clustered by family
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first vce(cluster nfam)
	local Nbobs = `e(N)'	// just so that N appears after CLR p-values in table
	qui weakiv, null(0) small
	local CLR2 = round(e(clr_p), 0.001)
* Second-stage coefficients
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first
	outreg2 using "${dirresu}\Table7_A", keep($polit) stats(coef) nocons label noobs dec(2) noas ///
	ctitle("tax rate") addtext(CLR-pval, `CLR1', CLR-pval 2, `CLR2', Nb observations, `Nbobs') tex
* First stage coefs in Panel B
qui reg $polit syntheticT biorder $hechter $controlsb $polbefore
	local F1 = round(e(F),0.01)
qui ivreg2 rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first savefirst
	est restore _ivreg2_d_MPb_aft
	outreg2 using "${dirresu}\Table7_B", keep(syntheticT) tex ctitle("MP (b)") label dec(3) noaster nocons nor2 stats(coef pval) addtext(F-stat, `F1', cluster, .)
qui ivreg2 rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first cluster(nfam) savefirst
	est restore _ivreg2_d_MPb_aft
	outreg2 using "${dirresu}\Table7_B", keep(syntheticT) tex ctitle("MP (b)") label dec(3) noaster nocons nor2 stats(coef pval) bracket addtext(F-stat, `F1', cluster, family)

	
* Col [3]: Years brother is MP after marriage

global polit MPb_years_aft
global polbefore MPf_years_bef
* CLR p-values
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first
	qui weakiv, null(0) small
	local CLR1 = round(e(clr_p), 0.001)
* CLR p-values clustered by family
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first vce(cluster nfam)
	local Nbobs = `e(N)'	// just so that N appears after CLR p-values in table
	qui weakiv, null(0) small
	local CLR2 = round(e(clr_p), 0.001)
* Second-stage coefficients
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first
	outreg2 using "${dirresu}\Table7_A", keep($polit) stats(coef) nocons label noobs dec(2) noas ///
	ctitle("tax rate") addtext(CLR-pval, `CLR1', CLR-pval 2, `CLR2', Nb observations, `Nbobs') tex
* First stage coefs in Panel B
qui reg $polit syntheticT biorder $hechter $controlsb $polbefore
	local F1 = round(e(F),0.01)
qui ivreg2 rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first savefirst
	est restore _ivreg2_MPb_years_aft
	outreg2 using "${dirresu}\Table7_B", keep(syntheticT) tex ctitle("Years MP (b)") label dec(3) noaster nocons nor2 stats(coef pval) addtext(F-stat, `F1', cluster, .)
qui ivreg2 rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first cluster(nfam) savefirst
	est restore _ivreg2_MPb_years_aft
	outreg2 using "${dirresu}\Table7_B", keep(syntheticT) tex ctitle("Years MP (b)") label dec(3) noaster nocons nor2 stats(coef pval) bracket addtext(F-stat, `F1', cluster, family)


* Col [4]: Any brother is local MP after marriage

global polit d_MPb_locaft
global polbefore d_MPf_local
* CLR p-values
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first
	qui weakiv, null(0) small
	local CLR1 = round(e(clr_p), 0.001)
* CLR p-values clustered by family
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first vce(cluster nfam)
	local Nbobs = `e(N)'	// just so that N appears after CLR p-values in table
	qui weakiv, null(0) small
	local CLR2 = round(e(clr_p), 0.001)
* Second-stage coefficients
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first
	outreg2 using "${dirresu}\Table7_A", keep($polit) stats(coef) nocons label noobs dec(2) noas ///
	ctitle("tax rate") addtext(CLR-pval, `CLR1', CLR-pval 2, `CLR2', Nb observations, `Nbobs') tex
* First stage coefs in Panel B
qui reg $polit syntheticT biorder $hechter $controlsb $polbefore
	local F1 = round(e(F),0.01)
qui ivreg2 rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first savefirst
	est restore _ivreg2_d_MPb_locaft
	outreg2 using "${dirresu}\Table7_B", keep(syntheticT) tex ctitle("local MP (b)") label dec(3) noaster nocons nor2 stats(coef pval) addtext(F-stat, `F1', cluster, .)
qui ivreg2 rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first cluster(nfam) savefirst
	est restore _ivreg2_d_MPb_locaft
	outreg2 using "${dirresu}\Table7_B", keep(syntheticT) tex ctitle("local MP (b)") label dec(3) noaster nocons nor2 stats(coef pval) bracket addtext(F-stat, `F1', cluster, family)


* Col [5]: Years brother is local MP after marriage

global polit MPb_years_locaft
global polbefore MPf_years_locbef
* CLR p-values
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first
	qui weakiv, null(0) small
	local CLR1 = round(e(clr_p), 0.001)
* CLR p-values clustered by family
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first vce(cluster nfam)
	local Nbobs = `e(N)'	// just so that N appears after CLR p-values in table
	qui weakiv, null(0) small
	local CLR2 = round(e(clr_p), 0.001)
* Second-stage coefficients
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first
	outreg2 using "${dirresu}\Table7_A", keep($polit) stats(coef) nocons label noobs dec(2) noas ///
	ctitle("tax rate") addtext(CLR-pval, `CLR1', CLR-pval 2, `CLR2', Nb observations, `Nbobs') tex
* First stage coefs in Panel B
qui reg $polit syntheticT biorder $hechter $controlsb $polbefore
	local F1 = round(e(F),0.01)
qui ivreg2 rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first savefirst
	est restore _ivreg2_MPb_years_locaft
	outreg2 using "${dirresu}\Table7_B", keep(syntheticT) tex ctitle("local years (b)") label dec(3) noaster nocons nor2 stats(coef pval) addtext(F-stat, `F1', cluster, .)
qui ivreg2 rateperpou ($polit = syntheticT biorder) $hechter $controlsb $polbefore , first cluster(nfam) savefirst
	est restore _ivreg2_MPb_years_locaft
	outreg2 using "${dirresu}\Table7_B", keep(syntheticT) tex ctitle("local years (b)") label dec(3) noaster nocons nor2 stats(coef pval) bracket addtext(F-stat, `F1', cluster, family)


* Col [6]: Family head is local MP after marriage

global polit d_MPh_aft
global polbefore d_MPh_bef
* CLR p-values
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsh $polbefore , first
	qui weakiv, null(0) small
	local CLR1 = round(e(clr_p), 0.001)
* CLR p-values clustered by family
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsh $polbefore , first vce(cluster nfam)
	local Nbobs = `e(N)'	// just so that N appears after CLR p-values in table
	qui weakiv, null(0) small
	local CLR2 = round(e(clr_p), 0.001)
* Second-stage coefficients
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsh $polbefore , first
	outreg2 using "${dirresu}\Table7_A", keep($polit) stats(coef) nocons label noobs dec(2) noas ///
	ctitle("tax rate") addtext(CLR-pval, `CLR1', CLR-pval 2, `CLR2', Nb observations, `Nbobs') tex
* First stage coefs in Panel B
qui reg $polit syntheticT biorder $hechter $controlsh $polbefore
	local F1 = round(e(F),0.01)
qui ivreg2 rateperpou ($polit = syntheticT biorder) $hechter $controlsh $polbefore , first savefirst
	est restore _ivreg2_d_MPh_aft
	outreg2 using "${dirresu}\Table7_B", keep(syntheticT) tex ctitle("MP (h)") label dec(3) noaster nocons nor2 stats(coef pval) addtext(F-stat, `F1', cluster, .)
qui ivreg2 rateperpou ($polit = syntheticT biorder) $hechter $controlsh $polbefore , first cluster(nfam) savefirst
	est restore _ivreg2_d_MPh_aft
	outreg2 using "${dirresu}\Table7_B", keep(syntheticT) tex ctitle("MP (h)") label dec(3) noaster nocons nor2 stats(coef pval) bracket addtext(F-stat, `F1', cluster, family)


* Col [7]: Years family head is local MP after marriage

global polit MPh_years_aft
global polbefore MPh_years_bef
* CLR p-values
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsh $polbefore , first
	qui weakiv, null(0) small
	local CLR1 = round(e(clr_p), 0.001)
* CLR p-values clustered by family
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsh $polbefore , first vce(cluster nfam)
	local Nbobs = `e(N)'	// just so that N appears after CLR p-values in table
	qui weakiv, null(0) small
	local CLR2 = round(e(clr_p), 0.001)
* Second-stage coefficients
qui ivregress liml rateperpou ($polit = syntheticT biorder) $hechter $controlsh $polbefore , first
	outreg2 using "${dirresu}\Table7_A", keep($polit) stats(coef) nocons label noobs dec(2) noas ///
	ctitle("tax rate") addtext(CLR-pval, `CLR1', CLR-pval 2, `CLR2', Nb observations, `Nbobs') tex
* First stage coefs in Panel B
qui reg $polit syntheticT biorder $hechter $controlsh $polbefore
	local F1 = round(e(F),0.01)
qui ivreg2 rateperpou ($polit = syntheticT biorder) $hechter $controlsh $polbefore , first savefirst
	est restore _ivreg2_MPh_years_aft
	outreg2 using "${dirresu}\Table7_B", keep(syntheticT) tex ctitle("Years MP (h)") label dec(3) noaster nocons nor2 stats(coef pval) addtext(F-stat, `F1', cluster, .)
qui ivreg2 rateperpou ($polit = syntheticT biorder) $hechter $controlsh $polbefore , first cluster(nfam) savefirst
	est restore _ivreg2_MPh_years_aft
	outreg2 using "${dirresu}\Table7_B", keep(syntheticT) tex ctitle("Years MP (h)") label dec(3) noaster nocons nor2 stats(coef pval) bracket addtext(F-stat, `F1', cluster, family)