-
Notifications
You must be signed in to change notification settings - Fork 2
/
cs_pdslasso.do
2664 lines (2486 loc) · 94.5 KB
/
cs_pdslasso.do
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
* cert script for pdslasso/ivlasso/rlasso/CHS 1.0.06 MS 14oct2019
* uses 4 external datasets:
* 1. Levitt dataset from Belloni et al. J. of Econ. Persp. 28:2.
* Ascii file levitt_ex.dat available online from journal publisher.
* Replicates using pdslasso and rlasso.
* 2. BLP dataset from Belloni et al. Econometrica 2012, 80:6.
* Original data available online from journal publisher. Also used in
* Chernozhukov et al., American Economic Review 2015, 105:5.
* Assembled into Stata dataset separately and used here as BLP.dta.
* Replicates using ivlasso and rlasso.
* 3. AJR dataset from Acemoglu et al. American Economic Review 2001, 91:5.
* Original data available from economics.mit.edu; see ivlasso help file.
* 4. Stata online panel dataset abdata.
* Replicated results are inserted in this do file.
* #1 replicates results using original Stata code (modified slightly here).
* #2 replicates results from original Matlab code.
* #3 and #4 used for checking options etc.
cscript "rlasso/pdslasso/pdslasso" adofile rlasso pdslasso ivlasso lassoutils
clear all
capture log close
set more off
set rmsg on
program drop _all
log using cs_pdslasso,replace
about
which pdslasso
which ivlasso
which rlasso
which lassoutils
// ***************** LEVITT DATASET ************************* //
// Based on BCH JEP replication do file.
// Differences:
// changed locals to globals (easier to check contents)
// fixed typo in constructing initial differences
// all generated vars are doubles
// instead of dropping if trend==0, added "if trend>0" to original commands
// use tweaked lassoShootingCBH instead of original lassoShooting
// as of lassoutils 1.1.01 08nov2018 need c0(0.55) option to replicate cbh
// because of different varnames (FVs vs created by hand), coef vectors
// are sorted before comparing
insheet using ..\Current\Data\levitt_ex.dat, clear
* Drop DC, Alaska, and Hawaii
*drop if statenum == 9 | statenum == 2 | statenum == 12
* Drop DC
drop if statenum == 9
* Drop years not used
drop if year < 85 | year > 97
* Normalized trend variable
qui gen double trend = (year - 85)/12
// added
qui gen double trendsq=trend^2
tsset statenum year
xi i.year
* Generate variables for LASSO
replace xxincome = xxincome/100
replace xxpover = xxpover/100
replace xxafdc15 = xxafdc15/10000
replace xxbeer = xxbeer/100
global tdums _Iyear_87 _Iyear_88 _Iyear_89 _Iyear_90 _Iyear_91 _Iyear_92 _Iyear_93 _Iyear_94 _Iyear_95 _Iyear_96 _Iyear_97
global xx xxprison xxpolice xxunemp xxincome xxpover xxafdc15 xxgunlaw xxbeer
// Time dummies
sum $tdums
sum i.year
* Differences
global Dxx
foreach x of global xx {
qui gen double D`x' = D.`x'
local tempname = "D`x'"
global Dxx : list global(Dxx) | tempname
}
sum $Dxx
sum D.($xx)
* Squared Differences
global Dxx2
foreach x of global Dxx {
qui gen double `x'2 = `x'^2
local tempname = "`x'2"
global Dxx2 : list global(Dxx2) | tempname
}
* Difference Interactions
global DxxInt
local nxx : word count $Dxx
forvalues ii = 1/`nxx' {
local start = `ii'+1
forvalues jj = `start'/`nxx' {
local temp1 : word `ii' of $Dxx
local temp2 : word `jj' of $Dxx
qui gen double `temp1'X`temp2' = `temp1'*`temp2'
local tempname = "`temp1'X`temp2'"
global DxxInt : list global(DxxInt) | tempname
}
}
* Lags
global Lxx
foreach x of global xx {
qui gen double L`x' = L.`x'
local tempname = "L`x'"
global Lxx : list global(Lxx) | tempname
}
* Squared Lags
global Lxx2
foreach x of global Lxx {
qui gen double `x'2 = `x'^2
local tempname = "`x'2"
global Lxx2 : list global(Lxx2) | tempname
}
* Means
global Mxx
foreach x of global xx {
qui by statenum: egen double M`x' = mean(`x')
local tempname = "M`x'"
global Mxx : list global(Mxx) | tempname
}
* Squared Means
global Mxx2
foreach x of global Mxx {
qui gen double `x'2 = `x'^2
local tempname = "`x'2"
global Mxx2 : list global(Mxx2) | tempname
}
* Initial Levels
local xx0
foreach x of global xx {
qui by statenum: gen double `x'0 = `x'[1]
local tempname = "`x'0"
global xx0 : list global(xx0) | tempname
}
* Squared Initial Levels
global xx02
foreach x of global xx0 {
qui gen double `x'2 = `x'^2
local tempname = "`x'2"
global xx02 : list global(xx02) | tempname
}
* Initial Differences
global Dxx0
foreach x of global Dxx {
qui by statenum: gen double `x'0 = `x'[2]
local tempname = "`x'0"
// typo in original code?
// local xx0 : list local xx0 | tempname
global Dxx0 : list global(Dxx0) | tempname
}
* Squared Initial Differences
global Dxx02
foreach x of global Dxx0 {
qui gen double `x'2 = `x'^2
local tempname = "`x'2"
global Dxx02 : list global(Dxx02) | tempname
}
* Interactions with trends
global biglist : list global(Dxx) | global(Dxx2)
global biglist : list global(biglist) | global(DxxInt)
global biglist : list global(biglist) | global(Lxx)
global biglist : list global(biglist) | global(Lxx2)
global biglist : list global(biglist) | global(Mxx)
global biglist : list global(biglist) | global(Mxx2)
global biglist : list global(biglist) | global(xx0)
global biglist : list global(biglist) | global(xx02)
global biglist : list global(biglist) | global(Dxx0)
global biglist : list global(biglist) | global(Dxx02)
global IntT
local nxx : word count $biglist
foreach x of global biglist {
qui gen double `x'Xt = `x'*trend
qui gen double `x'Xt2 = `x'*(trend^2)
local tempname = "`x'Xt `x'Xt2"
global IntT : list global(IntT) | tempname
}
global shared : list global(biglist) | global(IntT)
* Violence specific controls
qui gen double Dviol = D.efaviol
qui by statenum: gen double viol0 = efaviol[1]
qui by statenum: gen double Dviol0 = Dviol[2]
qui gen double viol02 = viol0^2
qui gen double Dviol02 = Dviol0^2
qui gen double viol0Xt = viol0*trend
qui gen double viol0Xt2 = viol0*(trend^2)
qui gen double viol02Xt = viol02*trend
qui gen double viol02Xt2 = viol02*(trend^2)
qui gen double Dviol0Xt = Dviol0*trend
qui gen double Dviol0Xt2 = Dviol0*(trend^2)
qui gen double Dviol02Xt = Dviol02*trend
qui gen double Dviol02Xt2 = Dviol02*(trend^2)
global contviol viol0 viol0Xt viol0Xt2 viol02 viol02Xt viol02Xt2 Dviol0 Dviol0Xt Dviol0Xt2 Dviol02 Dviol02Xt Dviol02Xt2
global AllViol : list global(contviol) | global(shared)
* Property specifc controls
qui gen double Dprop = D.efaprop
qui by statenum: gen double prop0 = efaprop[1]
qui by statenum: gen double Dprop0 = Dprop[2]
qui gen double prop02 = prop0^2
qui gen double Dprop02 = Dprop0^2
qui gen double prop0Xt = prop0*trend
qui gen double prop0Xt2 = prop0*(trend^2)
qui gen double prop02Xt = prop02*trend
qui gen double prop02Xt2 = prop02*(trend^2)
qui gen double Dprop0Xt = Dprop0*trend
qui gen double Dprop0Xt2 = Dprop0*(trend^2)
qui gen double Dprop02Xt = Dprop02*trend
qui gen double Dprop02Xt2 = Dprop02*(trend^2)
global contprop prop0 prop0Xt prop0Xt2 prop02 prop02Xt prop02Xt2 Dprop0 Dprop0Xt Dprop0Xt2 Dprop02 Dprop02Xt Dprop02Xt2
global AllProp : list global(contprop) | global(shared)
* Murder specific controls
qui gen double Dmurd = D.efamurd
qui by statenum: gen double murd0 = efamurd[1]
qui by statenum: gen double Dmurd0 = Dmurd[2]
qui gen double murd02 = murd0^2
qui gen double Dmurd02 = Dmurd0^2
qui gen double murd0Xt = murd0*trend
qui gen double murd0Xt2 = murd0*(trend^2)
qui gen double murd02Xt = murd02*trend
qui gen double murd02Xt2 = murd02*(trend^2)
qui gen double Dmurd0Xt = Dmurd0*trend
qui gen double Dmurd0Xt2 = Dmurd0*(trend^2)
qui gen double Dmurd02Xt = Dmurd02*trend
qui gen double Dmurd02Xt2 = Dmurd02*(trend^2)
global contmurd murd0 murd0Xt murd0Xt2 murd02 murd02Xt murd02Xt2 Dmurd0 Dmurd0Xt Dmurd0Xt2 Dmurd02 Dmurd02Xt Dmurd02Xt2
global AllMurd : list global(contmurd) | global(shared)
* Differenced outcomes
qui gen double Dyviol = D.lpc_viol
qui gen double Dyprop = D.lpc_prop
qui gen double Dymurd = D.lpc_murd
// replaced with "if trend>0" below
// drop if trend == 0
*********************** Violence ************************************
* Variable selection
* Violence Outcome
rlasso D.lpc_viol ///
/// no trend
c.viol0##c.viol0 ///
c.Dviol0##c.Dviol0 ///
c.(D.($xx))##c.(D.($xx)) /// note macro
c.(L.xxprison)##c.(L.xxprison) ///
c.(L.xxpolice)##c.(L.xxpolice) ///
c.(L.xxunemp)##c.(L.xxunemp) ///
c.(L.xxincome)##c.(L.xxincome) ///
c.(L.xxpover)##c.(L.xxpover) ///
c.(L.xxafdc15)##c.(L.xxafdc15) ///
c.(L.xxgunlaw)##c.(L.xxgunlaw) ///
c.(L.xxbeer)##c.(L.xxbeer) ///
c.Mxxprison##c.Mxxprison ///
c.Mxxpolice##c.Mxxpolice ///
c.Mxxunemp##c.Mxxunemp ///
c.Mxxincome##c.Mxxincome ///
c.Mxxpover##c.Mxxpover ///
c.Mxxafdc15##c.Mxxafdc15 ///
c.Mxxgunlaw##c.Mxxgunlaw ///
c.Mxxbeer##c.Mxxbeer ///
c.xxprison0##c.xxprison0 ///
c.xxpolice0##c.xxpolice0 ///
c.xxunemp0##c.xxunemp0 ///
c.xxincome0##c.xxincome0 ///
c.xxpover0##c.xxpover0 ///
c.xxafdc150##c.xxafdc150 ///
c.xxgunlaw0##c.xxgunlaw0 ///
c.xxbeer0##c.xxbeer0 ///
c.Dxxprison0##c.Dxxprison0 ///
c.Dxxpolice0##c.Dxxpolice0 ///
c.Dxxunemp0##c.Dxxunemp0 ///
c.Dxxincome0##c.Dxxincome0 ///
c.Dxxpover0##c.Dxxpover0 ///
c.Dxxafdc150##c.Dxxafdc150 ///
c.Dxxgunlaw0##c.Dxxgunlaw0 ///
c.Dxxbeer0##c.Dxxbeer0 ///
///
(c.viol0##c.viol0)#(c.trend##c.trend) /// now interacted with trend
(c.Dviol0##c.Dviol0)#(c.trend##c.trend) ///
(c.(D.($xx))##c.(D.($xx)))#(c.trend##c.trend) /// note macro
(c.(L.xxprison)##c.(L.xxprison))#(c.trend##c.trend) ///
(c.(L.xxpolice)##c.(L.xxpolice))#(c.trend##c.trend) ///
(c.(L.xxunemp)##c.(L.xxunemp))#(c.trend##c.trend) ///
(c.(L.xxincome)##c.(L.xxincome))#(c.trend##c.trend) ///
(c.(L.xxpover)##c.(L.xxpover))#(c.trend##c.trend) ///
(c.(L.xxafdc15)##c.(L.xxafdc15))#(c.trend##c.trend) ///
(c.(L.xxgunlaw)##c.(L.xxgunlaw))#(c.trend##c.trend) ///
(c.(L.xxbeer)##c.(L.xxbeer))#(c.trend##c.trend) ///
(c.Mxxprison##c.Mxxprison)#(c.trend##c.trend) ///
(c.Mxxpolice##c.Mxxpolice)#(c.trend##c.trend) ///
(c.Mxxunemp##c.Mxxunemp )#(c.trend##c.trend) ///
(c.Mxxincome##c.Mxxincome)#(c.trend##c.trend) ///
(c.Mxxpover##c.Mxxpover )#(c.trend##c.trend) ///
(c.Mxxafdc15##c.Mxxafdc15)#(c.trend##c.trend) ///
(c.Mxxgunlaw##c.Mxxgunlaw)#(c.trend##c.trend) ///
(c.Mxxbeer##c.Mxxbeer)#(c.trend##c.trend) ///
(c.xxprison0##c.xxprison0)#(c.trend##c.trend) ///
(c.xxpolice0##c.xxpolice0)#(c.trend##c.trend) ///
(c.xxunemp0##c.xxunemp0)#(c.trend##c.trend) ///
(c.xxincome0##c.xxincome0)#(c.trend##c.trend) ///
(c.xxpover0##c.xxpover0)#(c.trend##c.trend) ///
(c.xxafdc150##c.xxafdc150)#(c.trend##c.trend) ///
(c.xxgunlaw0##c.xxgunlaw0)#(c.trend##c.trend) ///
(c.xxbeer0##c.xxbeer0)#(c.trend##c.trend) ///
(c.Dxxprison0##c.Dxxprison0)#(c.trend##c.trend) ///
(c.Dxxpolice0##c.Dxxpolice0)#(c.trend##c.trend) ///
(c.Dxxunemp0##c.Dxxunemp0)#(c.trend##c.trend) ///
(c.Dxxincome0##c.Dxxincome0)#(c.trend##c.trend) ///
(c.Dxxpover0##c.Dxxpover0)#(c.trend##c.trend) ///
(c.Dxxafdc150##c.Dxxafdc150)#(c.trend##c.trend) ///
(c.Dxxgunlaw0##c.Dxxgunlaw0)#(c.trend##c.trend) ///
(c.Dxxbeer0##c.Dxxbeer0 )#(c.trend##c.trend) ///
i.year, partial(i.year) robust lalt corrnum(0) ///
maxpsiiter(100) c0(0.55)
di "p=" e(p)
global yvSelrlasso `e(selected)'
di "$yvSelrlasso"
mat b_rlasso=e(b)
if `e(s)' {
mat b_rlasso=b_rlasso[1,1..`e(s)']
}
else {
mat b_rlasso=.
}
/*
* Violence Outcome
lassoShootingCBH Dyviol $AllViol if trend>0, controls($tdums) lasiter(100) verbose(0) fdisplay(1)
// no vars selected
di "p=" r(p)
global yvSel `r(selected)'
di "$yvSel"
mat b_cbh=r(betaL)
mat b_cbh=b_cbh'
*/
global yvSel
mat b_cbh=.
// sort cols and compare
mata: st_matrix("b_rlasso",sort(st_matrix("b_rlasso")',1)')
mata: st_matrix("b_cbh",sort(st_matrix("b_cbh")',1)')
assert mreldif(b_rlasso,b_cbh)<1e-4
* Violence Abortion
rlasso D.efaviol ///
/// no trend
c.viol0##c.viol0 ///
c.Dviol0##c.Dviol0 ///
c.(D.($xx))##c.(D.($xx)) /// note macro
c.(L.xxprison)##c.(L.xxprison) ///
c.(L.xxpolice)##c.(L.xxpolice) ///
c.(L.xxunemp)##c.(L.xxunemp) ///
c.(L.xxincome)##c.(L.xxincome) ///
c.(L.xxpover)##c.(L.xxpover) ///
c.(L.xxafdc15)##c.(L.xxafdc15) ///
c.(L.xxgunlaw)##c.(L.xxgunlaw) ///
c.(L.xxbeer)##c.(L.xxbeer) ///
c.Mxxprison##c.Mxxprison ///
c.Mxxpolice##c.Mxxpolice ///
c.Mxxunemp##c.Mxxunemp ///
c.Mxxincome##c.Mxxincome ///
c.Mxxpover##c.Mxxpover ///
c.Mxxafdc15##c.Mxxafdc15 ///
c.Mxxgunlaw##c.Mxxgunlaw ///
c.Mxxbeer##c.Mxxbeer ///
c.xxprison0##c.xxprison0 ///
c.xxpolice0##c.xxpolice0 ///
c.xxunemp0##c.xxunemp0 ///
c.xxincome0##c.xxincome0 ///
c.xxpover0##c.xxpover0 ///
c.xxafdc150##c.xxafdc150 ///
c.xxgunlaw0##c.xxgunlaw0 ///
c.xxbeer0##c.xxbeer0 ///
c.Dxxprison0##c.Dxxprison0 ///
c.Dxxpolice0##c.Dxxpolice0 ///
c.Dxxunemp0##c.Dxxunemp0 ///
c.Dxxincome0##c.Dxxincome0 ///
c.Dxxpover0##c.Dxxpover0 ///
c.Dxxafdc150##c.Dxxafdc150 ///
c.Dxxgunlaw0##c.Dxxgunlaw0 ///
c.Dxxbeer0##c.Dxxbeer0 ///
///
(c.viol0##c.viol0)#(c.trend##c.trend) /// now interacted with trend
(c.Dviol0##c.Dviol0)#(c.trend##c.trend) ///
(c.(D.($xx))##c.(D.($xx)))#(c.trend##c.trend) /// note macro
(c.(L.xxprison)##c.(L.xxprison))#(c.trend##c.trend) ///
(c.(L.xxpolice)##c.(L.xxpolice))#(c.trend##c.trend) ///
(c.(L.xxunemp)##c.(L.xxunemp))#(c.trend##c.trend) ///
(c.(L.xxincome)##c.(L.xxincome))#(c.trend##c.trend) ///
(c.(L.xxpover)##c.(L.xxpover))#(c.trend##c.trend) ///
(c.(L.xxafdc15)##c.(L.xxafdc15))#(c.trend##c.trend) ///
(c.(L.xxgunlaw)##c.(L.xxgunlaw))#(c.trend##c.trend) ///
(c.(L.xxbeer)##c.(L.xxbeer))#(c.trend##c.trend) ///
(c.Mxxprison##c.Mxxprison)#(c.trend##c.trend) ///
(c.Mxxpolice##c.Mxxpolice)#(c.trend##c.trend) ///
(c.Mxxunemp##c.Mxxunemp )#(c.trend##c.trend) ///
(c.Mxxincome##c.Mxxincome)#(c.trend##c.trend) ///
(c.Mxxpover##c.Mxxpover )#(c.trend##c.trend) ///
(c.Mxxafdc15##c.Mxxafdc15)#(c.trend##c.trend) ///
(c.Mxxgunlaw##c.Mxxgunlaw)#(c.trend##c.trend) ///
(c.Mxxbeer##c.Mxxbeer)#(c.trend##c.trend) ///
(c.xxprison0##c.xxprison0)#(c.trend##c.trend) ///
(c.xxpolice0##c.xxpolice0)#(c.trend##c.trend) ///
(c.xxunemp0##c.xxunemp0)#(c.trend##c.trend) ///
(c.xxincome0##c.xxincome0)#(c.trend##c.trend) ///
(c.xxpover0##c.xxpover0)#(c.trend##c.trend) ///
(c.xxafdc150##c.xxafdc150)#(c.trend##c.trend) ///
(c.xxgunlaw0##c.xxgunlaw0)#(c.trend##c.trend) ///
(c.xxbeer0##c.xxbeer0)#(c.trend##c.trend) ///
(c.Dxxprison0##c.Dxxprison0)#(c.trend##c.trend) ///
(c.Dxxpolice0##c.Dxxpolice0)#(c.trend##c.trend) ///
(c.Dxxunemp0##c.Dxxunemp0)#(c.trend##c.trend) ///
(c.Dxxincome0##c.Dxxincome0)#(c.trend##c.trend) ///
(c.Dxxpover0##c.Dxxpover0)#(c.trend##c.trend) ///
(c.Dxxafdc150##c.Dxxafdc150)#(c.trend##c.trend) ///
(c.Dxxgunlaw0##c.Dxxgunlaw0)#(c.trend##c.trend) ///
(c.Dxxbeer0##c.Dxxbeer0 )#(c.trend##c.trend) ///
i.year, partial(i.year) robust lalt corrnum(0) ///
maxpsiiter(100) c0(0.55)
di "p=" e(p)
global xvSelrlasso `e(selected)'
di "$xvSelrlasso"
mat b_rlasso=e(b)
if `e(s)' {
mat b_rlasso=b_rlasso[1,1..`e(s)']
}
else {
mat b_rlasso=.
}
/*
* Violence Abortion
lassoShootingCBH Dviol $AllViol if trend>0, controls($tdums) lasiter(100) verbose(0) fdisplay(1)
di "p=" r(p)
global xvSel `r(selected)'
di "$xvSel"
mat b_cbh=r(betaL)
mat b_cbh=b_cbh'
*/
global xvSel viol0 Lxxprison Lxxpolice Mxxincome Dxxincome0 LxxpoliceXt MxxincomeXt Dxxincome0Xt Dxxbeer0Xt
mat b_cbh = .65842111 , .00346113 , .01813694 , 3.5867181 , 5.6965391 , .00434867 , 23.924844 , 30.420403 , .5716038
// sort cols and compare
mata: st_matrix("b_rlasso",sort(st_matrix("b_rlasso")',1)')
mata: st_matrix("b_cbh",sort(st_matrix("b_cbh")',1)')
assert mreldif(b_rlasso,b_cbh)<1e-4
* Violence equation with selected controls
pdslasso D.lpc_viol D.efaviol ///
( /// no trend
c.viol0##c.viol0 ///
c.Dviol0##c.Dviol0 ///
c.(D.($xx))##c.(D.($xx)) /// note macro
c.(L.xxprison)##c.(L.xxprison) ///
c.(L.xxpolice)##c.(L.xxpolice) ///
c.(L.xxunemp)##c.(L.xxunemp) ///
c.(L.xxincome)##c.(L.xxincome) ///
c.(L.xxpover)##c.(L.xxpover) ///
c.(L.xxafdc15)##c.(L.xxafdc15) ///
c.(L.xxgunlaw)##c.(L.xxgunlaw) ///
c.(L.xxbeer)##c.(L.xxbeer) ///
c.Mxxprison##c.Mxxprison ///
c.Mxxpolice##c.Mxxpolice ///
c.Mxxunemp##c.Mxxunemp ///
c.Mxxincome##c.Mxxincome ///
c.Mxxpover##c.Mxxpover ///
c.Mxxafdc15##c.Mxxafdc15 ///
c.Mxxgunlaw##c.Mxxgunlaw ///
c.Mxxbeer##c.Mxxbeer ///
c.xxprison0##c.xxprison0 ///
c.xxpolice0##c.xxpolice0 ///
c.xxunemp0##c.xxunemp0 ///
c.xxincome0##c.xxincome0 ///
c.xxpover0##c.xxpover0 ///
c.xxafdc150##c.xxafdc150 ///
c.xxgunlaw0##c.xxgunlaw0 ///
c.xxbeer0##c.xxbeer0 ///
c.Dxxprison0##c.Dxxprison0 ///
c.Dxxpolice0##c.Dxxpolice0 ///
c.Dxxunemp0##c.Dxxunemp0 ///
c.Dxxincome0##c.Dxxincome0 ///
c.Dxxpover0##c.Dxxpover0 ///
c.Dxxafdc150##c.Dxxafdc150 ///
c.Dxxgunlaw0##c.Dxxgunlaw0 ///
c.Dxxbeer0##c.Dxxbeer0 ///
///
(c.viol0##c.viol0)#(c.trend##c.trend) /// now interacted with trend
(c.Dviol0##c.Dviol0)#(c.trend##c.trend) ///
(c.(D.($xx))##c.(D.($xx)))#(c.trend##c.trend) /// note macro
(c.(L.xxprison)##c.(L.xxprison))#(c.trend##c.trend) ///
(c.(L.xxpolice)##c.(L.xxpolice))#(c.trend##c.trend) ///
(c.(L.xxunemp)##c.(L.xxunemp))#(c.trend##c.trend) ///
(c.(L.xxincome)##c.(L.xxincome))#(c.trend##c.trend) ///
(c.(L.xxpover)##c.(L.xxpover))#(c.trend##c.trend) ///
(c.(L.xxafdc15)##c.(L.xxafdc15))#(c.trend##c.trend) ///
(c.(L.xxgunlaw)##c.(L.xxgunlaw))#(c.trend##c.trend) ///
(c.(L.xxbeer)##c.(L.xxbeer))#(c.trend##c.trend) ///
(c.Mxxprison##c.Mxxprison)#(c.trend##c.trend) ///
(c.Mxxpolice##c.Mxxpolice)#(c.trend##c.trend) ///
(c.Mxxunemp##c.Mxxunemp )#(c.trend##c.trend) ///
(c.Mxxincome##c.Mxxincome)#(c.trend##c.trend) ///
(c.Mxxpover##c.Mxxpover )#(c.trend##c.trend) ///
(c.Mxxafdc15##c.Mxxafdc15)#(c.trend##c.trend) ///
(c.Mxxgunlaw##c.Mxxgunlaw)#(c.trend##c.trend) ///
(c.Mxxbeer##c.Mxxbeer)#(c.trend##c.trend) ///
(c.xxprison0##c.xxprison0)#(c.trend##c.trend) ///
(c.xxpolice0##c.xxpolice0)#(c.trend##c.trend) ///
(c.xxunemp0##c.xxunemp0)#(c.trend##c.trend) ///
(c.xxincome0##c.xxincome0)#(c.trend##c.trend) ///
(c.xxpover0##c.xxpover0)#(c.trend##c.trend) ///
(c.xxafdc150##c.xxafdc150)#(c.trend##c.trend) ///
(c.xxgunlaw0##c.xxgunlaw0)#(c.trend##c.trend) ///
(c.xxbeer0##c.xxbeer0)#(c.trend##c.trend) ///
(c.Dxxprison0##c.Dxxprison0)#(c.trend##c.trend) ///
(c.Dxxpolice0##c.Dxxpolice0)#(c.trend##c.trend) ///
(c.Dxxunemp0##c.Dxxunemp0)#(c.trend##c.trend) ///
(c.Dxxincome0##c.Dxxincome0)#(c.trend##c.trend) ///
(c.Dxxpover0##c.Dxxpover0)#(c.trend##c.trend) ///
(c.Dxxafdc150##c.Dxxafdc150)#(c.trend##c.trend) ///
(c.Dxxgunlaw0##c.Dxxgunlaw0)#(c.trend##c.trend) ///
(c.Dxxbeer0##c.Dxxbeer0 )#(c.trend##c.trend) ///
i.year ///
) ///
, partial(i.year) robust ///
lopt(lalt corrnum(0) maxpsiiter(100) c0(0.55))
mat b_pdslasso=e(b)
* Get union of selected instruments
global vDS : list global(yvSel) | global(xvSel)
* Violence equation with selected controls
// Original - clustered SEs (but not cluster lasso)
// reg Dyviol Dviol $vDS $tdums if trend>0, cluster(statenum)
// robust, no cluster
reg Dyviol Dviol $vDS $tdums if trend>0, robust
mat b_regress=e(b)
// sort cols and compare
// may be diff lengths and include 0s (for dropped base vars)
// so compare abs values > 0
mata: st_matrix("b_pdslasso",abs(sort(-abs(st_matrix("b_pdslasso"))',1))')
mata: st_matrix("b_regress",abs(sort(-abs(st_matrix("b_regress"))',1))')
local k1 = colsof(b_pdslasso)
local k2 = colsof(b_regress)
mat b_pdslasso = b_pdslasso[1,1..min(`k1',`k2')]
mat b_regress = b_regress[1,1..min(`k1',`k2')]
assert mreldif(b_pdslasso,b_regress)<1e-6
******************************** Property ******************************
* Property Outcome
// need low tol settings in order to match
rlasso D.lpc_prop ///
/// no trend
c.prop0##c.prop0 ///
c.Dprop0##c.Dprop0 ///
c.(D.($xx))##c.(D.($xx)) /// note macro
c.(L.xxprison)##c.(L.xxprison) ///
c.(L.xxpolice)##c.(L.xxpolice) ///
c.(L.xxunemp)##c.(L.xxunemp) ///
c.(L.xxincome)##c.(L.xxincome) ///
c.(L.xxpover)##c.(L.xxpover) ///
c.(L.xxafdc15)##c.(L.xxafdc15) ///
c.(L.xxgunlaw)##c.(L.xxgunlaw) ///
c.(L.xxbeer)##c.(L.xxbeer) ///
c.Mxxprison##c.Mxxprison ///
c.Mxxpolice##c.Mxxpolice ///
c.Mxxunemp##c.Mxxunemp ///
c.Mxxincome##c.Mxxincome ///
c.Mxxpover##c.Mxxpover ///
c.Mxxafdc15##c.Mxxafdc15 ///
c.Mxxgunlaw##c.Mxxgunlaw ///
c.Mxxbeer##c.Mxxbeer ///
c.xxprison0##c.xxprison0 ///
c.xxpolice0##c.xxpolice0 ///
c.xxunemp0##c.xxunemp0 ///
c.xxincome0##c.xxincome0 ///
c.xxpover0##c.xxpover0 ///
c.xxafdc150##c.xxafdc150 ///
c.xxgunlaw0##c.xxgunlaw0 ///
c.xxbeer0##c.xxbeer0 ///
c.Dxxprison0##c.Dxxprison0 ///
c.Dxxpolice0##c.Dxxpolice0 ///
c.Dxxunemp0##c.Dxxunemp0 ///
c.Dxxincome0##c.Dxxincome0 ///
c.Dxxpover0##c.Dxxpover0 ///
c.Dxxafdc150##c.Dxxafdc150 ///
c.Dxxgunlaw0##c.Dxxgunlaw0 ///
c.Dxxbeer0##c.Dxxbeer0 ///
///
(c.prop0##c.prop0)#(c.trend##c.trend) /// now interacted with trend
(c.Dprop0##c.Dprop0)#(c.trend##c.trend) ///
(c.(D.($xx))##c.(D.($xx)))#(c.trend##c.trend) /// note macro
(c.(L.xxprison)##c.(L.xxprison))#(c.trend##c.trend) ///
(c.(L.xxpolice)##c.(L.xxpolice))#(c.trend##c.trend) ///
(c.(L.xxunemp)##c.(L.xxunemp))#(c.trend##c.trend) ///
(c.(L.xxincome)##c.(L.xxincome))#(c.trend##c.trend) ///
(c.(L.xxpover)##c.(L.xxpover))#(c.trend##c.trend) ///
(c.(L.xxafdc15)##c.(L.xxafdc15))#(c.trend##c.trend) ///
(c.(L.xxgunlaw)##c.(L.xxgunlaw))#(c.trend##c.trend) ///
(c.(L.xxbeer)##c.(L.xxbeer))#(c.trend##c.trend) ///
(c.Mxxprison##c.Mxxprison)#(c.trend##c.trend) ///
(c.Mxxpolice##c.Mxxpolice)#(c.trend##c.trend) ///
(c.Mxxunemp##c.Mxxunemp )#(c.trend##c.trend) ///
(c.Mxxincome##c.Mxxincome)#(c.trend##c.trend) ///
(c.Mxxpover##c.Mxxpover )#(c.trend##c.trend) ///
(c.Mxxafdc15##c.Mxxafdc15)#(c.trend##c.trend) ///
(c.Mxxgunlaw##c.Mxxgunlaw)#(c.trend##c.trend) ///
(c.Mxxbeer##c.Mxxbeer)#(c.trend##c.trend) ///
(c.xxprison0##c.xxprison0)#(c.trend##c.trend) ///
(c.xxpolice0##c.xxpolice0)#(c.trend##c.trend) ///
(c.xxunemp0##c.xxunemp0)#(c.trend##c.trend) ///
(c.xxincome0##c.xxincome0)#(c.trend##c.trend) ///
(c.xxpover0##c.xxpover0)#(c.trend##c.trend) ///
(c.xxafdc150##c.xxafdc150)#(c.trend##c.trend) ///
(c.xxgunlaw0##c.xxgunlaw0)#(c.trend##c.trend) ///
(c.xxbeer0##c.xxbeer0)#(c.trend##c.trend) ///
(c.Dxxprison0##c.Dxxprison0)#(c.trend##c.trend) ///
(c.Dxxpolice0##c.Dxxpolice0)#(c.trend##c.trend) ///
(c.Dxxunemp0##c.Dxxunemp0)#(c.trend##c.trend) ///
(c.Dxxincome0##c.Dxxincome0)#(c.trend##c.trend) ///
(c.Dxxpover0##c.Dxxpover0)#(c.trend##c.trend) ///
(c.Dxxafdc150##c.Dxxafdc150)#(c.trend##c.trend) ///
(c.Dxxgunlaw0##c.Dxxgunlaw0)#(c.trend##c.trend) ///
(c.Dxxbeer0##c.Dxxbeer0 )#(c.trend##c.trend) ///
i.year, partial(i.year) robust lalt corrnum(0) ///
maxpsiiter(100) tolopt(1e-10) tolzero(1e-10) tolpsi(1e-10) ///
c0(0.55)
di "p=" e(p)
global ypSelrlasso `e(selected)'
di "$ypSelrlasso"
mat b_rlasso=e(b)
if `e(s)' {
mat b_rlasso=b_rlasso[1,1..`e(s)']
}
else {
mat b_rlasso=.
}
* Property Outcome
/*
lassoShootingCBH Dyprop $AllProp if trend>0, controls($tdums) lasiter(100) verbose(0) fdisplay(1) ltol(1e-10) tolpsi(1e-10) tolzero(1e-10)
di "p=" r(p)
global ypSel `r(selected)'
di "$ypSel"
mat b_cbh=r(betaL)
mat b_cbh=b_cbh'
*/
global ypSel Mxxincome2Xt2 xxincome02Xt2
mat b_cbh = -11.179967 , -.91841177
// sort cols and compare
mata: st_matrix("b_rlasso",sort(st_matrix("b_rlasso")',1)')
mata: st_matrix("b_cbh",sort(st_matrix("b_cbh")',1)')
assert mreldif(b_rlasso,b_cbh)<1e-4
* Property Abortion
rlasso D.efaprop ///
/// no trend
c.prop0##c.prop0 ///
c.Dprop0##c.Dprop0 ///
c.(D.($xx))##c.(D.($xx)) /// note macro
c.(L.xxprison)##c.(L.xxprison) ///
c.(L.xxpolice)##c.(L.xxpolice) ///
c.(L.xxunemp)##c.(L.xxunemp) ///
c.(L.xxincome)##c.(L.xxincome) ///
c.(L.xxpover)##c.(L.xxpover) ///
c.(L.xxafdc15)##c.(L.xxafdc15) ///
c.(L.xxgunlaw)##c.(L.xxgunlaw) ///
c.(L.xxbeer)##c.(L.xxbeer) ///
c.Mxxprison##c.Mxxprison ///
c.Mxxpolice##c.Mxxpolice ///
c.Mxxunemp##c.Mxxunemp ///
c.Mxxincome##c.Mxxincome ///
c.Mxxpover##c.Mxxpover ///
c.Mxxafdc15##c.Mxxafdc15 ///
c.Mxxgunlaw##c.Mxxgunlaw ///
c.Mxxbeer##c.Mxxbeer ///
c.xxprison0##c.xxprison0 ///
c.xxpolice0##c.xxpolice0 ///
c.xxunemp0##c.xxunemp0 ///
c.xxincome0##c.xxincome0 ///
c.xxpover0##c.xxpover0 ///
c.xxafdc150##c.xxafdc150 ///
c.xxgunlaw0##c.xxgunlaw0 ///
c.xxbeer0##c.xxbeer0 ///
c.Dxxprison0##c.Dxxprison0 ///
c.Dxxpolice0##c.Dxxpolice0 ///
c.Dxxunemp0##c.Dxxunemp0 ///
c.Dxxincome0##c.Dxxincome0 ///
c.Dxxpover0##c.Dxxpover0 ///
c.Dxxafdc150##c.Dxxafdc150 ///
c.Dxxgunlaw0##c.Dxxgunlaw0 ///
c.Dxxbeer0##c.Dxxbeer0 ///
///
(c.prop0##c.prop0)#(c.trend##c.trend) /// now interacted with trend
(c.Dprop0##c.Dprop0)#(c.trend##c.trend) ///
(c.(D.($xx))##c.(D.($xx)))#(c.trend##c.trend) /// note macro
(c.(L.xxprison)##c.(L.xxprison))#(c.trend##c.trend) ///
(c.(L.xxpolice)##c.(L.xxpolice))#(c.trend##c.trend) ///
(c.(L.xxunemp)##c.(L.xxunemp))#(c.trend##c.trend) ///
(c.(L.xxincome)##c.(L.xxincome))#(c.trend##c.trend) ///
(c.(L.xxpover)##c.(L.xxpover))#(c.trend##c.trend) ///
(c.(L.xxafdc15)##c.(L.xxafdc15))#(c.trend##c.trend) ///
(c.(L.xxgunlaw)##c.(L.xxgunlaw))#(c.trend##c.trend) ///
(c.(L.xxbeer)##c.(L.xxbeer))#(c.trend##c.trend) ///
(c.Mxxprison##c.Mxxprison)#(c.trend##c.trend) ///
(c.Mxxpolice##c.Mxxpolice)#(c.trend##c.trend) ///
(c.Mxxunemp##c.Mxxunemp )#(c.trend##c.trend) ///
(c.Mxxincome##c.Mxxincome)#(c.trend##c.trend) ///
(c.Mxxpover##c.Mxxpover )#(c.trend##c.trend) ///
(c.Mxxafdc15##c.Mxxafdc15)#(c.trend##c.trend) ///
(c.Mxxgunlaw##c.Mxxgunlaw)#(c.trend##c.trend) ///
(c.Mxxbeer##c.Mxxbeer)#(c.trend##c.trend) ///
(c.xxprison0##c.xxprison0)#(c.trend##c.trend) ///
(c.xxpolice0##c.xxpolice0)#(c.trend##c.trend) ///
(c.xxunemp0##c.xxunemp0)#(c.trend##c.trend) ///
(c.xxincome0##c.xxincome0)#(c.trend##c.trend) ///
(c.xxpover0##c.xxpover0)#(c.trend##c.trend) ///
(c.xxafdc150##c.xxafdc150)#(c.trend##c.trend) ///
(c.xxgunlaw0##c.xxgunlaw0)#(c.trend##c.trend) ///
(c.xxbeer0##c.xxbeer0)#(c.trend##c.trend) ///
(c.Dxxprison0##c.Dxxprison0)#(c.trend##c.trend) ///
(c.Dxxpolice0##c.Dxxpolice0)#(c.trend##c.trend) ///
(c.Dxxunemp0##c.Dxxunemp0)#(c.trend##c.trend) ///
(c.Dxxincome0##c.Dxxincome0)#(c.trend##c.trend) ///
(c.Dxxpover0##c.Dxxpover0)#(c.trend##c.trend) ///
(c.Dxxafdc150##c.Dxxafdc150)#(c.trend##c.trend) ///
(c.Dxxgunlaw0##c.Dxxgunlaw0)#(c.trend##c.trend) ///
(c.Dxxbeer0##c.Dxxbeer0 )#(c.trend##c.trend) ///
i.year, partial(i.year) robust lalt corrnum(0) ///
maxpsiiter(100) c0(0.55)
di "p=" e(p)
global ypSelrlasso `e(selected)'
di "$xpSelrlasso"
mat b_rlasso=e(b)
if `e(s)' {
mat b_rlasso=b_rlasso[1,1..`e(s)']
}
else {
mat b_rlasso=.
}
* Property Abortion
/*
lassoShootingCBH Dprop $AllProp if trend>0, controls($tdums) lasiter(100) verbose(0) fdisplay(1)
global xpSel `r(selected)'
di "$xpSel"
mat b_cbh=r(betaL)
mat b_cbh=b_cbh'
*/
global xpSel prop0 Lxxprison Lxxpolice Lxxincome Mxxincome Dxxincome0 Dxxincome0Xt
mat b_cbh = .09225667 , .00802776 , .02081152 , 7.955133 , 16.997832 , 24.938141 , 28.140729
// sort cols and compare
mata: st_matrix("b_rlasso",sort(st_matrix("b_rlasso")',1)')
mata: st_matrix("b_cbh",sort(st_matrix("b_cbh")',1)')
assert mreldif(b_rlasso,b_cbh)<1e-4
* Property equation with selected controls
pdslasso D.lpc_prop D.efaprop ///
( /// no trend
c.prop0##c.prop0 ///
c.Dprop0##c.Dprop0 ///
c.(D.($xx))##c.(D.($xx)) /// note macro
c.(L.xxprison)##c.(L.xxprison) ///
c.(L.xxpolice)##c.(L.xxpolice) ///
c.(L.xxunemp)##c.(L.xxunemp) ///
c.(L.xxincome)##c.(L.xxincome) ///
c.(L.xxpover)##c.(L.xxpover) ///
c.(L.xxafdc15)##c.(L.xxafdc15) ///
c.(L.xxgunlaw)##c.(L.xxgunlaw) ///
c.(L.xxbeer)##c.(L.xxbeer) ///
c.Mxxprison##c.Mxxprison ///
c.Mxxpolice##c.Mxxpolice ///
c.Mxxunemp##c.Mxxunemp ///
c.Mxxincome##c.Mxxincome ///
c.Mxxpover##c.Mxxpover ///
c.Mxxafdc15##c.Mxxafdc15 ///
c.Mxxgunlaw##c.Mxxgunlaw ///
c.Mxxbeer##c.Mxxbeer ///
c.xxprison0##c.xxprison0 ///
c.xxpolice0##c.xxpolice0 ///
c.xxunemp0##c.xxunemp0 ///
c.xxincome0##c.xxincome0 ///
c.xxpover0##c.xxpover0 ///
c.xxafdc150##c.xxafdc150 ///
c.xxgunlaw0##c.xxgunlaw0 ///
c.xxbeer0##c.xxbeer0 ///
c.Dxxprison0##c.Dxxprison0 ///
c.Dxxpolice0##c.Dxxpolice0 ///
c.Dxxunemp0##c.Dxxunemp0 ///
c.Dxxincome0##c.Dxxincome0 ///
c.Dxxpover0##c.Dxxpover0 ///
c.Dxxafdc150##c.Dxxafdc150 ///
c.Dxxgunlaw0##c.Dxxgunlaw0 ///
c.Dxxbeer0##c.Dxxbeer0 ///
///
(c.prop0##c.prop0)#(c.trend##c.trend) /// now interacted with trend
(c.Dprop0##c.Dprop0)#(c.trend##c.trend) ///
(c.(D.($xx))##c.(D.($xx)))#(c.trend##c.trend) /// note macro
(c.(L.xxprison)##c.(L.xxprison))#(c.trend##c.trend) ///
(c.(L.xxpolice)##c.(L.xxpolice))#(c.trend##c.trend) ///
(c.(L.xxunemp)##c.(L.xxunemp))#(c.trend##c.trend) ///
(c.(L.xxincome)##c.(L.xxincome))#(c.trend##c.trend) ///
(c.(L.xxpover)##c.(L.xxpover))#(c.trend##c.trend) ///
(c.(L.xxafdc15)##c.(L.xxafdc15))#(c.trend##c.trend) ///
(c.(L.xxgunlaw)##c.(L.xxgunlaw))#(c.trend##c.trend) ///
(c.(L.xxbeer)##c.(L.xxbeer))#(c.trend##c.trend) ///
(c.Mxxprison##c.Mxxprison)#(c.trend##c.trend) ///
(c.Mxxpolice##c.Mxxpolice)#(c.trend##c.trend) ///
(c.Mxxunemp##c.Mxxunemp )#(c.trend##c.trend) ///
(c.Mxxincome##c.Mxxincome)#(c.trend##c.trend) ///
(c.Mxxpover##c.Mxxpover )#(c.trend##c.trend) ///
(c.Mxxafdc15##c.Mxxafdc15)#(c.trend##c.trend) ///
(c.Mxxgunlaw##c.Mxxgunlaw)#(c.trend##c.trend) ///
(c.Mxxbeer##c.Mxxbeer)#(c.trend##c.trend) ///
(c.xxprison0##c.xxprison0)#(c.trend##c.trend) ///
(c.xxpolice0##c.xxpolice0)#(c.trend##c.trend) ///
(c.xxunemp0##c.xxunemp0)#(c.trend##c.trend) ///
(c.xxincome0##c.xxincome0)#(c.trend##c.trend) ///
(c.xxpover0##c.xxpover0)#(c.trend##c.trend) ///
(c.xxafdc150##c.xxafdc150)#(c.trend##c.trend) ///
(c.xxgunlaw0##c.xxgunlaw0)#(c.trend##c.trend) ///
(c.xxbeer0##c.xxbeer0)#(c.trend##c.trend) ///
(c.Dxxprison0##c.Dxxprison0)#(c.trend##c.trend) ///
(c.Dxxpolice0##c.Dxxpolice0)#(c.trend##c.trend) ///
(c.Dxxunemp0##c.Dxxunemp0)#(c.trend##c.trend) ///
(c.Dxxincome0##c.Dxxincome0)#(c.trend##c.trend) ///
(c.Dxxpover0##c.Dxxpover0)#(c.trend##c.trend) ///
(c.Dxxafdc150##c.Dxxafdc150)#(c.trend##c.trend) ///
(c.Dxxgunlaw0##c.Dxxgunlaw0)#(c.trend##c.trend) ///
(c.Dxxbeer0##c.Dxxbeer0 )#(c.trend##c.trend) ///
i.year ///
) ///
, partial(i.year) robust ///
lopt(lalt corrnum(0) maxpsiiter(100) c0(0.55))
mat b_pdslasso=e(b)
* Get union of selected instruments
global pDS : list global(ypSel) | global(xpSel)
* Property equation with selected controls
// Original - clustered SEs (but not cluster lasso)
// reg Dyprop Dprop $pDS $tdums if trend>0, cluster(statenum)
// robust, no cluster
reg Dyprop Dprop $pDS $tdums if trend>0, robust
mat b_regress=e(b)
// sort cols and compare
// may be diff lengths and include 0s (for dropped base vars)
// so compare abs values > 0
mata: st_matrix("b_pdslasso",abs(sort(-abs(st_matrix("b_pdslasso"))',1))')
mata: st_matrix("b_regress",abs(sort(-abs(st_matrix("b_regress"))',1))')
local k1 = colsof(b_pdslasso)
local k2 = colsof(b_regress)
mat b_pdslasso = b_pdslasso[1,1..min(`k1',`k2')]
mat b_regress = b_regress[1,1..min(`k1',`k2')]
assert mreldif(b_pdslasso,b_regress)<1e-6
********************************* Murder ***********************************
* Violence Outcome
rlasso D.lpc_murd ///
/// no trend
c.murd0##c.murd0 ///
c.Dmurd0##c.Dmurd0 ///
c.(D.($xx))##c.(D.($xx)) /// note macro
c.(L.xxprison)##c.(L.xxprison) ///
c.(L.xxpolice)##c.(L.xxpolice) ///
c.(L.xxunemp)##c.(L.xxunemp) ///
c.(L.xxincome)##c.(L.xxincome) ///
c.(L.xxpover)##c.(L.xxpover) ///
c.(L.xxafdc15)##c.(L.xxafdc15) ///
c.(L.xxgunlaw)##c.(L.xxgunlaw) ///
c.(L.xxbeer)##c.(L.xxbeer) ///
c.Mxxprison##c.Mxxprison ///
c.Mxxpolice##c.Mxxpolice ///
c.Mxxunemp##c.Mxxunemp ///
c.Mxxincome##c.Mxxincome ///
c.Mxxpover##c.Mxxpover ///
c.Mxxafdc15##c.Mxxafdc15 ///
c.Mxxgunlaw##c.Mxxgunlaw ///
c.Mxxbeer##c.Mxxbeer ///
c.xxprison0##c.xxprison0 ///
c.xxpolice0##c.xxpolice0 ///
c.xxunemp0##c.xxunemp0 ///
c.xxincome0##c.xxincome0 ///
c.xxpover0##c.xxpover0 ///
c.xxafdc150##c.xxafdc150 ///
c.xxgunlaw0##c.xxgunlaw0 ///
c.xxbeer0##c.xxbeer0 ///
c.Dxxprison0##c.Dxxprison0 ///
c.Dxxpolice0##c.Dxxpolice0 ///
c.Dxxunemp0##c.Dxxunemp0 ///
c.Dxxincome0##c.Dxxincome0 ///
c.Dxxpover0##c.Dxxpover0 ///
c.Dxxafdc150##c.Dxxafdc150 ///
c.Dxxgunlaw0##c.Dxxgunlaw0 ///
c.Dxxbeer0##c.Dxxbeer0 ///
///
(c.murd0##c.murd0)#(c.trend##c.trend) /// now interacted with trend
(c.Dmurd0##c.Dmurd0)#(c.trend##c.trend) ///
(c.(D.($xx))##c.(D.($xx)))#(c.trend##c.trend) /// note macro
(c.(L.xxprison)##c.(L.xxprison))#(c.trend##c.trend) ///
(c.(L.xxpolice)##c.(L.xxpolice))#(c.trend##c.trend) ///
(c.(L.xxunemp)##c.(L.xxunemp))#(c.trend##c.trend) ///
(c.(L.xxincome)##c.(L.xxincome))#(c.trend##c.trend) ///
(c.(L.xxpover)##c.(L.xxpover))#(c.trend##c.trend) ///
(c.(L.xxafdc15)##c.(L.xxafdc15))#(c.trend##c.trend) ///
(c.(L.xxgunlaw)##c.(L.xxgunlaw))#(c.trend##c.trend) ///
(c.(L.xxbeer)##c.(L.xxbeer))#(c.trend##c.trend) ///
(c.Mxxprison##c.Mxxprison)#(c.trend##c.trend) ///
(c.Mxxpolice##c.Mxxpolice)#(c.trend##c.trend) ///
(c.Mxxunemp##c.Mxxunemp )#(c.trend##c.trend) ///
(c.Mxxincome##c.Mxxincome)#(c.trend##c.trend) ///
(c.Mxxpover##c.Mxxpover )#(c.trend##c.trend) ///
(c.Mxxafdc15##c.Mxxafdc15)#(c.trend##c.trend) ///
(c.Mxxgunlaw##c.Mxxgunlaw)#(c.trend##c.trend) ///
(c.Mxxbeer##c.Mxxbeer)#(c.trend##c.trend) ///
(c.xxprison0##c.xxprison0)#(c.trend##c.trend) ///
(c.xxpolice0##c.xxpolice0)#(c.trend##c.trend) ///
(c.xxunemp0##c.xxunemp0)#(c.trend##c.trend) ///
(c.xxincome0##c.xxincome0)#(c.trend##c.trend) ///
(c.xxpover0##c.xxpover0)#(c.trend##c.trend) ///
(c.xxafdc150##c.xxafdc150)#(c.trend##c.trend) ///
(c.xxgunlaw0##c.xxgunlaw0)#(c.trend##c.trend) ///
(c.xxbeer0##c.xxbeer0)#(c.trend##c.trend) ///
(c.Dxxprison0##c.Dxxprison0)#(c.trend##c.trend) ///
(c.Dxxpolice0##c.Dxxpolice0)#(c.trend##c.trend) ///
(c.Dxxunemp0##c.Dxxunemp0)#(c.trend##c.trend) ///
(c.Dxxincome0##c.Dxxincome0)#(c.trend##c.trend) ///
(c.Dxxpover0##c.Dxxpover0)#(c.trend##c.trend) ///
(c.Dxxafdc150##c.Dxxafdc150)#(c.trend##c.trend) ///
(c.Dxxgunlaw0##c.Dxxgunlaw0)#(c.trend##c.trend) ///
(c.Dxxbeer0##c.Dxxbeer0 )#(c.trend##c.trend) ///
i.year, partial(i.year) robust lalt corrnum(0) ///
maxpsiiter(100) c0(0.55)
di "p=" e(p)
global ymSelrlasso `e(selected)'
di "$ymSelrlasso"
mat b_rlasso=e(b)
if `e(s)' {
mat b_rlasso=b_rlasso[1,1..`e(s)']
}
else {
mat b_rlasso=.
}
* Murder Outcome
/*
// no variables selected
lassoShootingCBH Dymurd $AllMurd if trend>0, controls($tdums) lasiter(100) verbose(0) fdisplay(1)
global ymSel `r(selected)'
di "`$mSel"
mat b_cbh=r(betaL)
mat b_cbh=b_cbh'
*/
global ymSel
mat b_cbh=.
// sort cols and compare
mata: st_matrix("b_rlasso",sort(st_matrix("b_rlasso")',1)')
mata: st_matrix("b_cbh",sort(st_matrix("b_cbh")',1)')
assert mreldif(b_rlasso,b_cbh)<1e-4
* Murder Abortion
rlasso D.efamurd ///