-
Notifications
You must be signed in to change notification settings - Fork 1
/
dissertation-chapter-2-yearly-data-creation.do
1614 lines (1169 loc) · 45.2 KB
/
dissertation-chapter-2-yearly-data-creation.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
***=====================================================***
* CHAPTER 2 DATA CREATION
* FIRM-YEAR LEVEL DATASET COMBINING
* CSRHUB AND COMPUSTAT GLOBAL AND NORTH AMERICA
***=====================================================***
clear all
/*
***===============================***
* COLLAPSE CSRHUB TO YEAR LEVEL *
***===============================***
/// LOAD DATA
use data/csrhub-all.dta, clear
/* Created at D:\Dropbox\Data\csrhub-data\code-csrHub-data\CREATE-CSRHub-full-dataset.do */
drop firm_n csrhub_cr
/// KEEP UNIQUE CUSIP YM
bysort cusip ym: gen N=_N
drop if N>1
*111,062 observations deleted, either missing CUSIPs (110,221) or ///
* duplicate CUSIP ym values (841)
drop N
/// SET PANEL
encode cusip, gen(cusip_n)
xtset cusip_n ym
/// CREATE LAST MONTH OF YEAR VARIABLE
gsort cusip -ym
by cusip: gen last_ob = (_n==1)
label var last_ob "(CSRHUB) =1 if last ym CUSIP appears in CSRHUB data"
gen right_censor = (ym==692)
label var right_censor "(CSRHUB) =1 if last ym for CUSIP is 2017m9, the last ym in data"
*** Genearate last month of year variable for each rating
foreach variable of varlist over_rtg board_rtg cmty_rtg com_dev_phl_rtg comp_ben_rtg ///
div_lab_rtg emp_rtg enrgy_climchge_rtg enviro_pol_rpt_rtg enviro_rtg ///
gov_rtg humrts_supchain_rtg industry_avg_rtg ldrship_ethics_rtg ///
over_pct_rank prod_rtg resource_mgmt_rtg train_hlth_safe_rtg trans_report_rtg {
capt drop var maxmth
mark var
markout var `variable'
sort cusip year month
markout var year month `variable'
by cusip year: egen maxmth=max(month) if var==1
gen `variable'_lym = `variable' if month==maxmth
label var `variable'_lym "(CSRHUB) Last ym of `variable' for each year"
}
drop var maxmth
/// COLLAPSE TO YEAR LEVEL
foreach variable of varlist *rtg {
gen `variable'_mean = `variable'
gen `variable'_med = `variable'
}
collapse (max) *lym (mean) *_mean (median) *_med, by(cusip year firm isin industry)
order *, alpha
order cusip year firm
*** Drop duplicate cusip years
bysort cusip year: gen N=_N
tab N
/* N | Freq. Percent Cum.
------------+-----------------------------------
1 | 84,012 99.98 99.98
2 | 20 0.02 100.00
------------+-----------------------------------
Total | 84,032 100.00
*/
drop if N>1
drop N
*** Generate indicator variable
gen in_csrhub=1
label var in_csrhub "Indicator = 1 if in CSRHub data"
/// SAVE
compress
xtset, clear
label data "Year-level CSRHub 2008-2017"
save data/csrhub-all-year-level-pre-manual-match.dta, replace
***=======================================================***
* MERGE MANUALLY-MATCHED CSRHUB-CSTAT FIRM INFORMATION *
***=======================================================***
/// PREP MANUALLY-MATCHED DATA FOR MERGE
import excel "data\manual-match-csrhub-to-cstat.xlsx", ///
firstrow allstring clear
*** Label variables
label var firm_csrhub "(CSRHub) firm name from manual CSRHUB-CSTAT match"
label var cusip8 "(CSRHub) cusip8 from manual CSRHUB-CSTAT match"
label var cusip9 "(CSRHub) cusip9 from manual CSRHUB-CSTAT match"
label var isin "(CSRHub) isin from manual CSRHUB-CSTAT match"
label var firm "(CSTAT) firm name from manual CSRHUB-CSTAT match"
label var tic "(CSTAT) ticker from manual CSRHUB-CSTAT match"
label var cusip "(CSTAT) cusip9 from manual CSRHUB-CSTAT match"
label var cik "(CSTAT) cik from manual CSRHUB-CSTAT match"
label var gvkey "(CSTAT) gvkey from manual CSRHUB-CSTAT match"
*** Drop unneeded variables
drop isin tic cik gvkey
*** Rename variables to preserve through merge
rename (cusip8 cusip9 firm cusip) (cusip8_csr_man cusip9_csr_man firm_cstat_man cusip9_cstat_man)
*** Clean
replace firm_csrhub=upper(firm_csrhub)
*** Save manually-matched data
compress
save data/manually-matched-csrhub-cstat-firms.dta, replace
/// LOAD CSRHUB DATA
use data/csrhub-all-year-level-pre-manual-match.dta, clear
/// MERGE
gen firm_csrhub=upper(firm)
label var firm_csrhub "(CSRHUB) firm name used to match to manual CSTAT match"
merge m:1 firm_csrhub using data/manually-matched-csrhub-cstat-firms.dta, ///
update assert(1 2 3 4 5)
/* Result # of obs.
-----------------------------------------
not matched 75,921
from master 75,921 (_merge==1)
from using 0 (_merge==2)
matched 2,883
not updated 2,883 (_merge==3)
missing updated 0 (_merge==4)
nonmissing conflict 0 (_merge==5)
-----------------------------------------
*/
drop _merge
/// SAVE CSRHUB WITH MANUALLY-MATCHED CSTAT IDENTIFIERS
save data/csrhub-all-year-level.dta, replace
*/
***===============================================***
* CREATE CSTAT GLOBAL CURRENCY CONVERSION FILE *
***===============================================***
/* PROBLEM: CSTAT Global reports local currency. CSTAT North Am reports USA dollars.
Need to convert CSTAT Global to USA dollars.
This can be done by using the currency exchange file from CSTAT,
matching on curcd to convert to British pounds, then converting
from British pounds to USD.
The Compustat Global Fundamentals Annual Exchange Rate Monthly
data were accessed at https://wrds-web.wharton.upenn.edu/wrds/tools/variable.cfm?library_id=162&file_id=95591
*/
/// CREATE .DTA FILE
import delimited "data\cstat-global-exchange-rate-monthly.csv", clear
*** Keep needed variables
* exratm: Exchange rate monthly.
* datadate: The date for which exratm is valid? Documentation does not specify.
keep datadate fromcurm tocurm exratm
*** Generate variables
tostring(datadate), gen(datestring)
gen date = date(datestring,"YMD")
gen year=year(date)
gen month=month(date)
drop datestring
gen curcd = tocurm
*** Save
compress
label var tocurm "Exchange rate to currency code"
label var exratm "Exchange rate"
label var fromcurm "Exchange rate from currency code"
label var curcd "Currency code of dollar values in row"
save data\cstat-global-exchange-rate-monthly.dta, replace
*** Save only GBP to USD conversion
keep if tocurm=="USD"
rename exratm exratm_gbp_to_usd
label var exratm_gbp_to_usd "Exchange rate of GBP to USD"
rename tocurm to_usd
label var to_usd "Exchange rate currency code USD only"
drop curcd
drop datadate
compress
save data\cstat-global-exchange-rate-monthly-gbp-to-usd-only.dta, replace
***===========================================***
* MERGE CSRHUB AND CSTAT GLOBAL ON ISIN YEAR *
***===========================================***
/// PREPARE COMPUSTAT GLOBAL FOR MERGE
use data/cstat-all-firms-fundamentals-annual-global-2000-2018.dta, clear
*** Keep unique isin-years
gen year=fyear
codebook isin
/*
unique values: 38,028 missing "": 2,611/479,423
*/
drop if isin==""
bysort isin year indfmt: gen N=_N
tab N
/*
N | Freq. Percent Cum.
------------+-----------------------------------
1 | 578,800 99.28 99.28
2 | 4,128 0.71 99.99
3 | 42 0.01 100.00
4 | 4 0.00 100.00
14 | 14 0.00 100.00
------------+-----------------------------------
Total | 582,988 100.00
*/
keep if N==1
drop N
*** Generate indicator variable
gen in_cstatg=1
label var in_cstatg "(CSTAT Global) =1 if in CSTAT Global"
*** Save
compress
save data/mergefile-cstat-fundamentals-annual-global-2000-2018.dta, replace
/// MERGE CSRHUB WITH CSTAT GLOBAL ON ISIN
*** Merge and keep matched
use data/csrhub-all-year-level.dta, clear
merge 1:1 isin year using ///
data/mergefile-cstat-fundamentals-annual-global-2000-2018.dta, ///
keep(match)
/*
Result # of obs.
-----------------------------------------
not matched 0
matched 32,745 (_merge==3)
-----------------------------------------
*/
* Save matched
drop _merge
compress
save data/matched-csrhub-cstat-global-isin-year.dta, replace
*** Merge and keep unmatched
use data/csrhub-all-year-level.dta, clear
merge 1:1 isin year using ///
data/mergefile-cstat-fundamentals-annual-global-2000-2018.dta
/*
Result # of obs.
-----------------------------------------
not matched 592,114
from master 46,059 (_merge==1)
from using 546,055 (_merge==2)
matched 32,745 (_merge==3)
-----------------------------------------
*/
* Save unmatched
keep if _merge==1
drop _merge gvkey indfmt datafmt consol popsrc fyear fyr datadate exchg sedol ///
conm costat fic cik conml loc naics sic in_cstatg
compress
save data/unmatched-csrhub-cstat-global-isin-year.dta, replace
***===============================================================***
* MERGE UNMATCHED CSRHUB AND CSTAT NORTH AMERICA ON CUSIP9 YEAR *
***===============================================================***
/// PREPARE COMPUSTAT NORTH AMERICA FOR MERGE
use data/cstat-all-firms-fundamentals-annual-north-am-2006-2017.dta, clear
gen year = fyear
rename cusip cusip9
bysort cusip9 year indfmt: gen N=_N
tab N
/* N | Freq. Percent Cum.
------------+-----------------------------------
1 | 124,099 99.68 99.68
2 | 126 0.10 99.78
3 | 84 0.07 99.85
4 | 48 0.04 99.89
5 | 10 0.01 99.89
10 | 10 0.01 99.90
15 | 15 0.01 99.91
17 | 34 0.03 99.94
18 | 72 0.06 100.00
------------+-----------------------------------
Total | 124,498 100.00
*/
drop if N>1
drop N
*** Generate indicator variable
gen in_cstatn = 1
label var in_cstatn "(CSTAT North Am) =1 if in CSTAT North America"
*** Keep industrial format when duplicate cusip9 year observations
bysort cusip9 year: gen N=_N
tab N
/* N | Freq. Percent Cum.
------------+-----------------------------------
1 | 110,820 80.66 80.66
2 | 26,580 19.34 100.00
------------+-----------------------------------
Total | 137,400 100.00
*/
bysort cusip9 year: gen n=_n
tab n
/* n | Freq. Percent Cum.
------------+-----------------------------------
1 | 124,110 90.33 90.33
2 | 13,290 9.67 100.00
------------+-----------------------------------
Total | 137,400 100.00
*/
drop if indfmt=="FS" & N==2
bysort cusip9 year: gen N2=_N
tab N2
/* N2 | Freq. Percent Cum.
------------+-----------------------------------
1 | 124,110 100.00 100.00
------------+-----------------------------------
Total | 124,110 100.00
*/
drop N N2 n
*** Save
compress
save data/mergefile-cstat-fundamentals-annual-northam-2005-2017.dta, replace
/// MERGE NONMATCHED CSRHUB WITH CSTAT NORTH AM ON CUSIP9 YEAR
*** Merge and keep matched
use data/unmatched-csrhub-cstat-global-isin-year.dta, clear
* Merge with CSRHub on cusip9-year
merge 1:1 cusip9 year using ///
data/mergefile-cstat-fundamentals-annual-northam-2005-2017.dta, ///
keep(match)
/*
Result # of obs.
-----------------------------------------
not matched 0
matched 22,928 (_merge==3)
-----------------------------------------
*/
* Save matched
drop _merge
compress
save data/matched-csrhub-cstat-northam-cusip9-year.dta, replace
*** Merge and keep unmatched
use data/unmatched-csrhub-cstat-global-isin-year.dta, clear
* Merge with CSRHub on cusip9-year
merge 1:1 cusip9 year using ///
data/mergefile-cstat-fundamentals-annual-northam-2005-2017.dta
/*
Result # of obs.
-----------------------------------------
not matched 124,313
from master 23,131 (_merge==1)
from using 101,182 (_merge==2)
matched 22,928 (_merge==3)
-----------------------------------------
*/
* Save unmatched
keep if _merge==1
drop _merge tic cik gvkey datadate fyear fyr naics sic spcindcd spcseccd curcd ///
exchg costat gsubind fic loc city ipodate indfmt conm conml in_cstatn
compress
save data/unmatched-after-csrhub-cstat-global-and-northam-exact-merges.dta, replace
***===================================================================***
* APPEND CSRHUB/CSTAT GLOBAL AND CSRHUB/CSTAT NORTHAM DATASETS *
***===================================================================***
/// APPEND
use data/matched-csrhub-cstat-global-isin-year.dta, clear
append using data/matched-csrhub-cstat-northam-cusip9-year.dta
/// CLEAN
*** Indictor variables
foreach variable in in_cstatg in_cstatn {
replace `variable'=0 if `variable'==.
}
tab in_cstat*
/*
(CSTAT |
Global) =1 | (CSTAT North Am) =1
if in | if in CSTAT North
CSTAT | America
Global | 0 1 | Total
-----------+----------------------+----------
0 | 0 22,928 | 22,928
1 | 32,745 0 | 32,745
-----------+----------------------+----------
Total | 32,745 22,928 | 55,673
*/
/// SAVE
compress
save data/merged-matched-csrhub-cstat-global-and-northam.dta, replace
***===============================================================***
* EXPORT MATCHED FIRM IDENTIFIERS TO USE IN WRDS CSTAT DOWNLOAD *
***===============================================================***
/// CSTAT NORTH AMERICA
use data/merged-matched-csrhub-cstat-global-and-northam.dta, clear
*** Keep North America
keep if in_cstatn==1
compress
*** Keep identifiers
keep firm_csrhub conm year cusip8 cusip9 year isin gvkey cik
order firm_csrhub conm year cusip8 cusip9 year isin gvkey cik
*** Keep unique gvkey
bysort gvkey: gen n=_n
tab n
/*
n | Freq. Percent Cum.
------------+-----------------------------------
1 | 4,356 19.00 19.00
2 | 3,733 16.28 35.28
3 | 3,363 14.67 49.95
4 | 2,955 12.89 62.84
5 | 2,549 11.12 73.95
6 | 2,144 9.35 83.30
7 | 1,716 7.48 90.79
8 | 1,170 5.10 95.89
9 | 942 4.11 100.00
------------+-----------------------------------
Total | 22,928 100.00
*/
keep if n==1
drop n
*** Export list of unique gvkey
keep gvkey
export delimited using ///
"data\unique-csrhub-gvkeys-matched-in-csrhub-and-cstat-northam.txt", ///
delimiter(tab) novarnames replace
/// CSTAT GLOBAL
use data/merged-matched-csrhub-cstat-global-and-northam.dta, clear
*** Keep North America
keep if in_cstatg==1
compress
*** Keep identifiers
keep firm_csrhub conm year cusip8 cusip9 year isin gvkey
order firm_csrhub conm year cusip8 cusip9 year isin gvkey
*** Keep unique gvkey
bysort gvkey: gen n=_n
tab n
/*
n | Freq. Percent Cum.
------------+-----------------------------------
1 | 5,736 17.52 17.52
2 | 5,358 16.36 33.88
3 | 4,219 12.88 46.76
4 | 3,633 11.09 57.86
5 | 3,263 9.96 67.82
6 | 2,926 8.94 76.76
7 | 2,561 7.82 84.58
8 | 2,184 6.67 91.25
9 | 1,699 5.19 96.44
10 | 1,166 3.56 100.00
------------+-----------------------------------
Total | 32,745 100.00
*/
keep if n==1
drop n
*** Export list of unique gvkey
keep gvkey
export delimited using ///
"data\unique-csrhub-gvkeys-matched-in-csrhub-and-cstat-global.txt", ///
delimiter(tab) novarnames replace
***===================================================================***
* MERGE NORTHAM MATCHES WITH NORTHAM AND GLOBAL DATA ON GVKEY-YEAR *
***===================================================================***
/// PREPARE CSTAT NORTH AM DATA FOR MERGE
use data/cstat-all-variables-for-gvkeys-in-matched-csrhub-cstat-northam.dta, clear
*** Generate year and drop missing
gen year = fyear
drop if year==.
*** Drop business description
drop busdesc
*** Drop duplicate gvkey year
bysort gvkey year: gen N=_N
tab N
/* N | Freq. Percent Cum.
------------+-----------------------------------
1 | 46,161 67.54 67.54
2 | 22,182 32.46 100.00
------------+-----------------------------------
Total | 68,343 100.00
*/
bysort gvkey year indfmt: gen N2=_N
tab N2
/*
N2 | Freq. Percent Cum.
------------+-----------------------------------
1 | 68,343 100.00 100.00
------------+-----------------------------------
Total | 68,343 100.00
*/
* Drop indfmt FS if duplicate INDL in gvkey year
drop if indfmt=="FS" & N==2
bysort gvkey year: gen N3=_N
tab N3
/*
N3 | Freq. Percent Cum.
------------+-----------------------------------
1 | 57,252 100.00 100.00
------------+-----------------------------------
Total | 57,252 100.00
*/
drop N N2 N3
*** Save
compress
save data/cstat-all-variables-for-gvkeys-in-matched-csrhub-cstat-northam-for-merge.dta, replace
/// PREPARE CSTAT GLOBAL DATA FOR MERGE
use data/cstat-all-variables-for-gvkeys-in-matched-csrhub-cstat-global.dta, clear
*** Generate year and drop duplicates
gen year = fyear
bysort gvkey year: gen N=_N
tab N
/*
N | Freq. Percent Cum.
------------+-----------------------------------
1 | 83,749 99.56 99.56
2 | 370 0.44 100.00
------------+-----------------------------------
Total | 84,119 100.00
*/
drop if N>1
drop N
*** Prep for merge
gen month=fyr
* Fix incorrect curcd codes
replace curcd="VND" if gvkey=="286468" & year==2013
*** Merge on curcd year month
merge m:1 curcd year month using data\cstat-global-exchange-rate-monthly.dta
/*
Result # of obs.
-----------------------------------------
not matched 60,845
from master 3,745 (_merge==1)
from using 57,100 (_merge==2)
matched 80,004 (_merge==3)
-----------------------------------------
*/
drop if _merge==2
drop if _merge==1 /* All 2018 observations */
drop _merge
*** Merge on fromcurm year month to get GBP to USD conversion
merge m:1 fromcurm year month ///
using data\cstat-global-exchange-rate-monthly-gbp-to-usd-only.dta, ///
update assert(1 2 3 4 5)
/*
Result # of obs.
-----------------------------------------
not matched 247
from master 0 (_merge==1)
from using 247 (_merge==2)
matched 80,004
not updated 80,004 (_merge==3)
missing updated 0 (_merge==4)
nonmissing conflict 0 (_merge==5)
-----------------------------------------
*/
drop if _merge==2
drop _merge
/// CONVERT CURRENCY VARIABLES USED IN EMPIRICAL ANALYSIS TO USD
foreach variable in revt dltt at csho ceq {
gen `variable'_usd = (`variable'/exratm)*exratm_gbp_to_usd
label var `variable'_usd "`variable' in United States dollars"
}
*** Save
drop busdesc weburl
compress
save data/cstat-all-variables-for-gvkeys-in-matched-csrhub-cstat-global-for-merge.dta, replace
/// MERGE CSRHUB-CSTAT WITH CSTAT NORTHAM DATA
use data/merged-matched-csrhub-cstat-global-and-northam.dta, clear
*** Merge on gvkey year
merge 1:1 gvkey year using ///
data/cstat-all-variables-for-gvkeys-in-matched-csrhub-cstat-northam-for-merge.dta, ///
gen(_merge_northam)
/*
Result # of obs.
-----------------------------------------
not matched 67,081
from master 32,751 (_merge_northam==1)
from using 34,330 (_merge_northam==2)
matched 22,922 (_merge_northam==3)
-----------------------------------------
*/
drop if _merge_northam==2
/// MERGE CSRHUB-CSTAT WITH CSTAT GLOBAL DATA
*** Merge on gvkey year and update missing values of compustat
merge 1:1 gvkey year using ///
data/cstat-all-variables-for-gvkeys-in-matched-csrhub-cstat-global-for-merge.dta, ///
gen(_merge_global) ///
update assert(1 2 3 4 5)
/*
Result # of obs.
-----------------------------------------
not matched 73,932
from master 22,928 (_merge_global==1)
from using 51,004 (_merge_global==2)
matched 32,745
not updated 0 (_merge_global==3)
missing updated 32,700 (_merge_global==4)
nonmissing conflict 45 (_merge_global==5)
-----------------------------------------
*/
drop if _merge_global==2
/// EXAMINE
*** Ensure all observations merged
tab _merge*, miss
/*
| _merge_global
_merge_northam | master on missing u nonmissin | Total
----------------------+---------------------------------+----------
master only (1) | 11 32,700 40 | 32,751
matched (3) | 22,917 0 5 | 22,922
----------------------+---------------------------------+----------
Total | 22,928 32,700 45 | 55,673
*/
*** List firms that merged in neither
list firm year if _merge_northam==1 & _merge_global==1
/*
+-------------------------------------------------------+
| firm year |
|-------------------------------------------------------|
7977. | TMX Group, Inc. 2011 |
9660. | Science Applications International Corporation 2008 |
10453. | ServiceMaster Company 2009 |
10454. | ServiceMaster Company 2010 |
10455. | ServiceMaster Company 2011 |
|-------------------------------------------------------|
10456. | ServiceMaster Company 2012 |
11450. | Exterran 2012 |
11455. | The Babcock & Wilcox Company 2010 |
11456. | The Babcock & Wilcox Company 2011 |
11457. | The Babcock & Wilcox Company 2012 |
|-------------------------------------------------------|
16570. | Bright Horizons Family Solutions, Inc. 2008 |
+-------------------------------------------------------+
*/
*** List firms that merged in both
list firm year if _merge_northam==3 & _merge_global==5
/*
+-------------------------+
| firm year |
|-------------------------|
8434. | Signet Group PLC 2009 |
8435. | Signet Group PLC 2010 |
8436. | Signet Group PLC 2011 |
8437. | Signet Group PLC 2012 |
8438. | Signet Group PLC 2013 |
+-------------------------+
*/
/// KEEP NEEDED VARIABLES
keep firm year *_lym gvkey fyear industry in_* conm loc naics sic tic ipodate ///
cusip *_usd revt dltt at csho ceq cusip8 xad* xrd* curcd prcc_c prcc_f emp
/// SAVE
compress
save data/matched-csrhub-cstat-northam-and-global-2008-2017, replace
***===============================***
* *
* CREATE FIRM AGE VARIABLE *
* *
***===============================***
/// CSTAT NORTH AMERICA
use data/cstat-north-am-for-age-calculation.dta, clear
* Create age variable
bysort gvkey: gen n=_n
gen start = fyear if n==1
bysort gvkey: replace start=start[_n-1] if start==.
gen age = (fyear - start) + 1
drop n start
* Keep CSRHub years
keep if fyear > 2007
keep if fyear < 2018
* Save
compress
save data/cstat-north-am-for-age-calculation-with-age-variable.dta, replace
/// MERGED MATCHED DATA WITH AGE VARIABLE
use data/matched-csrhub-cstat-northam-and-global-2008-2017, clear
merge 1:1 gvkey fyear using ///
data/cstat-north-am-for-age-calculation-with-age-variable.dta, ///
keepusing(age) update assert(1 2 3 4 5)
/* Result # of obs.
-----------------------------------------
not matched 117,320
from master 29,999 (_merge==1)
from using 87,321 (_merge==2)
matched 25,674
not updated 25,674 (_merge==3)
missing updated 0 (_merge==4)
nonmissing conflict 0 (_merge==5)
-----------------------------------------
*/
drop if _merge==2
/// CSTAT GLOBAL
*** NOTE: CSTAT GLOBAL is unreliable for creating firm age from first
* appearance in the data
* Might use ipodate, but many missing.
/// REPLACE MISSING AGE WITH IPODATE WHERE AVAILABLE
gen ipoyear=year(ipodate)
replace age = (fyear - ipoyear) + 1 if age == .
drop ipoyear
replace age = . if age < 1
***===============================***
* *
* CURRENCY-ADJUST VARIABLES
* *
***===============================***
/* Varibales to adjust: revt dltt at csho ceq */
foreach variable in revt dltt at csho ceq {
replace `variable'_usd=`variable' if in_cstatn==1 & `variable'_usd==.
label var `variable'_usd "(CSTAT) `variable' in USD"
}
/// SAVE
compress
save data/matched-csrhub-cstat-northam-and-global-2008-2017-with-age.dta, replace
***======================================================***
* CREATE TREATMENT VARIABLES
* - Binary +/- deviation from standard deviation
* - Continuous measure number of standard deviations
* - Categorical measure standard deviations rounded to integer
***======================================================***
/// LOAD DATA
clear all
use data/matched-csrhub-cstat-northam-and-global-2008-2017-with-age.dta, clear
/// SET PANEL
encode gvkey, gen(gvkey_num)
xtset gvkey_num year, y
/// Generate year-on-year change in over_rtg
rename over_rtg_lym over_rtg
gen over_rtg_yoy = over_rtg - l.over_rtg
label var over_rtg_yoy "Year-on-year change in CSRHub overall rating"
/// Binary +/- deviation from standard deviation
*** Firm-specific within-firm standard deviation
* Generate firm-specific within-firm over_rtg standard deviation
by gvkey_num: egen sdw = sd(over_rtg)
label var sdw "Within-firm standard deviation of over_rtg for each gvkey_num"
replace sdw=. if over_rtg==.
* Generate treatment variables
foreach threshold in 3 2 1 {
* Treatment event
gen trt`threshold'_sdw_pos = over_rtg_yoy > (`threshold' * sdw) & ///
over_rtg_yoy!=.
label var trt`threshold'_sdw_pos ///
"Treatment = 1 if year-on-year over_rtg > `threshold' std dev of sdw and positive"
replace trt`threshold'_sdw_pos=. if over_rtg==.
gen trt`threshold'_sdw_neg = over_rtg_yoy < (-`threshold' * sdw) & over_rtg_yoy!=.
label var trt`threshold'_sdw_neg "Treatment = 1 if year-on-year over_rtg > `threshold' std dev of sdw and negative"
replace trt`threshold'_sdw_neg=. if over_rtg==.
* Treatment year
by gvkey_num: gen trt_yr_sdw_pos = year if trt`threshold'_sdw_pos==1
sort gvkey_num trt_yr_sdw_pos
by gvkey_num: replace trt_yr_sdw_pos = trt_yr_sdw_pos[_n-1] if _n!=1
replace trt_yr_sdw_pos = . if over_rtg==.
by gvkey_num: gen trt_yr_sdw_neg = year if trt`threshold'_sdw_neg==1
sort gvkey_num trt_yr_sdw_neg
by gvkey_num: replace trt_yr_sdw_neg = trt_yr_sdw_neg[_n-1] if _n!=1
replace trt_yr_sdw_neg = . if over_rtg==.
* Post-treatment years
by gvkey_num: gen post`threshold'_sdw_pos=(year>trt_yr_sdw_pos)
label var post`threshold'_sdw_pos ///
"Indicator =1 if post-treatment year for `threshold' std dev of sdw"
replace post`threshold'_sdw_pos=. if over_rtg==.
by gvkey_num: gen post`threshold'_sdw_neg=(year>trt_yr_sdw_neg)
label var post`threshold'_sdw_neg ///
"Indicator =1 if post-treatment year for `threshold' std dev of sdw"
replace post`threshold'_sdw_neg=. if over_rtg==.
* Treated firms
by gvkey_num: egen trt`threshold'_sdw_pos_grp= max(post`threshold'_sdw_pos)
label var trt`threshold'_sdw_pos_grp ///
"Indicator = 1 if treatment group for `threshold' std dev of sdw"
by gvkey_num: egen trt`threshold'_sdw_neg_grp= max(post`threshold'_sdw_neg)
label var trt`threshold'_sdw_neg_grp ///
"Indicator = 1 if treatment group for `threshold' std dev of sdw"
qui xtset
drop trt_yr_sdw_*
}
/// Continuous measure number of standard deviations
*** Combined
xtset
gen trt_cont_sdw = over_rtg_yoy / sdw
label var trt_cont_sdw "Continuous treatment = over_rtg_yoy / sdw"
*** Positive and negative
* sdw
gen trt_cont_sdw_pos = trt_cont_sdw
replace trt_cont_sdw_pos = . if trt_cont_sdw_pos < 0
label var trt_cont_sdw_pos "Continuous value of trt_cont_sdw if trt_cont_sdw >= 0"
gen trt_cont_sdw_neg = trt_cont_sdw
replace trt_cont_sdw_neg = . if trt_cont_sdw_neg > 0
label var trt_cont_sdw_neg "Continuous value of trt_cont_sdw if trt_cont_sdw <= 0"
/// Categorical measure standard deviations rounded to integer
*** Firm-specific standard deviation
xtset
gen trt_cat_sdw_pos = .
gen trt_cat_sdw_neg = .
foreach threshold in 0 1 2 3 4 5 6 7 {
replace trt_cat_sdw_pos = `threshold' if over_rtg_yoy >= `threshold'*sdw
replace trt_cat_sdw_pos = . if over_rtg_yoy == .
replace trt_cat_sdw_neg = (-1*`threshold') if over_rtg_yoy <= `threshold'*(-1*sdw)
replace trt_cat_sdw_neg = . if over_rtg_yoy == .
}
label var trt_cat_sdw_pos "Categorical treatment = integer of over_rtg_yoy positive std dev from sdw"
label var trt_cat_sdw_neg "Categorical treatment = integer of over_rtg_yoy negative std dev from sdw"
*** These variables should be mutually exclusive except where year-on-year
*** over_rtg change is zero
tab trt_cat_sdw_pos trt_cat_sdw_neg
/*
Categorica |
l |
treatment |
= integer |
of |
over_rtg_y | Categorical treatment
oy | = integer of
positive | over_rtg_yoy negative
std dev | std dev from sdw
from sdw | -7 0 | Total
-----------+----------------------+----------
0 | 0 86 | 86
7 | 21 0 | 21
-----------+----------------------+----------
Total | 21 86 | 107
*/
sum over_rtg_yoy if trt_cat_sdw_pos==7 & trt_cat_sdw_neg==-7
/*
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------