my-markdown-library 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/F24LS_md/ Lecture 4 - Public.md +347 -0
  3. data/F24LS_md/Lecture 1 - Introduction and Overview.md +327 -0
  4. data/F24LS_md/Lecture 10 - Development_.md +631 -0
  5. data/F24LS_md/Lecture 11 - Econometrics.md +345 -0
  6. data/F24LS_md/Lecture 12 - Finance.md +692 -0
  7. data/F24LS_md/Lecture 13 - Environmental Economics.md +299 -0
  8. data/F24LS_md/Lecture 15 - Conclusion.md +272 -0
  9. data/F24LS_md/Lecture 2 - Demand.md +349 -0
  10. data/F24LS_md/Lecture 3 - Supply.md +329 -0
  11. data/F24LS_md/Lecture 5 - Production C-D.md +291 -0
  12. data/F24LS_md/Lecture 6 - Utility and Latex.md +440 -0
  13. data/F24LS_md/Lecture 7 - Inequality.md +607 -0
  14. data/F24LS_md/Lecture 8 - Macroeconomics.md +704 -0
  15. data/F24LS_md/Lecture 8 - Macro.md +700 -0
  16. data/F24LS_md/Lecture 9 - Game Theory_.md +436 -0
  17. data/F24LS_md/summary.yaml +105 -0
  18. data/F24Lec_MD/LecNB_summary.yaml +206 -0
  19. data/F24Lec_MD/lec01/lec01.md +267 -0
  20. data/F24Lec_MD/lec02/Avocados_demand.md +425 -0
  21. data/F24Lec_MD/lec02/Demand_Steps_24.md +126 -0
  22. data/F24Lec_MD/lec02/PriceElasticity.md +83 -0
  23. data/F24Lec_MD/lec02/ScannerData_Beer.md +171 -0
  24. data/F24Lec_MD/lec02/demand-curve-Fa24.md +213 -0
  25. data/F24Lec_MD/lec03/3.0-CubicCostCurve.md +239 -0
  26. data/F24Lec_MD/lec03/3.1-Supply.md +274 -0
  27. data/F24Lec_MD/lec03/3.2-sympy.md +332 -0
  28. data/F24Lec_MD/lec03/3.3a-california-energy.md +120 -0
  29. data/F24Lec_MD/lec03/3.3b-a-really-hot-tuesday.md +121 -0
  30. data/F24Lec_MD/lec04/lec04-CSfromSurvey-closed.md +335 -0
  31. data/F24Lec_MD/lec04/lec04-CSfromSurvey.md +331 -0
  32. data/F24Lec_MD/lec04/lec04-Supply-Demand-closed.md +519 -0
  33. data/F24Lec_MD/lec04/lec04-Supply-Demand.md +514 -0
  34. data/F24Lec_MD/lec04/lec04-four-plot-24.md +34 -0
  35. data/F24Lec_MD/lec04/lec04-four-plot.md +34 -0
  36. data/F24Lec_MD/lec05/Lec5-Cobb-Douglas.md +131 -0
  37. data/F24Lec_MD/lec05/Lec5-CobbD-AER1928.md +283 -0
  38. data/F24Lec_MD/lec06/6.1-Sympy-Differentiation.md +253 -0
  39. data/F24Lec_MD/lec06/6.2-3D-utility.md +287 -0
  40. data/F24Lec_MD/lec06/6.3-QuantEcon-Optimization.md +399 -0
  41. data/F24Lec_MD/lec06/6.4-latex.md +138 -0
  42. data/F24Lec_MD/lec06/6.5-Edgeworth.md +269 -0
  43. data/F24Lec_MD/lec07/7.1-inequality.md +283 -0
  44. data/F24Lec_MD/lec07/7.2-historical-inequality.md +237 -0
  45. data/F24Lec_MD/lec08/macro-fred-api.md +313 -0
  46. data/F24Lec_MD/lec09/lecNB-prisoners-dilemma.md +88 -0
  47. data/F24Lec_MD/lec10/Lec10.2-waterguard.md +401 -0
  48. data/F24Lec_MD/lec10/lec10.1-mapping.md +199 -0
  49. data/F24Lec_MD/lec11/11.1-slr.md +305 -0
  50. data/F24Lec_MD/lec11/11.2-mlr.md +171 -0
  51. data/F24Lec_MD/lec12/Lec12-4-PersonalFinance.md +590 -0
  52. data/F24Lec_MD/lec12/lec12-1_Interest_Payments.md +267 -0
  53. data/F24Lec_MD/lec12/lec12-2-stocks-options.md +235 -0
  54. data/F24Lec_MD/lec13/Co2_ClimateChange.md +139 -0
  55. data/F24Lec_MD/lec13/ConstructingMAC.md +213 -0
  56. data/F24Lec_MD/lec13/EmissionsTracker.md +170 -0
  57. data/F24Lec_MD/lec13/KuznetsHypothesis.md +219 -0
  58. data/F24Lec_MD/lec13/RoslingPlots.md +217 -0
  59. data/F24Lec_MD/lec15/vibecession.md +485 -0
  60. data/F24Textbook_MD/00-intro/index.md +292 -0
  61. data/F24Textbook_MD/01-demand/01-demand.md +152 -0
  62. data/F24Textbook_MD/01-demand/02-example.md +131 -0
  63. data/F24Textbook_MD/01-demand/03-log-log.md +284 -0
  64. data/F24Textbook_MD/01-demand/04-elasticity.md +248 -0
  65. data/F24Textbook_MD/01-demand/index.md +15 -0
  66. data/F24Textbook_MD/02-supply/01-supply.md +203 -0
  67. data/F24Textbook_MD/02-supply/02-eep147-example.md +86 -0
  68. data/F24Textbook_MD/02-supply/03-sympy.md +138 -0
  69. data/F24Textbook_MD/02-supply/04-market-equilibria.md +204 -0
  70. data/F24Textbook_MD/02-supply/index.md +16 -0
  71. data/F24Textbook_MD/03-public/govt-intervention.md +73 -0
  72. data/F24Textbook_MD/03-public/index.md +10 -0
  73. data/F24Textbook_MD/03-public/surplus.md +351 -0
  74. data/F24Textbook_MD/03-public/taxes-subsidies.md +282 -0
  75. data/F24Textbook_MD/04-production/index.md +15 -0
  76. data/F24Textbook_MD/04-production/production.md +178 -0
  77. data/F24Textbook_MD/04-production/shifts.md +296 -0
  78. data/F24Textbook_MD/05-utility/budget-constraints.md +166 -0
  79. data/F24Textbook_MD/05-utility/index.md +15 -0
  80. data/F24Textbook_MD/05-utility/utility.md +136 -0
  81. data/F24Textbook_MD/06-inequality/historical-inequality.md +253 -0
  82. data/F24Textbook_MD/06-inequality/index.md +15 -0
  83. data/F24Textbook_MD/06-inequality/inequality.md +226 -0
  84. data/F24Textbook_MD/07-game-theory/bertrand.md +257 -0
  85. data/F24Textbook_MD/07-game-theory/cournot.md +333 -0
  86. data/F24Textbook_MD/07-game-theory/equilibria-oligopolies.md +96 -0
  87. data/F24Textbook_MD/07-game-theory/expected-utility.md +61 -0
  88. data/F24Textbook_MD/07-game-theory/index.md +19 -0
  89. data/F24Textbook_MD/07-game-theory/python-classes.md +340 -0
  90. data/F24Textbook_MD/08-development/index.md +35 -0
  91. data/F24Textbook_MD/09-macro/CentralBanks.md +101 -0
  92. data/F24Textbook_MD/09-macro/Indicators.md +77 -0
  93. data/F24Textbook_MD/09-macro/fiscal_policy.md +36 -0
  94. data/F24Textbook_MD/09-macro/index.md +14 -0
  95. data/F24Textbook_MD/09-macro/is_curve.md +76 -0
  96. data/F24Textbook_MD/09-macro/phillips_curve.md +70 -0
  97. data/F24Textbook_MD/10-finance/index.md +10 -0
  98. data/F24Textbook_MD/10-finance/options.md +178 -0
  99. data/F24Textbook_MD/10-finance/value-interest.md +60 -0
  100. data/F24Textbook_MD/11-econometrics/index.md +16 -0
  101. data/F24Textbook_MD/11-econometrics/multivariable.md +218 -0
  102. data/F24Textbook_MD/11-econometrics/reading-econ-papers.md +25 -0
  103. data/F24Textbook_MD/11-econometrics/single-variable.md +483 -0
  104. data/F24Textbook_MD/11-econometrics/statsmodels.md +58 -0
  105. data/F24Textbook_MD/12-environmental/KuznetsHypothesis-Copy1.md +187 -0
  106. data/F24Textbook_MD/12-environmental/KuznetsHypothesis.md +187 -0
  107. data/F24Textbook_MD/12-environmental/MAC.md +254 -0
  108. data/F24Textbook_MD/12-environmental/index.md +36 -0
  109. data/F24Textbook_MD/LICENSE.md +11 -0
  110. data/F24Textbook_MD/intro.md +26 -0
  111. data/F24Textbook_MD/references.md +25 -0
  112. data/F24Textbook_MD/summary.yaml +414 -0
  113. metadata +155 -0
@@ -0,0 +1,217 @@
1
+ ---
2
+ title: "RoslingPlots"
3
+ type: lecture-notebook
4
+ week: 13
5
+ source_path: "/Users/ericvandusen/Documents/Data88E-ForTraining/F24Lec_NBs/lec13/RoslingPlots.ipynb"
6
+ ---
7
+
8
+ <table style="width: 100%;">
9
+ <tr style="background-color: transparent;"><td>
10
+ <img src="https://data-88e.github.io/assets/images/blue_text.png" width="250px" style="margin-left: 0;" />
11
+ </td><td>
12
+ <p style="text-align: right; font-size: 10pt;"><strong>Economic Models</strong>, Fall 2024<br>
13
+ Peter Grinde-Hollevik<br>
14
+ Dr. Eric Van Dusen
15
+ </p></td></tr>
16
+ </table>
17
+
18
+ ```python
19
+ from datascience import *
20
+ import matplotlib.pyplot as plt
21
+ import numpy as np
22
+ import pandas as pd
23
+ from matplotlib import patches
24
+ %matplotlib inline
25
+ from matplotlib.pyplot import figure
26
+ pd.plotting.register_matplotlib_converters()
27
+ import seaborn as sns
28
+ from pylab import *
29
+ from ipywidgets import interact
30
+ from IPython.lib.display import YouTubeVideo
31
+ ```
32
+
33
+ ### Plotting Global Emissions with "Rosling"-style Plots
34
+
35
+ This notebook is inspired by the late Professor Hans Rösling's wonderful contributions to the world of data visualization, which can be seen at the Gapminder website.
36
+
37
+ [You can see the Gapminder version of this visualization here](https://www.gapminder.org/tools/#$model$markers$bubble$encoding$y$data$concept=co2_emissions_tonnes_per_person&space@=country&=time;;&scale$domain:null&zoomed:null&type:null;;&frame$value=2018;;;;;&chart-type=bubbles&url=v1).
38
+
39
+ This notebook aims to reproduce the "bubble charts" in understanding the historical, global emissions of the last century.
40
+
41
+ As a warm-up exercise, feel free to check out his famous ["200 Countries, 200 years, 4 minutes"](https://www.youtube.com/watch?v=jbkSRLYSojo) from the BBC series *The Joy of Stats*. This video plots life expectancy over changing per capita income. After watching this, you'll understand why the arguments made by Professor Rösling's visualization have had such an impact.
42
+
43
+ ```python
44
+ YouTubeVideo('jbkSRLYSojo')
45
+ ```
46
+
47
+ ### Building Our Own Rosling Plot
48
+
49
+ The goal of this exercise is to gain some experience in data cleaning, making sense of it with basic plots, and present it in the most "friendly" manner for scientific communication. The two first will be accomplished by using tools from DATA 8, while the latter requires the usage of methods you might not be familiar with yet. However, with this walkthrough, you ought to be more comfortable with building a Rosling Plot of your own in the future.
50
+
51
+ We start off by importing a Gapminder Foundation Dataset containing per capita GDP and per capita emissions of $CO_2$.
52
+
53
+ ```python
54
+ co2_table = Table.read_table('co2-emissions-vs-gdp.csv')
55
+ co2_table
56
+ ```
57
+
58
+ Our first Rosling Plot will focus on the latest year of data: 2018. Hence, we select only the rows where 'Year' = 2018.
59
+
60
+ ```python
61
+ co2_table = co2_table.where('Year', 2018)
62
+ co2_table
63
+ ```
64
+
65
+ Now, let's consider what we would like to plot for year 2018: Following Rosling's philosophy we should consider how emissions change over economic development. Hence, our x-axis should be GDP per capita. Our y-axis could be a new column: Total Emissions, made by the product of Per Capita $CO_2$ emissions and the total population of each country.
66
+
67
+ ```python
68
+ #Make the 'Total CO2 Emissions' column
69
+ total_co2_emissions = co2_table.column('Per capita CO2 emissions') * co2_table.column('Total population (Gapminder, HYDE & UN)')
70
+ co2_table = co2_table.with_column('Total CO2 Emissions', total_co2_emissions )
71
+ co2_table.sort("GDP per capita", descending=True)
72
+ ```
73
+
74
+ Observe the 'nan' values spread across almost all columns. These are 'empty' data points, where data has simply not been collected. To ensure the validity of our analysis, we decide to remove all rows with 'per capita $CO_2$ emissions' and 'total $CO_2$ emissions' are empty. For this, we use the **.where** and **.are.above(0)** methods from DATA 8. Furthermore, we select the columns relevant to our inquiry. We also sort the table to have the biggest emitters at the top and remove any continent from the 'entity column'.
75
+
76
+ ```python
77
+ #Selecting relevant columns, removing 'NaN' values, & sorting descending
78
+ co2_table = co2_table.select('Entity', 'Total CO2 Emissions', 'GDP per capita')
79
+ co2_table = co2_table.sort('Total CO2 Emissions', descending=True)
80
+ co2_table = co2_table.where('Total CO2 Emissions', are.above(0))
81
+ co2_table = co2_table.where('GDP per capita', are.above(0))
82
+ continents = make_array('World', 'Asia', 'Europe', 'Africa', 'North America', 'Latin America', 'Oceania')
83
+ co2_table = co2_table.where('Entity', are.not_contained_in(continents))
84
+ co2_table
85
+ ```
86
+
87
+ Having cleaned our data, look at a scatter plot and see if we can make sense of it. What might we expect to see plotting Total CO2 emissions over GDP per capita? Do you expect any outliers? If so, what countries do you think that would be?
88
+
89
+ ```python
90
+ #Let's scatter plot our data. See any association between GDP per capita and Total CO2 Emissions?
91
+ co2_table.scatter('GDP per capita', 'Total CO2 Emissions')
92
+ ```
93
+
94
+ This plot is hard to read, and is dominated by a few outliers (large emitters and very wealthy nations). Hence, let us take the log of each axis. Percentage changes in GDP per capita should now refer to percentage changes in total emissions in each country.
95
+
96
+ ```python
97
+ # use np.log on each column
98
+ gdp_log = np.log(co2_table.column('GDP per capita'))
99
+ co2_log = np.log(co2_table.column('Total CO2 Emissions'))
100
+
101
+ #Log-plot. Easier to see the association?
102
+ log_co2_table = co2_table.with_columns('Log GDP per capita', gdp_log, 'Log Total CO2 Emissions', co2_log)
103
+ log_co2_table.scatter('Log GDP per capita', 'Log Total CO2 Emissions', fit_line = True)
104
+ ```
105
+
106
+ To find out the slope and intercept of that line fitted through the data, we run a simple Linear Regression model using Numpy.
107
+
108
+ ```python
109
+ x = gdp_log
110
+ y = co2_log
111
+ np.polyfit(x, y,1)
112
+ ```
113
+
114
+ ### Part 2: A Historical View on $CO_2$ emissions
115
+
116
+ As of now, it seems like we have a strong linear association between log total $CO_2$ emissions and log GDP per capita. To explore this association further, let us view this from a historical perspective by answering the following question: How has the relationship between the two variables changed over time? To do so, we build the Rosling Plot we sought out in the first place; one for each year the last 120 years.
117
+
118
+ ```python
119
+ #For this, we need the population & continent of each country.
120
+ gapminder = Table.read_table('gapminder - gapminder.csv')
121
+ gapminder
122
+ ```
123
+
124
+ We use the DATA 8 method **.join** you are familiar with by now to add continent and population for each nation. The color of the "bubbles" we are making will represent the continent, while its size represents the population.
125
+
126
+ ```python
127
+ bubble_table = co2_table.join('Entity', gapminder, 'country')
128
+ bubble_table = bubble_table.select('Entity', 'Total CO2 Emissions', 'GDP per capita','population','continent')
129
+ bubble_table.sort('Total CO2 Emissions', descending=True)
130
+ ```
131
+
132
+ Using this newly created table, we can visualize the log-plot from above in a "friendlier" manner using an imported method called Seaborn. Feel free to check out its documentation here: https://seaborn.pydata.org/generated/seaborn.scatterplot.html
133
+
134
+ ```python
135
+ population = bubble_table.column('population')
136
+ plt.figure(figsize = (8,6), dpi=250)
137
+ #sns.scatterplot(bubble_table.column('GDP per capita'), bubble_table.column('Total CO2 Emissions'), hue = bubble_table.column('continent'), size= population, sizes=(20,400), legend=False);
138
+ sns.scatterplot(
139
+ x=bubble_table.column('GDP per capita'),
140
+ y=bubble_table.column('Total CO2 Emissions'),
141
+ hue=bubble_table.column('continent'),
142
+ size=population,
143
+ sizes=(20, 400),
144
+ legend=False
145
+ )
146
+ plt.grid(True)
147
+ plt.xscale('log')
148
+ plt.yscale('log')
149
+ plt.xlabel('GDP per capita [USD]')
150
+ plt.ylabel('Total CO2 Emissions [Tons]')
151
+ plt.title('World CO2 Emission in 2018')
152
+ plt.xticks([1000, 10000, 100000],['1k', '10k', '100k'])
153
+ plt.show();
154
+ ```
155
+
156
+ So, this was our Rosling Plot for 2018. From here, we aim to create a function that we can apply to each year in our original dataset. Remember the one with 50.000+ entries, each representing a country in a given year?
157
+
158
+ One thing to note is that our could be changed a tad: Would it not make sense to plot $CO_2$ emissions per capita over GDP per capita? Doing so, we get a sense of the $CO_2$ intensity of GDP.
159
+
160
+ ```python
161
+ def the_bubble_plot(emissions_data, population_data, income_data, geography_data, year):
162
+ # Selecting data for given year & relabel columns
163
+ emissions_data = emissions_data.select('country', f"{year}").relabel(1, 'CO2 per capita [tons]')
164
+ population_data = population_data.select('country', f"{year}").relabel(1, 'Population')
165
+ income_data = income_data.select('country', f"{year}").relabel(1, 'GDP per capita [USD]')
166
+
167
+ # Creating the 'the_bubble_table' with emission, population, income, continent for given year
168
+ the_bubble_table = emissions_data.join('country', population_data)
169
+ the_bubble_table = the_bubble_table.join('country', income_data)
170
+ the_bubble_table = the_bubble_table.join('country', geography_data)
171
+
172
+ # Filter to ensure we have valid emissions data for the given year
173
+ the_bubble_table = the_bubble_table.where('CO2 per capita [tons]', are.above(0))
174
+
175
+ # Prepare data for Seaborn (convert to NumPy arrays)
176
+ gdp_per_capita = the_bubble_table.column('GDP per capita [USD]')
177
+ co2_per_capita = the_bubble_table.column('CO2 per capita [tons]')
178
+ population = the_bubble_table.column('Population')
179
+ continent = the_bubble_table.column('continent')
180
+
181
+ # Create the scatter plot
182
+ plt.figure(figsize=(8, 6), dpi=250)
183
+ sns.scatterplot(
184
+ x=gdp_per_capita,
185
+ y=co2_per_capita,
186
+ hue=continent,
187
+ size=population,
188
+ sizes=(20, 400),
189
+ legend=False
190
+ )
191
+
192
+ # Adjusting the plot for better visualization
193
+ plt.grid(False)
194
+ plt.xscale('log')
195
+ plt.yscale('log')
196
+ plt.xlabel('GDP per capita [USD]', fontsize='large')
197
+ plt.ylabel('CO2 per capita [tons]', fontsize='large')
198
+ plt.title(f"World CO2 Emissions in {year}", fontsize='x-large')
199
+ plt.xticks([10**0, 10**1, 10**2], ['1k', '10k', '100k'])
200
+ plt.yticks([10**-2, 10**-1, 10**0, 10**1], ['0.01', '0.1', '1', '10'])
201
+ plt.show()
202
+
203
+
204
+ # Importing data from the Gapminder Foundation
205
+ emissions_data = Table.read_table('co2_emissions_tonnes_per_person.csv')
206
+ population_data = Table.read_table('population_total.csv')
207
+ income_data = Table.read_table('income_per_person_gdppercapita_ppp_inflation_adjusted.csv')
208
+ geography_data = Table.read_table('gapminder - gapminder.csv').select('country', 'continent')
209
+
210
+ # Call the function for the year 2017
211
+ the_bubble_plot(emissions_data, population_data, income_data, geography_data, 2017)
212
+ ```
213
+
214
+ ```python
215
+
216
+ ```
217
+