-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorrreport.ado
More file actions
909 lines (753 loc) · 22.9 KB
/
Copy pathcorrreport.ado
File metadata and controls
909 lines (753 loc) · 22.9 KB
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
*Version 2.9
program define corrreport
syntax varlist [if] [in] [, iv(varlist) by(varname) bootstrap(numlist missingokay max=1) estround(numlist max=1 integer) bootcorr(name) pval log]
qui {
set more off
tempfile master using
save `master', replace
capture keep $_if
capture keep $_in
capture drop if `by'==.
if "`log'" =="log" {
foreach var of varlist `varlist' {
sum `var'
local min=r(min)
if `min' < 0 {
noi: display as error "Cannot Log Transform Variables with Negative Numbers"
}
else {
if `min'>=0 & `min'<1 {
replace `var'=log(`var'+1)
}
else {
replace `var'=log(`var')
}
}
}
save `using', replace
}
else {
save `using', replace
}
tempfile output temp
clear
set more off
set obs 1
gen var=""
save `output', replace
if "`by'" == "" & "`bootstrap'" ==""{
use `using', clear
foreach indv in `iv' {
use `using', clear
foreach var of varlist `varlist' {
use `using', clear
*Non Parametric
spearman `var' `indv'
local srho=r(rho)
local sn=r(N)
local sp=r(p)
*Parametric
corr `var' `indv'
local prho=r(rho)
regress `var' `indv'
local pn=e(N)
test `indv'
local pp=r(p)
clear
set obs 1
gen var="`var'"
gen iv="`indv'"
gen N=`sn'
gen spearman=`srho'
gen spearman_p=`sp'
gen pearson=`prho'
gen pearson_p=`pp'
if "`estround'" != "" {
tostring spearman pearson, force format(%9.`estround'fc) replace
}
else {
tostring spearman pearson, force format(%9.2fc) replace
}
tostring N, force format(%9.0f) replace
if "`pval'" !="" {
tostring spearman_p pearson_p, force format(%9.4f) replace
replace spearman_p = "<.0001" if spearman_p =="0.0000"
replace pearson_p = "<.0001" if pearson_p =="0.0000"
}
if "`pval'" =="" {
gen sstar="†" if spearman_p <=0.10
replace sstar="*" if spearman_p<=0.05
replace sstar="**" if spearman_p<=0.01
replace sstar="***" if spearman_p<=0.001
gen pstar="†" if pearson_p <=0.10
replace pstar="*" if pearson_p<=0.05
replace pstar="**" if pearson_p<=0.01
replace pstar="***" if pearson_p<=0.001
replace spearman=sstar + spearman
replace pearson=pstar+ pearson
drop spearman_p pearson_p *star
}
save `temp', replace
use `output', clear
append using `temp'
drop if var==""
save `output', replace
}/*var*/
}/*iv*/
}/*by*/
if "`by'" != "" & "`bootstrap'"==""{
use `using', clear
foreach indv in `iv' {
use `using', clear
foreach var of varlist `varlist' {
use `using', clear
table `by', replace
local num=_N
forvalues i=1(1)`num' {
local grp`i'=`by' in `i'
}
use `using', clear
forvalues i=1(1)`num' {
use `using', clear
*Non Parametric
spearman `var' `indv' if `by'==`grp`i''
local srho=r(rho)
local sn=r(N)
local sp=r(p)
*Parametric
corr `var' `indv' if `by'==`grp`i''
local prho=r(rho)
regress `var' `indv' if `by'==`grp`i''
local pn=e(N)
test `indv'
local pp=r(p)
clear
set obs 1
gen var="`var'"
gen iv="`indv'"
gen grp=`grp`i''
gen N=`sn'
gen spearman=`srho'
gen spearman_p=`sp'
gen pearson=`prho'
gen pearson_p=`pp'
if "`estround'" != "" {
tostring spearman pearson, force format(%9.`estround'fc) replace
}
else {
tostring spearman pearson, force format(%9.2fc) replace
}
tostring N, force format(%9.0f) replace
tempfile temp`i'
save `temp`i'', replace
}
use `temp1', clear
forvalues i=2(1)`num' {
append using `temp`i''
}
reshape wide N spearman* pearson*, i(var iv) j(grp)
if "`pval'" !="" {
tostring spearman_p* pearson_p*, force format(%9.4f) replace
forvalues i=1(1)`num' {
replace spearman_p`grp`i'' = "<.0001" if spearman_p`grp`i''=="0.0000"
replace pearson_p`grp`i'' = "<.0001" if pearson_p`grp`i''=="0.0000"
}
}
if "`pval'" =="" {
forvalues i=1(1)`num' {
gen sstar`grp`i''="†" if spearman_p`grp`i'' <=0.10
replace sstar`grp`i''="*" if spearman_p`grp`i''<=0.05
replace sstar`grp`i''="**" if spearman_p`grp`i''<=0.01
replace sstar`grp`i''="***" if spearman_p`grp`i''<=0.001
gen pstar`grp`i''="†" if pearson_p`grp`i'' <=0.10
replace pstar`grp`i''="*" if pearson_p`grp`i''<=0.05
replace pstar`grp`i''="**" if pearson_p`grp`i''<=0.01
replace pstar`grp`i''="***" if pearson_p`grp`i''<=0.001
replace spearman`grp`i''=sstar`grp`i'' + spearman`grp`i''
replace pearson`grp`i''=pstar`grp`i''+ pearson`grp`i''
}/*Forvalues*/
drop spearman_p* pearson_p* *star*
}
save `temp', replace
use `output', clear
append using `temp'
drop if var==""
save `output', replace
}/*var*/
}/*iv*/
}/*by*/
if "`by'" =="" & "`bootstrap'" != "" {
use `using', clear
foreach indv in `iv' {
use `using', clear
foreach var of varlist `varlist' {
use `using', clear
tempfile `var' tempall
if "`bootcorr'" == "spearman" {
bootstrap `var'=r(rho), seed(`bootstrap') reps(`bootstrap') saving(``var'', replace) : spearman `var' `indv'
matrix x=e(b)
local `var'rho=x[1,1]
matrix y= e(ci_percentile)
local `var'lo=y[1,1]
local `var'hi=y[2,1]
spearman `var' `indv'
local `var'p=r(p)
}
if "`bootcorr'" == "pearson" {
bootstrap `var'=r(rho), seed(`bootstrap') reps(`bootstrap') saving(``var'', replace) : corr `var' `indv'
matrix x=e(b)
local `var'rho=x[1,1]
matrix y= e(ci_percentile)
local `var'lo=y[1,1]
local `var'hi=y[2,1]
regress `var' `indv'
test `indv'
local `var'p=r(p)
}
else {
bootstrap `var'=r(rho), seed(`bootstrap') reps(`bootstrap') saving(``var'', replace) : corr `var' `indv'
matrix x=e(b)
local `var'rho=x[1,1]
matrix y= e(ci_percentile)
local `var'lo=y[1,1]
local `var'hi=y[2,1]
regress `var' `indv'
test `indv'
local `var'p=r(p)
}
use ``var'', clear
egen order=seq()
save ``var'', replace
}
foreach var in `varlist' {
use ``var'', clear
save `tempall', replace
}
use `tempall', clear
foreach var in `varlist' {
joinby order using ``var'', unmatched(none)
}
duplicates drop
local threshold=_N/2
foreach x of varlist `varlist' {
gen `x'1= ``x'rho'
gen `x'2= ``x'lo'
gen `x'3= ``x'hi'
gen `x'p=``x'p'
if "`estround'" != "" {
tostring `x'1 `x'2 `x'3, force format(%9.`estround'fc) replace
}
else {
tostring `x'1 `x'2 `x'3, force format(%9.3f) replace
}
gen `x'star="†" if `x'p <=0.10
replace `x'star="*" if `x'p<=0.05
replace `x'star="**" if `x'p<=0.01
replace `x'star="***" if `x'p<=0.001
gen `x'rho=`x'star + `x'1 + " (" + `x'2 + ", " + `x'3 + ")"
drop `x'1 `x'2 `x'3 `x'star `x'p
capture label var `x'rho "Rho of `x' and IV"
foreach y of varlist `varlist' {
gen `x'_`y'_p= `x' >=`y'
count if `x'_`y'_p ==1
local n=r(N)
if `n' >= `threshold' {
replace `x'_`y'_p=2* (1-(`n'/`bootstrap'))
replace `x'_`y'_p=0.9999 if `x'_`y'_p>=1
}
if `n' < `threshold' {
replace `x'_`y'_p=2* (1-((`bootstrap'-`n')/`bootstrap'))
replace `x'_`y'_p=0.9999 if `x'_`y'_p>=1
}
if "`y'" == "`x'" {
capture drop `y'_`x'_p
capture drop `x'_`y'_p
}
capture label var `x'_`y'_p "P value of Rho comparison of of `x' and IV to `y' and IV"
}/*Y*/
} /*X*/
gen iv="`indv'"
keep iv *_p *rho
keep in 1
if `bootstrap' <=100 {
tostring *_p, force format(%9.2f) replace
foreach x of varlist *_p {
replace `x' ="<.01" if `x'=="0.00"
}
}
if `bootstrap' >100 & `bootstrap' <=1000{
tostring *_p, force format(%9.3f) replace
foreach x of varlist *_p {
replace `x' ="<.001" if `x'=="0.000"
}
}
if `bootstrap' >1000 {
tostring *_p, force format(%9.4f) replace
foreach x of varlist *_p {
replace `x' ="<.0001" if `x'=="0.0000"
}
}
save `temp', replace
use `output', clear
append using `temp'
save `output', replace
} /*IV*/
drop var
drop if iv==""
order iv
}/*BY*/
if "`by'" !="" & "`bootstrap'" != "" {
use `using', clear
foreach indv in `iv' {
use `using', clear
foreach var of varlist `varlist' {
use `using', clear
tempfile tempall
table `by', replace
local num=_N
forvalues i=1(1)`num' {
local grp`i'=`by' in `i'
}
use `using', clear
forvalues i=1(1)`num' {
use `using', clear
tempfile temp`i'
if "`bootcorr'" == "spearman" {
bootstrap v`grp`i''=r(rho), seed(`bootstrap') reps(`bootstrap') saving(`temp`i'', replace) : spearman `var' `indv' if `by'==`grp`i''
matrix x=e(b)
local rho`i'=x[1,1]
matrix y= e(ci_percentile)
local lo`i'=y[1,1]
local hi`i'=y[2,1]
spearman `var' `indv' if `by'==`grp`i''
local p`i'=r(p)
}
if "`bootcorr'" == "pearson" {
bootstrap v`grp`i''=r(rho), seed(`bootstrap') reps(`bootstrap') saving(`temp`i'', replace) : corr `var' `indv' if `by'==`grp`i''
matrix x=e(b)
local rho`i'=x[1,1]
matrix y= e(ci_percentile)
local lo`i'=y[1,1]
local hi`i'=y[2,1]
regress `var' `indv' if `by'==`grp`i''
test `indv'
local p`i'=r(p)
}
else {
bootstrap v`grp`i''=r(rho), seed(`bootstrap') reps(`bootstrap') saving(`temp`i'', replace) : corr `var' `indv' if `by'==`grp`i''
matrix x=e(b)
local rho`i'=x[1,1]
matrix y= e(ci_percentile)
local lo`i'=y[1,1]
local hi`i'=y[2,1]
regress `var' `indv' if `by'==`grp`i''
test `indv'
local p`i'=r(p)
}
use `temp`i'', clear
egen order=seq()
save `temp`i'', replace
}
use `temp1', clear
forvalues i=1(1)`num' {
joinby order using `temp`i'', unmatched(none)
}
local threshold=_N/2
forvalues i=1(1)`num' {
gen rho`grp`i''= `rho`i''
gen lo`grp`i''= `lo`i''
gen hi`grp`i''= `hi`i''
gen p`grp`i''=`p`i''
if "`estround'" != "" {
tostring rho* lo* hi*, force format(%9.`estround'fc) replace
}
else {
tostring rho* lo* hi*, force format(%9.3f) replace
}
gen star`grp`i''="†" if p`grp`i'' <=0.10
replace star`grp`i''="*" if p`grp`i''<=0.05
replace star`grp`i''="**" if p`grp`i''<=0.01
replace star`grp`i''="***" if p`grp`i''<=0.001
gen rho_`grp`i''=star`grp`i'' + rho`grp`i'' + " (" + lo`grp`i'' + ", " + hi`grp`i'' + ")"
drop rho`grp`i'' lo`grp`i'' hi`grp`i'' star`grp`i'' p`grp`i''
capture label var rho_`grp`i'' "Rho of Var and IV in `by'==`grp`i''"
forvalues y=2(1)`num' {
gen grp`grp`i''_`grp`y''_p= v`grp`i'' >= v`grp`y''
count if grp`grp`i''_`grp`y''_p ==1
local n=r(N)
if `n' >= `threshold' {
replace grp`grp`i''_`grp`y''_p=2* (1-(`n'/`bootstrap'))
replace grp`grp`i''_`grp`y''_p=0.9999 if grp`grp`i''_`grp`y''_p>=1
}
if `n' < `threshold' {
replace grp`grp`i''_`grp`y''_p=2* (1-((`bootstrap'-`n')/`bootstrap'))
replace grp`grp`i''_`grp`y''_p=0.9999 if grp`grp`i''_`grp`y''_p>=1
}
if "`y'" == "`i'" {
capture drop grp`grp`i''_`grp`y''_p
capture drop grp`grp`y''_`grp`i''_p
}
if "`y'" > "`i'" {
capture drop grp`grp`y''_`grp`i''_p
}
capture label var grp`grp`i''_`grp`y''_p "P value of Rho comparison for `by' groups `grp`i'' vs `grp`y'"
}/*Y*/
} /*X*/
gen var="`var'"
gen iv="`indv'"
keep iv var *_p rho*
keep in 1
if `bootstrap' <=100 {
tostring *_p, force format(%9.2f) replace
foreach x of varlist *_p {
replace `x' ="<.01" if `x'=="0.00"
}
}
if `bootstrap' >100 & `bootstrap' <=1000{
tostring *_p, force format(%9.3f) replace
foreach x of varlist *_p {
replace `x' ="<.001" if `x'=="0.000"
}
}
if `bootstrap' >1000 {
tostring *_p, force format(%9.4f) replace
foreach x of varlist *_p {
replace `x' ="<.0001" if `x'=="0.0000"
}
}
save `temp', replace
use `output', clear
append using `temp'
save `output', replace
} /*IV*/
drop if iv==""
order iv var
}/*VAR*/
}/*BY*/
}/*QUI*/
end
/*if "`by'" != "" & "`bootstrap'"!=""{
use `using', clear
foreach indv in `iv' {
use `using', clear
foreach var of varlist `varlist' {
use `using', clear
table `by', replace
local num=_N
forvalues i=1(1)`num' {
local grp`i'=`by' in `i'
}
use `using', clear
forvalues i=1(1)`num' {
use `using', clear
*Non Parametric
spearman `var' `indv' if `by'==`grp`i''
local srho=r(rho)
local sn=r(N)
local sp=r(p)
*Parametric
corr `var' `indv' if `by'==`grp`i''
local prho=r(rho)
regress `var' `iv' if `by'==`grp`i''
local pn=e(N)
test `iv'
local pp=r(p)
clear
set obs 1
gen var="`var'"
gen iv="`indv'"
gen grp=`grp`i''
gen N=`sn'
gen spearman=`srho'
gen spearman_p=`sp'
gen pearson=`prho'
gen pearson_p=`pp'
tostring spearman pearson, force format(%9.3f) replace
tostring N, force format(%9.0f) replace
tempfile temp`i'
save `temp`i'', replace
}
use `temp1', clear
forvalues i=2(1)`num' {
append using `temp`i''
}
reshape wide N spearman* pearson*, i(var iv) j(grp)
if "`pval'" !="" {
tostring spearman_p* pearson_p*, force format(%9.4f) replace
}
if "`pval'" =="" {
forvalues i=1(1)`num' {
gen sstar`grp`i''="†" if spearman_p`grp`i'' <=0.10
replace sstar`grp`i''="*" if spearman_p`grp`i''<=0.05
replace sstar`grp`i''="**" if spearman_p`grp`i''<=0.01
replace sstar`grp`i''="***" if spearman_p`grp`i''<=0.001
gen pstar`grp`i''="†" if pearson_p`grp`i'' <=0.10
replace pstar`grp`i''="*" if pearson_p`grp`i''<=0.05
replace pstar`grp`i''="**" if pearson_p`grp`i''<=0.01
replace pstar`grp`i''="***" if pearson_p`grp`i''<=0.001
replace spearman`grp`i''=sstar`grp`i'' + spearman`grp`i''
replace pearson`grp`i''=pstar`grp`i''+ pearson`grp`i''
}/*Forvalues*/
drop spearman_p* pearson_p* *star*
}
save `temp', replace
use `output', clear
append using `temp'
drop if var==""
save `output', replace
}/*var*/
}/*iv*/
}/*by*/
}/*qui*/
end
/*OLD CODE Prior to 07/29/2011
save faketemp.dta, replace
use faketemp.dta, clear
if "`pval'"=="" {
corrreportnop `varlist' $_if, iv(`iv') bootstrap(`bootstrap')
}
if "`pval'"!="" {
corrreportp `varlist' $_if, iv(`iv') bootstrap(`bootstrap')
}
drop if var==""
capture erase `temp'
capture erase faketemp.dta
capture label var bs_reps "Bootstrap Repititions"
capture label var n "N"
capture label var spearman "Spearman Rho"
capture label var pearson "Pearson Rho"
capture label var spearman_p "Spearman P Value"
capture label var pearson_p "Pearson P Value"
capture label var spearman_ci "Spearman Bootstrap Percentile CI"
capture label var pearson_ci "Pearson Bootstrap Percentile CI"
}
list , noobs divider sepby(var)
end
program corrreportnop
syntax varlist [if] [, iv(varlist) bootstrap(numlist missingokay max=1)]
qui {
tempfile output temp
clear
set more off
set obs 1
gen var=""
save `output', replace
if "`bootstrap'"=="" {
use faketemp.dta, clear
foreach iv in `iv' {
use faketemp.dta, clear
foreach var of varlist `varlist' {
use faketemp.dta, clear
/***Overall Adjusted means***/
spearman `var' `iv' $_if
local srho=r(rho)
local sn=r(N)
local sp=r(p)
corr `var' `iv' $_if
local prho=r(rho)
regress `var' `iv' $_if
local pn=e(N)
test `iv'
local pp=r(p)
clear
set obs 1
gen srho=`srho'
gen prho=`prho'
gen sn=`sn'
gen pn=`pn'
gen sp=`sp'
gen pp=`pp'
gen sstar="†" if sp <=0.10
replace sstar="*" if sp<=0.05
replace sstar="**" if sp<=0.01
replace sstar="***" if sp<=0.001
capture gen pstar="†" if pp <=0.10
capture replace pstar="*" if pp<=0.05
capture replace pstar="**" if pp<=0.01
capture replace pstar="***" if pp<=0.001
tostring *rho, force format(%9.3f) replace
tostring *n, force format(%9.0f) replace
gen var="`var'"
gen iv="`iv'"
gen n="(" + sn + ")"
gen spearman= sstar + srho
gen pearson= pstar + prho
keep var iv n spearman pearson
save `temp', replace
use `output', clear
append using `temp'
save `output', replace
}
}
}
if "`bootstrap'"!=""{
use faketemp.dta, clear
foreach iv in `iv' {
use faketemp.dta, clear
foreach var of varlist `varlist' {
use faketemp.dta, clear
/***Overall Adjusted means***/
drop if `var'==.
drop if `iv'==.
capture keep $_if
bootstrap r(rho), reps(`bootstrap') seed(`bootstrap'): spearman `var' `iv' $_if
local srho=_b[_bs_1]
matrix s=e(ci_percentile)
local sn=e(N)
test _bs_1
local sp=r(p)
bootstrap r(rho), reps(`bootstrap') seed(`bootstrap'): corr `var' `iv' $_if
local prho=_b[_bs_1]
local pn=e(N)
matrix p=e(ci_percentile)
test _bs_1
local pp=r(p)
clear
set obs 1
gen srho=`srho'
gen prho=`prho'
gen s_hi=s[2,1]
gen s_lo=s[1,1]
gen p_hi=p[2,1]
gen p_lo=p[1,1]
tostring p_* s_*, force format(%9.3f) replace
gen pearson_ci=p_lo + " - " +p_hi
gen spearman_ci=s_lo + " - " +s_hi
gen sn=`sn'
gen pn=`pn'
gen sp=`sp'
gen pp=`pp'
gen bs_reps=`bootstrap'
gen sstar="†" if sp <=0.10
replace sstar="*" if sp<=0.05
replace sstar="**" if sp<=0.01
replace sstar="***" if sp<=0.001
capture gen pstar="†" if pp <=0.10
capture replace pstar="*" if pp<=0.05
capture replace pstar="**" if pp<=0.01
capture replace pstar="***" if pp<=0.001
tostring *rho, force format(%9.3f) replace
tostring *n bs_reps, force format(%9.0f) replace
gen var="`var'"
gen iv="`iv'"
gen n="(" + sn + ")"
gen spearman= sstar + srho
gen pearson= pstar + prho
keep var iv bs_reps n spearman spearman_ci pearson pearson_ci
order var iv bs_reps n spearman spearman_ci pearson pearson_ci
save `temp', replace
use `output', clear
append using `temp'
save `output', replace
}
}
}
}
end
program corrreportp
syntax varlist [if] [, iv(varlist) bootstrap(numlist missingokay max=1)]
tempfile output temp
clear
set more off
set obs 1
gen var=""
save `output', replace
if "`bootstrap'"=="" {
use faketemp.dta, clear
foreach iv in `iv' {
use faketemp.dta, clear
foreach var of varlist `varlist' {
use faketemp.dta, clear
/***Overall Adjusted means***/
spearman `var' `iv' $_if
local srho=r(rho)
local sn=r(N)
local sp=r(p)
corr `var' `iv' $_if
local prho=r(rho)
regress `var' `iv' $_if
local pn=e(N)
test `iv'
local pp=r(p)
clear
set obs 1
gen srho=`srho'
gen prho=`prho'
gen sn=`sn'
gen pn=`pn'
gen spearman_p=`sp'
gen pearson_p=`pp'
tostring *rho, force format(%9.3f) replace
tostring *n, force format(%9.0f) replace
tostring *_p, force format(%9.4f) replace
gen var="`var'"
gen iv="`iv'"
gen n="(" + sn + ")"
gen spearman= srho
gen pearson= prho
keep var iv n spearman spearman_p pearson pearson_p
order var iv n spearman spearman_p pearson pearson_p
save `temp', replace
use `output', clear
append using `temp'
save `output', replace
}
}
}
if "`bootstrap'"!=""{
use faketemp.dta, clear
foreach iv in `iv' {
use faketemp.dta, clear
foreach var of varlist `varlist' {
use faketemp.dta, clear
/***Overall Adjusted means***/
drop if `var'==.
drop if `iv'==.
capture keep $_if
bootstrap r(rho), reps(`bootstrap') seed(`bootstrap'): spearman `var' `iv' $_if
local srho=_b[_bs_1]
matrix s=e(ci_percentile)
local sn=e(N)
test _bs_1
local sp=r(p)
bootstrap r(rho), reps(`bootstrap') seed(`bootstrap'): corr `var' `iv' $_if
local prho=_b[_bs_1]
local pn=e(N)
matrix p=e(ci_percentile)
test _bs_1
local pp=r(p)
clear
set obs 1
gen srho=`srho'
gen prho=`prho'
gen s_hi=s[2,1]
gen s_lo=s[1,1]
gen p_hi=p[2,1]
gen p_lo=p[1,1]
tostring p_* s_*, force format(%9.3f) replace
gen pearson_ci=p_lo + " - " +p_hi
gen spearman_ci=s_lo + " - " +s_hi
gen sn=`sn'
gen pn=`pn'
gen spearman_p=`sp'
gen pearson_p=`pp'
gen bs_reps=`bootstrap'
tostring *rho, force format(%9.3f) replace
tostring *n bs_reps, force format(%9.0f) replace
tostring *_p, force format(%9.4f) replace
gen var="`var'"
gen iv="`iv'"
gen n="(" + sn + ")"
gen spearman=srho
gen pearson= prho
keep var iv bs_reps n spearman spearman_p pearson pearson_p spearman_ci pearson_ci
order var iv bs_reps n spearman spearman_ci spearman_p pearson pearson_ci pearson_p
save `temp', replace
use `output', clear
append using `temp'
save `output', replace
}
}
}
end
exit