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:
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 datablackrock_etf_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
# 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 objectmini_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)
## \# 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 datasetblackrock_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 sizeggplot(By_ESG, aes(x = is_esg, y=averageco2intensity)) +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 fundsggplot(By_ESG_Continent, aes(x = region, y=averageco2intensity)) +geom_col()