-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cobb Douglas.R
1265 lines (846 loc) · 116 KB
/
Cobb Douglas.R
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
## Load libraries
library(plyr)
library(dplyr)
library(data.table)
library(datasets)
library(igraph)
library(tidyverse)
library(tidygraph)
library(ggraph)
library(graphlayouts)
library(RColorBrewer)
library(cluster)
library(rio)
library(stringr)
library(stringi)
library(qdap)
library(sqldf)
library(lubridate)
library(rlist)
library(purrr)
library(taRifx)
library(devtools)
library(splitstackshape)
library(pbapply)
library(maps)
library(geosphere)
library(ggplot2)
library(shiny)
library(magick)
library(reshape2)
library(ggallin)
library(Hmisc)
library(BSDA)
library(marima)
library(lmtest)
library(dynlm)
library(tseries)
library(XML)
library(xml2)
library(foreach)
library(doParallel)
library(snow)
library(doSNOW)
library(fuzzyjoin)
library(shadowtext)
## import orbis data
EBT <- rio::import("ImportEBT.xlsx", which = "Results")
EBT <- cbind(data.frame("CompanyBVDID" = c(EBT$`BvD ID number`)),EBT[,4:13])
Assets <- rio::import("ImportAssets.xlsx", which = "Results")
Assets <- cbind(data.frame("CompanyBVDID" = c(Assets$`BvD ID number`)),Assets[,4:13])
EmployeeCost <- rio::import("ImportEC.xlsx", which = "Results")
EmployeeCost <- cbind(data.frame("CompanyBVDID" = c(EmployeeCost$`BvD ID number`)),EmployeeCost[,4:13])
BvDIDNorm <- intersect(EBT$CompanyBVDID, Assets$CompanyBVDID)
BvDIDNorm2 <- intersect(BvDIDNorm, EmployeeCost$CompanyBVDID)
BvDIDNorm <- intersect(BvDIDNorm, BvDIDNorm2)
BvDIDNorm <- data.frame("CompanyBVDID" = c(BvDIDNorm))
EBT <- left_join(BvDIDNorm, EBT, by = "CompanyBVDID")
Assets <- left_join(BvDIDNorm, Assets, by = "CompanyBVDID")
EmployeeCost <- left_join(BvDIDNorm, EmployeeCost, by = "CompanyBVDID")
for(i in 1:nrow(EBT)) {
for (j in 3:ncol(EBT)) {
EBT[i,j] <- ifelse(!is.na(as.numeric(EBT[i,j])) & !is.na(as.numeric(Assets[i,j])) & !is.na(as.numeric(EmployeeCost[i,j])), as.numeric(EBT[i,j]) , NA )
}
}
for(i in 1:nrow(Assets)) {
for (j in 3:ncol(Assets)) {
Assets[i,j] <- ifelse(!is.na(as.numeric(EBT[i,j])) & !is.na(as.numeric(Assets[i,j])) & !is.na(as.numeric(EmployeeCost[i,j])), as.numeric(Assets[i,j]) , NA )
}
}
for(i in 1:nrow(EmployeeCost)) {
for (j in 3:ncol(EmployeeCost)) {
EmployeeCost[i,j] <- ifelse(!is.na(as.numeric(EBT[i,j])) & !is.na(as.numeric(Assets[i,j])) & !is.na(as.numeric(EmployeeCost[i,j])), as.numeric(EmployeeCost[i,j]) , NA )
}
}
EmployeeCost$sum <- apply(EmployeeCost,1,function(y) sum(as.numeric(y), na.rm = TRUE))
EBT$sum <- apply(EBT,1,function(y) sum(as.numeric(y), na.rm = TRUE))
Assets$sum <- apply(Assets,1,function(y) sum(as.numeric(y), na.rm = TRUE))
CDEstimate <- lm(log(EBT$sum[EBT$sum > 0]) ~ log(Assets$sum[EBT$sum > 0]) + log(EmployeeCost$sum[EBT$sum > 0]))
CD <- coefficients(CDEstimate)
EmployeeCost$sum <- NULL
EBT$sum <- NULL
Assets$sum <- NULL
CobDou.List <- vector(mode = "list")
CobDou.List[[1]] <- vector(mode = "list")
names(CobDou.List) <- "ByCSH"
#Domestic firms unweightet CobDou
CobDou.List[["DeDom"]][["CompanyList"]] <- vector(mode = "list")
for(i in 2:10) {CobDou.List[["DeDom"]][["CompanyList"]][[(i-1)]] <- EdgelistDeDom[[i]]}
names(CobDou.List[["DeDom"]][["CompanyList"]]) <- paste(2020:2012)
for (i in 1:length(CobDou.List[["DeDom"]][["CompanyList"]])) {
CobDou.List[["DeDom"]][["CompanyList"]][[i]] <- na.omit(unique(as.character(as.matrix(CobDou.List[["DeDom"]][["CompanyList"]][[i]]))))
}
Temp1 <- CobDou.List[["DeDom"]][["CompanyList"]][[1]]
for(i in 2:length(CobDou.List[["DeDom"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,(CobDou.List[["DeDom"]][["CompanyList"]][[i]])))
}
CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]] <- subset(EmployeeCost, EmployeeCost$CompanyBVDID %in% Temp1)
for (i in 1:nrow(CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]])) {
for (j in 3:ncol(CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]])) {
CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]][i,j])) & CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]][i,1] %in% CobDou.List[["DeDom"]][["CompanyList"]][[(j-2)]], CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]][i,j], NA)
}}
CobDou.List[["DeDom"]][["CobDouunweightedEBT"]] <- subset(EBT, EBT$CompanyBVDID %in% Temp1)
for (i in 1:nrow(CobDou.List[["DeDom"]][["CobDouunweightedEBT"]])) {
for (j in 3:ncol(CobDou.List[["DeDom"]][["CobDouunweightedEBT"]])) {
CobDou.List[["DeDom"]][["CobDouunweightedEBT"]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["DeDom"]][["CobDouunweightedEBT"]][i,j])) & CobDou.List[["DeDom"]][["CobDouunweightedEBT"]][i,1] %in% CobDou.List[["DeDom"]][["CompanyList"]][[(j-2)]], CobDou.List[["DeDom"]][["CobDouunweightedEBT"]][i,j], NA)
}}
CobDou.List[["DeDom"]][["CobDouunweightedAssets"]] <- subset(Assets, Assets$CompanyBVDID %in% Temp1)
for (i in 1:nrow(CobDou.List[["DeDom"]][["CobDouunweightedAssets"]])) {
for (j in 3:ncol(CobDou.List[["DeDom"]][["CobDouunweightedAssets"]])) {
CobDou.List[["DeDom"]][["CobDouunweightedAssets"]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["DeDom"]][["CobDouunweightedAssets"]][i,j])) & CobDou.List[["DeDom"]][["CobDouunweightedAssets"]][i,1] %in% CobDou.List[["DeDom"]][["CompanyList"]][[(j-2)]], CobDou.List[["DeDom"]][["CobDouunweightedAssets"]][i,j], NA)
}}
CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]]$sum <- sapply(1:nrow(CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]]), function (y) sum(as.numeric(CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]][y,2:11]) , na.rm = TRUE ))
CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]]$sum[CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]]$sum == 0] <- NA
CobDou.List[["DeDom"]][["CobDouunweightedEBT"]]$sum <- sapply(1:nrow(CobDou.List[["DeDom"]][["CobDouunweightedEBT"]]), function (y) sum(as.numeric(CobDou.List[["DeDom"]][["CobDouunweightedEBT"]][y,2:11]), na.rm = TRUE))
CobDou.List[["DeDom"]][["CobDouunweightedEBT"]]$sum[CobDou.List[["DeDom"]][["CobDouunweightedEBT"]]$sum == 0] <- NA
CobDou.List[["DeDom"]][["CobDouunweightedAssets"]]$sum <- sapply(1:nrow(CobDou.List[["DeDom"]][["CobDouunweightedAssets"]]), function (y) sum(as.numeric(CobDou.List[["DeDom"]][["CobDouunweightedAssets"]][y,2:11]), na.rm = TRUE))
CobDou.List[["DeDom"]][["CobDouunweightedAssets"]]$sum[CobDou.List[["DeDom"]][["CobDouunweightedAssets"]]$sum == 0] <- NA
CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]]$LProf <- sapply(1:nrow(CobDou.List[["DeDom"]][["CobDouunweightedEBT"]]), function (y) CobDou.List[["DeDom"]][["CobDouunweightedEBT"]][[y,12]] / CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]][[y,12]])
CobDou.List[["DeDom"]][["CobDouunweightedAssets"]]$CProf <- sapply(1:nrow(CobDou.List[["DeDom"]][["CobDouunweightedEBT"]]), function (y) CobDou.List[["DeDom"]][["CobDouunweightedEBT"]][[y,12]] / CobDou.List[["DeDom"]][["CobDouunweightedAssets"]][[y,12]])
CobDou.List[["DeDom"]][["CobDouunweighted"]] <- data.frame("ISO" = "DEDOM",
"LProf" = mean(CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]][,13], na.rm = TRUE),
"CProf" = mean(CobDou.List[["DeDom"]][["CobDouunweightedAssets"]][,13], na.rm = TRUE),
"EBT" = mean(CobDou.List[["DeDom"]][["CobDouunweightedEBT"]][,12], na.rm = TRUE),
"EBTCD" = mean(exp(CD[1] + CD[2]*log(CobDou.List[["DeDom"]][["CobDouunweightedAssets"]]$sum) + CD[3]*log(CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]]$sum)), na.rm = TRUE),
"PercentUW" = mean(CobDou.List[["DeDom"]][["CobDouunweightedEBT"]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["DeDom"]][["CobDouunweightedAssets"]]$sum) + CD[3]*log(CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]]$sum)), na.rm = TRUE),
"PercentUW-SD" = sd(CobDou.List[["DeDom"]][["CobDouunweightedEBT"]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["DeDom"]][["CobDouunweightedAssets"]]$sum) + CD[3]*log(CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]]$sum)), na.rm = TRUE),
"PercentW" = sum(CobDou.List[["DeDom"]][["CobDouunweightedEBT"]][,12], na.rm = TRUE) / sum(exp(CD[1] + CD[2]*log(CobDou.List[["DeDom"]][["CobDouunweightedAssets"]]$sum) + CD[3]*log(CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]]$sum)), na.rm = TRUE),
"PercentW-SD" = sqrt(wtd.var(CobDou.List[["DeDom"]][["CobDouunweightedEBT"]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["DeDom"]][["CobDouunweightedAssets"]]$sum) + CD[3]*log(CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]]$sum)), sqrt(exp(CD[1] + CD[2]*log(CobDou.List[["DeDom"]][["CobDouunweightedAssets"]]$sum) + CD[3]*log(CobDou.List[["DeDom"]][["CobDouunweightedEmployeeCost"]]$sum))^2), na.rm = TRUE)),
"n" = length(CobDou.List[["DeDom"]][["CobDouunweightedEBT"]]$sum[!is.na(as.numeric(CobDou.List[["DeDom"]][["CobDouunweightedEBT"]]$sum))])
)
#International firms unweightet CobyDobby
CobDou.List[["DeInt"]][["CompanyList"]] <- vector(mode = "list")
for(i in 2:10) {CobDou.List[["DeInt"]][["CompanyList"]][[(i-1)]] <- EdgelistInt[[i]][sapply(EdgelistInt[[i]], function (y) Nodelist.List[[(i+1)]]$CompanyISO[match(y, Nodelist.List[[(i+1)]]$CompanyBvDID)] == "DE")]}
names(CobDou.List[["DeInt"]][["CompanyList"]]) <- paste(2020:2012)
for (i in 1:length(CobDou.List[["DeInt"]][["CompanyList"]])) {
CobDou.List[["DeInt"]][["CompanyList"]][[i]] <- na.omit(unique(as.character(as.matrix(CobDou.List[["DeInt"]][["CompanyList"]][[i]]))))
}
Temp1 <- CobDou.List[["DeInt"]][["CompanyList"]][[1]]
for(i in 2:length(CobDou.List[["DeInt"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,(CobDou.List[["DeInt"]][["CompanyList"]][[i]])))
}
CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]] <- subset(EmployeeCost, EmployeeCost$CompanyBVDID %in% Temp1)
for (i in 1:nrow(CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]])) {
for (j in 3:ncol(CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]])) {
CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]][i,j])) & CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]][i,1] %in% CobDou.List[["DeInt"]][["CompanyList"]][[(j-2)]], CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]][i,j], NA)
}}
CobDou.List[["DeInt"]][["CobDouunweightedEBT"]] <- subset(EBT, EBT$CompanyBVDID %in% Temp1)
for (i in 1:nrow(CobDou.List[["DeInt"]][["CobDouunweightedEBT"]])) {
for (j in 3:ncol(CobDou.List[["DeInt"]][["CobDouunweightedEBT"]])) {
CobDou.List[["DeInt"]][["CobDouunweightedEBT"]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["DeInt"]][["CobDouunweightedEBT"]][i,j])) & CobDou.List[["DeInt"]][["CobDouunweightedEBT"]][i,1] %in% CobDou.List[["DeInt"]][["CompanyList"]][[(j-2)]], CobDou.List[["DeInt"]][["CobDouunweightedEBT"]][i,j], NA)
}}
CobDou.List[["DeInt"]][["CobDouunweightedAssets"]] <- subset(Assets, Assets$CompanyBVDID %in% Temp1)
for (i in 1:nrow(CobDou.List[["DeInt"]][["CobDouunweightedAssets"]])) {
for (j in 3:ncol(CobDou.List[["DeInt"]][["CobDouunweightedAssets"]])) {
CobDou.List[["DeInt"]][["CobDouunweightedAssets"]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["DeInt"]][["CobDouunweightedAssets"]][i,j])) & CobDou.List[["DeInt"]][["CobDouunweightedAssets"]][i,1] %in% CobDou.List[["DeInt"]][["CompanyList"]][[(j-2)]], CobDou.List[["DeInt"]][["CobDouunweightedAssets"]][i,j], NA)
}}
CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]]$sum <- sapply(1:nrow(CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]]), function (y) sum(as.numeric(CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]][y,2:11]) , na.rm = TRUE ))
CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]]$sum[CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]]$sum == 0] <- NA
CobDou.List[["DeInt"]][["CobDouunweightedEBT"]]$sum <- sapply(1:nrow(CobDou.List[["DeInt"]][["CobDouunweightedEBT"]]), function (y) sum(as.numeric(CobDou.List[["DeInt"]][["CobDouunweightedEBT"]][y,2:11]), na.rm = TRUE))
CobDou.List[["DeInt"]][["CobDouunweightedEBT"]]$sum[CobDou.List[["DeInt"]][["CobDouunweightedEBT"]]$sum == 0] <- NA
CobDou.List[["DeInt"]][["CobDouunweightedAssets"]]$sum <- sapply(1:nrow(CobDou.List[["DeInt"]][["CobDouunweightedAssets"]]), function (y) sum(as.numeric(CobDou.List[["DeInt"]][["CobDouunweightedAssets"]][y,2:11]), na.rm = TRUE))
CobDou.List[["DeInt"]][["CobDouunweightedAssets"]]$sum[CobDou.List[["DeInt"]][["CobDouunweightedAssets"]]$sum == 0] <- NA
CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]]$LProf <- sapply(1:nrow(CobDou.List[["DeInt"]][["CobDouunweightedEBT"]]), function (y) CobDou.List[["DeInt"]][["CobDouunweightedEBT"]][[y,12]] / CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]][[y,12]])
CobDou.List[["DeInt"]][["CobDouunweightedAssets"]]$CProf <- sapply(1:nrow(CobDou.List[["DeInt"]][["CobDouunweightedEBT"]]), function (y) CobDou.List[["DeInt"]][["CobDouunweightedEBT"]][[y,12]] / CobDou.List[["DeInt"]][["CobDouunweightedAssets"]][[y,12]])
CobDou.List[["DeInt"]][["CobDouunweighted"]] <- data.frame("ISO" = "DEINT",
"LProf" = mean(CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]][,13], na.rm = TRUE),
"CProf" = mean(CobDou.List[["DeInt"]][["CobDouunweightedAssets"]][,13], na.rm = TRUE),
"EBT" = mean(CobDou.List[["DeInt"]][["CobDouunweightedEBT"]][,12], na.rm = TRUE),
"EBTCD" = mean(exp(CD[1] + CD[2]*log(CobDou.List[["DeInt"]][["CobDouunweightedAssets"]]$sum) + CD[3]*log(CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]]$sum)), na.rm = TRUE),
"PercentUW" = mean(CobDou.List[["DeInt"]][["CobDouunweightedEBT"]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["DeInt"]][["CobDouunweightedAssets"]]$sum) + CD[3]*log(CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]]$sum)), na.rm = TRUE),
"PercentUW-SD" = sd(CobDou.List[["DeInt"]][["CobDouunweightedEBT"]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["DeInt"]][["CobDouunweightedAssets"]]$sum) + CD[3]*log(CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]]$sum)), na.rm = TRUE),
"PercentW" = sum(CobDou.List[["DeInt"]][["CobDouunweightedEBT"]][,12], na.rm = TRUE) / sum(exp(CD[1] + CD[2]*log(CobDou.List[["DeInt"]][["CobDouunweightedAssets"]]$sum) + CD[3]*log(CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]]$sum)), na.rm = TRUE),
"PercentW-SD" = sqrt(wtd.var(CobDou.List[["DeInt"]][["CobDouunweightedEBT"]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["DeInt"]][["CobDouunweightedAssets"]]$sum) + CD[3]*log(CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]]$sum)), sqrt(exp(CD[1] + CD[2]*log(CobDou.List[["DeInt"]][["CobDouunweightedAssets"]]$sum) + CD[3]*log(CobDou.List[["DeInt"]][["CobDouunweightedEmployeeCost"]]$sum))^2), na.rm = TRUE)),
"n" = length(CobDou.List[["DeInt"]][["CobDouunweightedEBT"]]$sum[!is.na(as.numeric(CobDou.List[["DeInt"]][["CobDouunweightedEBT"]]$sum))])
)
#CSH unweighted LProf
CobDou.List[["ByCSH"]][["CompanyList"]] <- vector(mode = "list")
for(i in 2:10) {CobDou.List[["ByCSH"]][["CompanyList"]][[(i-1)]] <- EdgelistByCSH[[i]]}
names(CobDou.List[["ByCSH"]][["CompanyList"]]) <- paste(2020:2012)
for(i in 1:length(CobDou.List[["ByCSH"]][["CompanyList"]])) {CobDou.List[["ByCSH"]][["CompanyList"]][[i]][["DE"]] <- NULL}
for (i in 1:length(CobDou.List[["ByCSH"]][["CompanyList"]])) {
for (j in 1:length(CobDou.List[["ByCSH"]][["CompanyList"]][[i]])) {
CobDou.List[["ByCSH"]][["CompanyList"]][[i]][[j]] <- CobDou.List[["ByCSH"]][["CompanyList"]][[i]][[j]][cbind(c(FALSE), sapply(2:ncol(CobDou.List[["ByCSH"]][["CompanyList"]][[i]][[j]]), function (y) Nodelist.List[[i+1]]$CompanyISO[match(CobDou.List[["ByCSH"]][["CompanyList"]][[i]][[j]][,y], Nodelist.List[[i+1]]$CompanyBvDID)] == "DE" & Nodelist.List[[i+1]]$CompanyISO[match(CobDou.List[["ByCSH"]][["CompanyList"]][[i]][[j]][,(y-1)], Nodelist.List[[i+1]]$CompanyBvDID)] == names(CobDou.List[["ByCSH"]][["CompanyList"]][[i]][j])))]
}}
CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"][na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"] != "DE"]
for (i in 1:length(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]])) {
Temp1 <- CobDou.List[["ByCSH"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["ByCSH"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["ByCSH"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[i]] <- subset(EmployeeCost, EmployeeCost$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[i]]) == 0 ) {CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]])) {
for (i in 1:nrow(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[x]])) {
for (j in 3:ncol(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[x]])) {
CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[x]][i,j])) & CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[x]][i,1] %in% CobDou.List[["ByCSH"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[x]][i,j], NA)
}}}
CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]])) {
Temp1 <- CobDou.List[["ByCSH"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["ByCSH"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["ByCSH"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[i]] <- subset(EBT, EBT$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[i]]) == 0 ) {CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]])) {
for (i in 1:nrow(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]])) {
for (j in 3:ncol(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]])) {
CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]][i,j])) & CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]][i,1] %in% CobDou.List[["ByCSH"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]][i,j], NA)
}}}
CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]])) {
Temp1 <- CobDou.List[["ByCSH"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["ByCSH"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["ByCSH"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[i]] <- subset(Assets, Assets$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[i]]) == 0 ) {CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]])) {
for (i in 1:nrow(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[x]])) {
for (j in 3:ncol(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[x]])) {
CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[x]][i,j])) & CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[x]][i,1] %in% CobDou.List[["ByCSH"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[x]][i,j], NA)
}}}
for (x in 1:length(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]])) {
CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[x]]), function (y) sum(as.numeric(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[x]][y,2:11]) , na.rm = TRUE ))
CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[x]]$sum[CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[x]]$sum == 0] <- NA
CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]]), function (y) sum(as.numeric(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]][y,2:11]), na.rm = TRUE))
CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]]$sum[CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]]$sum == 0] <- NA
CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[x]]), function (y) sum(as.numeric(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[x]][y,2:11]), na.rm = TRUE))
CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[x]]$sum[CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[x]]$sum == 0] <- NA
CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[x]]$LProf <- sapply(1:nrow(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]]), function (y) CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]][[y,12]] / CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[x]][y,12])
CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[x]]$CProf <- sapply(1:nrow(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]]), function (y) CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[x]][[y,12]] / CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[x]][y,12])
}
CobDou.List[["ByCSH"]][["CobDouunweighted"]] <- data.frame("ISO" = c(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]),
"LProf" = c(sapply(1:length(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[y]][,13], na.rm = TRUE))),
"CProf" = c(sapply(1:length(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[y]][,13], na.rm = TRUE))),
"EBT" = c(sapply(1:length(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[y]][,12], na.rm = TRUE))),
"EBTCD" = c(sapply(1:length(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]]),function(y) mean(exp(CD[1] + CD[2]*log(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentUW" = c(sapply(1:length(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentUW-SD" = c(sapply(1:length(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]]),function(y) sd(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentW" = c(sapply(1:length(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]]),function(y) sum(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[y]][,12], na.rm = TRUE) / sum(exp(CD[1] + CD[2]*log(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentW-SD" = c(sapply(1:length(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]]), function(y) sqrt(wtd.var(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), sqrt(exp(CD[1] + CD[2]*log(CobDou.List[["ByCSH"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["ByCSH"]][["CobDouunweightedEmployeeCost"]][[y]]$sum))^2), na.rm = TRUE)))),
"n" = c(sapply(1:length(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]]),function(y) length(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[y]][,12][!is.na(as.numeric(CobDou.List[["ByCSH"]][["CobDouunweightedEBT"]][[y]][,12]))]))))
#GUO unweighted LProf
CobDou.List[["ByGUO"]][["CompanyList"]] <- vector(mode = "list")
for(i in 2:10) {CobDou.List[["ByGUO"]][["CompanyList"]][[(i-1)]] <- EdgelistByGUO[[i]]}
names(CobDou.List[["ByGUO"]][["CompanyList"]]) <- paste(2020:2012)
for(i in 1:length(CobDou.List[["ByGUO"]][["CompanyList"]])) {CobDou.List[["ByGUO"]][["CompanyList"]][[i]][["DE"]] <- NULL}
for (i in 1:length(CobDou.List[["ByGUO"]][["CompanyList"]])) {
for (j in 1:length(CobDou.List[["ByGUO"]][["CompanyList"]][[i]])) {
CobDou.List[["ByGUO"]][["CompanyList"]][[i]][[j]] <- CobDou.List[["ByGUO"]][["CompanyList"]][[i]][[j]][cbind(c(FALSE), sapply(2:ncol(CobDou.List[["ByGUO"]][["CompanyList"]][[i]][[j]]), function (y) Nodelist.List[[i+1]]$CompanyISO[match(CobDou.List[["ByGUO"]][["CompanyList"]][[i]][[j]][,y], Nodelist.List[[i+1]]$CompanyBvDID)] == "DE" & Nodelist.List[[i+1]]$CompanyISO[match(CobDou.List[["ByGUO"]][["CompanyList"]][[i]][[j]][,1], Nodelist.List[[i+1]]$CompanyBvDID)] == names(CobDou.List[["ByGUO"]][["CompanyList"]][[i]][j])))]
}}
CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]])) {
Temp1 <- CobDou.List[["ByGUO"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["ByGUO"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["ByGUO"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[i]] <- subset(EmployeeCost, EmployeeCost$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[i]]) == 0 ) {CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]])) {
for (i in 1:nrow(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[x]])) {
for (j in 3:ncol(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[x]])) {
CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[x]][i,j])) & CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[x]][i,1] %in% CobDou.List[["ByGUO"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[x]][i,j], NA)
}}}
CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]])) {
Temp1 <- CobDou.List[["ByGUO"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["ByGUO"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["ByGUO"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[i]] <- subset(EBT, EBT$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[i]]) == 0 ) {CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]])) {
for (i in 1:nrow(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]])) {
for (j in 3:ncol(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]])) {
CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]][i,j])) & CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]][i,1] %in% CobDou.List[["ByGUO"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]][i,j], NA)
}}}
CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]])) {
Temp1 <- CobDou.List[["ByGUO"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["ByGUO"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["ByGUO"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[i]] <- subset(Assets, Assets$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[i]]) == 0 ) {CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]])) {
for (i in 1:nrow(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[x]])) {
for (j in 3:ncol(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[x]])) {
CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[x]][i,j])) & CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[x]][i,1] %in% CobDou.List[["ByGUO"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[x]][i,j], NA)
}}}
for (x in 1:length(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]])) {
CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[x]]), function (y) sum(as.numeric(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[x]][y,2:11]) , na.rm = TRUE ))
CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[x]]$sum[CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[x]]$sum == 0] <- NA
CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]]), function (y) sum(as.numeric(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]][y,2:11]), na.rm = TRUE))
CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]]$sum[CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]]$sum == 0] <- NA
CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[x]]), function (y) sum(as.numeric(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[x]][y,2:11]), na.rm = TRUE))
CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[x]]$sum[CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[x]]$sum == 0] <- NA
CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[x]]$LProf <- sapply(1:nrow(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]]), function (y) CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]][[y,12]] / CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[x]][y,12])
CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[x]]$CProf <- sapply(1:nrow(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]]), function (y) CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[x]][[y,12]] / CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[x]][y,12])
}
CobDou.List[["ByGUO"]][["CobDouunweighted"]] <- data.frame("ISO" = c(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]),
"LProf" = c(sapply(1:length(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[y]][,13], na.rm = TRUE))),
"CProf" = c(sapply(1:length(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[y]][,13], na.rm = TRUE))),
"EBT" = c(sapply(1:length(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[y]][,12], na.rm = TRUE))),
"EBTCD" = c(sapply(1:length(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]]),function(y) mean(exp(CD[1] + CD[2]*log(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentUW" = c(sapply(1:length(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentUW-SD" = c(sapply(1:length(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]]),function(y) sd(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentW" = c(sapply(1:length(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]]),function(y) sum(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[y]][,12], na.rm = TRUE) / sum(exp(CD[1] + CD[2]*log(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentW-SD" = c(sapply(1:length(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]]), function(y) sqrt(wtd.var(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), sqrt(exp(CD[1] + CD[2]*log(CobDou.List[["ByGUO"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["ByGUO"]][["CobDouunweightedEmployeeCost"]][[y]]$sum))^2), na.rm = TRUE)))),
"n" = c(sapply(1:length(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]]),function(y) length(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[y]][,12][!is.na(as.numeric(CobDou.List[["ByGUO"]][["CobDouunweightedEBT"]][[y]][,12]))]))))
#anyown unweighted CobDou
CobDou.List[["Byanyown"]][["CompanyList"]] <- vector(mode = "list")
for(i in 2:10) {CobDou.List[["Byanyown"]][["CompanyList"]][[(i-1)]] <- EdgelistByanyown[[i]]}
names(CobDou.List[["Byanyown"]][["CompanyList"]]) <- paste(2020:2012)
for(i in 1:length(CobDou.List[["Byanyown"]][["CompanyList"]])) {CobDou.List[["Byanyown"]][["CompanyList"]][[i]][["DE"]] <- NULL}
for (i in 1:length(CobDou.List[["Byanyown"]][["CompanyList"]])) {
for (j in 1:length(CobDou.List[["Byanyown"]][["CompanyList"]][[i]])) {
if (!isTruthy(CobDou.List[["Byanyown"]][["CompanyList"]][[i]][[j]])) {next}
if (all(is.na(CobDou.List[["Byanyown"]][["CompanyList"]][[i]][[j]][,1]))) {next}
if (nrow(CobDou.List[["Byanyown"]][["CompanyList"]][[i]][[j]]) < 20) {CobDou.List[["Byanyown"]][["CompanyList"]][[i]][[j]] <- rbind(CobDou.List[["Byanyown"]][["CompanyList"]][[i]][[j]],c("DUMMY"),c("DUMMY"),c("DUMMY"),c("DUMMY"))}
Temp1 <- apply(CobDou.List[["Byanyown"]][["CompanyList"]][[i]][[j]],1, function (y) as.numeric(which(Nodelist.List[[i+1]]$CompanyISO[match(y, Nodelist.List[[i+1]]$CompanyBvDID)] == names(CobDou.List[["Byanyown"]][["CompanyList"]][[i]][j]))))
Temp2 <- apply(CobDou.List[["Byanyown"]][["CompanyList"]][[i]][[j]],1, function (y) as.numeric(which(Nodelist.List[[i+1]]$CompanyISO[match(y, Nodelist.List[[i+1]]$CompanyBvDID)] == "DE")))
Temp3 <- sapply(1:length(Temp2), function (z) Temp2[[z]] > first(Temp1[[z]]))
Temp4 <- CobDou.List[["Byanyown"]][["CompanyList"]][[i]][[j]]
for (g in 1:ncol(Temp4)) {Temp4[,g] <- g}
for (g in 1:nrow(Temp4)) {
for(h in 1:ncol(Temp4)) {
Temp4[g,h] <- ifelse(Temp4[g,h] %in% Temp2[[g]], as.character(Temp3[[g]][Temp2[[g]] == Temp4[g,h]]) , "FALSE")
}
}
Temp4 <- sapply(Temp4, function (y) y == "TRUE")
CobDou.List[["Byanyown"]][["CompanyList"]][[i]][[j]] <- CobDou.List[["Byanyown"]][["CompanyList"]][[i]][[j]][Temp4]
}}
CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]])) {
Temp1 <- CobDou.List[["Byanyown"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["Byanyown"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["Byanyown"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[i]] <- subset(EmployeeCost, EmployeeCost$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[i]]) == 0 ) {CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]])) {
for (i in 1:nrow(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[x]])) {
for (j in 3:ncol(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[x]])) {
CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[x]][i,j])) & CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[x]][i,1] %in% CobDou.List[["Byanyown"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[x]][i,j], NA)
}}}
CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]])) {
Temp1 <- CobDou.List[["Byanyown"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["Byanyown"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["Byanyown"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[i]] <- subset(EBT, EBT$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[i]]) == 0 ) {CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]])) {
for (i in 1:nrow(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]])) {
for (j in 3:ncol(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]])) {
CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]][i,j])) & CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]][i,1] %in% CobDou.List[["Byanyown"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]][i,j], NA)
}}}
CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]])) {
Temp1 <- CobDou.List[["Byanyown"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["Byanyown"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["Byanyown"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[i]] <- subset(Assets, Assets$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[i]]) == 0 ) {CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]])) {
for (i in 1:nrow(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[x]])) {
for (j in 3:ncol(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[x]])) {
CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[x]][i,j])) & CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[x]][i,1] %in% CobDou.List[["Byanyown"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[x]][i,j], NA)
}}}
for (x in 1:length(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]])) {
CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[x]]), function (y) sum(as.numeric(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[x]][y,2:11]) , na.rm = TRUE ))
CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[x]]$sum[CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[x]]$sum == 0] <- NA
CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]]), function (y) sum(as.numeric(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]][y,2:11]), na.rm = TRUE))
CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]]$sum[CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]]$sum == 0] <- NA
CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[x]]), function (y) sum(as.numeric(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[x]][y,2:11]), na.rm = TRUE))
CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[x]]$sum[CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[x]]$sum == 0] <- NA
CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[x]]$LProf <- sapply(1:nrow(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]]), function (y) CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]][[y,12]] / CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[x]][y,12])
CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[x]]$CProf <- sapply(1:nrow(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]]), function (y) CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[x]][[y,12]] / CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[x]][y,12])
}
CobDou.List[["Byanyown"]][["CobDouunweighted"]] <- data.frame("ISO" = c(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]),
"LProf" = c(sapply(1:length(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[y]][,13], na.rm = TRUE))),
"CProf" = c(sapply(1:length(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[y]][,13], na.rm = TRUE))),
"EBT" = c(sapply(1:length(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[y]][,12], na.rm = TRUE))),
"EBTCD" = c(sapply(1:length(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]]),function(y) mean(exp(CD[1] + CD[2]*log(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentUW" = c(sapply(1:length(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentUW-SD" = c(sapply(1:length(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]]),function(y) sd(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentW" = c(sapply(1:length(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]]),function(y) sum(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[y]][,12], na.rm = TRUE) / sum(exp(CD[1] + CD[2]*log(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentW-SD" = c(sapply(1:length(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]]), function(y) sqrt(wtd.var(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), sqrt(exp(CD[1] + CD[2]*log(CobDou.List[["Byanyown"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Byanyown"]][["CobDouunweightedEmployeeCost"]][[y]]$sum))^2), na.rm = TRUE)))),
"n" = c(sapply(1:length(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]]),function(y) length(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[y]][,12][!is.na(as.numeric(CobDou.List[["Byanyown"]][["CobDouunweightedEBT"]][[y]][,12]))]))))
#intermed unweighted LProf
CobDou.List[["Byintermed"]][["CompanyList"]] <- vector(mode = "list")
for(i in 2:10) {CobDou.List[["Byintermed"]][["CompanyList"]][[(i-1)]] <- EdgelistByintermed[[i]]}
names(CobDou.List[["Byintermed"]][["CompanyList"]]) <- paste(2020:2012)
for(i in 1:length(CobDou.List[["Byintermed"]][["CompanyList"]])) {CobDou.List[["Byintermed"]][["CompanyList"]][[i]][["DE"]] <- NULL}
for (i in 1:length(CobDou.List[["Byintermed"]][["CompanyList"]])) {
for (j in 1:length(CobDou.List[["Byintermed"]][["CompanyList"]][[i]])) {
if (!isTruthy(CobDou.List[["Byintermed"]][["CompanyList"]][[i]][[j]])) {next}
if (all(is.na(CobDou.List[["Byintermed"]][["CompanyList"]][[i]][[j]][,1]))) {next}
if (nrow(CobDou.List[["Byintermed"]][["CompanyList"]][[i]][[j]]) < 20) {CobDou.List[["Byintermed"]][["CompanyList"]][[i]][[j]] <- rbind(CobDou.List[["Byintermed"]][["CompanyList"]][[i]][[j]],c("DUMMY"),c("DUMMY"),c("DUMMY"),c("DUMMY"))}
Temp1 <- apply(CobDou.List[["Byintermed"]][["CompanyList"]][[i]][[j]],1, function (y) as.numeric(which(Nodelist.List[[i+1]]$CompanyISO[match(y, Nodelist.List[[i+1]]$CompanyBvDID)] == names(CobDou.List[["Byintermed"]][["CompanyList"]][[i]][j]))))
Temp2 <- apply(CobDou.List[["Byintermed"]][["CompanyList"]][[i]][[j]],1, function (y) as.numeric(which(Nodelist.List[[i+1]]$CompanyISO[match(y, Nodelist.List[[i+1]]$CompanyBvDID)] == "DE")))
Temp3 <- sapply(1:length(Temp2), function (z) Temp2[[z]] > first(Temp1[[z]]))
Temp4 <- CobDou.List[["Byintermed"]][["CompanyList"]][[i]][[j]]
for (g in 1:ncol(Temp4)) {Temp4[,g] <- g}
for (g in 1:nrow(Temp4)) {
for(h in 1:ncol(Temp4)) {
Temp4[g,h] <- ifelse(Temp4[g,h] %in% Temp2[[g]], as.character(Temp3[[g]][Temp2[[g]] == Temp4[g,h]]) , "FALSE")
}
}
Temp4 <- sapply(Temp4, function (y) y == "TRUE")
CobDou.List[["Byintermed"]][["CompanyList"]][[i]][[j]] <- CobDou.List[["Byintermed"]][["CompanyList"]][[i]][[j]][Temp4]
}}
CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]])) {
Temp1 <- CobDou.List[["Byintermed"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["Byintermed"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["Byintermed"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[i]] <- subset(EmployeeCost, EmployeeCost$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[i]]) == 0 ) {CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]])) {
for (i in 1:nrow(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[x]])) {
for (j in 3:ncol(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[x]])) {
CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[x]][i,j])) & CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[x]][i,1] %in% CobDou.List[["Byintermed"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[x]][i,j], NA)
}}}
CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]])) {
Temp1 <- CobDou.List[["Byintermed"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["Byintermed"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["Byintermed"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[i]] <- subset(EBT, EBT$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[i]]) == 0 ) {CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]])) {
for (i in 1:nrow(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]])) {
for (j in 3:ncol(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]])) {
CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]][i,j])) & CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]][i,1] %in% CobDou.List[["Byintermed"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]][i,j], NA)
}}}
CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]])) {
Temp1 <- CobDou.List[["Byintermed"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["Byintermed"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["Byintermed"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[i]] <- subset(Assets, Assets$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[i]]) == 0 ) {CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]])) {
for (i in 1:nrow(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[x]])) {
for (j in 3:ncol(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[x]])) {
CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[x]][i,j])) & CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[x]][i,1] %in% CobDou.List[["Byintermed"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[x]][i,j], NA)
}}}
for (x in 1:length(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]])) {
CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[x]]), function (y) sum(as.numeric(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[x]][y,2:11]) , na.rm = TRUE ))
CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[x]]$sum[CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[x]]$sum == 0] <- NA
CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]]), function (y) sum(as.numeric(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]][y,2:11]), na.rm = TRUE))
CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]]$sum[CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]]$sum == 0] <- NA
CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[x]]), function (y) sum(as.numeric(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[x]][y,2:11]), na.rm = TRUE))
CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[x]]$sum[CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[x]]$sum == 0] <- NA
CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[x]]$LProf <- sapply(1:nrow(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]]), function (y) CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]][[y,12]] / CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[x]][y,12])
CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[x]]$CProf <- sapply(1:nrow(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]]), function (y) CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[x]][[y,12]] / CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[x]][y,12])
}
CobDou.List[["Byintermed"]][["CobDouunweighted"]] <- data.frame("ISO" = c(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]),
"LProf" = c(sapply(1:length(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[y]][,13], na.rm = TRUE))),
"CProf" = c(sapply(1:length(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[y]][,13], na.rm = TRUE))),
"EBT" = c(sapply(1:length(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[y]][,12], na.rm = TRUE))),
"EBTCD" = c(sapply(1:length(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]]),function(y) mean(exp(CD[1] + CD[2]*log(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentUW" = c(sapply(1:length(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentUW-SD" = c(sapply(1:length(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]]),function(y) sd(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentW" = c(sapply(1:length(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]]),function(y) sum(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[y]][,12], na.rm = TRUE) / sum(exp(CD[1] + CD[2]*log(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentW-SD" = c(sapply(1:length(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]]), function(y) sqrt(wtd.var(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), sqrt(exp(CD[1] + CD[2]*log(CobDou.List[["Byintermed"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Byintermed"]][["CobDouunweightedEmployeeCost"]][[y]]$sum))^2), na.rm = TRUE)))),
"n" = c(sapply(1:length(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]]),function(y) length(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[y]][,12][!is.na(as.numeric(CobDou.List[["Byintermed"]][["CobDouunweightedEBT"]][[y]][,12]))]))))
#LProf unweighted Loops
CobDou.List[["Loop"]][["CompanyList"]] <- vector(mode = "list")
for(i in 2:10) {CobDou.List[["Loop"]][["CompanyList"]][[(i-1)]] <- EdgelistByanyown[[i]]}
names(CobDou.List[["Loop"]][["CompanyList"]]) <- paste(2020:2012)
for(i in 1:length(CobDou.List[["Loop"]][["CompanyList"]])) {
for (j in 1:length(CobDou.List[["Loop"]][["CompanyList"]][[i]])) {
if (!isTruthy(CobDou.List[["Loop"]][["CompanyList"]][[i]][[j]])) {next}
CobDou.List[["Loop"]][["CompanyList"]][[i]][[j]] <- CobDou.List[["Loop"]][["CompanyList"]][[i]][[j]][ Nodelist.List[[(i+1)]]$CompanyISO[match(CobDou.List[["Loop"]][["CompanyList"]][[i]][[j]][,1], Nodelist.List[[(i+1)]]$CompanyBvDID)] == "DE",]
}
}
for(i in 1:length(CobDou.List[["Loop"]][["CompanyList"]])) {CobDou.List[["Loop"]][["CompanyList"]][[i]][["DE"]] <- NULL}
for (i in 1:length(CobDou.List[["Loop"]][["CompanyList"]])) {
for (j in 1:length(CobDou.List[["Loop"]][["CompanyList"]][[i]])) {
if (!isTruthy(CobDou.List[["Loop"]][["CompanyList"]][[i]][[j]])) {next}
if (all(is.na(CobDou.List[["Loop"]][["CompanyList"]][[i]][[j]][,1]))) {next}
if (nrow(CobDou.List[["Loop"]][["CompanyList"]][[i]][[j]]) < 20) {CobDou.List[["Loop"]][["CompanyList"]][[i]][[j]] <- rbind(CobDou.List[["Loop"]][["CompanyList"]][[i]][[j]],c("DUMMY"),c("DUMMY"),c("DUMMY"),c("DUMMY"))}
Temp1 <- apply(CobDou.List[["Loop"]][["CompanyList"]][[i]][[j]],1, function (y) as.numeric(which(Nodelist.List[[i+1]]$CompanyISO[match(y, Nodelist.List[[i+1]]$CompanyBvDID)] == names(CobDou.List[["Loop"]][["CompanyList"]][[i]][j]))))
Temp2 <- apply(CobDou.List[["Loop"]][["CompanyList"]][[i]][[j]],1, function (y) as.numeric(which(Nodelist.List[[i+1]]$CompanyISO[match(y, Nodelist.List[[i+1]]$CompanyBvDID)] == "DE")))
Temp3 <- sapply(1:length(Temp2), function (z) Temp2[[z]] > first(Temp1[[z]]))
Temp4 <- CobDou.List[["Loop"]][["CompanyList"]][[i]][[j]]
for (g in 1:ncol(Temp4)) {Temp4[,g] <- g}
for (g in 1:nrow(Temp4)) {
for(h in 1:ncol(Temp4)) {
Temp4[g,h] <- ifelse(Temp4[g,h] %in% Temp2[[g]], as.character(Temp3[[g]][Temp2[[g]] == Temp4[g,h]]) , "FALSE")
}
}
Temp4 <- sapply(Temp4, function (y) y == "TRUE")
CobDou.List[["Loop"]][["CompanyList"]][[i]][[j]] <- CobDou.List[["Loop"]][["CompanyList"]][[i]][[j]][Temp4]
}}
CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]])) {
Temp1 <- CobDou.List[["Loop"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["Loop"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["Loop"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[i]] <- subset(EmployeeCost, EmployeeCost$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[i]]) == 0 ) {CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]])) {
for (i in 1:nrow(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[x]])) {
for (j in 3:ncol(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[x]])) {
CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[x]][i,j])) & CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[x]][i,1] %in% CobDou.List[["Loop"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[x]][i,j], NA)
}}}
CobDou.List[["Loop"]][["CobDouunweightedEBT"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["Loop"]][["CobDouunweightedEBT"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["Loop"]][["CobDouunweightedEBT"]])) {
Temp1 <- CobDou.List[["Loop"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["Loop"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["Loop"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[i]] <- subset(EBT, EBT$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[i]]) == 0 ) {CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["Loop"]][["CobDouunweightedEBT"]])) {
for (i in 1:nrow(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]])) {
for (j in 3:ncol(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]])) {
CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]][i,j])) & CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]][i,1] %in% CobDou.List[["Loop"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]][i,j], NA)
}}}
CobDou.List[["Loop"]][["CobDouunweightedAssets"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["Loop"]][["CobDouunweightedAssets"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["Loop"]][["CobDouunweightedAssets"]])) {
Temp1 <- CobDou.List[["Loop"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["Loop"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["Loop"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[i]] <- subset(Assets, Assets$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[i]]) == 0 ) {CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["Loop"]][["CobDouunweightedAssets"]])) {
for (i in 1:nrow(CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[x]])) {
for (j in 3:ncol(CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[x]])) {
CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[x]][i,j])) & CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[x]][i,1] %in% CobDou.List[["Loop"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[x]][i,j], NA)
}}}
for (x in 1:length(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]])) {
CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[x]]), function (y) sum(as.numeric(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[x]][y,2:11]) , na.rm = TRUE ))
CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[x]]$sum[CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[x]]$sum == 0] <- NA
CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]]), function (y) sum(as.numeric(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]][y,2:11]), na.rm = TRUE))
CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]]$sum[CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]]$sum == 0] <- NA
CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[x]]$sum <- sapply(1:nrow(CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[x]]), function (y) sum(as.numeric(CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[x]][y,2:11]), na.rm = TRUE))
CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[x]]$sum[CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[x]]$sum == 0] <- NA
CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[x]]$LProf <- sapply(1:nrow(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]]), function (y) CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]][[y,12]] / CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[x]][y,12])
CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[x]]$CProf <- sapply(1:nrow(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]]), function (y) CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[x]][[y,12]] / CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[x]][y,12])
}
CobDou.List[["Loop"]][["CobDouunweighted"]] <- data.frame("ISO" = c(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]),
"LProf" = c(sapply(1:length(CobDou.List[["Loop"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[y]][,13], na.rm = TRUE))),
"CProf" = c(sapply(1:length(CobDou.List[["Loop"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[y]][,13], na.rm = TRUE))),
"EBT" = c(sapply(1:length(CobDou.List[["Loop"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[y]][,12], na.rm = TRUE))),
"EBTCD" = c(sapply(1:length(CobDou.List[["Loop"]][["CobDouunweightedEBT"]]),function(y) mean(exp(CD[1] + CD[2]*log(CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentUW" = c(sapply(1:length(CobDou.List[["Loop"]][["CobDouunweightedEBT"]]),function(y) mean(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentUW-SD" = c(sapply(1:length(CobDou.List[["Loop"]][["CobDouunweightedEBT"]]),function(y) sd(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentW" = c(sapply(1:length(CobDou.List[["Loop"]][["CobDouunweightedEBT"]]),function(y) sum(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[y]][,12], na.rm = TRUE) / sum(exp(CD[1] + CD[2]*log(CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), na.rm = TRUE))),
"PercentW-SD" = c(sapply(1:length(CobDou.List[["Loop"]][["CobDouunweightedEBT"]]), function(y) sqrt(wtd.var(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[y]][,12] / exp(CD[1] + CD[2]*log(CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[y]]$sum)), sqrt(exp(CD[1] + CD[2]*log(CobDou.List[["Loop"]][["CobDouunweightedAssets"]][[y]]$sum) + CD[3]*log(CobDou.List[["Loop"]][["CobDouunweightedEmployeeCost"]][[y]]$sum))^2), na.rm = TRUE)))),
"n" = c(sapply(1:length(CobDou.List[["Loop"]][["CobDouunweightedEBT"]]),function(y) length(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[y]][,12][!is.na(as.numeric(CobDou.List[["Loop"]][["CobDouunweightedEBT"]][[y]][,12]))]))))
#anysub unweighted LProf
CobDou.List[["Byanysub"]][["CompanyList"]] <- vector(mode = "list")
for(i in 2:10) {CobDou.List[["Byanysub"]][["CompanyList"]][[(i-1)]] <- EdgelistByanysub[[i]]}
names(CobDou.List[["Byanysub"]][["CompanyList"]]) <- paste(2020:2012)
for(i in 1:length(CobDou.List[["Byanysub"]][["CompanyList"]])) {CobDou.List[["Byanysub"]][["CompanyList"]][[i]][["DE"]] <- NULL}
for (i in 1:length(CobDou.List[["Byanysub"]][["CompanyList"]])) {
for (j in 1:length(CobDou.List[["Byanysub"]][["CompanyList"]][[i]])) {
if (all(is.na(CobDou.List[["Byanysub"]][["CompanyList"]][[i]][[j]][,1]))) {next}
if (nrow(CobDou.List[["Byanysub"]][["CompanyList"]][[i]][[j]]) < 20) {CobDou.List[["Byanysub"]][["CompanyList"]][[i]][[j]] <- rbind(CobDou.List[["Byanysub"]][["CompanyList"]][[i]][[j]],c("DUMMY"),c("DUMMY"),c("DUMMY"),c("DUMMY"))}
Temp1 <- apply(CobDou.List[["Byanysub"]][["CompanyList"]][[i]][[j]],1, function (y) as.numeric(which(Nodelist.List[[i+1]]$CompanyISO[match(y, Nodelist.List[[i+1]]$CompanyBvDID)] == names(CobDou.List[["Byanysub"]][["CompanyList"]][[i]][j]))))
Temp2 <- apply(CobDou.List[["Byanysub"]][["CompanyList"]][[i]][[j]],1, function (y) as.numeric(which(Nodelist.List[[i+1]]$CompanyISO[match(y, Nodelist.List[[i+1]]$CompanyBvDID)] == "DE")))
Temp3 <- sapply(1:length(Temp2), function (z) Temp2[[z]] < last(Temp1[[z]]))
Temp4 <- CobDou.List[["Byanysub"]][["CompanyList"]][[i]][[j]]
for (g in 1:ncol(Temp4)) {Temp4[,g] <- g}
for (g in 1:nrow(Temp4)) {
for(h in 1:ncol(Temp4)) {
Temp4[g,h] <- ifelse(Temp4[g,h] %in% Temp2[[g]], as.character(Temp3[[g]][Temp2[[g]] == Temp4[g,h]]) , "FALSE")
}
}
Temp4 <- sapply(Temp4, function (y) y == "TRUE")
CobDou.List[["Byanysub"]][["CompanyList"]][[i]][[j]] <- CobDou.List[["Byanysub"]][["CompanyList"]][[i]][[j]][Temp4]
}}
CobDou.List[["Byanysub"]][["CobDouunweightedEmployeeCost"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["Byanysub"]][["CobDouunweightedEmployeeCost"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["Byanysub"]][["CobDouunweightedEmployeeCost"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["Byanysub"]][["CobDouunweightedEmployeeCost"]])) {
Temp1 <- CobDou.List[["Byanysub"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["Byanysub"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["Byanysub"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["Byanysub"]][["CobDouunweightedEmployeeCost"]][[i]] <- subset(EmployeeCost, EmployeeCost$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["Byanysub"]][["CobDouunweightedEmployeeCost"]][[i]]) == 0 ) {CobDou.List[["Byanysub"]][["CobDouunweightedEmployeeCost"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["Byanysub"]][["CobDouunweightedEmployeeCost"]])) {
for (i in 1:nrow(CobDou.List[["Byanysub"]][["CobDouunweightedEmployeeCost"]][[x]])) {
for (j in 3:ncol(CobDou.List[["Byanysub"]][["CobDouunweightedEmployeeCost"]][[x]])) {
CobDou.List[["Byanysub"]][["CobDouunweightedEmployeeCost"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["Byanysub"]][["CobDouunweightedEmployeeCost"]][[x]][i,j])) & CobDou.List[["Byanysub"]][["CobDouunweightedEmployeeCost"]][[x]][i,1] %in% CobDou.List[["Byanysub"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["Byanysub"]][["CobDouunweightedEmployeeCost"]][[x]][i,j], NA)
}}}
CobDou.List[["Byanysub"]][["CobDouunweightedEBT"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["Byanysub"]][["CobDouunweightedEBT"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["Byanysub"]][["CobDouunweightedEBT"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["Byanysub"]][["CobDouunweightedEBT"]])) {
Temp1 <- CobDou.List[["Byanysub"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["Byanysub"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["Byanysub"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["Byanysub"]][["CobDouunweightedEBT"]][[i]] <- subset(EBT, EBT$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["Byanysub"]][["CobDouunweightedEBT"]][[i]]) == 0 ) {CobDou.List[["Byanysub"]][["CobDouunweightedEBT"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["Byanysub"]][["CobDouunweightedEBT"]])) {
for (i in 1:nrow(CobDou.List[["Byanysub"]][["CobDouunweightedEBT"]][[x]])) {
for (j in 3:ncol(CobDou.List[["Byanysub"]][["CobDouunweightedEBT"]][[x]])) {
CobDou.List[["Byanysub"]][["CobDouunweightedEBT"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["Byanysub"]][["CobDouunweightedEBT"]][[x]][i,j])) & CobDou.List[["Byanysub"]][["CobDouunweightedEBT"]][[x]][i,1] %in% CobDou.List[["Byanysub"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["Byanysub"]][["CobDouunweightedEBT"]][[x]][i,j], NA)
}}}
CobDou.List[["Byanysub"]][["CobDouunweightedAssets"]] <- vector(mode = "list")
for (i in 1:length(na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"])) {CobDou.List[["Byanysub"]][["CobDouunweightedAssets"]][[i]] <- data.frame("CompanyBVDID" = c(NA))}
names(CobDou.List[["Byanysub"]][["CobDouunweightedAssets"]]) <- na.omit(unique(NodelistALL$CompanyISO))[na.omit(unique(NodelistALL$CompanyISO)) != "DE"]
for (i in 1:length(CobDou.List[["Byanysub"]][["CobDouunweightedAssets"]])) {
Temp1 <- CobDou.List[["Byanysub"]][["CompanyList"]][[1]][[i]]
for (j in 2:length(CobDou.List[["Byanysub"]][["CompanyList"]])) {
Temp1 <- unique(c(Temp1,CobDou.List[["Byanysub"]][["CompanyList"]][[j]][[i]]))
}
CobDou.List[["Byanysub"]][["CobDouunweightedAssets"]][[i]] <- subset(Assets, Assets$CompanyBVDID %in% Temp1)
if (nrow(CobDou.List[["Byanysub"]][["CobDouunweightedAssets"]][[i]]) == 0 ) {CobDou.List[["Byanysub"]][["CobDouunweightedAssets"]][[i]][1,] <- NA}
}
for (x in 1:length(CobDou.List[["Byanysub"]][["CobDouunweightedAssets"]])) {
for (i in 1:nrow(CobDou.List[["Byanysub"]][["CobDouunweightedAssets"]][[x]])) {
for (j in 3:ncol(CobDou.List[["Byanysub"]][["CobDouunweightedAssets"]][[x]])) {
CobDou.List[["Byanysub"]][["CobDouunweightedAssets"]][[x]][i,j] <- ifelse(!is.na(as.numeric(CobDou.List[["Byanysub"]][["CobDouunweightedAssets"]][[x]][i,j])) & CobDou.List[["Byanysub"]][["CobDouunweightedAssets"]][[x]][i,1] %in% CobDou.List[["Byanysub"]][["CompanyList"]][[(j-2)]][[x]], CobDou.List[["Byanysub"]][["CobDouunweightedAssets"]][[x]][i,j], NA)