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.
- checksums.yaml +7 -0
- data/F24LS_md/ Lecture 4 - Public.md +347 -0
- data/F24LS_md/Lecture 1 - Introduction and Overview.md +327 -0
- data/F24LS_md/Lecture 10 - Development_.md +631 -0
- data/F24LS_md/Lecture 11 - Econometrics.md +345 -0
- data/F24LS_md/Lecture 12 - Finance.md +692 -0
- data/F24LS_md/Lecture 13 - Environmental Economics.md +299 -0
- data/F24LS_md/Lecture 15 - Conclusion.md +272 -0
- data/F24LS_md/Lecture 2 - Demand.md +349 -0
- data/F24LS_md/Lecture 3 - Supply.md +329 -0
- data/F24LS_md/Lecture 5 - Production C-D.md +291 -0
- data/F24LS_md/Lecture 6 - Utility and Latex.md +440 -0
- data/F24LS_md/Lecture 7 - Inequality.md +607 -0
- data/F24LS_md/Lecture 8 - Macroeconomics.md +704 -0
- data/F24LS_md/Lecture 8 - Macro.md +700 -0
- data/F24LS_md/Lecture 9 - Game Theory_.md +436 -0
- data/F24LS_md/summary.yaml +105 -0
- data/F24Lec_MD/LecNB_summary.yaml +206 -0
- data/F24Lec_MD/lec01/lec01.md +267 -0
- data/F24Lec_MD/lec02/Avocados_demand.md +425 -0
- data/F24Lec_MD/lec02/Demand_Steps_24.md +126 -0
- data/F24Lec_MD/lec02/PriceElasticity.md +83 -0
- data/F24Lec_MD/lec02/ScannerData_Beer.md +171 -0
- data/F24Lec_MD/lec02/demand-curve-Fa24.md +213 -0
- data/F24Lec_MD/lec03/3.0-CubicCostCurve.md +239 -0
- data/F24Lec_MD/lec03/3.1-Supply.md +274 -0
- data/F24Lec_MD/lec03/3.2-sympy.md +332 -0
- data/F24Lec_MD/lec03/3.3a-california-energy.md +120 -0
- data/F24Lec_MD/lec03/3.3b-a-really-hot-tuesday.md +121 -0
- data/F24Lec_MD/lec04/lec04-CSfromSurvey-closed.md +335 -0
- data/F24Lec_MD/lec04/lec04-CSfromSurvey.md +331 -0
- data/F24Lec_MD/lec04/lec04-Supply-Demand-closed.md +519 -0
- data/F24Lec_MD/lec04/lec04-Supply-Demand.md +514 -0
- data/F24Lec_MD/lec04/lec04-four-plot-24.md +34 -0
- data/F24Lec_MD/lec04/lec04-four-plot.md +34 -0
- data/F24Lec_MD/lec05/Lec5-Cobb-Douglas.md +131 -0
- data/F24Lec_MD/lec05/Lec5-CobbD-AER1928.md +283 -0
- data/F24Lec_MD/lec06/6.1-Sympy-Differentiation.md +253 -0
- data/F24Lec_MD/lec06/6.2-3D-utility.md +287 -0
- data/F24Lec_MD/lec06/6.3-QuantEcon-Optimization.md +399 -0
- data/F24Lec_MD/lec06/6.4-latex.md +138 -0
- data/F24Lec_MD/lec06/6.5-Edgeworth.md +269 -0
- data/F24Lec_MD/lec07/7.1-inequality.md +283 -0
- data/F24Lec_MD/lec07/7.2-historical-inequality.md +237 -0
- data/F24Lec_MD/lec08/macro-fred-api.md +313 -0
- data/F24Lec_MD/lec09/lecNB-prisoners-dilemma.md +88 -0
- data/F24Lec_MD/lec10/Lec10.2-waterguard.md +401 -0
- data/F24Lec_MD/lec10/lec10.1-mapping.md +199 -0
- data/F24Lec_MD/lec11/11.1-slr.md +305 -0
- data/F24Lec_MD/lec11/11.2-mlr.md +171 -0
- data/F24Lec_MD/lec12/Lec12-4-PersonalFinance.md +590 -0
- data/F24Lec_MD/lec12/lec12-1_Interest_Payments.md +267 -0
- data/F24Lec_MD/lec12/lec12-2-stocks-options.md +235 -0
- data/F24Lec_MD/lec13/Co2_ClimateChange.md +139 -0
- data/F24Lec_MD/lec13/ConstructingMAC.md +213 -0
- data/F24Lec_MD/lec13/EmissionsTracker.md +170 -0
- data/F24Lec_MD/lec13/KuznetsHypothesis.md +219 -0
- data/F24Lec_MD/lec13/RoslingPlots.md +217 -0
- data/F24Lec_MD/lec15/vibecession.md +485 -0
- data/F24Textbook_MD/00-intro/index.md +292 -0
- data/F24Textbook_MD/01-demand/01-demand.md +152 -0
- data/F24Textbook_MD/01-demand/02-example.md +131 -0
- data/F24Textbook_MD/01-demand/03-log-log.md +284 -0
- data/F24Textbook_MD/01-demand/04-elasticity.md +248 -0
- data/F24Textbook_MD/01-demand/index.md +15 -0
- data/F24Textbook_MD/02-supply/01-supply.md +203 -0
- data/F24Textbook_MD/02-supply/02-eep147-example.md +86 -0
- data/F24Textbook_MD/02-supply/03-sympy.md +138 -0
- data/F24Textbook_MD/02-supply/04-market-equilibria.md +204 -0
- data/F24Textbook_MD/02-supply/index.md +16 -0
- data/F24Textbook_MD/03-public/govt-intervention.md +73 -0
- data/F24Textbook_MD/03-public/index.md +10 -0
- data/F24Textbook_MD/03-public/surplus.md +351 -0
- data/F24Textbook_MD/03-public/taxes-subsidies.md +282 -0
- data/F24Textbook_MD/04-production/index.md +15 -0
- data/F24Textbook_MD/04-production/production.md +178 -0
- data/F24Textbook_MD/04-production/shifts.md +296 -0
- data/F24Textbook_MD/05-utility/budget-constraints.md +166 -0
- data/F24Textbook_MD/05-utility/index.md +15 -0
- data/F24Textbook_MD/05-utility/utility.md +136 -0
- data/F24Textbook_MD/06-inequality/historical-inequality.md +253 -0
- data/F24Textbook_MD/06-inequality/index.md +15 -0
- data/F24Textbook_MD/06-inequality/inequality.md +226 -0
- data/F24Textbook_MD/07-game-theory/bertrand.md +257 -0
- data/F24Textbook_MD/07-game-theory/cournot.md +333 -0
- data/F24Textbook_MD/07-game-theory/equilibria-oligopolies.md +96 -0
- data/F24Textbook_MD/07-game-theory/expected-utility.md +61 -0
- data/F24Textbook_MD/07-game-theory/index.md +19 -0
- data/F24Textbook_MD/07-game-theory/python-classes.md +340 -0
- data/F24Textbook_MD/08-development/index.md +35 -0
- data/F24Textbook_MD/09-macro/CentralBanks.md +101 -0
- data/F24Textbook_MD/09-macro/Indicators.md +77 -0
- data/F24Textbook_MD/09-macro/fiscal_policy.md +36 -0
- data/F24Textbook_MD/09-macro/index.md +14 -0
- data/F24Textbook_MD/09-macro/is_curve.md +76 -0
- data/F24Textbook_MD/09-macro/phillips_curve.md +70 -0
- data/F24Textbook_MD/10-finance/index.md +10 -0
- data/F24Textbook_MD/10-finance/options.md +178 -0
- data/F24Textbook_MD/10-finance/value-interest.md +60 -0
- data/F24Textbook_MD/11-econometrics/index.md +16 -0
- data/F24Textbook_MD/11-econometrics/multivariable.md +218 -0
- data/F24Textbook_MD/11-econometrics/reading-econ-papers.md +25 -0
- data/F24Textbook_MD/11-econometrics/single-variable.md +483 -0
- data/F24Textbook_MD/11-econometrics/statsmodels.md +58 -0
- data/F24Textbook_MD/12-environmental/KuznetsHypothesis-Copy1.md +187 -0
- data/F24Textbook_MD/12-environmental/KuznetsHypothesis.md +187 -0
- data/F24Textbook_MD/12-environmental/MAC.md +254 -0
- data/F24Textbook_MD/12-environmental/index.md +36 -0
- data/F24Textbook_MD/LICENSE.md +11 -0
- data/F24Textbook_MD/intro.md +26 -0
- data/F24Textbook_MD/references.md +25 -0
- data/F24Textbook_MD/summary.yaml +414 -0
- metadata +155 -0
@@ -0,0 +1,292 @@
|
|
1
|
+
---
|
2
|
+
title: index
|
3
|
+
type: textbook
|
4
|
+
source_path: content/00-intro/index.ipynb
|
5
|
+
chapter: 0
|
6
|
+
---
|
7
|
+
|
8
|
+
# Introduction
|
9
|
+
|
10
|
+
## The Financial Benefits of Your Major
|
11
|
+
|
12
|
+
```python
|
13
|
+
import ipywidgets as widgets
|
14
|
+
from datascience import *
|
15
|
+
import numpy as np
|
16
|
+
from ipywidgets import interact, interactive, fixed, interact_manual
|
17
|
+
import ipywidgets as widgets
|
18
|
+
from IPython.display import display
|
19
|
+
import pandas as pd
|
20
|
+
%matplotlib inline
|
21
|
+
import matplotlib.pyplot as plt
|
22
|
+
plt.style.use('fivethirtyeight')
|
23
|
+
```
|
24
|
+
|
25
|
+
```python
|
26
|
+
import plotly.graph_objects as go
|
27
|
+
from plotly.offline import plot
|
28
|
+
from IPython.display import display, HTML
|
29
|
+
```
|
30
|
+
|
31
|
+
Welcome to Data 88E: *Economics Models*! This class will explore the intersection of Data Science and Economics.
|
32
|
+
Specifically, we will utilize methods and techniques in data science to examine both basic and upper-division Economics concepts.
|
33
|
+
Throughout the course, we will consider a variety of economic problems both on the macro and micro level.
|
34
|
+
|
35
|
+
In the first demo of the course, we hope to give you a sense of the types problems you can expect to explore this semester by considering a problem that may be of personal relevance to you: the post-graduate incomes of different majors at Cal.
|
36
|
+
|
37
|
+
We will be using various visualization techniques to analyze the median incomes of different majors at UC Berkeley, in addition to the median incomes of those same majors at other colleges.
|
38
|
+
If you forgot, the median income is the "middle" value: if you sorted all the individual incomes of a major in ascending order, the median would be the value that's exactly in the middle. The median is also called the 50th percentile -- at the median, exactly 50% of the individuals have an income lower than the median.
|
39
|
+
|
40
|
+
Do not be concerned if you don't understand the code below: this entire exercise is purely a demo to motivate many profound concepts in Economics.
|
41
|
+
If you're interested, you may choose to come back to this demo at the end of the course and consider all the different techniques utilized in it - it'd be a great way of reflecting upon how much you've learnt!
|
42
|
+
|
43
|
+
## Data Collection
|
44
|
+
|
45
|
+
Before we can use data science to tackle any issue, we must–well–obtain data (kind of mind-boggling, I know).
|
46
|
+
Recall that we want to examine the median incomes of different majors at UC Berkeley as well as the median incomes of those same majors at other colleges.
|
47
|
+
The term 'other colleges' is a fairly general one, and in this case we shall consider the average median incomes of those majors at alll other colleges in the United States.
|
48
|
+
|
49
|
+
In order to obtain a dataset, you can either collect it yourself (via surveys, questionnaires, etc.) or you can use datasets that others have gathered for you.
|
50
|
+
In this demo, we are combining 3 different datasets:
|
51
|
+
- The median income for each major at Cal was obtained from [Cal's 2024 First Destination survey](https://calviz.berkeley.edu/t/SAPublic/views/FirstDestinations2024-2/Employment).
|
52
|
+
- The median income for each major overall was obtained from surveys conducted by the American Community Survey (ACS) from 2010 to 2012, a very popular data source for Economics Research! In the survey, ACS essentially calls college graduates and asked them their income as well as what they majored in at college. (As a side note, FiveThirtyEight later published this article:[The Economic Guide to Picking a College Major](https://fivethirtyeight.com/features/the-economic-guide-to-picking-a-college-major/) using the results of the survey.) In this project, we will be using a modified version of the ACS survey - we will only be looking at the respondents who are 28 or younger. Can you think of why we would do this?
|
53
|
+
- The longitudinal data on long-run outcomes of UC Berkeley alumni was obtained from the [University of California webpage](https://www.universityofcalifornia.edu/infocenter/berkeley-outcomes). We will use this dataset later for a slightly different analysis.
|
54
|
+
|
55
|
+
Take a moment to consider the ways in which the 3 different datasets were created.
|
56
|
+
Is it fair to draw direct comparisons between the datasets? What would be some potential issues and how could the differences in our datasets affect our analysis?
|
57
|
+
|
58
|
+
|
59
|
+
### Mean vs Median
|
60
|
+
Before proceeding further, it is important to consider why we are choosing to look at the median, and not the average, income.
|
61
|
+
In order to answer this question, let us think about what the *distribution* of incomes for a population would look like.
|
62
|
+
Most likely, you would see a high amount of incomes around or slightly below the mean, with a few massive outlier incomes above the mean.
|
63
|
+
For example, consider a theatre major who becomes a star on Broadway - while they'd be doing absolutely fantastic in their career, they are not representative of the average theatre graduate from Berkeley and would likely pull the average income way up.
|
64
|
+
For this reason, using the median is more *robust*: it gives us a better idea of what the typical graduate for any major can generally expect to earn.
|
65
|
+
|
66
|
+
Now we'll load in all the data.
|
67
|
+
Take a look at the tables for each dataset.
|
68
|
+
Note that `P25th` referes to the 25th percentile of incomes (the income level at which exactly 25% of incomes are lower) and `P75th` refers to the 75th percentile of incomes (the income level at which exactly 75% of incomes are lower).
|
69
|
+
You may not know what all the different columns in the tables mean. That's okay!
|
70
|
+
As data scientists, we often encounter a lot of irrelevant data that we will discard later.
|
71
|
+
|
72
|
+
```python
|
73
|
+
# Load in table of all majors' median incomes at Cal
|
74
|
+
cal_income = Table.read_table("cal_income.csv")
|
75
|
+
cal_income.show(10)
|
76
|
+
```
|
77
|
+
|
78
|
+
```python
|
79
|
+
# Load in table of all other universities' average major median incomes
|
80
|
+
other_income = Table.read_table("recent-grads.csv")
|
81
|
+
other_income.show(10)
|
82
|
+
```
|
83
|
+
|
84
|
+
To make direct comparisons across majors, we combined all the tables above into a single one for us to use below.
|
85
|
+
|
86
|
+
```python
|
87
|
+
majors = Table.read_table("cal_vs_all.csv")
|
88
|
+
majors.show(10)
|
89
|
+
```
|
90
|
+
|
91
|
+
Our combined table above dropped the columns in above tables that we didn't need to conduct our exploration.
|
92
|
+
It has a column `Median Income Difference`: this column is the Berkeley median income minus the overall median income for each major.
|
93
|
+
It gives us a sense of the value of Cal over the average university: the difference is the additional income we recieve from obtaining a Cal degree.
|
94
|
+
|
95
|
+
Before moving forward, take a second to consider how well the above tables would match with each other.
|
96
|
+
For example, Electrical Engineering and Computer Science (EECS) is a popular major at Berkeley. However, the `majors` dataset didn't have a direct equivalent for it.
|
97
|
+
Instead, the `majors` dataset had Electrical Engineering, Electrical Engineering Technologies and Computer Engineering as separate majors.
|
98
|
+
Since in theory students in EECS focus more on computer engineering, we chose to use the computer engineering data for drawing comparions in our final, combined table.
|
99
|
+
However, there's room for ambiguity here and that is another potential flaw in our exploration!
|
100
|
+
|
101
|
+
The below graph displays all the median salaries for all the majors in our dataset side by side. Feel free to look at the values for a few seconds - do you find anything interesting?
|
102
|
+
[Following image is a bar chart of Median Incomes for Selected Majors]
|
103
|
+
|
104
|
+
```python
|
105
|
+
def display_major_table(major):
|
106
|
+
selected = majors.where("Major", are.contained_in(major))
|
107
|
+
selected.show()
|
108
|
+
|
109
|
+
ind = np.arange(selected.num_rows)
|
110
|
+
width = 0.35
|
111
|
+
|
112
|
+
fig, ax = plt.subplots()
|
113
|
+
rects1 = ax.bar(ind - width/2, selected.column("Cal Median"), width,
|
114
|
+
label='Cal Median', color = "navy")
|
115
|
+
rects2 = ax.bar(ind + width/2, selected.column("Overall Median"), width,
|
116
|
+
label='Overall Median', color = "goldenrod")
|
117
|
+
|
118
|
+
ax.set_ylabel('Income')
|
119
|
+
ax.set_xticks(ind)
|
120
|
+
ax.set_xticklabels(selected.column("Major"))
|
121
|
+
ax.set_title("Median Incomes for Selected Majors at Cal (Blue) and Other Universities (Gold)", fontsize= 13)
|
122
|
+
plt.xticks(rotation=90)
|
123
|
+
|
124
|
+
|
125
|
+
dropdown_majors = widgets.SelectMultiple(
|
126
|
+
options=majors.column("Major"),
|
127
|
+
description="Major",
|
128
|
+
disabled=False
|
129
|
+
)
|
130
|
+
widgets.interact(display_major_table, major=dropdown_majors)
|
131
|
+
```
|
132
|
+
|
133
|
+
```python
|
134
|
+
mjs = majors.column("Major")[::-1]
|
135
|
+
cal = majors.column("Cal Median")[::-1]
|
136
|
+
ovr = majors.column("Overall Median")[::-1]
|
137
|
+
|
138
|
+
fig = go.Figure()
|
139
|
+
fig.add_trace(go.Bar(name="Cal Median", y=mjs, x=cal, orientation="h"))
|
140
|
+
fig.add_trace(go.Bar(name="Overall Median", y=mjs, x=ovr, orientation="h"))
|
141
|
+
fig.update_layout(
|
142
|
+
title="Median Incomes for Selected Majors at Cal (Blue) and Other Universities (Red)",
|
143
|
+
yaxis=dict(title=dict(text="Major")),
|
144
|
+
height=1200,
|
145
|
+
)
|
146
|
+
plot(fig, filename="fig0.html", auto_open=False)
|
147
|
+
|
148
|
+
display(HTML("fig0.html"))
|
149
|
+
```
|
150
|
+
|
151
|
+
## The most lucrative major
|
152
|
+
|
153
|
+
Let's imagine that Belfort is a freshman at Berkeley.
|
154
|
+
Belfort is a very unique individual - he is someone who would be equally good at all majors and enjoys all majors equally.
|
155
|
+
He also believes that money is the most important thing in the world.
|
156
|
+
These assumptions are vastly oversimplifcations and not the case for anyone in real life; but in Economics you'll find that we end up making significant simplifications to abstract away all the potential complications!
|
157
|
+
|
158
|
+
Since Belfort is equally good at and happy with all majors at Cal, the major he chooses is purely dependent on how much money he can earn after college with that major.
|
159
|
+
Therefore, he will choose the major with the highest median income.
|
160
|
+
|
161
|
+
Let us sort our table by the `Cal Median` column in descending order to see which major that would be.
|
162
|
+
|
163
|
+
```python
|
164
|
+
majors.sort('Cal Median',descending=True).show(10)
|
165
|
+
```
|
166
|
+
|
167
|
+
However, what if instead of just wanting the maximum amount of cash after college, Belfort was super proud of getting into Berkeley and instead wanted to maximise the amount of additional benefit he recieves from attending Berkeley over other universities?
|
168
|
+
Let's sort our table by the `Median Income Difference` column in descending order to see which major would give Belfort the highest additional income from going to Berkeley.
|
169
|
+
|
170
|
+
Do any values in either of our sorted table surprise you? Why might that be?
|
171
|
+
|
172
|
+
```python
|
173
|
+
majors.sort("Median Income Difference",descending=True).show(10)
|
174
|
+
```
|
175
|
+
|
176
|
+
Let's now do the opposite and sort our table by the `Median Income Difference` column in ascending order.
|
177
|
+
|
178
|
+
```python
|
179
|
+
majors.sort("Median Income Difference").show(10)
|
180
|
+
```
|
181
|
+
|
182
|
+
As you can see in the table, the median income difference for both nuclear engineering and astrophysics is negative.
|
183
|
+
This is rather peculiar, especially since Cal has great programs for both those majors.
|
184
|
+
Why would Cal graduates earn less income than the graduates of the average college for those 2 majors?
|
185
|
+
|
186
|
+
*Hint*: consider what each of our datasets describes. Is it an apples-to-apples comparison?
|
187
|
+
|
188
|
+
The answer is because the dataset with the median incomes for all colleges actually described recent graduates (people who are 28 and younger, rather than just fresh college graduates.
|
189
|
+
It is likely that most people who graduate with Nuclear Engineering and Astrophysics degrees in other colleges tend to stay in the industry for their fields and keep accumulating experience. This would explain why a dataset that includes data from 28 year olds would have a higher median income than fresh Cal graduates in the same field.
|
190
|
+
|
191
|
+
### Generalization and Causal Inference
|
192
|
+
|
193
|
+
While Belfort would be equally good at and enjoy all majors equally, the implications for him may not generalize for anyone else.
|
194
|
+
|
195
|
+
If you decide to major in EECS, it does not mean that you will have more income post-grad than that from majoring in anything else. For example, someone who is a fantastic artist but not very good at computer science would probably make far more money majoring in art than in EECS. In addition, just because EECS has the highest median income overall doesn't mean that any individual is guaranteed a high median income if they decide to major in EECS. Overall, our results are not completely *generalizable* to others.
|
196
|
+
|
197
|
+
The causal effect of majoring in EECS on incomes may also be overstated. Consider the fact that those who major in EECS tend to come from families whose parents are already in working in tech. As a result, these students will likely also find better jobs post-grad. This is what we call a confounding variable -- it is positively correlated with our treatment variable of majoring in EECS. If we do not observe this confounding factor, our analysis would likely overstate the effect of an EECS degree on post-grad incomes.
|
198
|
+
|
199
|
+
### A brief discourse on utility
|
200
|
+
|
201
|
+
From seeing our results, you may be wondering: *why doesn't everyone just major in EECS then*?
|
202
|
+
|
203
|
+
For Belfort, money is the only thing in the world that derives happiness.
|
204
|
+
However, this is once again an oversimplication for the vast majority of people in the real world.
|
205
|
+
People derive utility from sources other than just their bank account; often, we choose relatively lower-paying jobs in order to derive more happiness in our lives.
|
206
|
+
|
207
|
+
**Utility** is a measure of 'satisfaction' or 'happiness' when we consume a good, while **disutility** is a measure of 'unsatisfaction' or 'harm' when we consume a *bad*. In economics, one assumption we will always make is that people will always seek to maximize their utility and minimize their disutility.
|
208
|
+
|
209
|
+
However, we encounter *diminishing marginal utility* as we consume more and more of a good. For example, the utility of the first cookie you eat is likely much higher than the 20th cookie you eat. Similarly, we may encounter *increasing marginal disutility* as we consume more and more of a bad. For example, the disutility of the first hour doing something you dread is probably not as bad as the 10th hour of doing something you dread.
|
210
|
+
|
211
|
+
For many of us, money provides a source of utility, while working or the studying required to get there may provide a source of disutility. This presents a tradeoff: for some, the disutility from studying EECS or working as a programmer greatly outweights the utility from the money. Perhaps another job in a different field requires significantly lower disutility to achieve, without much impact on the utility of the income associated with it. This phenomenon would explain why not everyone decides to major in EECS!
|
212
|
+
|
213
|
+
## Incomes Over Time: Computer Science vs Economics
|
214
|
+
|
215
|
+
So far our exploration of the data has considered a rather general timeframe of "post graduation", but perhaps it would be more insightful if we dove in and took a look at how incomes differed across various ages. We can do so using the table below that consists of data collected by the [UC ClioMetric History Project](http://uccliometric.org/).
|
216
|
+
By compiling a database of digital student transcripts of all UC undergraduates and then linking California wages to individuals in the transcript database,
|
217
|
+
they were able to produce comprehensive dashboards that visualize demographics, major choices, and long-run incomes of each UC campus’s alumni over the past 70 years.
|
218
|
+
|
219
|
+
|
220
|
+
You can learn more about how they collected the data in [Incomes Over Time ](https://www.universityofcalifornia.edu/infocenter/long-run-methodology), but for now we will just focus on a snapshot of the data.
|
221
|
+
In particular, we are interested in exploring how percentile incomes compare between Cal alumni who majored in computer science versus those who majored in economics. Run the following cell to check it out.
|
222
|
+
|
223
|
+
```python
|
224
|
+
cs_vs_econ=Table.read_table("cs_econ_by_age.csv")
|
225
|
+
cs_vs_econ.show(10)
|
226
|
+
```
|
227
|
+
|
228
|
+
Here we have a table where each row corresponds to a certain age.
|
229
|
+
It begins with age 23 (typically how old people are when getting their first job out of college), and goes up until age 62 (when people retire from the workforce).
|
230
|
+
|
231
|
+
Let's graph our data using some line plots: line plots are especially useful when trying to visualize trends that change over time.
|
232
|
+
|
233
|
+
Run the following cell to visualize the data. The yellow lines correspond to CS incomes, while the blue lines correspond to Econ incomes.
|
234
|
+
|
235
|
+
[Following image is a graph of "Comparing Incomes of Computer Science Majors vs Economics Majors"]
|
236
|
+
|
237
|
+
```python
|
238
|
+
from labellines import labelLines
|
239
|
+
df = cs_vs_econ.to_df()
|
240
|
+
df.plot("Age",color=["#8A3B00","#E03B00","#DD31E6","#BB689C","navy","mediumblue","royalblue","#5A83A4"])
|
241
|
+
plt.ylabel("Annual Income in Dollars")
|
242
|
+
plt.title("Comparing Incomes of Computer Science Majors vs Economics Majors");
|
243
|
+
|
244
|
+
#add labels
|
245
|
+
# plt.text(62.5, 65000, 'Econ 25th Percentile')
|
246
|
+
# plt.text(62.5, 100000, 'CS 25th Percentile')
|
247
|
+
# plt.text(62.5, 120000, 'Econ Median')
|
248
|
+
|
249
|
+
xvals = [55, 55, 55, 55, 55, 55, 55, 55]
|
250
|
+
lines = plt.gca().get_lines()
|
251
|
+
labelLines(lines, align=True, xvals=xvals)
|
252
|
+
|
253
|
+
fig = plt.gcf()
|
254
|
+
fig.set_size_inches(15, 11)
|
255
|
+
```
|
256
|
+
|
257
|
+
Let's take a look at how the incomes compare at each percentile. The most notable trend is probably the fact that for the most the part, CS majors typically make more money than Econ majors.
|
258
|
+
We especially observe this trend in the 25th and 50th percentiles, and this follows accordingly with our exploration earlier in the notebook that students who majored in L&S Computer Science on average had a higher median income than pretty much every other major.
|
259
|
+
|
260
|
+
The graph above helps explain why CS is one of the most popular majors here at Berkeley.
|
261
|
+
Software engineering and related disciplines have a huge demand for fresh talent, so that individuals entering these fields are duly compensated. This in and of itself is a big appeal of students wanting to major in computer science.
|
262
|
+
|
263
|
+
Right off the bat out of college, fresh CS graduates are looking at a six figure income: even the 25th percentile of CS majors are making over $103,000 by the time they are 25. At any given percentile level, CS graduates outearn their Economics counterparts immediately post-graduation.
|
264
|
+
|
265
|
+
### Intertemporal Effects
|
266
|
+
|
267
|
+
However, we don't just choose our majors based off of the immediate post-graduation income. Intuitively, we would want to maximize our total lifetime income we make. This idea is called *intertermporal utility maximization*: Economists often take into account one's utility across all possible time periods.
|
268
|
+
|
269
|
+
Considering lifetime income, which major would be better? Well, it depends: if you are at the bottom 25th or 50th percentile, CS is better. This suggests that the typical Economics major will likely never outearn the the typical CS major.
|
270
|
+
|
271
|
+
However, we observe that Economics majors at higher percentiles ultimately overtake CS majors in earnings. Intuitively, this should make sense. Perhaps top Economics majors are more likely to become successful executives later on in their careers while make more money than top CS majors, who continue to stay as software engineers or become engineering managers.
|
272
|
+
|
273
|
+
### Risk
|
274
|
+
We observe that Economics majors have a much larger spread in their lifetime earnings than CS majors: top Economics graduates make significantly more than bottom Economics graduates, compared to top CS and bottom CS graduates.
|
275
|
+
|
276
|
+
This brings to the light the notion of risk. Majoring in CS carries relatively lower variance: whether you are
|
277
|
+
a top notch developer in the 75th percentile or a subpar developer in the 25th percentile, you will probably make a solid living. Since most CS majors typically end up pursuing similar careers in the realms of software development, there is less **variance** in the occupations. There is also less **risk**: most CS majors can expect to land a software engineering job and continue working as one twenty years into their career.
|
278
|
+
|
279
|
+
The same story is less true for Economics majors: a top-notch Economics major will significantly out-earn a subpar Economics major. This is partly due to the vastly differing occupation types Economics majors become: analysts, bankers, consultants, just to name a few (Economics is a very versatile degree, afterall). Twenty years down the line, the top Economics majors will have higher ceilings perhaps with a lot of opportunity for leadership or executive positions. There is a lot more **variance** in the types of jobs and thus salaries that Economics majors will attain. In addition, there is a lot more **risk**: not every Economics major will become a top executive, and most end up with more 'average' jobs that earn less than that of similar percentile CS majors.
|
280
|
+
|
281
|
+
This means that if you know you are at the top regardless of your major, you will tend to ultimately earn more income as an Economics major than a CS major. But a caveat: it's impossible to guarantee that you will be in the top, no matter how hard you work. Often, life has uncertainties and involves a great deal of luck to become successful.
|
282
|
+
|
283
|
+
The table and graph above only considered the percentile incomes of CS and Economics majors, but if you're interested in drawing more comparisons, check out [Long Run outcomes for UC Berkeley Alumni](https://www.universityofcalifornia.edu/infocenter/berkeley-outcomes). You can compare between all types of popular majors at UC Berkeley, and even toggle around with more features like gender, ethnicity, or even specific courses.
|
284
|
+
|
285
|
+
## An Afterword
|
286
|
+
|
287
|
+
In this demo, we've covered a series of fundamental Economics ideas such as income, utility, and risk. We've also gone over a series of more statistical concepts that are also at the heart of empirical Economics such as causal inference, generalization, and unobserved variables. We did this all using data science techniques and visualizations, while being cognizant of potential sources of error. We will be revisiting a lot of these themes in later parts of the course.
|
288
|
+
|
289
|
+
From this exercise you may have noticed that pursuing either Economics, Data Science, or both are great options in terms of post-graduation incomes. This means you've probably chosen wisely to have ended up in this class.
|
290
|
+
|
291
|
+
Welcome to Data 88E!
|
292
|
+
|
@@ -0,0 +1,152 @@
|
|
1
|
+
---
|
2
|
+
title: 01-demand
|
3
|
+
type: textbook
|
4
|
+
source_path: content/01-demand/01-demand.ipynb
|
5
|
+
chapter: 1
|
6
|
+
---
|
7
|
+
|
8
|
+
```python
|
9
|
+
from datascience import *
|
10
|
+
|
11
|
+
import sympy
|
12
|
+
import matplotlib.pyplot as plt
|
13
|
+
import matplotlib as mpl
|
14
|
+
import matplotlib.patches as patches
|
15
|
+
# plt.style.use('seaborn-muted')
|
16
|
+
%matplotlib inline
|
17
|
+
|
18
|
+
from IPython.display import display
|
19
|
+
import numpy as np
|
20
|
+
import pandas as pd
|
21
|
+
solve = lambda x,y: sympy.solve(x-y)[0] if len(sympy.solve(x-y))==1 else "Not Single Solution"
|
22
|
+
import warnings
|
23
|
+
warnings.filterwarnings('ignore')
|
24
|
+
```
|
25
|
+
|
26
|
+
# Demand Curves
|
27
|
+
|
28
|
+
In this chapter, we will explore one of the most foundational yet important concepts in economics: demand curves. The demand curve shows the graphical relationship between the price of a good or service and the quantity demanded for it over a given period of time.
|
29
|
+
In other words, it shows the quantity of goods or services consumers are willing to buy at each market price.
|
30
|
+
The quantity of goods or services demanded or supplied can be modeled as a function of price, as in:
|
31
|
+
|
32
|
+
$$\text{Quantity} = f(\text{Price})$$
|
33
|
+
|
34
|
+
Notably, the curve is downwards sloping because of the law of demand, which states that *as the price of a good or service increases, the quantity demanded for it decreases, assuming all other factors are held constant*.
|
35
|
+
|
36
|
+
This should make intuitive sense: as prices increase, fewer people are willing to pay the higher price for the same good. On the other hand, as prices decrease, more people are willing to pay the lower price for the same good. Hence, the quantity demanded of a good or service has an inverse relationship with the price.
|
37
|
+
|
38
|
+
For now, let's assume that the relationship is somewhat linear and can be described as
|
39
|
+
|
40
|
+
$$\text{Quantity}_{d}=-a \cdot \text{Price}_{d} + b$$
|
41
|
+
|
42
|
+
We can interpret the equation above as follows: *as the price of a unit increases by 1, there is an $a$ unit decrease in the quantity demanded.* For example, $\text{Quantity}_{d}=-2 \cdot \text{Price}_{d} + 3$ would suggest that a price increase by 1 would decrease overall quantity demanded in the market by 2.
|
43
|
+
|
44
|
+
Price can also be measured as function of quantity to denote demand. In this case, we use an inverse demand function, as it is the inverse function of the demand function above. Since price is a function of quantity,
|
45
|
+
|
46
|
+
$$\text{Price} = f(\text{Quantity})$$
|
47
|
+
|
48
|
+
As we are solving for the inverse of the previous demand function, the inverse demand function for the example above is
|
49
|
+
|
50
|
+
$$\text{Price}_{d}=-\frac{1}{2} \cdot \text{Quantity}_{d} + \dfrac{3}{2}$$
|
51
|
+
|
52
|
+
## Movement and the Demand Curve
|
53
|
+
|
54
|
+
### Shifts in the Demand Curve
|
55
|
+
The demand curve can shift in or out based on exogenous events that occur outside of the market.
|
56
|
+
Some factors other than a change in price of the good/service could be changes in:
|
57
|
+
|
58
|
+
* buyer's income
|
59
|
+
* consumer preferences
|
60
|
+
* expectation of future price/supply/demand
|
61
|
+
* changes in the price of related goods
|
62
|
+
|
63
|
+
If any of these changes occur and causes the demand for the selected good/service to decrease, then the curve shifts to the left as less of the good or service will be demanded at every price. Similarly, if any of these changes causes the demand for the selected good/service to increase, the curve would shift to the right. This signifies that more of the good or service will be demanded at every price. For example, consumers' incomes decreased during the 2008 recession, thus decreasing overall buying power and shifting the demand curve leftwards; a left shift in the demand curve suggests that consumers would purchase fewer quantities of goods at every price.
|
64
|
+
|
65
|
+
```python
|
66
|
+
xs = np.linspace(-10, 20, 100)
|
67
|
+
ys = -3 * xs + 8
|
68
|
+
ys2 = -3 * xs + 3
|
69
|
+
|
70
|
+
arx = 5
|
71
|
+
ary = -8
|
72
|
+
ardx = -1
|
73
|
+
ardy = 0
|
74
|
+
|
75
|
+
fig = plt.figure(figsize=[7,7])
|
76
|
+
plt.plot(xs, ys, label="Original Demand Curve", linewidth=2)
|
77
|
+
plt.plot(xs, ys2, label="Shifted Demand Curve", linestyle="dashed", linewidth=2, color="#049348")
|
78
|
+
plt.arrow(arx, ary, ardx, ardy, head_width=0.8, head_length=0.5, length_includes_head=True)
|
79
|
+
plt.xticks([])
|
80
|
+
plt.yticks([])
|
81
|
+
plt.xlabel("Quantity", size=16)
|
82
|
+
plt.ylabel("Price", size=16)
|
83
|
+
plt.xlim([-0.5, 10.5])
|
84
|
+
plt.ylim([-25, 10])
|
85
|
+
plt.legend()
|
86
|
+
fig.savefig('fig-01-demand-orig-shifted-demand.png', bbox_inches='tight')
|
87
|
+
plt.close(fig)
|
88
|
+
plt.show()
|
89
|
+
```
|
90
|
+
|
91
|
+
```{figure} fig-01-demand-orig-shifted-demand.png
|
92
|
+
---
|
93
|
+
name: orig-shifted-demand.png
|
94
|
+
alt: Graph of shifting demand curve
|
95
|
+
---
|
96
|
+
Fig. Graph of a shifting demand curve
|
97
|
+
```
|
98
|
+
|
99
|
+
### Movements along the Demand Curve
|
100
|
+
|
101
|
+
Above, we looked at when exogenous events affect the demand curve. Another concept is movements along the demand curve, which would be considered endogenous events. In movements along the demand curve, changes in price affect the quantity demanded of the good or service. This assumes ceteris paribus, which means holding all other factors constant. This phenomenom is called the Movement of the Demand Curve. With a change in price, the quantity demanded for the good or service can shift the quantity demanded either upward or downward on the demand curve. For example, consider the shift on the graph below from quantity $q_1$ at price $p_1$ to quantity $q_2$ at price $p_2$.
|
102
|
+
|
103
|
+
[Following image is a graph of a shift along a demand curve]
|
104
|
+
|
105
|
+
```python
|
106
|
+
xs = np.linspace(-10, 20, 100)
|
107
|
+
ys = -3 * xs + 8
|
108
|
+
|
109
|
+
q_1, p_1 = 1, 5
|
110
|
+
q_2, p_2 = 8, -16
|
111
|
+
|
112
|
+
fig = plt.figure(figsize=[7,7])
|
113
|
+
plt.plot(xs, ys, color="#1F578E")
|
114
|
+
plt.scatter([q_1, q_2], [p_1, p_2], s=200, color="g", zorder=15)
|
115
|
+
plt.arrow(q_1, p_1, q_2 - q_1, p_2 - p_1, color="#CB7432", width=.1, head_length=1.5, head_width=0.5, length_includes_head=True, zorder=-1)
|
116
|
+
|
117
|
+
# (q_1, p_1)
|
118
|
+
plt.vlines(q_1, -1000, p_1, linestyle="dashed", color="#1F578E")
|
119
|
+
plt.hlines(p_1, -1000, q_1, linestyle="dashed", color="#1F578E")
|
120
|
+
|
121
|
+
# (q_2, p_2)
|
122
|
+
plt.vlines(q_2, -1000, p_2, linestyle="dashed", color="#1F578E")
|
123
|
+
plt.hlines(p_2, -1000, q_2, linestyle="dashed", color="#1F578E")
|
124
|
+
|
125
|
+
plt.xticks([q_1, q_2], [r"$q_1$", r"$q_2$"], size=14)
|
126
|
+
plt.yticks([p_1, p_2], [r"$p_1$", r"$p_2$"], size=14)
|
127
|
+
plt.xlabel("Quantity", size=16)
|
128
|
+
plt.ylabel("Price", size=16)
|
129
|
+
plt.xlim([-0.5, 10.5])
|
130
|
+
plt.ylim([-25, 10])
|
131
|
+
fig.savefig('fig-01-demand-q1-p1-q2-p2.png', bbox_inches='tight')
|
132
|
+
plt.close(fig)
|
133
|
+
```
|
134
|
+
|
135
|
+
```{figure} fig-01-demand-q1-p1-q2-p2.png
|
136
|
+
---
|
137
|
+
name: fig-01-demand-q1-p1-q2-p2.png
|
138
|
+
alt: Graph of demand curve illustrating change in quantity purchased(q1) at price one(p1) to quanitity purchased(q2) at price two (p2)
|
139
|
+
---
|
140
|
+
Fig. Graph of a shifting demand curve as prices changes -- all other factors constant
|
141
|
+
```
|
142
|
+
|
143
|
+
## Income and Substitution Effect
|
144
|
+
|
145
|
+
Changes in the price of a good also leads to 2 effects, which can help explain the law of demand:
|
146
|
+
|
147
|
+
- **Income Effect**: Examines how the change in price of the good affects income, which then affects the quantity demanded of a good or service. If the price of a good increases, it would require the consumer to spend more of their income on the good. This dissuades consumers from purchasing more of the good, decreasing the quantity demanded. If the price of a good decreases, consumers would spend less money to receive the same good. This increases the quantity demanded for the good, because consumers would have more income remaining to purchase additional units, given the increase in the amount of purchasing power required to obtain the good.
|
148
|
+
- **Substitution Effect**: Examines how the change in price of the good affects its demand relative to other goods and services. If the price of a good increases, then consumers might look at similar goods that function in the same way or yield an equivalent amount of utility as the original good. Consumers are effectively shifting or substituting away from the relatively more expensive good to a cheaper alternative, thereby decreasing the quantity demanded for the original good. The converse is also true: if the price of a good decreases, then consumers that currently purchase other similar goods might start consuming this good instead, because it would cost less money for them to obtain.
|
149
|
+
|
150
|
+
|
151
|
+
For example, if the price of gas increases, the higher price for gas might encourage consumers to look at purchasing more efficient cars, such as electric or hybrid cars, thus decreasing the demand for gas. This is the subsitution effect. If the consumer stays with their original car, then they would have less disposable income after purchasing the now-more-expensive gas, so they might purchase less gas. This is the income effect.
|
152
|
+
|
@@ -0,0 +1,131 @@
|
|
1
|
+
---
|
2
|
+
title: 02-example
|
3
|
+
type: textbook
|
4
|
+
source_path: content/01-demand/02-example.ipynb
|
5
|
+
chapter: 1
|
6
|
+
---
|
7
|
+
|
8
|
+
```python
|
9
|
+
# HIDDEN
|
10
|
+
import numpy as np
|
11
|
+
import pandas as pd
|
12
|
+
import matplotlib.pyplot as plt
|
13
|
+
import warnings
|
14
|
+
warnings.simplefilter("ignore")
|
15
|
+
from matplotlib import patches
|
16
|
+
from datascience import *
|
17
|
+
%matplotlib inline
|
18
|
+
from ipywidgets import interact, interactive, fixed
|
19
|
+
import ipywidgets as widgets
|
20
|
+
```
|
21
|
+
|
22
|
+
# An Empirical Demand Curve
|
23
|
+
|
24
|
+
Let's examine some historical data on non-organic avocado prices and sales volumes in San Francisco from 2015 to 2018. The original dataset is taken from Kaggle and can be found here:[Kaggle Dataset on Avocado Prices](https://www.kaggle.com/neuromusic/avocado-prices).
|
25
|
+
|
26
|
+
```python
|
27
|
+
avocados = Table.read_table("avocados.csv") # is it avocados or avocadoes?
|
28
|
+
avocados
|
29
|
+
```
|
30
|
+
|
31
|
+
## Visualizing the Relationship between Price and Quantity
|
32
|
+
|
33
|
+
To construct the demand curve, let's first see what the relationship between price and quantity is. We would expect to see a downward-sloping line between price and quantity; if a product's price increases, consumers will purchase less, and if a product's price decreases, then consumers will purchase more.
|
34
|
+
|
35
|
+
To find this, we will create a scatterplot and draw a regression line (by setting `fit_line = True` in the `tbl.scatter` call) between the points. Regression lines are helpful because they consolidate all the datapoints into a single line, helping us better understand the relationship between the two variables.
|
36
|
+
|
37
|
+
[Following image is a scatter plot of a demand curve for Avocados]
|
38
|
+
|
39
|
+
```python
|
40
|
+
avocados.scatter("Total Volume", "Average Price", fit_line = True, width = 7, height = 7)
|
41
|
+
plt.title("Demand Curve for Avocados", fontsize = 16);
|
42
|
+
```
|
43
|
+
|
44
|
+
The visualization shows a negative relationship between quantity and price, which is exactly what we expected! As we've discussed, as the price increases, fewer consumers will purchase avocados, so the quantity demanded will decrease. This corresponds to a leftward movement along the demand curve. Alternatively, as the price decreases, the quantity sold will increase because consumers want to maximize their purchasing power and buy more avocados; this is shown by a rightward movement along the curve.
|
45
|
+
|
46
|
+
|
47
|
+
As a quick refresher, scatterplots can show positive, negative, or neutral correlations among two variables:
|
48
|
+
- If two variables have a positive correlation, then as one variable increases, the other increases too.
|
49
|
+
- If two variables have a negative correlation, then as one variable increases, the other decreases.
|
50
|
+
- If two variables have a neutral correlation, then if one varible increases, the other variable is unaffected.
|
51
|
+
|
52
|
+
Note that scatterplots do not show or prove causation between two variables-- it is up to the data scientists to prove any causation.
|
53
|
+
|
54
|
+
## Fitting a Linear Demand Curve
|
55
|
+
|
56
|
+
We will now quantify our demand curve using NumPy's [`np.polyfit` function](https://numpy.org/doc/stable/reference/generated/numpy.polyfit.html). `np.polyfit` returns an array of size 2, where the first element is the slope and the second is the $y$-intercept.
|
57
|
+
|
58
|
+
It takes 3 parameters:
|
59
|
+
- array of x-coordinates
|
60
|
+
- array of y-coordinates
|
61
|
+
- degree of polynomial
|
62
|
+
|
63
|
+
Because we are looking for a **linear** function to serve as the demand curve, we will use 1 for the degree of polynomial.
|
64
|
+
|
65
|
+
The general template for the demand curve is $y = mx + b$, where $m$ is the slope and $b$ is $y$-intercept.
|
66
|
+
|
67
|
+
### Demand with Price as a Function of Quantity
|
68
|
+
|
69
|
+
First, we will fit a demand curve expressed in terms of price as a function of quantity. This aligns with the axes of supply and demand curves, in which the quantity is on the x-axis and price is on the y-axis:
|
70
|
+
|
71
|
+
$$P(Q) = m\cdot Q + b$$
|
72
|
+
|
73
|
+
```python
|
74
|
+
slope, intercept = np.polyfit(avocados.column("Total Volume"), avocados.column("Average Price"), 1)
|
75
|
+
print("The slope is:", slope)
|
76
|
+
print("The intercept is:", intercept)
|
77
|
+
```
|
78
|
+
|
79
|
+
Thus, our demand curve is $P(Q) = -0.00000109Q+ 2.2495$; The slope is -0.00000109 and $y$-intercept is 2.2495. This means that as the quantity demanded increases by 1 unit (in this case, 1 avocado), we would expect to see price to decrease by 0.00000109 units.
|
80
|
+
|
81
|
+
We can plot this line on a graph. Notice that it is the same line as the one when we indicated `fit_line=True` above.
|
82
|
+
|
83
|
+
[Following image is a scatter plot of a demand curve for Avocados]
|
84
|
+
|
85
|
+
```python
|
86
|
+
plt.scatter(avocados.column("Total Volume"), avocados.column("Average Price"))
|
87
|
+
quantities = np.arange(400000, 1600000, 1000)
|
88
|
+
predicted_prices = slope * quantities + intercept
|
89
|
+
plt.plot(quantities, predicted_prices, color = 'red', label = "Demand curve")
|
90
|
+
plt.xlabel("Quantity")
|
91
|
+
plt.ylabel("Price")
|
92
|
+
plt.legend();
|
93
|
+
```
|
94
|
+
|
95
|
+
### Demand with Quantity as a Function of Price
|
96
|
+
|
97
|
+
Our interpretation of the demand curve and its slope above was probably not quite intuitive: changes in quantity demanded likely do not trigger changes in price, but instead it is the other way around. In addition, the slope was tiny: the marginal increase of one additional avocado sold had very little effect from the change in price.
|
98
|
+
|
99
|
+
Thus, it is more intuitive to think the effect a one dollar change in price has on the quantity demanded, and to flip our axes:
|
100
|
+
|
101
|
+
$$D(P) = Q(P) = m\cdot P + b$$
|
102
|
+
|
103
|
+
In this course, we will write $Q(P)$ and $D(P)$ fairly interchangeably when referencing demand.
|
104
|
+
|
105
|
+
One key thing to remember: our axes are flipped for this demand curve! If you want to plot it, note that the left hand side (dependent variable) is actually the x-axis variable, while the independent variable is the y-axis variable.
|
106
|
+
|
107
|
+
Fitting our data using this function, we get:
|
108
|
+
|
109
|
+
```python
|
110
|
+
slope, intercept = np.polyfit(avocados.column("Average Price"), avocados.column("Total Volume"), 1)
|
111
|
+
print("The slope is:", slope)
|
112
|
+
print("The intercept is:", intercept)
|
113
|
+
```
|
114
|
+
|
115
|
+
Here, our demand curve is roughly $Q(P) = -476413P+ 1446952$; the slope is -476413 and $y$-intercept is 1446952. This means that as the price increases by 1 unit (in this case, \$1), we would expect to see quantity demanded to decrease by 476413 units (in this case, 476413 avocados).
|
116
|
+
|
117
|
+
Note that this demand curve is not the same as the previous demand curve! It is not simply the inverse of the previous demand curve.
|
118
|
+
|
119
|
+
Plotting this line on a graph, we see a slightly different demand curve: can you see what is different between the two?
|
120
|
+
|
121
|
+
[Following image is a scatter plot and fit line of a demand curve for Avocados]
|
122
|
+
|
123
|
+
```python
|
124
|
+
plt.scatter(avocados.column("Total Volume"), avocados.column("Average Price"))
|
125
|
+
prices = np.arange(0.2, 2.3, 0.01)
|
126
|
+
predicted_quantities = slope * prices + intercept
|
127
|
+
plt.plot(predicted_quantities, prices, color = 'red', label = "Demand curve")
|
128
|
+
plt.xlabel("Quantity")
|
129
|
+
plt.ylabel("Price")
|
130
|
+
plt.legend();
|
131
|
+
```
|