Running regression on the impact of ESG on Stock returns.
Introduction:
Environmental, social, and governance (ESG) investing is a rapidly growing field that seeks to invest in companies that meet certain criteria related to sustainability and responsible corporate behavior. One way to evaluate the impact of ESG on stock returns is through a Fama and French analysis, which uses regression analysis to determine the relationship between ESG factors and stock returns.
In this post, I will show you how to perform a Fama and French analysis on the impact of ESG on stock returns using R programming. I will use data from the MSCI ESG Fundamentals dataset, which provides ESG ratings for over 6,000 companies worldwide.
Step 1: Load the data
The first step is to load the data into R. I will use the “read.csv” function to read the data from a CSV file:
esg_data <- read.csv("~/Desktop/data/esg_data.csv")
Step 2: Clean and prepare the data
Next, we will clean and prepare the data for analysis. We will remove any missing values and create a new variable for the excess returns of each stock. We will also convert the ESG ratings into a factor variable:
# Remove missing values esg_data <- na.omit(esg_data)
Here’s a step-by-step guide on how to write the R code for performing Fama and French analysis on the impact of ESG on stock returns:
Step 3: Load the Required Libraries
library(quantmod) library(tidyverse) library(data.table)
Step 4: Download Stock Price Data
esg_returns <- dailyReturn(Ad(esg_stock_prices)) market_returns <- dailyReturn(Ad(market_stock_prices))
We compute the daily stock returns for both ESG and the market using the dailyReturn
function from the quantmod
library. The Ad
the function is used to extract the adjusted close prices from the stock price data.
Step 5: Merge Stock Returns into a Data Frame
returns_df <- merge(esg_returns, market_returns, join = "inner") colnames(returns_df) <- c("ESG", "Market")
We merge the stock returns into a single data frame using the merge
function from the tidyverse
library. The join
argument is set to "inner"
to keep only the dates for which we have both ESG and market returns. We also renamed the "ESG" and "Market" columns for clarity.
Step 5: Load Fama and French Data
ff_data <- fread("https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/F-F_Research_Data_Factors_CSV.zip")
We download the Fama and French data from Ken French’s website using the fread
function from the data.table
library. The data is in a ZIP file, so we need to provide the URL to the ZIP file.
ff_data[, `:=`( MktRF = Mkt-RF, SMB = SMB-RF, HML = HML-RF, RMW = RMW-RF, CMA = CMA-RF )] ff_returns <- ff_data[, .(MktRF, SMB, HML, RMW, CMA)]
We compute the daily Fama and French factor returns by subtracting the risk-free rate (RF) from each factor’s return. We do this using the :=
operator in the data.table
syntax to create new columns for each factor. Then, we create a new data table called ff_returns
that includes only the factor returns.
Step 7: Merge Stock and Fama-French Returns into a Single Data Frame
all_returns <- merge(returns_df, ff_returns, join = "inner")
We merge the stock returns and the Fama-French factor returns into a single data frame using the merge
function from the tidyverse
library. The join
the argument is set to "inner"
to keep only the dates for which we have
Step 8: Run Regression
Here’s the final step to run a regression analysis on the ESG returns using the market factor (MktRF), the size factor (SMB), and the value factor (HML) from the Fama-French model:
results <- lm(ESG ~ MktRF + SMB + HML, data = all_returns) summary(results)
We use the lm
Function to run a linear regression analysis with the ESG returns as the dependent variable and the market factor (MktRF), the size factor (SMB), and the value factor (HML) as the independent variables. The data
the argument specifies the data frame all_returns
that includes both the stock returns and the Fama-French factor returns.
The summary
the function is used to display the regression analysis results, which include the coefficients for each independent variable (MktRF, SMB, and HML), the intercept, the standard errors, the t-statistics, and the p-values. This summary output allows us to determine the statistical significance of the impact of ESG on stock returns after controlling for the Fama-French factors.
Read Article on Medium
“Disclaimer: The information provided in this post is for educational purposes only and should not be considered financial or investment advice. The opinions expressed in this post are solely those of the author and do not reflect the views or opinions of any organization or entity. Investing in the stock market involves risk, and past performance does not necessarily indicate future results. The author is not liable for any losses or damages that may arise from the use of the information presented in this post.”