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,296 @@
|
|
1
|
+
---
|
2
|
+
title: shifts
|
3
|
+
type: textbook
|
4
|
+
source_path: content/04-production/shifts.ipynb
|
5
|
+
chapter: 4
|
6
|
+
---
|
7
|
+
|
8
|
+
```python
|
9
|
+
from textbook_utils import *
|
10
|
+
```
|
11
|
+
|
12
|
+
# Analyzing Shifts in $A$ and $\alpha$
|
13
|
+
|
14
|
+
## Shifts in $A$ and their Effect on Output
|
15
|
+
|
16
|
+
First, let us plot a 3D surface of the Cobb-Douglas production function. Output, $Y$ , will go on the vertical (or $z$ ) axis. Capital and labor will go on the $y$ and $x$ axes, resp. The plot below plots the Cobb-Douglas function with $A=2$, also showing $A=1$ for reference.
|
17
|
+
|
18
|
+
[Following image is a 3D plot of Output increasing with Capital and Labor]
|
19
|
+
|
20
|
+
```python
|
21
|
+
#change_A(2, filename="fig1.html")
|
22
|
+
display(HTML("fig1.html"))
|
23
|
+
```
|
24
|
+
|
25
|
+
Supply or total factor productivity shocks could cause $A$ to change. These occur if there is a change in total output for a given level of capital and labor. Examples of these include financial crises, technology shocks, natural environment/distasters and energy prices.
|
26
|
+
|
27
|
+
[Following image is an interactive 3D plot of Output increasing with Capital and Labor as A changes]
|
28
|
+
|
29
|
+
```python
|
30
|
+
filename = "fig6.html"
|
31
|
+
|
32
|
+
# L_s = np.arange(0, 10.11, 0.1)
|
33
|
+
# K_s = np.arange(0, 10.11, 0.1)
|
34
|
+
# alpha = 0.5
|
35
|
+
# xx, yy = np.meshgrid(K_s, L_s)
|
36
|
+
# # plot_cobb_douglas(curr_V, orig_cobb_douglas(), fr"A = {A}", r"A = 1", filename=filename)
|
37
|
+
|
38
|
+
# layout = go.Layout(
|
39
|
+
# title = "Cobb-Douglas Production Function", autosize=False, width=500, height=500, margin = dict(l = 65, r = 50, b = 65, t = 90),
|
40
|
+
# scene = dict(xaxis = dict(title = 'K'), yaxis = dict(title = 'L'), zaxis = dict(title = 'Y'))
|
41
|
+
# )
|
42
|
+
|
43
|
+
# fig = go.Figure(layout = layout)
|
44
|
+
|
45
|
+
# active = None
|
46
|
+
# As = []
|
47
|
+
# for i, A in enumerate(np.arange(0.5, 10.1, 0.5)):
|
48
|
+
# As.append(A)
|
49
|
+
# if A == 1:
|
50
|
+
# active = i
|
51
|
+
# V = cobb_douglas(A, xx, yy, alpha)
|
52
|
+
# fig.add_trace(go.Surface(
|
53
|
+
# z = V, contours = go.surface.Contours(
|
54
|
+
# z = go.surface.contours.Z(
|
55
|
+
# show = False, project = dict(z = True)
|
56
|
+
# )
|
57
|
+
# ), colorscale = "Electric", showscale = False, name=f"A = {A}", visible=False
|
58
|
+
# ))
|
59
|
+
|
60
|
+
# fig.data[active].visible = True
|
61
|
+
|
62
|
+
# steps = []
|
63
|
+
# for i in range(len(fig.data)):
|
64
|
+
# step = dict(
|
65
|
+
# method="update", args=[
|
66
|
+
# {"visible": [False] * len(fig.data) + [True]},
|
67
|
+
# ], label=f"A = {As[i]}"
|
68
|
+
# )
|
69
|
+
# step["args"][0]["visible"][i] = True
|
70
|
+
# steps.append(step)
|
71
|
+
|
72
|
+
# sliders = [dict(
|
73
|
+
# active=active,
|
74
|
+
# currentvalue={"prefix": ""},
|
75
|
+
# pad={"t": 50},
|
76
|
+
# steps=steps
|
77
|
+
# )]
|
78
|
+
|
79
|
+
# fig.update_layout(sliders=sliders, width=500, height=600)
|
80
|
+
|
81
|
+
# orig_V = orig_cobb_douglas()
|
82
|
+
# fig.add_trace(go.Surface(
|
83
|
+
# z = orig_V, contours = go.surface.Contours(
|
84
|
+
# z = go.surface.contours.Z(
|
85
|
+
# show = False, project = dict(z = True)
|
86
|
+
# )
|
87
|
+
# ), colorscale = "Viridis", showscale = False, name="A = 1"
|
88
|
+
# ))
|
89
|
+
|
90
|
+
# plot(fig, filename=filename, auto_open=False, include_mathjax='cdn')
|
91
|
+
|
92
|
+
display(HTML(filename))
|
93
|
+
```
|
94
|
+
|
95
|
+
Favorable shocks rotate the production function upward through an increase in A. Thus, each unit of input from capital and labor now simulataneously produce more output. What does this mean for the rental rate of capital and the real wage? Recall the functions for both of them:
|
96
|
+
|
97
|
+
$$\begin{aligned}
|
98
|
+
\text{MPL} &= A (1 - \alpha) \left ( \frac{K}{L} \right )^{\alpha} \\
|
99
|
+
\text{MPK} &= \alpha A \left ( \frac{L}{K} \right )^{1 - \alpha}
|
100
|
+
\end{aligned}$$
|
101
|
+
|
102
|
+
Both MPK and MPL will increase by a factor of $A$. Thus, it would be more expensive to hire an additional unit of labor or rent an additional unit of capital. As they are both more productive than previously, they are both more valuable to a business and thus will cost more. Negative shocks do the opposite. They rotate the production function downward through a decrease in $A$. Each unit of input is now less productive, meaning that both the rental rate of capital and the real wage are lower.
|
103
|
+
|
104
|
+
## Shifts in $\alpha$ and their Effect on Output
|
105
|
+
|
106
|
+
We will now plot what happens to the Cobb-Douglas function as we vary $\alpha$, while holding all other variables constant. The plot below shows $\alpha = 0.8$ (the purple-yellow surface) with $\alpha=0.5$ for reference (the blue-yellow surface). Try and hypothesize what this will do to our production function.
|
107
|
+
|
108
|
+
[Following image is a 3D plot of Output increasing with Capital and Labor, with shifts as alpha changes]
|
109
|
+
|
110
|
+
```python
|
111
|
+
#change_alpha(0.8, filename="fig2.html")
|
112
|
+
display(HTML("fig2.html"))
|
113
|
+
```
|
114
|
+
|
115
|
+
The next plot has $\alpha = 0.2$ (the purple-yellow surface) with $\alpha=0.5$ for reference (the blue-yellow surface). What is the difference between the plot above and the one below?
|
116
|
+
|
117
|
+
[Following image is a 3D plot of Output increasing with Capital and Labor, with shifts as alpha changes]
|
118
|
+
|
119
|
+
```python
|
120
|
+
#change_alpha(0.3, filename="fig3.html")
|
121
|
+
display(HTML("fig3.html"))
|
122
|
+
```
|
123
|
+
|
124
|
+
Below is an interactive plot with a slider to change $\alpha$. Try out different values and see how the shape of the production function changes.
|
125
|
+
|
126
|
+
[Following image is an interactive 3D plot of Output increasing with Capital and Labor as alpha changes]
|
127
|
+
|
128
|
+
```python
|
129
|
+
filename = "fig7.html"
|
130
|
+
|
131
|
+
# #L_s = np.arange(0, 10.11, 0.1)
|
132
|
+
# K_s = np.arange(0, 10.11, 0.1)
|
133
|
+
# A = 1
|
134
|
+
# xx, yy = np.meshgrid(K_s, L_s)
|
135
|
+
|
136
|
+
# layout = go.Layout(
|
137
|
+
# title = "Cobb-Douglas Production Function", autosize=False, width=500, height=500, margin = dict(l = 65, r = 50, b = 65, t = 90),
|
138
|
+
# scene = dict(xaxis = dict(title = 'K'), yaxis = dict(title = 'L'), zaxis = dict(title = 'Y'))
|
139
|
+
# )
|
140
|
+
|
141
|
+
# fig = go.Figure(layout = layout)
|
142
|
+
|
143
|
+
# active = None
|
144
|
+
# alphas = []
|
145
|
+
# for i, alpha in enumerate(np.arange(0.1, 1.01, 0.1)):
|
146
|
+
# alphas.append(alpha)
|
147
|
+
# if alpha == 0.5:
|
148
|
+
# active = i
|
149
|
+
# V = cobb_douglas(A, xx, yy, alpha)
|
150
|
+
# fig.add_trace(go.Surface(
|
151
|
+
# z = V, contours = go.surface.Contours(
|
152
|
+
# z = go.surface.contours.Z(
|
153
|
+
# show = False, project = dict(z = True)
|
154
|
+
# )
|
155
|
+
# ), colorscale = "Electric", showscale = False, name=f"alpha = {alpha}", visible=False
|
156
|
+
# ))
|
157
|
+
|
158
|
+
# fig.data[active].visible = True
|
159
|
+
|
160
|
+
# steps = []
|
161
|
+
# for i in range(len(fig.data)):
|
162
|
+
# step = dict(
|
163
|
+
# method="update", args=[
|
164
|
+
# {"visible": [False] * len(fig.data) + [True]},
|
165
|
+
# ], label=f"alpha = {alphas[i]}"
|
166
|
+
# )
|
167
|
+
# step["args"][0]["visible"][i] = True
|
168
|
+
# steps.append(step)
|
169
|
+
|
170
|
+
# sliders = [dict(
|
171
|
+
# active=active,
|
172
|
+
# currentvalue={"prefix": ""},
|
173
|
+
# pad={"t": 50},
|
174
|
+
# steps=steps
|
175
|
+
# )]
|
176
|
+
|
177
|
+
# fig.update_layout(sliders=sliders, width=500, height=600)
|
178
|
+
|
179
|
+
# orig_V = orig_cobb_douglas()
|
180
|
+
# fig.add_trace(go.Surface(
|
181
|
+
# z = orig_V, contours = go.surface.Contours(
|
182
|
+
# z = go.surface.contours.Z(
|
183
|
+
# show = False, project = dict(z = True)
|
184
|
+
# )
|
185
|
+
# ), colorscale = "Viridis", showscale = False, name="alpha = 0.5"
|
186
|
+
# ))
|
187
|
+
|
188
|
+
# plot(fig, filename=filename, auto_open=False, include_mathjax='cdn')
|
189
|
+
|
190
|
+
display(HTML(filename))
|
191
|
+
```
|
192
|
+
|
193
|
+
$\alpha$ and $\beta$ are called the output elasticities of capital and labor, respectively. They measure the responsiveness of output to a change in the levels of either labor or capital, holding all else constant. This means that if $\alpha$ or $\beta$ were high, then any small increase in their respective input would lead to a relatively large increase in output. As an example, if $\alpha$ was 0.4, then a 1% increase in capital would lead to a 0.4% increase in output.
|
194
|
+
|
195
|
+
Note, we assume that there are constant returns to scale. Thus, an increase in $\alpha$ necessarily means $\beta$ decreases. This reveals something important when comparing countries: the higher the $\alpha$, the more capital-intensive the country's production is. This means that $\alpha$ and $\beta$ give economists and policymakers insight as to how resources are allocated across nations.
|
196
|
+
|
197
|
+
## Returns to Scale
|
198
|
+
|
199
|
+
The significance of the exponents adding up to 1 ($\alpha + \beta = 1$) is that this implies constant returns to scale. If all inputs are scaled by a common non-zero factor, the output will be scaled by that same factor. Below is a generalization of this:
|
200
|
+
|
201
|
+
$$\begin{aligned}
|
202
|
+
Y &= A (c \cdot K)^\alpha (c \cdot L)^{1 - \alpha} \\
|
203
|
+
&= A c^\alpha K ^ \alpha c^{1 - \alpha}L^{1 - \alpha} \\
|
204
|
+
&= A c^{\alpha + 1 - \alpha}K^\alpha L^{1 - \alpha} \\
|
205
|
+
&= c \cdot A K^\alpha L^{1 - \alpha}
|
206
|
+
\end{aligned}$$
|
207
|
+
|
208
|
+
Thus, any increase in either of the inputs will lead to a 1-1 increase in output. This is a significant assumption to make, as it essentially incentivizes companies to continue to "scale" their production inputs. They are not losing out on how much return is produced - they are getting output that matches exactly what they put into production.
|
209
|
+
|
210
|
+
The alternative case is when $\alpha + \beta < 1$. This is called decreasing returns to scale, and occurs when a company scales their production inputs by a factor of c, but gets a scaling in output that is less than c.
|
211
|
+
|
212
|
+
The last case is the most profitable one, when $\alpha + \beta > 1$. This is called increasing returns to scale, and occurs when a company increases their production inputs by c, but gets an increase in output that is greater than c.
|
213
|
+
|
214
|
+
Let us visually examine how values of $\alpha$ and $\beta$ affect output.
|
215
|
+
|
216
|
+
```python
|
217
|
+
#change_alpha_beta(2, filename="fig4.html")
|
218
|
+
display(HTML("fig4.html"))
|
219
|
+
```
|
220
|
+
|
221
|
+
The above graph shows increasing returns to scale with $\alpha + \beta = 2$ (the purble-yellow surface) with constant returns to scale for comparison (the blue-yellow surface). Notice how the orange function no longer increases at a decreasing rate, but seems to mimic exponential growth. This is once again because of the definition of increasing returns to scale. As companies continue to increase their inputs by a factor of $c$, they see their output increase by more than that factor. Thus, as inputs $(K, L)$ increase, output will increase at an even faster rate than that - in this case by the square.
|
222
|
+
|
223
|
+
```python
|
224
|
+
#change_alpha_beta(0.5, filename="fig5.html")
|
225
|
+
display(HTML("fig5.html"))
|
226
|
+
```
|
227
|
+
|
228
|
+
The above graph exhibits decreasing returns to scale as $\alpha + \beta = 0.5$ (the purple-yellow surface) with constant returns to scale for comparison (the blue-yellow surface). This time, the orange production function flattens out far faster than the regular constant returns to scale function. You can prove this to yourself using the slider below, which adjusts the value of $\alpha + \beta$.
|
229
|
+
|
230
|
+
```python
|
231
|
+
filename = "fig8.html"
|
232
|
+
|
233
|
+
# L_s = np.arange(0, 10.11, 0.1)
|
234
|
+
# K_s = np.arange(0, 10.11, 0.1)
|
235
|
+
# A = 1
|
236
|
+
# xx, yy = np.meshgrid(K_s, L_s)
|
237
|
+
|
238
|
+
# layout = go.Layout(
|
239
|
+
# title = "Cobb-Douglas Production Function", autosize=False, width=500, height=500, margin = dict(l = 65, r = 50, b = 65, t = 90),
|
240
|
+
# scene = dict(xaxis = dict(title = 'K'), yaxis = dict(title = 'L'), zaxis = dict(title = 'Y'))
|
241
|
+
# )
|
242
|
+
|
243
|
+
# fig = go.Figure(layout = layout)
|
244
|
+
|
245
|
+
# active = None
|
246
|
+
# default = 1
|
247
|
+
# ab_sums = []
|
248
|
+
# for i, ab_sum in enumerate(np.arange(0.1, 3.01, 0.1)):
|
249
|
+
# ab_sums.append(ab_sum)
|
250
|
+
# if ab_sum == default:
|
251
|
+
# active = i
|
252
|
+
# alpha, beta = ab_sum / 2, ab_sum / 2
|
253
|
+
# V = cobb_douglas(A, xx, yy, alpha, beta)
|
254
|
+
# fig.add_trace(go.Surface(
|
255
|
+
# z = V, contours = go.surface.Contours(
|
256
|
+
# z = go.surface.contours.Z(
|
257
|
+
# show = False, project = dict(z = True)
|
258
|
+
# )
|
259
|
+
# ), colorscale = "Electric", showscale = False, name=f"alpha + beta = {ab_sum}", visible=False
|
260
|
+
# ))
|
261
|
+
|
262
|
+
# fig.data[active].visible = True
|
263
|
+
|
264
|
+
# steps = []
|
265
|
+
# for i in range(len(fig.data)):
|
266
|
+
# step = dict(
|
267
|
+
# method="update", args=[
|
268
|
+
# {"visible": [False] * len(fig.data) + [True]},
|
269
|
+
# ], label=f"alpha + beta = {ab_sums[i]}"
|
270
|
+
# )
|
271
|
+
# step["args"][0]["visible"][i] = True
|
272
|
+
# steps.append(step)
|
273
|
+
|
274
|
+
# sliders = [dict(
|
275
|
+
# active=active,
|
276
|
+
# currentvalue={"prefix": ""},
|
277
|
+
# pad={"t": 50},
|
278
|
+
# steps=steps
|
279
|
+
# )]
|
280
|
+
|
281
|
+
# fig.update_layout(sliders=sliders, width=500, height=600)
|
282
|
+
|
283
|
+
# orig_V = orig_cobb_douglas()
|
284
|
+
# fig.add_trace(go.Surface(
|
285
|
+
# z = orig_V, contours = go.surface.Contours(
|
286
|
+
# z = go.surface.contours.Z(
|
287
|
+
# show = False, project = dict(z = True)
|
288
|
+
# )
|
289
|
+
# ), colorscale = "Viridis", showscale = False, name=f"alpha + beta = {default}"
|
290
|
+
# ))
|
291
|
+
|
292
|
+
# plot(fig, filename=filename, auto_open=False, include_mathjax='cdn')
|
293
|
+
|
294
|
+
display(HTML(filename))
|
295
|
+
```
|
296
|
+
|
@@ -0,0 +1,166 @@
|
|
1
|
+
---
|
2
|
+
title: budget-constraints
|
3
|
+
type: textbook
|
4
|
+
source_path: content/05-utility/budget-constraints.ipynb
|
5
|
+
chapter: 5
|
6
|
+
---
|
7
|
+
|
8
|
+
```python
|
9
|
+
import pandas as pd
|
10
|
+
import numpy as np
|
11
|
+
import chart_studio.plotly as py
|
12
|
+
import plotly.graph_objs as go
|
13
|
+
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
|
14
|
+
from ipywidgets import interact, interactive, fixed, interact_manual
|
15
|
+
import ipywidgets as widgets
|
16
|
+
from IPython.display import display, HTML
|
17
|
+
import warnings
|
18
|
+
warnings.filterwarnings('ignore')
|
19
|
+
```
|
20
|
+
|
21
|
+
# Budget Constraints and Utility Maximization
|
22
|
+
|
23
|
+
In this section, we will assume that $\alpha = 0.5$ (i.e. the utility function is: $u(x_1, x_2) = x_1^{0.5}x_2^{0.5}$).
|
24
|
+
|
25
|
+
Now we introduce the concept of money into our model. Consumers face a budget constraint when choosing to maximize their utility. Given an income $M$ and prices $p_1$ for good $x_1$ and $p_2$ for good $x_2$, the consumer can at most spend up to $M$ for both goods:
|
26
|
+
|
27
|
+
$$M \geq p_1x_1 + p_2x_2$$
|
28
|
+
|
29
|
+
Since goods will always bring non-negative marginal utility, consumers will try to consume as many goods as they can. Hence, we can rewrite the budget constraint as an equality instead (since if they have more income leftover, they will use it to buy more goods).
|
30
|
+
|
31
|
+
$$M = p_1x_1 + p_2x_2$$
|
32
|
+
|
33
|
+
This means that any bundle of goods $(x_1,x_2)$ that consumers choose to consume will adhere to the equality above. What does this mean on our graph? Let's examine the indifference curve plots, assuming that $M = 32$, and $p_1 =2$ and $p_2 = 4$.
|
34
|
+
|
35
|
+
[Following image is s graph of a series of nested convex Indifference Curves with a budget constraint ]
|
36
|
+
|
37
|
+
```python
|
38
|
+
M = 32
|
39
|
+
p_1 = 2
|
40
|
+
p_2 = 4
|
41
|
+
|
42
|
+
# Plot default indifference curves
|
43
|
+
utilities = np.arange(1, 9)
|
44
|
+
x1_indiff_val = np.linspace(0,50,1000)
|
45
|
+
x2_indiff_vals = []
|
46
|
+
for u in utilities:
|
47
|
+
x2_indiff_vals.append(((u/(x1_indiff_val ** (1/2))) ** (2)))
|
48
|
+
traces = []
|
49
|
+
colors = ['blue', 'red','green','purple'] + ['blue', 'red','green','purple']
|
50
|
+
for u,c,x2 in zip(utilities,colors,x2_indiff_vals):
|
51
|
+
traces.append(go.Scatter(
|
52
|
+
x = x1_indiff_val,
|
53
|
+
y = x2,
|
54
|
+
name = 'utility = ' + str(u),
|
55
|
+
line = dict(color = c,width = 1)))
|
56
|
+
|
57
|
+
# for i in range(len(traces) - 4):
|
58
|
+
# del traces[-1] # This is a hacky method to not continually append to TRACES upon an update from the slider.
|
59
|
+
x2_bc_val = (M - (p_1*x1_indiff_val))/p_2
|
60
|
+
traces.append(go.Scatter(
|
61
|
+
x = x1_indiff_val,
|
62
|
+
y = x2_bc_val,
|
63
|
+
name = 'Budget Constraint',
|
64
|
+
line = dict(color = 'black',width = 1,dash="dot")))
|
65
|
+
data = traces
|
66
|
+
layout = dict(title = 'Budget Constraint and Indifference Curves for the Cobb-Douglas Utility Function (alpha = 0.5)',
|
67
|
+
xaxis = dict(title = 'X1', range = [0,18]),
|
68
|
+
yaxis = dict(title = 'X2', range = [0,10]),)
|
69
|
+
fig = dict(data=data, layout=layout)
|
70
|
+
|
71
|
+
plot(fig, filename="fig3.html", auto_open=False)
|
72
|
+
display(HTML("fig3.html"))
|
73
|
+
```
|
74
|
+
|
75
|
+
The budget constraint is like a possibilities curve: moving up or down the constraint means gaining more of one good while sacrificing the other.
|
76
|
+
|
77
|
+
Let's take a look at what this budget constraint means. Because of the budget constraint, any bundle of goods $(x_1,x_2)$ that consumers ultimately decide to consume will lie on the budget constraint line. Adhering to this constraint where $M=32, p_1 = 2, p_2 = 4$, we can see that consumers will be able to achieve 2 units of utility, and can also achieve 4 units of utility. But what is the maximum amount of utility that consumers can achieve?
|
78
|
+
|
79
|
+
Notice an interesting property about indifference curves: **the utility level of the indifference curves gets larger as we move up and to the right.** Hence, the maximizing amount of utility in this budget constraint is the rightmost indifference curve that still touches the budget constraint line. In fact, it'll only 'touch' (and not intersect) the budget constraint and be tangential to it.
|
80
|
+
|
81
|
+
[Following image is s graph of a series of nested convex Indifference Curves with a budget constraint ]
|
82
|
+
|
83
|
+
```python
|
84
|
+
M = 32
|
85
|
+
p_1 = 2
|
86
|
+
p_2 = 4
|
87
|
+
|
88
|
+
# Plot default indifference curves
|
89
|
+
utilities = np.arange(1, 9)
|
90
|
+
x1_indiff_val = np.linspace(0,50,1000)
|
91
|
+
x2_indiff_vals = []
|
92
|
+
for u in utilities:
|
93
|
+
x2_indiff_vals.append(((u/(x1_indiff_val ** (1/2))) ** (2)))
|
94
|
+
traces = []
|
95
|
+
colors = ['blue', 'red','green','purple'] + ['blue', 'red','green','purple']
|
96
|
+
for u,c,x2 in zip(utilities,colors,x2_indiff_vals):
|
97
|
+
traces.append(go.Scatter(
|
98
|
+
x = x1_indiff_val,
|
99
|
+
y = x2,
|
100
|
+
name = 'utility = ' + str(u),
|
101
|
+
line = dict(color = c,width = 1)))
|
102
|
+
|
103
|
+
# PLOT BC
|
104
|
+
x2_bc_val = (M - (p_1*x1_indiff_val))/p_2
|
105
|
+
traces.append(go.Scatter(
|
106
|
+
x = x1_indiff_val,
|
107
|
+
y = x2_bc_val,
|
108
|
+
name = 'Budget Constraint',
|
109
|
+
line = dict(color = 'black',width = 1,dash="dot")))
|
110
|
+
|
111
|
+
|
112
|
+
# PLOT MAX UTIL INDIFF CURVE
|
113
|
+
max_utility = ((1/2*M/p_1) ** (1/2)) * ((1/2*M/p_2) ** (1/2))
|
114
|
+
x2_max_util = (max_utility/(x1_indiff_val ** (1/2))) ** 2
|
115
|
+
x2_max_util = (max_utility/(x1_indiff_val ** (1/2))) ** 2
|
116
|
+
traces.append(go.Scatter(
|
117
|
+
x = x1_indiff_val,
|
118
|
+
y = x2_max_util,
|
119
|
+
name = 'Maximized Utility = ' + str(round(max_utility, 2)),
|
120
|
+
line = dict(color = 'black',width = 2)))
|
121
|
+
data = traces
|
122
|
+
|
123
|
+
layout = dict(title = 'Budget Constraint and Indifference Curves for the Cobb-Douglas Utility Function (alpha = 0.5)',
|
124
|
+
xaxis = dict(title = 'X1', range = [0,20]),
|
125
|
+
yaxis = dict(title = 'X2', range = [0,15]),)
|
126
|
+
fig = dict(data=data, layout=layout)
|
127
|
+
|
128
|
+
plot(fig, filename="fig4.html", auto_open=False)
|
129
|
+
display(HTML("fig4.html"))
|
130
|
+
```
|
131
|
+
|
132
|
+
Notice that as the price of one good increases, the indifference curve that represents the maximum attainable utility shifts towards the left (i.e. the max utility decreases). Intuitively, this makes sense. As the price of one good increases, consumers have to make adjustments to their consumption bundles and buy less of one, or both, goods. Hence, their maximum utility will decrease.
|
133
|
+
|
134
|
+
Let's visualize the budget constraint in 3D where $M=30, p_1=3, p_2=3$. Here, any point along the curve in which the 2 planes intersect represents an amount of utility in which the budget constraint holds true (i.e. where we've spent all our income). The utility maximizing quantity is a point on this intersecting curve at which the utility level is the highest.
|
135
|
+
|
136
|
+
[Following image is an interactive 3D plot of Utility increasing with X1 and X2, wih a plane representing the budget constraint]
|
137
|
+
|
138
|
+
```python
|
139
|
+
def cobb_douglas(x1, x2):
|
140
|
+
return (x1 ** (1/2)) * (x2 ** (1/2))
|
141
|
+
x1 = np.linspace(0,10,10)
|
142
|
+
x2 = np.linspace(0,10,10)
|
143
|
+
X1,X2 = np.meshgrid(x1,x2)
|
144
|
+
z = cobb_douglas(X1,X2)
|
145
|
+
|
146
|
+
def budget_constraint(x1, x2):
|
147
|
+
return 10000*(3*x1 + 3*x2 - 30) # We multiply this by 10000 to get a very steep plane, which should be similar to the actual BC, a vertical plane.
|
148
|
+
|
149
|
+
z2 = budget_constraint(X1, X2)
|
150
|
+
|
151
|
+
data = [go.Surface(
|
152
|
+
z=z, contours=go.surface.Contours(z=go.surface.contours.Z(show=True,usecolormap=True,highlightcolor="#42f462",
|
153
|
+
project=dict(z=True))), name="Cobb-Douglas Utility Function"),
|
154
|
+
go.Surface(
|
155
|
+
z=z2, contours=go.surface.Contours(z=go.surface.contours.Z(show=True,usecolormap=False,
|
156
|
+
highlightcolor="#42f462",project=dict(z=True))),showscale=False, colorscale="balance", name="Budget Constraint")]
|
157
|
+
layout = go.Layout(
|
158
|
+
title='Cobb-Douglas Utility Function with Budget Constraint', autosize=False,width=500, height=500, margin=dict(l=65,r=50,b=65,t=90),
|
159
|
+
scene = dict(xaxis = dict(title='X1', range = [0,10]), yaxis = dict(title='X2'),
|
160
|
+
zaxis = dict(title = 'Utility', nticks=4, range = [0,10],)))
|
161
|
+
fig = go.Figure(data=data, layout=layout)
|
162
|
+
|
163
|
+
plot(fig, filename="fig5.html", auto_open=False)
|
164
|
+
display(HTML("fig5.html"))
|
165
|
+
```
|
166
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
title: index
|
3
|
+
type: textbook
|
4
|
+
source_path: content/05-utility/index.md
|
5
|
+
chapter: 5
|
6
|
+
---
|
7
|
+
|
8
|
+
# Utility
|
9
|
+
|
10
|
+
**Student Learning Outcomes:**
|
11
|
+
|
12
|
+
* Understand the basic principles of utility
|
13
|
+
* Become familiar with utility function such as the Cobb-Douglas utility function
|
14
|
+
* Translate utility functions with 2 inputs to indifference curves
|
15
|
+
* Understand budget constraints and how they affect utility maximization
|
@@ -0,0 +1,136 @@
|
|
1
|
+
---
|
2
|
+
title: utility
|
3
|
+
type: textbook
|
4
|
+
source_path: content/05-utility/utility.ipynb
|
5
|
+
chapter: 5
|
6
|
+
---
|
7
|
+
|
8
|
+
```python
|
9
|
+
import pandas as pd
|
10
|
+
import numpy as np
|
11
|
+
import chart_studio.plotly as py
|
12
|
+
import plotly.graph_objs as go
|
13
|
+
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
|
14
|
+
from ipywidgets import interact, interactive, fixed, interact_manual
|
15
|
+
import ipywidgets as widgets
|
16
|
+
from IPython.display import display, HTML
|
17
|
+
import warnings
|
18
|
+
warnings.filterwarnings('ignore')
|
19
|
+
```
|
20
|
+
|
21
|
+
# Utility Functions and Indifference Curves
|
22
|
+
|
23
|
+
## What is Utility?
|
24
|
+
|
25
|
+
When we consume a good, we assume that the good will have some impact on our total utility. Utility is a fundamental measure that helps economists model how consumers make decisions. An assumed rule in economics is that consumers will always act rationally, which translates to the assumption that consumers will always attempt to maximize their own utility.
|
26
|
+
|
27
|
+
It is important to note that utility doesn't have specified units and even the face value of utility doesn't have any meaning. *What does an apple providing 5 utility units even mean?* What is valuable, however, is that utility can be compared; if an apple provides 5 utility units and an orange provides 3 utility units, then we prefer apples to oranges.
|
28
|
+
|
29
|
+
As a very simple example, say Anne has 6 dollars and she can choose to buy any combination of goods A and B. If good A costs 2 dollars and provides 5 utility units per unit of A consumed, while good B costs 3 dollars and provides 6 utility units per unit of B consumed, then Anne will buy 3 units of good A, since that maximizes her utility.
|
30
|
+
|
31
|
+
In economics, however, our models are a little more complex than that. Typically, utility is the product of the consumption of many goods; typically having a lot of one good but not another does not provide much utility. In addition, consumption of one good faces diminishing marginal returns, i.e. holding all things equal, the consumption of one additional unit of a good will provide less utility than the utility received from the previous unit. Intuitively, imagine Bob is very hungry and decides to eat slices of pizza. The first slice of pizza will bring Bob the most utility, but the 8th slice will be much less satisfying to eat.
|
32
|
+
|
33
|
+
## Utility Functions
|
34
|
+
A consumer's utility is determined by the amount of consumption from all the goods they consume. Typically, utility functions are multivariate: they take in multiple inputs (which represent the different amounts of consumption for each good, which we call a consumption bundle), and output one value, the utility. Today, we'll only look at the case where consumers can only choose between 2 goods $x_1$ and $x_2$. Hence, a utility function can be represented by: $u(x_1,x_2)$.
|
35
|
+
|
36
|
+
With that in mind, let's start graphing some utility functions!
|
37
|
+
|
38
|
+
### Cobb-Douglas Utility Function
|
39
|
+
|
40
|
+
Consider the following utility function across $x_1$ and $x_2$:
|
41
|
+
|
42
|
+
$$u(x_1, x_2)=x_1^{\alpha}x_2^{1-\alpha}\quad\text{where } 0<\alpha<1$$
|
43
|
+
|
44
|
+
This is known as the **Cobb-Douglas utility function**. To visualize this function, we'll need a 3D plot.
|
45
|
+
|
46
|
+
[Following image is an interactive 3D plot of Utility increasing with X1 and X2]
|
47
|
+
|
48
|
+
```python
|
49
|
+
alpha = 0.5
|
50
|
+
def cobb_douglas(x1, x2):
|
51
|
+
return (x1 ** alpha) * (x2 ** (1-alpha))
|
52
|
+
x1 = np.linspace(0,10,10)
|
53
|
+
x2 = np.linspace(0,10,10)
|
54
|
+
X1,X2 = np.meshgrid(x1,x2)
|
55
|
+
z = cobb_douglas(X1,X2)
|
56
|
+
data = [go.Surface(z=z, contours=go.surface.Contours(z=go.surface.contours.Z(show=True,usecolormap=True,highlightcolor="#42f462",project=dict(z=True))))]
|
57
|
+
layout = go.Layout(title='Cobb-Douglas Utility Function (alpha = 0.5)',autosize=False,width=500,height=500,margin=dict(l=65,r=50,b=65,t=90),
|
58
|
+
scene = dict(xaxis = dict(title='X1'),yaxis = dict(title=r'X2'),zaxis = dict(title='Utility'),))
|
59
|
+
fig = go.Figure(data=data, layout=layout)
|
60
|
+
|
61
|
+
plot(fig, filename="fig1.html", auto_open=False)
|
62
|
+
display(HTML("fig1.html"))
|
63
|
+
```
|
64
|
+
|
65
|
+
## Examining the Utility Function
|
66
|
+
|
67
|
+
There are 2 rules that utility functions generally follow:
|
68
|
+
|
69
|
+
- Non-negative marginal utility: the consumption of a good will not decrease the utility. Economists generally assume that 'more is better.' If the consumption of a good decreased utility, then we would consume less of a good.
|
70
|
+
- Diminishing marginal returns: all else equal, as consumption increases the marginal utility derived from each additional unit declines.
|
71
|
+
|
72
|
+
### Non-negative Marginal Utility
|
73
|
+
Say we are currently consuming 2 units of $x_1$ and $x_2$ each with $\alpha = \frac{1}{2}$, providing $u(2,2)=2^{0.5}2^{0.5}=2$ utility units. One additional unit of $x_1$ will provide me a higher point of utility: we can verify this result both graphically and numerically: $u(3,2)=3^{0.5}2^{0.5}\approx2.45$. Indeed, consuming one more unit of a good should increase our utility!
|
74
|
+
|
75
|
+
### Marginal Utility and the Law of Diminishing Returns
|
76
|
+
Now let's check for the second result: diminishing marginal returns. From above, we know that holding the consumption of $x_2$ constant at 2, going from 2 to 3 units of $x_1$ increases our utility by $2.45-2=0.45$. Going from 3 to 4 units of $x_1$ brings our utility to $u(4,2)=4^{0.5}2^{0.5}\approx 2.83$, an increase of $2.83-2.45=0.38$ utility units.
|
77
|
+
|
78
|
+
Using calculus, we can more formally define the marginal utility of a good. Since marginal utility is the change in utility that one additional unit of consumption provides (holding all others constant), the marginal utility with respect to $x_1$ is its partial derivative: $\frac{\partial u}{\partial x_1}$. In our case:
|
79
|
+
|
80
|
+
$$
|
81
|
+
\begin{aligned}
|
82
|
+
\textrm{Marginal Utility of } x_1: &\quad\frac{\partial u}{\partial x_1} = \frac{1}{2}x_1^{-0.5}x_2^{0.5} \\
|
83
|
+
\textrm{Marginal Utility of } x_2: &\quad\frac{\partial u}{\partial x_2} = \frac{1}{2}x_1^{0.5}x_2^{-0.5}
|
84
|
+
\end{aligned}
|
85
|
+
$$
|
86
|
+
|
87
|
+
Or, more generally,
|
88
|
+
|
89
|
+
$$\begin{aligned}
|
90
|
+
\textrm{Marginal Utility of } x_1: &\quad\frac{\partial u}{\partial x_1} = \alpha x_1^{\alpha-1}x_2^{1-\alpha} \\
|
91
|
+
\textrm{Marginal Utility of } x_2: &\quad\frac{\partial u}{\partial x_2} = (1-\alpha) x_1^{\alpha}x_2^{-\alpha}
|
92
|
+
\end{aligned}$$
|
93
|
+
|
94
|
+
|
95
|
+
With marginal utility defined, note that both conditions can be explained using the marginal utility function $\frac{\partial u}{\partial x}$:
|
96
|
+
|
97
|
+
- Non-negative marginal utility: $\frac{\partial u}{\partial x} \geq 0$
|
98
|
+
- Diminishing marginal returns: $\frac{\partial^2 u}{\partial x^2} < 0$
|
99
|
+
|
100
|
+
## Indifference Curves
|
101
|
+
|
102
|
+
Although the utility function above in 3D is cool, you'll typically find utility graphs to be in 2D with $x_1$ and $x_2$ as the axis (eliminating the utility axis).
|
103
|
+
|
104
|
+
To represent utility levels, we plot a set of indifference curves on the 2D graph. An indifference curve satisfies the property in which **any point on the curve has the exact same amount of utility**, so that consumers are _indifferent_ to any point on the curve. In our 3D plot, any point on the indifference curve has the exact same height, which represents the value of utility. If you're familar with contour plots, you can also think of indifference curves as following the same idea.
|
105
|
+
|
106
|
+
[Following image is s graph of a series of nested convex Indifference Curves for different amounts of X1 and X2 ]
|
107
|
+
|
108
|
+
```python
|
109
|
+
alpha = 0.5
|
110
|
+
utilities = np.arange(1, 9)
|
111
|
+
x1_indiff_val = np.linspace(0,50,1000)
|
112
|
+
x2_indiff_vals = []
|
113
|
+
for u in utilities:
|
114
|
+
x2_indiff_vals.append(((u/(x1_indiff_val ** alpha)) ** (1/(1-alpha))))
|
115
|
+
traces = []
|
116
|
+
colors = ['blue', 'red','green','purple'] + ['blue', 'red','green','purple']
|
117
|
+
for u, c, x2 in zip(utilities, colors, x2_indiff_vals):
|
118
|
+
traces.append(go.Scatter(
|
119
|
+
x = x1_indiff_val,
|
120
|
+
y = x2,
|
121
|
+
name = 'utility = ' + str(u),
|
122
|
+
line = dict(color = c,width = 1)))
|
123
|
+
|
124
|
+
data = traces
|
125
|
+
|
126
|
+
# Edit the layout
|
127
|
+
layout = dict(title = 'Indifference Curves for the Cobb-Douglas Utility Function (alpha = ' + str(alpha) + ')',
|
128
|
+
xaxis = dict(title = 'X1', range = [0,10]),
|
129
|
+
yaxis = dict(title = 'X2', range = [0,10]),)
|
130
|
+
|
131
|
+
fig = dict(data=data, layout=layout)
|
132
|
+
|
133
|
+
plot(fig, filename="fig2.html", auto_open=False)
|
134
|
+
display(HTML("fig2.html"))
|
135
|
+
```
|
136
|
+
|