Homework week 2

Author

Lara Gohr

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

library(tidyverse) 
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.0     ✔ purrr   1.0.1
✔ tibble  3.1.8     ✔ dplyr   1.1.0
✔ tidyr   1.3.0     ✔ stringr 1.5.0
✔ readr   2.1.3     ✔ forcats 1.0.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(ggplot2) 
library(dplyr) 
library(knitr)
library(lubridate) 

Attache Paket: 'lubridate'

Die folgenden Objekte sind maskiert von 'package:base':

    date, intersect, setdiff, union
# #in-class exercise

#assign the url to "github_raw_csv_url"

github_raw_csv_url <- "https://raw.githubusercontent.com/t-emery/sais-susfin_data/main/datasets/blackrock_etf_screener_2022-08-30.csv"

#read in the data, and assign it to the object `blackrock_etf_data`

blackrock_etf_data <- read_csv(github_raw_csv_url)
Rows: 393 Columns: 22
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (14): ticker, name, incept_date, net_assets_as_of, asset_class, sub_asse...
dbl  (8): gross_expense_ratio_percent, net_expense_ratio_percent, net_assets...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#print out the tibble to take a look at the data

blackrock_etf_data
# A tibble: 393 × 22
   ticker name    incep…¹ gross…² net_e…³ net_a…⁴ net_a…⁵ asset…⁶ sub_a…⁷ region
   <chr>  <chr>   <chr>     <dbl>   <dbl>   <dbl> <chr>   <chr>   <chr>   <chr> 
 1 IVV    iShare… 5/15/00    0.03    0.03 297663. 8/30/22 Equity  Large … North…
 2 IEFA   iShare… 10/18/…    0.07    0.07  84222. 8/30/22 Equity  All Cap Global
 3 AGG    iShare… 9/22/03    0.04    0.03  82344. 8/30/22 Fixed … Multi … North…
 4 IJR    iShare… 5/22/00    0.06    0.06  66533. 8/30/22 Equity  Small … North…
 5 IEMG   iShare… 10/18/…    0.09    0.09  64920. 8/30/22 Equity  All Cap Global
 6 IWF    iShare… 5/22/00    0.18    0.18  61831. 8/30/22 Equity  Large/… North…
 7 IJH    iShare… 5/22/00    0.05    0.05  61424. 8/30/22 Equity  Mid Cap North…
 8 IWM    iShare… 5/22/00    0.19    0.19  53048. 8/30/22 Equity  Small … North…
 9 IWD    iShare… 5/22/00    0.18    0.18  51913. 8/30/22 Equity  Large/… North…
10 EFA    iShare… 8/14/01    0.32    0.32  44144. 8/30/22 Equity  Large/… Global
# … with 383 more rows, 12 more variables: market <chr>, location <chr>,
#   investment_style <chr>,
#   sustainability_characteristics_msci_esg_fund_ratings_msci_esg_fund_rating_aaa_ccc <chr>,
#   msci_esg_quality_score_0_10 <dbl>,
#   msci_weighted_average_carbon_intensity_tons_co2e_m_sales <dbl>,
#   msci_esg_percent_coverage <dbl>, sustainable_classification <chr>,
#   name_wo_ishares_etf <chr>, is_esg <chr>, years_from_inception <dbl>, …
mini_blackrock_data <- blackrock_etf_data |> 
 group_by(is_esg) |> 
 slice_max(order_by = net_assets_usd_mn, n = 5) |> 
 select(ticker, name, asset_class, sub_asset_class, region, incept_date, net_assets_usd_mn, msci_weighted_average_carbon_intensity_tons_co2e_m_sales) |> rename(co2_intensity = msci_weighted_average_carbon_intensity_tons_co2e_m_sales) |> 
 ungroup()
Adding missing grouping variables: `is_esg`
mini_blackrock_data
# A tibble: 10 × 9
   is_esg       ticker name       asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
   <chr>        <chr>  <chr>      <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
 1 ESG Fund     ESGU   iShares E… Equity  Large/… North… 12/1/16  22377.   104. 
 2 ESG Fund     ESGD   iShares E… Equity  Large/… Global 6/28/16   6426.   104. 
 3 ESG Fund     ICLN   iShares G… Equity  All Cap Global 6/24/08   5628.   266. 
 4 ESG Fund     ESGE   iShares E… Equity  Large/… Global 6/28/16   4234.   168. 
 5 ESG Fund     DSI    iShares M… Equity  Large/… North… 11/14/…   3689.    72.7
 6 Regular Fund IVV    iShares C… Equity  Large … North… 5/15/00 297663.   148. 
 7 Regular Fund IEFA   iShares C… Equity  All Cap Global 10/18/…  84222.   127. 
 8 Regular Fund AGG    iShares C… Fixed … Multi … North… 9/22/03  82344.   283. 
 9 Regular Fund IJR    iShares C… Equity  Small … North… 5/22/00  66533.   133. 
10 Regular Fund IEMG   iShares C… Equity  All Cap Global 10/18/…  64920.   369. 
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
## \# Now you try: Select the columns with 1) the name of the fund, 2) whether the fund is an ESG fund or not, and 3) the asset class.

mini_blackrock_data |> select(is_esg, name, asset_class)
# A tibble: 10 × 3
   is_esg       name                                   asset_class 
   <chr>        <chr>                                  <chr>       
 1 ESG Fund     iShares ESG Aware MSCI USA ETF         Equity      
 2 ESG Fund     iShares ESG Aware MSCI EAFE ETF        Equity      
 3 ESG Fund     iShares Global Clean Energy ETF        Equity      
 4 ESG Fund     iShares ESG Aware MSCI EM ETF          Equity      
 5 ESG Fund     iShares MSCI KLD 400 Social ETF        Equity      
 6 Regular Fund iShares Core S&P 500 ETF               Equity      
 7 Regular Fund iShares Core MSCI EAFE ETF             Equity      
 8 Regular Fund iShares Core U.S. Aggregate Bond ETF   Fixed Income
 9 Regular Fund iShares Core S&P Small-Cap ETF         Equity      
10 Regular Fund iShares Core MSCI Emerging Markets ETF Equity      
## \# Now you try: Try filtering for the funds that are 1) ESG Funds, that 2) are fixed income funds.

mini_blackrock_data |> filter(is_esg == "ESG Fund")
# A tibble: 5 × 9
  is_esg   ticker name            asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
  <chr>    <chr>  <chr>           <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
1 ESG Fund ESGU   iShares ESG Aw… Equity  Large/… North… 12/1/16  22377.   104. 
2 ESG Fund ESGD   iShares ESG Aw… Equity  Large/… Global 6/28/16   6426.   104. 
3 ESG Fund ICLN   iShares Global… Equity  All Cap Global 6/24/08   5628.   266. 
4 ESG Fund ESGE   iShares ESG Aw… Equity  Large/… Global 6/28/16   4234.   168. 
5 ESG Fund DSI    iShares MSCI K… Equity  Large/… North… 11/14/…   3689.    72.7
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
mini_blackrock_data |> filter(asset_class == "Fixed Income")
# A tibble: 1 × 9
  is_esg       ticker name        asset…¹ sub_a…² region incep…³ net_a…⁴ co2_i…⁵
  <chr>        <chr>  <chr>       <chr>   <chr>   <chr>  <chr>     <dbl>   <dbl>
1 Regular Fund AGG    iShares Co… Fixed … Multi … North… 9/22/03  82344.    283.
# … with abbreviated variable names ¹​asset_class, ²​sub_asset_class,
#   ³​incept_date, ⁴​net_assets_usd_mn, ⁵​co2_intensity
#use mdy() from the lubridate package to turn the character string into a date object

mini_blackrock_data |> select(name, is_esg, incept_date) |> mutate(incept_date = lubridate::mdy(incept_date))
# A tibble: 10 × 3
   name                                   is_esg       incept_date
   <chr>                                  <chr>        <date>     
 1 iShares ESG Aware MSCI USA ETF         ESG Fund     2016-12-01 
 2 iShares ESG Aware MSCI EAFE ETF        ESG Fund     2016-06-28 
 3 iShares Global Clean Energy ETF        ESG Fund     2008-06-24 
 4 iShares ESG Aware MSCI EM ETF          ESG Fund     2016-06-28 
 5 iShares MSCI KLD 400 Social ETF        ESG Fund     2006-11-14 
 6 iShares Core S&P 500 ETF               Regular Fund 2000-05-15 
 7 iShares Core MSCI EAFE ETF             Regular Fund 2012-10-18 
 8 iShares Core U.S. Aggregate Bond ETF   Regular Fund 2003-09-22 
 9 iShares Core S&P Small-Cap ETF         Regular Fund 2000-05-22 
10 iShares Core MSCI Emerging Markets ETF Regular Fund 2012-10-18 
#extract the year from the date, calculate how many years since the fund was launched.

mini_blackrock_data |> select(name, is_esg, incept_date) |> mutate(incept_date = lubridate::mdy(incept_date), incept_year = lubridate::year(incept_date), years_since_incept = lubridate::interval(incept_date, Sys.Date())/lubridate::years(1))
# A tibble: 10 × 5
   name                                   is_esg      incept_d…¹ incep…² years…³
   <chr>                                  <chr>       <date>       <dbl>   <dbl>
 1 iShares ESG Aware MSCI USA ETF         ESG Fund    2016-12-01    2016    6.19
 2 iShares ESG Aware MSCI EAFE ETF        ESG Fund    2016-06-28    2016    6.62
 3 iShares Global Clean Energy ETF        ESG Fund    2008-06-24    2008   14.6 
 4 iShares ESG Aware MSCI EM ETF          ESG Fund    2016-06-28    2016    6.62
 5 iShares MSCI KLD 400 Social ETF        ESG Fund    2006-11-14    2006   16.2 
 6 iShares Core S&P 500 ETF               Regular Fu… 2000-05-15    2000   22.7 
 7 iShares Core MSCI EAFE ETF             Regular Fu… 2012-10-18    2012   10.3 
 8 iShares Core U.S. Aggregate Bond ETF   Regular Fu… 2003-09-22    2003   19.4 
 9 iShares Core S&P Small-Cap ETF         Regular Fu… 2000-05-22    2000   22.7 
10 iShares Core MSCI Emerging Markets ETF Regular Fu… 2012-10-18    2012   10.3 
# … with abbreviated variable names ¹​incept_date, ²​incept_year,
#   ³​years_since_incept
## \# Now You Try: Since the numbers are so large, it would be a lot more useful to have the net assets number in billions. Create net_assets_usd_bn from net_assets_usd_mn.

mini_blackrock_data |> select(net_assets_usd_mn) |> mutate(net_assets_usd_bn = net_assets_usd_mn/1000)
# A tibble: 10 × 2
   net_assets_usd_mn net_assets_usd_bn
               <dbl>             <dbl>
 1            22377.             22.4 
 2             6426.              6.43
 3             5628.              5.63
 4             4234.              4.23
 5             3689.              3.69
 6           297663.            298.  
 7            84222.             84.2 
 8            82344.             82.3 
 9            66533.             66.5 
10            64920.             64.9 
## \# Now You Try: What is the median carbon intensity of the funds?

mini_blackrock_data |> summarize(medianco2_intensity = median(co2_intensity))
# A tibble: 1 × 1
  medianco2_intensity
                <dbl>
1                141.
## \# Now You Try: Calculate the average carbon intensity of funds by asset class and sub asset class.

mini_blackrock_data |> group_by(asset_class, sub_asset_class) |> summarize(averageco2intensity = mean(co2_intensity))
`summarise()` has grouped output by 'asset_class'. You can override using the
`.groups` argument.
# A tibble: 5 × 3
# Groups:   asset_class [2]
  asset_class  sub_asset_class averageco2intensity
  <chr>        <chr>                         <dbl>
1 Equity       All Cap                        254.
2 Equity       Large Cap                      148.
3 Equity       Large/Mid Cap                  112.
4 Equity       Small Cap                      133.
5 Fixed Income Multi Sectors                  283.
## #Create 3 data visualizations about the BlackRock ESG ETFs

#rename CO2 intensity variable in big dataset

blackrock_etf_data <-blackrock_etf_data |> rename(co2_intensity = msci_weighted_average_carbon_intensity_tons_co2e_m_sales)

## #Are ESG funds CO2 intenstive than normal funds? (ignore NA's)

By_ESG <- blackrock_etf_data |> group_by(is_esg) |> summarize(averageco2intensity = mean(co2_intensity, na.rm = TRUE), averageAssetsize = mean(net_assets_usd_mn))

By_ESG
# A tibble: 2 × 3
  is_esg       averageco2intensity averageAssetsize
  <chr>                      <dbl>            <dbl>
1 ESG Fund                    130.            1847.
2 Regular Fund                254.            5886.
#plot CO2 intenstiy and asset size

ggplot(By_ESG, aes(x = is_esg, y=averageco2intensity)) + geom_col()

ggplot(By_ESG, aes(x = is_esg, y=averageAssetsize)) + geom_col()

#I think those two graphs represent two essential facts: ESG funds are on average about twice less CO2 intensive (assuming CO2 emissions are measured correctly) but about three times smaller in terms of average net assets

## #In which region can we find most ESG funds?

By_ESG_Continent <- blackrock_etf_data |> filter(is_esg == "ESG Fund") |> group_by(region) |> summarize(averageco2intensity = mean(co2_intensity, na.rm = TRUE))

By_ESG_Continent
# A tibble: 2 × 2
  region        averageco2intensity
  <chr>                       <dbl>
1 Global                       145.
2 North America                124.
#interesting: Blackrock has only north american and "Global" ESG funds

ggplot(By_ESG_Continent, aes(x = region, y=averageco2intensity)) + geom_col()

## #Are younger funds less CO2 intensive?

#first: mutate date

blackrock_etf_data <-blackrock_etf_data |> mutate(incept_date = lubridate::mdy(incept_date), incept_year = lubridate::year(incept_date), years_since_incept = lubridate::interval(incept_date, Sys.Date())/lubridate::years(1))

By_year_launched <-blackrock_etf_data |> filter(is_esg == "ESG Fund") |> group_by(year_launched) |> summarize(averageco2intensity = mean(co2_intensity, na.rm = TRUE))

By_year_launched
# A tibble: 11 × 2
   year_launched averageco2intensity
           <dbl>               <dbl>
 1          2005                58.9
 2          2006                72.7
 3          2008               266. 
 4          2014                73.3
 5          2016               124. 
 6          2017               135. 
 7          2018               333. 
 8          2019                68.8
 9          2020               106. 
10          2021               112. 
11          2022                29.6
#is there in trend in there?

ggplot(By_year_launched, aes(x = year_launched, y=averageco2intensity)) + geom_point()

#=\> younger ESG funds don't seem to have a higher or lower CO2 intensity. There is no trend.
1 + 1
[1] 2

You can add options to executable code like this

[1] 4

The echo: false option disables the printing of code (only output is displayed).