1 Recap the R-Basics

3 Learn (the regression modelling) by example

A. Download and import the datasheet

  • All files are available at this shared folder

  • For this Tutorial, download the file “FU902-dataset-01” to your local computer

  • Set a working directory using the command setwd(“C:/…/…/…/…”); where you have the downloaded file stored and where outputs will be exported (e.g., setwd(“C:/Users/MyPC/Documents/R/Paper01”)

  • Upload the download file from the working directory (for how to upload data in other formats, like txt, csv, please refer to the R-Basics)

library(readxl)
dataset <- as.data.frame(read_excel("FU902-dataset-01.xlsx"))
attach(dataset)
head(dataset)
##   Firm Year Industry Country Profit Revenue Orders ESG
## 1    1 2017 Services     ESP  68761  435676  1.038  58
## 2    1 2018 Services     ESP  27267  220696  0.976  39
## 3    1 2019 Services     ESP  69729  255782  1.111  85
## 4    1 2020 Services     ESP  87363  513659  1.055  63
## 5    1 2021 Services     ESP  74637  615406  1.013  50
## 6    1 2022 Services     ESP 139750  627756  1.112  85

B. Descriptive statistics

  1. Calculate the descriptive statistics across countries
library(psych)
describeBy(dataset, Country)
## 
##  Descriptive statistics by group 
## group: CZE
##           vars  n      mean        sd    median   trimmed       mad       min
## Firm         1 60     38.80     12.10     42.00     41.75      5.19      5.00
## Year         2 60   2019.50      1.72   2019.50   2019.50      2.22   2017.00
## Industry*    3 60      3.00      1.28      3.00      3.00      1.48      1.00
## Country*     4 60      1.00      0.00      1.00      1.00      0.00      1.00
## Profit       5 60  46665.45  40407.52  34165.50  42318.92  27075.24 -20361.00
## Revenue      6 60 341549.33 153517.89 316265.00 333537.83 177058.76 118035.00
## Orders       7 60      0.99      0.03      0.99      0.99      0.04      0.92
## ESG          8 60     48.42     16.42     43.50     47.77     12.60     15.00
##                 max     range  skew kurtosis       se
## Firm          49.00     44.00 -2.06     3.18     1.56
## Year        2022.00      5.00  0.00    -1.33     0.22
## Industry*      5.00      4.00  0.29    -1.04     0.16
## Country*       1.00      0.00   NaN      NaN     0.00
## Profit    161901.00 182262.00  1.02     0.71  5216.59
## Revenue   727096.00 609061.00  0.43    -0.79 19819.07
## Orders         1.07      0.15 -0.03    -0.34     0.00
## ESG           85.00     70.00  0.36    -0.34     2.12
## ------------------------------------------------------------ 
## group: ESP
##           vars  n      mean        sd   median   trimmed       mad       min
## Firm         1 72     25.67     13.65     29.0     26.28     14.83      1.00
## Year         2 72   2019.50      1.72   2019.5   2019.50      2.22   2017.00
## Industry*    3 72      2.42      0.96      3.0      2.41      0.74      1.00
## Country*     4 72      1.00      0.00      1.0      1.00      0.00      1.00
## Profit       5 72  59288.17  41743.17  50939.5  54950.24  39711.44  -2351.00
## Revenue      6 72 391353.92 171825.62 402012.5 387911.74 230438.29 111562.00
## Orders       7 72      1.01      0.05      1.0      1.00      0.05      0.92
## ESG          8 72     50.86     14.77     49.0     49.95     12.60     17.00
##                 max     range  skew kurtosis       se
## Firm          45.00     44.00 -0.38    -1.08     1.61
## Year        2022.00      5.00  0.00    -1.32     0.20
## Industry*      4.00      3.00 -0.33    -1.13     0.11
## Country*       1.00      0.00   NaN      NaN     0.00
## Profit    195802.00 198153.00  0.98     0.89  4919.48
## Revenue   717552.00 605990.00  0.10    -1.27 20249.84
## Orders         1.21      0.29  0.96     1.10     0.01
## ESG           90.00     73.00  0.51     0.09     1.74
## ------------------------------------------------------------ 
## group: NED
##           vars   n      mean        sd    median   trimmed       mad       min
## Firm         1 108     21.50     10.91     21.50     20.86     10.38      3.00
## Year         2 108   2019.50      1.72   2019.50   2019.50      2.22   2017.00
## Industry*    3 108      3.33      1.21      3.50      3.41      0.74      1.00
## Country*     4 108      1.00      0.00      1.00      1.00      0.00      1.00
## Profit       5 108  55115.19  44107.13  44900.00  51342.93  40479.43 -17488.00
## Revenue      6 108 381606.18 171534.37 365409.50 379468.38 217206.09 107043.00
## Orders       7 108      1.02      0.06      1.02      1.02      0.06      0.87
## ESG          8 108     48.66     15.90     47.00     47.86     13.34     16.00
##                 max     range  skew kurtosis       se
## Firm          48.00     45.00  0.50     0.05     1.05
## Year        2022.00      5.00  0.00    -1.30     0.17
## Industry*      5.00      4.00 -0.46    -0.65     0.12
## Country*       1.00      0.00   NaN      NaN     0.00
## Profit    177800.00 195288.00  0.78    -0.05  4244.21
## Revenue   741595.00 634552.00  0.12    -1.23 16505.90
## Orders         1.14      0.26  0.08    -0.57     0.01
## ESG           95.00     79.00  0.46     0.20     1.53
## ------------------------------------------------------------ 
## group: SWE
##           vars  n      mean        sd   median   trimmed       mad       min
## Firm         1 66     22.09     16.95     16.0     21.11     17.79      2.00
## Year         2 66   2019.50      1.72   2019.5   2019.50      2.22   2017.00
## Industry*    3 66      2.45      1.17      2.0      2.33      1.48      1.00
## Country*     4 66      1.00      0.00      1.0      1.00      0.00      1.00
## Profit       5 66  52268.59  47728.59  41557.5  47235.26  44079.92 -41478.00
## Revenue      6 66 377650.41 160171.43 374480.5 375495.63 198617.25 122046.00
## Orders       7 66      1.01      0.06      1.0      1.00      0.05      0.89
## ESG          8 66     48.65     16.92     46.0     47.59     11.86     16.00
##                 max     range skew kurtosis       se
## Firm          51.00     49.00 0.56    -1.13     2.09
## Year        2022.00      5.00 0.00    -1.32     0.21
## Industry*      5.00      4.00 0.80    -0.19     0.14
## Country*       1.00      0.00  NaN      NaN     0.00
## Profit    181660.00 223138.00 0.91     0.44  5874.98
## Revenue   704345.00 582299.00 0.10    -1.27 19715.74
## Orders         1.16      0.27 0.79     0.14     0.01
## ESG           97.00     81.00 0.67     0.40     2.08
  1. Calculate the descriptive statistics across industries
describeBy(dataset, Industry)
## 
##  Descriptive statistics by group 
## group: ICT
##           vars  n      mean        sd   median   trimmed       mad       min
## Firm         1 30     31.80     16.47     38.0     32.88     19.27      4.00
## Year         2 30   2019.50      1.74   2019.5   2019.50      2.22   2017.00
## Industry*    3 30      1.00      0.00      1.0      1.00      0.00      1.00
## Country*     4 30      2.20      0.76      2.0      2.25      1.48      1.00
## Profit       5 30  46424.43  42346.68  32678.5  42482.00  39989.43 -17488.00
## Revenue      6 30 341190.07 139867.82 335716.0 340168.96 183136.68 122046.00
## Orders       7 30      1.00      0.04      1.0      0.99      0.04      0.94
## ESG          8 30     48.33     11.35     47.5     47.25     12.60     29.00
##                 max     range  skew kurtosis       se
## Firm          51.00     47.00 -0.61    -0.98     3.01
## Year        2022.00      5.00  0.00    -1.38     0.32
## Industry*      1.00      0.00   NaN      NaN     0.00
## Country*       3.00      2.00 -0.33    -1.27     0.14
## Profit    159744.00 177232.00  0.78    -0.09  7731.41
## Revenue   595021.00 472975.00  0.18    -1.35 25536.25
## Orders         1.12      0.18  0.81     0.03     0.01
## ESG           73.00     44.00  0.62    -0.38     2.07
## ------------------------------------------------------------ 
## group: Manufacturing
##           vars  n      mean        sd    median   trimmed       mad       min
## Firm         1 78     27.77     17.09     31.00     28.16     20.76      2.00
## Year         2 78   2019.50      1.72   2019.50   2019.50      2.22   2017.00
## Industry*    3 78      1.00      0.00      1.00      1.00      0.00      1.00
## Country*     4 78      2.69      1.21      3.00      2.73      1.48      1.00
## Profit       5 78  47364.54  42649.50  36107.50  42990.47  35153.93 -41478.00
## Revenue      6 78 368430.49 163544.62 355289.00 364098.42 208491.37 118035.00
## Orders       7 78      1.00      0.05      0.99      1.00      0.04      0.89
## ESG          8 78     47.90     17.08     44.00     46.86     14.83     15.00
##                 max     range  skew kurtosis       se
## Firm          50.00     48.00 -0.31    -1.43     1.94
## Year        2022.00      5.00  0.00    -1.31     0.19
## Industry*      1.00      0.00   NaN      NaN     0.00
## Country*       4.00      3.00 -0.19    -1.56     0.14
## Profit    181660.00 223138.00  1.00     0.94  4829.10
## Revenue   704345.00 586310.00  0.20    -1.24 18517.78
## Orders         1.15      0.26  0.96     0.90     0.01
## ESG           97.00     82.00  0.60     0.28     1.93
## ------------------------------------------------------------ 
## group: Mining
##           vars  n      mean        sd    median   trimmed       mad       min
## Firm         1 72     24.67     12.97     22.00     24.10     11.12      8.00
## Year         2 72   2019.50      1.72   2019.50   2019.50      2.22   2017.00
## Industry*    3 72      1.00      0.00      1.00      1.00      0.00      1.00
## Country*     4 72      2.50      1.05      3.00      2.50      1.48      1.00
## Profit       5 72  59115.46  48335.25  48511.00  54980.86  43935.37 -20361.00
## Revenue      6 72 407734.46 173533.15 433565.00 406913.71 209018.43 111562.00
## Orders       7 72      1.02      0.06      1.02      1.02      0.05      0.89
## ESG          8 72     54.04     16.83     50.50     53.47     15.57     18.00
##                 max     range  skew kurtosis       se
## Firm          46.00     38.00  0.47    -1.19     1.53
## Year        2022.00      5.00  0.00    -1.32     0.20
## Industry*      1.00      0.00   NaN      NaN     0.00
## Country*       4.00      3.00 -0.22    -1.22     0.12
## Profit    177800.00 198161.00  0.72    -0.40  5696.36
## Revenue   741595.00 630033.00 -0.01    -1.17 20451.08
## Orders         1.14      0.25  0.28    -0.54     0.01
## ESG           95.00     77.00  0.30    -0.36     1.98
## ------------------------------------------------------------ 
## group: Services
##           vars  n      mean        sd    median   trimmed       mad       min
## Firm         1 84     26.64     13.74     26.50     26.88     16.31      1.00
## Year         2 84   2019.50      1.72   2019.50   2019.50      2.22   2017.00
## Industry*    3 84      1.00      0.00      1.00      1.00      0.00      1.00
## Country*     4 84      2.50      0.74      2.50      2.50      0.74      1.00
## Profit       5 84  57867.13  42439.02  53417.50  53974.62  38295.56 -14025.00
## Revenue      6 84 365588.99 172529.43 362280.50 359109.51 208808.64 107043.00
## Orders       7 84      1.01      0.06      1.01      1.01      0.06      0.87
## ESG          8 84     46.93     13.33     44.50     46.50     14.08     16.00
##                 max     range  skew kurtosis       se
## Firm          48.00     47.00 -0.07    -0.98     1.50
## Year        2022.00      5.00  0.00    -1.31     0.19
## Industry*      1.00      0.00   NaN      NaN     0.00
## Country*       4.00      3.00  0.00    -0.36     0.08
## Profit    195802.00 209827.00  0.93     0.83  4630.48
## Revenue   717552.00 610509.00  0.30    -1.16 18824.50
## Orders         1.21      0.34  0.59     0.44     0.01
## ESG           85.00     69.00  0.39     0.47     1.45
## ------------------------------------------------------------ 
## group: Utility
##           vars  n      mean        sd    median   trimmed       mad       min
## Firm         1 42     19.57     11.22     19.00     19.47     17.79      5.00
## Year         2 42   2019.50      1.73   2019.50   2019.50      2.22   2017.00
## Industry*    3 42      1.00      0.00      1.00      1.00      0.00      1.00
## Country*     4 42      2.43      1.06      3.00      2.41      1.48      1.00
## Profit       5 42  53964.83  40160.99  43756.50  49955.68  32646.11  -9245.00
## Revenue      6 42 375457.14 158993.22 358653.50 376042.12 195319.95 123638.00
## Orders       7 42      1.01      0.05      1.01      1.01      0.04      0.92
## ESG          8 42     47.95     18.44     47.50     47.35     12.60     15.00
##                 max     range  skew kurtosis       se
## Firm          35.00     30.00  0.15    -1.46     1.73
## Year        2022.00      5.00  0.00    -1.35     0.27
## Industry*      1.00      0.00   NaN      NaN     0.00
## Country*       4.00      3.00 -0.18    -1.34     0.16
## Profit    179293.00 188538.00  1.00     0.74  6196.98
## Revenue   632005.00 508367.00  0.03    -1.35 24533.19
## Orders         1.16      0.24  0.74     0.50     0.01
## ESG           89.00     74.00  0.39    -0.54     2.85

C. Inspect correlations

  1. What is the correlation coefficient between Profits and ESG Score?
cor(Profit, ESG, method = "pearson")
## [1] 0.308978
  1. Is the correlation between Profits and ESG Score statistically significant?
cor.test(Profit, ESG, method = "pearson")
## 
##  Pearson's product-moment correlation
## 
## data:  Profit and ESG
## t = 5.6644, df = 304, p-value = 3.421e-08
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.2039190 0.4070015
## sample estimates:
##      cor 
## 0.308978
  • Alternatively, rcorr() function from the Hmisc package can be applied both for the correlation and test
library(Hmisc)
rcorr(Profit, ESG, type="pearson")
##      x    y
## x 1.00 0.31
## y 0.31 1.00
## 
## n= 306 
## 
## 
## P
##   x  y 
## x     0
## y  0
  1. Calculate correlation coefficient for all variables
  • Please note that the “dataset” includes two non-numeric variables (Industry & Country), therefore the codes cor(dataset) or rcorr(dataset) cannot calculate the correlation matrix (try it)
sapply(dataset, class)
##        Firm        Year    Industry     Country      Profit     Revenue 
##   "numeric"   "numeric" "character" "character"   "numeric"   "numeric" 
##      Orders         ESG 
##   "numeric"   "numeric"
  • How to fix it? Put the character variables as factors!
cor(cbind(Firm, Year, as.factor(Industry), as.factor(Country), Profit, Revenue, Orders, ESG), method = "pearson")
##                Firm         Year                              Profit
## Firm     1.00000000  0.000000000 -0.17853656 -0.38065308 -0.03008774
## Year     0.00000000  1.000000000  0.00000000  0.00000000  0.05853613
##         -0.17853656  0.000000000  1.00000000 -0.14050003  0.08055415
##         -0.38065308  0.000000000 -0.14050003  1.00000000  0.02636924
## Profit  -0.03008774  0.058536131  0.08055415  0.02636924  1.00000000
## Revenue -0.03718055 -0.005873849  0.02910782  0.05802155  0.67161871
## Orders  -0.32345668  0.001889944  0.07354719  0.14154164  0.52607706
## ESG     -0.03896236  0.051334904 -0.02377912 -0.01412567  0.30897803
##              Revenue       Orders         ESG
## Firm    -0.037180546 -0.323456682 -0.03896236
## Year    -0.005873849  0.001889944  0.05133490
##          0.029107819  0.073547190 -0.02377912
##          0.058021554  0.141541636 -0.01412567
## Profit   0.671618714  0.526077060  0.30897803
## Revenue  1.000000000  0.204336248  0.14630965
## Orders   0.204336248  1.000000000  0.30523890
## ESG      0.146309651  0.305238901  1.00000000
rcorr(cbind(Firm, Year, as.factor(Industry), as.factor(Country), Profit, Revenue, Orders, ESG), type="pearson")
##          Firm  Year             Profit Revenue Orders   ESG
## Firm     1.00  0.00 -0.18 -0.38  -0.03   -0.04  -0.32 -0.04
## Year     0.00  1.00  0.00  0.00   0.06   -0.01   0.00  0.05
##         -0.18  0.00  1.00 -0.14   0.08    0.03   0.07 -0.02
##         -0.38  0.00 -0.14  1.00   0.03    0.06   0.14 -0.01
## Profit  -0.03  0.06  0.08  0.03   1.00    0.67   0.53  0.31
## Revenue -0.04 -0.01  0.03  0.06   0.67    1.00   0.20  0.15
## Orders  -0.32  0.00  0.07  0.14   0.53    0.20   1.00  0.31
## ESG     -0.04  0.05 -0.02 -0.01   0.31    0.15   0.31  1.00
## 
## n= 306 
## 
## 
## P
##         Firm   Year                 Profit Revenue Orders ESG   
## Firm           1.0000 0.0017 0.0000 0.6001 0.5170  0.0000 0.4971
## Year    1.0000        1.0000 1.0000 0.3074 0.9185  0.9737 0.3708
##         0.0017 1.0000        0.0139 0.1598 0.6120  0.1995 0.6786
##         0.0000 1.0000 0.0139        0.6459 0.3117  0.0132 0.8056
## Profit  0.6001 0.3074 0.1598 0.6459        0.0000  0.0000 0.0000
## Revenue 0.5170 0.9185 0.6120 0.3117 0.0000         0.0003 0.0104
## Orders  0.0000 0.9737 0.1995 0.0132 0.0000 0.0003         0.0000
## ESG     0.4971 0.3708 0.6786 0.8056 0.0000 0.0104  0.0000
  • Please note that Industry and Country variable names are not printed (their printing would require creating another dataset in which those two variables are transformed to numeric ones)

  • An additional option to calculate the correlation matrix is offered by the package “corrr” (but Industry & Country would not be included in the output)

library(corrr)
correlate(dataset, method = "pearson", diagonal = 1)
## Non-numeric variables removed from input: `Industry`, and `Country`
## Correlation computed with
## • Method: 'pearson'
## • Missing treated using: 'pairwise.complete.obs'
## # A tibble: 6 × 7
##   term       Firm     Year  Profit  Revenue   Orders     ESG
##   <chr>     <dbl>    <dbl>   <dbl>    <dbl>    <dbl>   <dbl>
## 1 Firm     1       0       -0.0301 -0.0372  -0.323   -0.0390
## 2 Year     0       1        0.0585 -0.00587  0.00189  0.0513
## 3 Profit  -0.0301  0.0585   1       0.672    0.526    0.309 
## 4 Revenue -0.0372 -0.00587  0.672   1        0.204    0.146 
## 5 Orders  -0.323   0.00189  0.526   0.204    1        0.305 
## 6 ESG     -0.0390  0.0513   0.309   0.146    0.305    1
  • Finally, the package “correlation” can do everything (even factors). The output is not so handsome, but it provides the confidence intervals in addition to the previous methods
library(correlation)
correlation(dataset, include_factors = TRUE, method = "pearson")
## # Correlation Matrix (pearson-method)
## 
## Parameter1             |             Parameter2 |         r |         95% CI | t(304) |         p
## -------------------------------------------------------------------------------------------------
## Firm                   |                   Year |      0.00 | [-0.11,  0.11] |   0.00 | > .999   
## Firm                   |           Industry.ICT |      0.13 | [ 0.02,  0.24] |   2.28 | > .999   
## Firm                   | Industry.Manufacturing |      0.07 | [-0.04,  0.18] |   1.23 | > .999   
## Firm                   |        Industry.Mining |     -0.05 | [-0.16,  0.06] |  -0.88 | > .999   
## Firm                   |      Industry.Services |      0.03 | [-0.09,  0.14] |   0.47 | > .999   
## Firm                   |       Industry.Utility |     -0.17 | [-0.28, -0.06] |  -3.08 | 0.167    
## Firm                   |            Country.CZE |      0.43 | [ 0.33,  0.52] |   8.29 | < .001***
## Firm                   |            Country.ESP |     -0.01 | [-0.12,  0.10] |  -0.22 | > .999   
## Firm                   |            Country.NED |     -0.23 | [-0.33, -0.12] |  -4.04 | 0.006**  
## Firm                   |            Country.SWE |     -0.14 | [-0.25, -0.03] |  -2.45 | > .999   
## Firm                   |                 Profit |     -0.03 | [-0.14,  0.08] |  -0.52 | > .999   
## Firm                   |                Revenue |     -0.04 | [-0.15,  0.08] |  -0.65 | > .999   
## Firm                   |                 Orders |     -0.32 | [-0.42, -0.22] |  -5.96 | < .001***
## Firm                   |                    ESG |     -0.04 | [-0.15,  0.07] |  -0.68 | > .999   
## Year                   |           Industry.ICT |      0.00 | [-0.11,  0.11] |   0.00 | > .999   
## Year                   | Industry.Manufacturing |      0.00 | [-0.11,  0.11] |   0.00 | > .999   
## Year                   |        Industry.Mining |      0.00 | [-0.11,  0.11] |   0.00 | > .999   
## Year                   |      Industry.Services |      0.00 | [-0.11,  0.11] |   0.00 | > .999   
## Year                   |       Industry.Utility |      0.00 | [-0.11,  0.11] |   0.00 | > .999   
## Year                   |            Country.CZE |      0.00 | [-0.11,  0.11] |   0.00 | > .999   
## Year                   |            Country.ESP |      0.00 | [-0.11,  0.11] |   0.00 | > .999   
## Year                   |            Country.NED |      0.00 | [-0.11,  0.11] |   0.00 | > .999   
## Year                   |            Country.SWE |      0.00 | [-0.11,  0.11] |   0.00 | > .999   
## Year                   |                 Profit |      0.06 | [-0.05,  0.17] |   1.02 | > .999   
## Year                   |                Revenue | -5.87e-03 | [-0.12,  0.11] |  -0.10 | > .999   
## Year                   |                 Orders |  1.89e-03 | [-0.11,  0.11] |   0.03 | > .999   
## Year                   |                    ESG |      0.05 | [-0.06,  0.16] |   0.90 | > .999   
## Industry.ICT           | Industry.Manufacturing |     -0.19 | [-0.30, -0.08] |  -3.43 | 0.055    
## Industry.ICT           |        Industry.Mining |     -0.18 | [-0.29, -0.07] |  -3.24 | 0.101    
## Industry.ICT           |      Industry.Services |     -0.20 | [-0.31, -0.09] |  -3.61 | 0.029*   
## Industry.ICT           |       Industry.Utility |     -0.13 | [-0.24, -0.02] |  -2.31 | > .999   
## Industry.ICT           |            Country.CZE |  3.26e-03 | [-0.11,  0.12] |   0.06 | > .999   
## Industry.ICT           |            Country.ESP |     -0.18 | [-0.29, -0.07] |  -3.24 | 0.101    
## Industry.ICT           |            Country.NED |      0.03 | [-0.08,  0.14] |   0.57 | > .999   
## Industry.ICT           |            Country.SWE |      0.15 | [ 0.04,  0.26] |   2.60 | 0.695    
## Industry.ICT           |                 Profit |     -0.06 | [-0.17,  0.06] |  -0.98 | > .999   
## Industry.ICT           |                Revenue |     -0.07 | [-0.18,  0.04] |  -1.18 | > .999   
## Industry.ICT           |                 Orders |     -0.07 | [-0.18,  0.05] |  -1.18 | > .999   
## Industry.ICT           |                    ESG |     -0.02 | [-0.13,  0.10] |  -0.29 | > .999   
## Industry.Manufacturing |        Industry.Mining |     -0.32 | [-0.42, -0.22] |  -5.98 | < .001***
## Industry.Manufacturing |      Industry.Services |     -0.36 | [-0.45, -0.26] |  -6.72 | < .001***
## Industry.Manufacturing |       Industry.Utility |     -0.23 | [-0.34, -0.12] |  -4.18 | 0.003**  
## Industry.Manufacturing |            Country.CZE |      0.05 | [-0.06,  0.16] |   0.89 | > .999   
## Industry.Manufacturing |            Country.ESP | -6.24e-03 | [-0.12,  0.11] |  -0.11 | > .999   
## Industry.Manufacturing |            Country.NED |     -0.24 | [-0.35, -0.14] |  -4.38 | 0.001**  
## Industry.Manufacturing |            Country.SWE |      0.24 | [ 0.13,  0.34] |   4.31 | 0.002**  
## Industry.Manufacturing |                 Profit |     -0.09 | [-0.20,  0.03] |  -1.52 | > .999   
## Industry.Manufacturing |                Revenue |     -0.02 | [-0.14,  0.09] |  -0.42 | > .999   
## Industry.Manufacturing |                 Orders |     -0.07 | [-0.18,  0.04] |  -1.30 | > .999   
## Industry.Manufacturing |                    ESG |     -0.05 | [-0.16,  0.07] |  -0.79 | > .999   
## Industry.Mining        |      Industry.Services |     -0.34 | [-0.44, -0.24] |  -6.33 | < .001***
## Industry.Mining        |       Industry.Utility |     -0.22 | [-0.33, -0.11] |  -3.96 | 0.008**  
## Industry.Mining        |            Country.CZE |      0.08 | [-0.04,  0.19] |   1.32 | > .999   
## Industry.Mining        |            Country.ESP |     -0.09 | [-0.20,  0.02] |  -1.57 | > .999   
## Industry.Mining        |            Country.NED |      0.07 | [-0.04,  0.18] |   1.29 | > .999   
## Industry.Mining        |            Country.SWE |     -0.07 | [-0.18,  0.05] |  -1.16 | > .999   
## Industry.Mining        |                 Profit |      0.07 | [-0.05,  0.18] |   1.18 | > .999   
## Industry.Mining        |                Revenue |      0.11 | [ 0.00,  0.22] |   1.91 | > .999   
## Industry.Mining        |                 Orders |      0.10 | [-0.01,  0.21] |   1.76 | > .999   
## Industry.Mining        |                    ESG |      0.17 | [ 0.06,  0.28] |   3.03 | 0.194    
## Industry.Services      |       Industry.Utility |     -0.25 | [-0.35, -0.14] |  -4.41 | 0.001**  
## Industry.Services      |            Country.CZE |     -0.19 | [-0.30, -0.08] |  -3.43 | 0.055    
## Industry.Services      |            Country.ESP |      0.28 | [ 0.17,  0.38] |   5.09 | < .001***
## Industry.Services      |            Country.NED |      0.10 | [-0.01,  0.21] |   1.71 | > .999   
## Industry.Services      |            Country.SWE |     -0.22 | [-0.32, -0.11] |  -3.85 | 0.012*   
## Industry.Services      |                 Profit |      0.06 | [-0.06,  0.17] |   1.00 | > .999   
## Industry.Services      |                Revenue |     -0.04 | [-0.15,  0.08] |  -0.62 | > .999   
## Industry.Services      |                 Orders |  6.75e-03 | [-0.11,  0.12] |   0.12 | > .999   
## Industry.Services      |                    ESG |     -0.09 | [-0.20,  0.03] |  -1.49 | > .999   
## Industry.Utility       |            Country.CZE |      0.09 | [-0.02,  0.20] |   1.58 | > .999   
## Industry.Utility       |            Country.ESP |     -0.09 | [-0.20,  0.03] |  -1.52 | > .999   
## Industry.Utility       |            Country.NED |      0.06 | [-0.05,  0.17] |   1.10 | > .999   
## Industry.Utility       |            Country.SWE |     -0.07 | [-0.18,  0.04] |  -1.23 | > .999   
## Industry.Utility       |                 Profit |  1.27e-03 | [-0.11,  0.11] |   0.02 | > .999   
## Industry.Utility       |                Revenue |  6.38e-04 | [-0.11,  0.11] |   0.01 | > .999   
## Industry.Utility       |                 Orders |      0.02 | [-0.09,  0.13] |   0.34 | > .999   
## Industry.Utility       |                    ESG |     -0.03 | [-0.14,  0.08] |  -0.51 | > .999   
## Country.CZE            |            Country.ESP |     -0.27 | [-0.37, -0.17] |  -4.97 | < .001***
## Country.CZE            |            Country.NED |     -0.36 | [-0.46, -0.26] |  -6.83 | < .001***
## Country.CZE            |            Country.SWE |     -0.26 | [-0.36, -0.15] |  -4.68 | < .001***
## Country.CZE            |                 Profit |     -0.08 | [-0.19,  0.03] |  -1.42 | > .999   
## Country.CZE            |                Revenue |     -0.10 | [-0.21,  0.01] |  -1.76 | > .999   
## Country.CZE            |                 Orders |     -0.18 | [-0.29, -0.07] |  -3.28 | 0.090    
## Country.CZE            |                    ESG |     -0.02 | [-0.13,  0.09] |  -0.39 | > .999   
## Country.ESP            |            Country.NED |     -0.41 | [-0.50, -0.31] |  -7.83 | < .001***
## Country.ESP            |            Country.SWE |     -0.29 | [-0.39, -0.18] |  -5.30 | < .001***
## Country.ESP            |                 Profit |      0.07 | [-0.04,  0.18] |   1.21 | > .999   
## Country.ESP            |                Revenue |      0.05 | [-0.06,  0.17] |   0.95 | > .999   
## Country.ESP            |                 Orders | -4.75e-03 | [-0.12,  0.11] |  -0.08 | > .999   
## Country.ESP            |                    ESG |      0.06 | [-0.05,  0.17] |   1.06 | > .999   
## Country.NED            |            Country.SWE |     -0.39 | [-0.48, -0.29] |  -7.32 | < .001***
## Country.NED            |                 Profit |      0.02 | [-0.09,  0.13] |   0.38 | > .999   
## Country.NED            |                Revenue |      0.03 | [-0.08,  0.14] |   0.50 | > .999   
## Country.NED            |                 Orders |      0.16 | [ 0.05,  0.27] |   2.89 | 0.301    
## Country.NED            |                    ESG |     -0.02 | [-0.13,  0.09] |  -0.38 | > .999   
## Country.SWE            |                 Profit |     -0.02 | [-0.13,  0.09] |  -0.33 | > .999   
## Country.SWE            |                Revenue |  7.78e-03 | [-0.10,  0.12] |   0.14 | > .999   
## Country.SWE            |                 Orders | -6.63e-03 | [-0.12,  0.11] |  -0.12 | > .999   
## Country.SWE            |                    ESG |     -0.02 | [-0.13,  0.10] |  -0.27 | > .999   
## Profit                 |                Revenue |      0.67 | [ 0.61,  0.73] |  15.81 | < .001***
## Profit                 |                 Orders |      0.53 | [ 0.44,  0.60] |  10.79 | < .001***
## Profit                 |                    ESG |      0.31 | [ 0.20,  0.41] |   5.66 | < .001***
## Revenue                |                 Orders |      0.20 | [ 0.09,  0.31] |   3.64 | 0.026*   
## Revenue                |                    ESG |      0.15 | [ 0.03,  0.25] |   2.58 | 0.737    
## Orders                 |                    ESG |      0.31 | [ 0.20,  0.40] |   5.59 | < .001***
## 
## p-value adjustment method: Holm (1979)
## Observations: 306
  1. Visualise the correlogram for the quantitative variables with underlying data
library(GGally)
## Loading required package: ggplot2
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
ggpairs(dataset[, c("Revenue", "Profit", "Orders", "ESG")]) + 
  theme(axis.line=element_blank(),
        axis.text=element_blank(),
        axis.ticks=element_blank())

D. Run the regression models

  1. Construct a simple linear model for Profit (dependent variable) and ESG Score (explanatory variable)
OLS.M1 <- lm(Profit ~ ESG, dataset)
summary(OLS.M1)
## 
## Call:
## lm(formula = Profit ~ ESG, data = dataset)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -78834 -28182  -9087  20803 148659 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  12191.7     7725.5   1.578    0.116    
## ESG            847.5      149.6   5.664 3.42e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 41610 on 304 degrees of freedom
## Multiple R-squared:  0.09547,    Adjusted R-squared:  0.09249 
## F-statistic: 32.09 on 1 and 304 DF,  p-value: 3.421e-08
  • How to visualise the results graphically?
plot(Profit ~ ESG, xlab = "ESG", ylab ="Profit", col = "#b10061")
abline(OLS.M1, col = "#00A5EB")

8. Construct a multiple linear model for Profit (dependent variable) and Revenue, Orders, ESG Score, Country and Industry (explanatory variables)

Model2 <- Profit ~ Revenue + Orders + ESG + Country + Industry
  1. For Model2, calculate the OLS regression (pooling) and panel data regression (Fixed Effects individual, Fixed Effects time, Fixed Effects both individual and time; Random Effects)
library(plm)
OLS.M2 <- plm(Model2, dataset, model= "pooling")
summary(OLS.M2)
## Pooling Model
## 
## Call:
## plm(formula = Model2, data = dataset, model = "pooling")
## 
## Balanced Panel: n = 51, T = 6, N = 306
## 
## Residuals:
##     Min.  1st Qu.   Median  3rd Qu.     Max. 
## -88486.6 -14695.4  -2275.6  13367.7  94979.8 
## 
## Coefficients:
##                          Estimate  Std. Error  t-value  Pr(>|t|)    
## (Intercept)           -3.3183e+05  2.9728e+04 -11.1620 < 2.2e-16 ***
## Revenue                1.5502e-01  9.5737e-03  16.1927 < 2.2e-16 ***
## Orders                 3.1748e+05  3.1267e+04  10.1538 < 2.2e-16 ***
## ESG                    3.1594e+02  1.0346e+02   3.0538  0.002466 ** 
## CountryESP            -5.5548e+03  4.9960e+03  -1.1118  0.267108    
## CountryNED            -1.0497e+04  4.5408e+03  -2.3117  0.021482 *  
## CountrySWE            -6.3042e+03  4.9215e+03  -1.2809  0.201219    
## IndustryManufacturing -5.8661e+03  5.8599e+03  -1.0011  0.317621    
## IndustryMining        -6.3739e+03  5.9799e+03  -1.0659  0.287341    
## IndustryServices       5.0419e+03  6.0439e+03   0.8342  0.404841    
## IndustryUtility       -2.4968e+03  6.5247e+03  -0.3827  0.702246    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    5.8185e+11
## Residual Sum of Squares: 2.1222e+11
## R-Squared:      0.63526
## Adj. R-Squared: 0.6229
## F-statistic: 51.3795 on 10 and 295 DF, p-value: < 2.22e-16
FEind.M2 <- plm(Model2, dataset, model= "within", effect="individual")
summary(FEind.M2)
## Oneway (individual) effect Within Model
## 
## Call:
## plm(formula = Model2, data = dataset, effect = "individual", 
##     model = "within")
## 
## Balanced Panel: n = 51, T = 6, N = 306
## 
## Residuals:
##     Min.  1st Qu.   Median  3rd Qu.     Max. 
## -91945.1 -13063.3   -740.1  12378.6  93192.2 
## 
## Coefficients:
##           Estimate Std. Error t-value Pr(>|t|)    
## Revenue 1.5556e-01 1.0229e-02 15.2072   <2e-16 ***
## Orders  3.6064e+05 3.4608e+04 10.4209   <2e-16 ***
## ESG     2.4956e+02 1.0845e+02  2.3012   0.0222 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    4.8233e+11
## Residual Sum of Squares: 1.6469e+11
## R-Squared:      0.65856
## Adj. R-Squared: 0.58675
## F-statistic: 162.015 on 3 and 252 DF, p-value: < 2.22e-16
FEtime.M2 <- plm(Model2, dataset, model= "within", effect="time")
summary(FEtime.M2)
## Oneway (time) effect Within Model
## 
## Call:
## plm(formula = Model2, data = dataset, effect = "time", model = "within")
## 
## Balanced Panel: n = 51, T = 6, N = 306
## 
## Residuals:
##     Min.  1st Qu.   Median  3rd Qu.     Max. 
## -90545.7 -15017.3  -1974.1  11569.4  93372.2 
## 
## Coefficients:
##                          Estimate  Std. Error t-value  Pr(>|t|)    
## Revenue                1.5575e-01  9.5797e-03 16.2582 < 2.2e-16 ***
## Orders                 3.1879e+05  3.1096e+04 10.2517 < 2.2e-16 ***
## ESG                    3.0097e+02  1.0381e+02  2.8993  0.004025 ** 
## CountryESP            -5.5633e+03  4.9654e+03 -1.1204  0.263469    
## CountryNED            -1.0560e+04  4.5131e+03 -2.3399  0.019968 *  
## CountrySWE            -6.3519e+03  4.8914e+03 -1.2986  0.195115    
## IndustryManufacturing -5.9121e+03  5.8240e+03 -1.0151  0.310891    
## IndustryMining        -6.3726e+03  5.9433e+03 -1.0722  0.284504    
## IndustryServices       4.9777e+03  6.0070e+03  0.8287  0.407979    
## IndustryUtility       -2.5544e+03  6.4848e+03 -0.3939  0.693935    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    5.7564e+11
## Residual Sum of Squares: 2.0607e+11
## R-Squared:      0.64202
## Adj. R-Squared: 0.6235
## F-statistic: 52.0094 on 10 and 290 DF, p-value: < 2.22e-16
FE.M2 <- plm(Model2, dataset, model= "within", effect="twoways")
summary(FE.M2)
## Twoways effects Within Model
## 
## Call:
## plm(formula = Model2, data = dataset, effect = "twoways", model = "within")
## 
## Balanced Panel: n = 51, T = 6, N = 306
## 
## Residuals:
##      Min.   1st Qu.    Median   3rd Qu.      Max. 
## -89370.09 -11924.44    485.24  11791.01  91388.61 
## 
## Coefficients:
##           Estimate Std. Error t-value Pr(>|t|)    
## Revenue 1.5645e-01 1.0216e-02 15.3136  < 2e-16 ***
## Orders  3.6231e+05 3.4316e+04 10.5582  < 2e-16 ***
## ESG     2.3090e+02 1.0859e+02  2.1263  0.03447 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    4.7611e+11
## Residual Sum of Squares: 1.5837e+11
## R-Squared:      0.66737
## Adj. R-Squared: 0.58927
## F-statistic: 165.192 on 3 and 247 DF, p-value: < 2.22e-16
RE.M2 <- plm(Model2, dataset, model= "random")
summary(RE.M2)
## Oneway (individual) effect Random Effect Model 
##    (Swamy-Arora's transformation)
## 
## Call:
## plm(formula = Model2, data = dataset, model = "random")
## 
## Balanced Panel: n = 51, T = 6, N = 306
## 
## Effects:
##                     var   std.dev share
## idiosyncratic 653516609     25564 0.906
## individual     67715703      8229 0.094
## theta: 0.2147
## 
## Residuals:
##     Min.  1st Qu.   Median  3rd Qu.     Max. 
## -89614.6 -14539.1  -1417.7  12778.1  90330.6 
## 
## Coefficients:
##                          Estimate  Std. Error  z-value  Pr(>|z|)    
## (Intercept)           -3.4431e+05  3.0157e+04 -11.4172 < 2.2e-16 ***
## Revenue                1.5541e-01  9.5362e-03  16.2972 < 2.2e-16 ***
## Orders                 3.3121e+05  3.1508e+04  10.5120 < 2.2e-16 ***
## ESG                    2.9422e+02  1.0242e+02   2.8726  0.004071 ** 
## CountryESP            -5.7778e+03  6.0613e+03  -0.9532  0.340472    
## CountryNED            -1.0941e+04  5.4872e+03  -1.9939  0.046163 *  
## CountrySWE            -6.6115e+03  5.9738e+03  -1.1067  0.268403    
## IndustryManufacturing -6.0059e+03  7.1354e+03  -0.8417  0.399956    
## IndustryMining        -6.5874e+03  7.2596e+03  -0.9074  0.364194    
## IndustryServices       4.8504e+03  7.3567e+03   0.6593  0.509692    
## IndustryUtility       -2.7396e+03  7.9397e+03  -0.3450  0.730059    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    5.4369e+11
## Residual Sum of Squares: 1.9429e+11
## R-Squared:      0.64265
## Adj. R-Squared: 0.63054
## Chisq: 530.525 on 10 DF, p-value: < 2.22e-16
library(stargazer)
stargazer(OLS.M2, FE.M2, RE.M2, type = "text", model.names = TRUE, column.labels = c("OLS", "FE.BOTH", "RE"))
## 
## =======================================================================================
##                                              Dependent variable:                       
##                       -----------------------------------------------------------------
##                                                    Profit                              
##                                                     panel                              
##                                                    linear                              
##                                 OLS                    FE.BOTH                RE       
##                                 (1)                      (2)                  (3)      
## ---------------------------------------------------------------------------------------
## Revenue                       0.155***                 0.156***            0.155***    
##                               (0.010)                  (0.010)              (0.010)    
##                                                                                        
## Orders                     317,476.300***           362,311.700***      331,206.600*** 
##                             (31,266.600)             (34,315.640)        (31,507.580)  
##                                                                                        
## ESG                          315.936***               230.900**           294.225***   
##                              (103.456)                (108.593)            (102.424)   
##                                                                                        
## CountryESP                   -5,554.804                                   -5,777.823   
##                             (4,996.004)                                   (6,061.291)  
##                                                                                        
## CountryNED                 -10,497.050**                                 -10,940.970** 
##                             (4,540.797)                                   (5,487.217)  
##                                                                                        
## CountrySWE                   -6,304.210                                   -6,611.534   
##                             (4,921.527)                                   (5,973.835)  
##                                                                                        
## IndustryManufacturing        -5,866.106                                   -6,005.856   
##                             (5,859.931)                                   (7,135.382)  
##                                                                                        
## IndustryMining               -6,373.948                                   -6,587.362   
##                             (5,979.876)                                   (7,259.582)  
##                                                                                        
## IndustryServices             5,041.865                                     4,850.397   
##                             (6,043.922)                                   (7,356.687)  
##                                                                                        
## IndustryUtility              -2,496.770                                   -2,739.561   
##                             (6,524.737)                                   (7,939.674)  
##                                                                                        
## Constant                  -331,827.600***                               -344,311.700***
##                             (29,728.270)                                 (30,157.350)  
##                                                                                        
## ---------------------------------------------------------------------------------------
## Observations                    306                      306                  306      
## R2                             0.635                    0.667                0.643     
## Adjusted R2                    0.623                    0.589                0.631     
## F Statistic           51.380*** (df = 10; 295) 165.192*** (df = 3; 247)   530.525***   
## =======================================================================================
## Note:                                                       *p<0.1; **p<0.05; ***p<0.01
  1. Inspect the Gauss-Markov assumptions
library(lmtest)
# Heterescedasticity
bptest(Model2, data = dataset)
## 
##  studentized Breusch-Pagan test
## 
## data:  Model2
## BP = 52.173, df = 10, p-value = 1.06e-07
# Auto (serial) correlation
dwtest(Model2, data = dataset)
## 
##  Durbin-Watson test
## 
## data:  Model2
## DW = 1.7761, p-value = 0.009831
## alternative hypothesis: true autocorrelation is greater than 0
# Cross-sectional dependance
pcdtest(Model2, dataset, index = c("Firm", "Year"))
## 
##  Pesaran CD test for cross-sectional dependence in panels
## 
## data:  Profit ~ Revenue + Orders + ESG + Country + Industry
## z = 3.5003, p-value = 0.0004647
## alternative hypothesis: cross-sectional dependence
# Multicolinearity (VIF analysis)
car::vif(OLS.M2)
##              GVIF Df GVIF^(1/(2*Df))
## Revenue  1.069475  1        1.034154
## Orders   1.197391  1        1.094254
## ESG      1.150658  1        1.072687
## Country  1.364049  3        1.053105
## Industry 1.349843  4        1.038211
  1. How to select among OLS, Fixed Effects, Random Effects
# OLS vs FE
pFtest (OLS.M2, FE.M2) 
## Warning in pf(stat, df1, df2, lower.tail = FALSE): NaNs produced
## 
##  F test for individual effects
## 
## data:  Model2
## F = 1.5596, df1 = -48, df2 = 295, p-value = NA
## alternative hypothesis: significant effects
# OLS vs RE
plmtest(OLS.M2, effect = "individual", type = "bp") 
## 
##  Lagrange Multiplier Test - (Breusch-Pagan)
## 
## data:  Model2
## chisq = 2.9882, df = 1, p-value = 0.08388
## alternative hypothesis: significant effects
# FE vs RE 
phtest(FE.M2, RE.M2) 
## 
##  Hausman Test
## 
## data:  Model2
## chisq = 8.2053, df = 3, p-value = 0.04195
## alternative hypothesis: one model is inconsistent