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,138 @@
1
+ ---
2
+ title: "6.4-latex"
3
+ type: lecture-notebook
4
+ week: 6
5
+ source_path: "/Users/ericvandusen/Documents/Data88E-ForTraining/F24Lec_NBs/lec06/6.4-latex.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><br>
13
+ Dr. Eric Van Dusen <br>
14
+ Akhil Venkatesh
15
+ </p></td></tr>
16
+ </table>
17
+
18
+ ## Writing Equations in LaTeX
19
+ ### Start by building up from elements
20
+
21
+ Let's start writing equations and make them more complicated little by little - let's use the $ sign to offset the equations within the cell. All of these will be in Markdown cells. When we use two dollar signs we get the equation displayed on its own line.
22
+
23
+ Start with a function that takes two arguments K and L
24
+ $$
25
+ f(K, L)
26
+ $$
27
+
28
+ then we want to use a greek symbol $alpha$
29
+ that we will use a \ to denote
30
+ $$
31
+ \alpha
32
+ $$
33
+
34
+ And we want to raise the value of K to the power of $\alpha$
35
+ $$
36
+ K^\alpha
37
+ $$
38
+
39
+ **Your turn!** You can go ahead and do the same thing for $L$ to the power of $\beta$
40
+ $$
41
+ ....
42
+ $$
43
+
44
+ Let's combine these elements to be the basis of the Cobb-Douglas Production Function:
45
+ $$
46
+ f(K, L) = K^\alpha L^\beta \\
47
+ $$
48
+
49
+ For modeling National GDP we can also add in $Y$ and the technology shifter $A$
50
+ $$
51
+ Y = A \cdot f(K, L) = A K^\alpha L^\beta
52
+ $$
53
+
54
+ A common simplification is to constrain $ \alpha + \beta = 1 $ which can be rearranged to
55
+ $$
56
+ \beta = 1 - \alpha
57
+ $$
58
+
59
+ First Derivative
60
+ $$
61
+ X_{1}^{\alpha - 1} X_{2}^{1 - \alpha} \alpha
62
+ $$
63
+
64
+ Second Derivative
65
+
66
+ $$
67
+ X_{1}^{\alpha - 2} X_{2}^{1 - \alpha} \alpha \left(\alpha - 1\right)
68
+ $$
69
+
70
+ So then we can rewrite the original equation as:
71
+ $$
72
+ Y = A K^\alpha L^{1 - \alpha}
73
+ $$
74
+
75
+ ## Writing Equations in LaTeX
76
+ Try completing some of these exercises as practice!
77
+
78
+ If you get stuck, check out the LaTeX Guide: https://math.hws.edu/gassert/LaTeX_Guide_Title.pdf!
79
+
80
+ **1. Quadratic Formula:**
81
+
82
+ ![quadratic.PNG](attachment:quadratic.PNG)
83
+
84
+ **Try it out!**
85
+ $$
86
+ ....
87
+ $$
88
+
89
+ # Lets try Markdown as well!
90
+
91
+ # Here's how you get each of the different heading sizes!
92
+ ___
93
+ # Heading 1
94
+ ## Heading 2
95
+ ### Heading 3
96
+ #### Heading 4
97
+ ##### Heading 5
98
+ ###### Heading 6
99
+
100
+ # How about a List ( unordered)
101
+ 1. here is one item
102
+ 2. here is a second item
103
+ 3. here is a third
104
+
105
+ ## Here is how to make a table
106
+
107
+ | Id | Label | Price |
108
+ |--- |----------| ------|
109
+ | 01 | Markdown |\$1600 |
110
+ | 02 | is | \$12 |
111
+ | 03 | AWESOME | \$999 |
112
+
113
+ **bold text**
114
+
115
+ *italics*
116
+
117
+ `code`
118
+
119
+ ```python
120
+
121
+ ```
122
+
123
+ # How about an Emoji?
124
+ ## You can copy and paste or.
125
+
126
+ 😊
127
+
128
+ &#128512;
129
+
130
+ # How about a link
131
+ [What a cool class!](https://data88e.org)
132
+
133
+
134
+
135
+ ```python
136
+
137
+ ```
138
+
@@ -0,0 +1,269 @@
1
+ ---
2
+ title: "6.5-Edgeworth"
3
+ type: lecture-notebook
4
+ week: 6
5
+ source_path: "/Users/ericvandusen/Documents/Data88E-ForTraining/F24Lec_NBs/lec06/6.5-Edgeworth.ipynb"
6
+ ---
7
+
8
+ ## Edgeworth Box Demo
9
+ ### as another application of Cobb-Douglas Utility Function
10
+
11
+
12
+ The code is taken from "Gaby Galvan"
13
+ https://deepnote.com/app/gaby-galvan/Edgeworth-Box-5c892517-cb51-4f3f-b20d-8e5dd8b5ac46
14
+
15
+ ```python
16
+ import numpy as np
17
+ import matplotlib.pyplot as plt
18
+ import pandas as pd
19
+ ```
20
+
21
+ ```python
22
+ out = 0
23
+ ```
24
+
25
+ ### Overview of the Edgeworth Box
26
+
27
+ An **Edgeworth box** is a graphical representation used in microeconomics to illustrate the distribution of resources (goods) between two consumers in a simple exchange economy. It shows all possible allocations of two goods between two consumers and helps analyze their preferences, trade possibilities, and potential for reaching Pareto-efficient outcomes.
28
+
29
+ In your scenario:
30
+
31
+ - **Two Consumers**: The consumers are trading Noodles and Cereal.
32
+ - **Objective**: To visualize how these consumers can trade to reach mutually beneficial (Pareto-efficient) allocations based on their utility preferences.
33
+
34
+ ---
35
+
36
+ ### Key Components of the Code
37
+
38
+ Let’s break down the main elements of your code to understand how it represents the economic concepts:
39
+
40
+ #### 1. Utility Functions (`U1` and `U2`)
41
+
42
+ - **Purpose**: Represent the satisfaction (utility) each consumer derives from consuming Noodles (X) and Cereal (Y).
43
+ - **Form**: Must be functions of two variables, e.g., `U1(x, y)` and `U2(x, y)`.
44
+ - **Interpretation**: The shape of the utility functions reflects each consumer's preferences and marginal rates of substitution (MRS) between Noodles and Cereal.
45
+
46
+ #### 2. Edgeworth Box Dimensions (`Xmax`, `Ymax`, `Xmin`, `Ymin`)
47
+
48
+ - **`Xmax` and `Ymax`**: Total available quantities of Noodles and Cereal in the economy.
49
+ - **`Xmin` and `Ymin`**: Set close to zero to avoid computational issues with logarithmic utilities or division by zero.
50
+ - **Interpretation**: The box's dimensions represent the entire feasible set of allocations between the two consumers.
51
+
52
+ #### 3. Indifference Curves
53
+
54
+ - **Definition**: Curves along which a consumer derives the same level of utility.
55
+ - **Implementation**: The code uses `plt.contour()` to draw these curves for both consumers.
56
+ - **Economic Intuition**:
57
+ - **Consumer 1**: Indifference curves are plotted from the origin at (0,0).
58
+ - **Consumer 2**: Indifference curves are plotted from the opposite corner (Xmax, Ymax), reflecting that any consumption by Consumer 1 reduces the amount available to Consumer 2.
59
+
60
+ #### 4. Contract Curve
61
+
62
+ - **Definition**: The set of allocations where the indifference curves of the two consumers are tangent—i.e., where their MRS are equal.
63
+ - **Implementation**:
64
+ - Calculated by finding where the gradients of the utility functions are proportional.
65
+ - The code computes gradients using `np.gradient()` and identifies where the determinant of the Jacobian (`out`) is zero.
66
+ - Plotted using `plt.contour()` with specific levels.
67
+ - **Economic Intuition**: Represents all Pareto-efficient allocations—no consumer can be made better off without making the other worse off.
68
+
69
+ #### 5. Allocation Point (`AlPoint`)
70
+
71
+ - **Purpose**: Represents a specific allocation of Noodles and Cereal between the two consumers.
72
+ - **Usage**:
73
+ - If provided, the code plots this point and the corresponding indifference curves passing through it for both consumers.
74
+ - Helps visualize the initial endowment and potential gains from trade.
75
+ - **Economic Intuition**: Demonstrates how consumers can move from an initial allocation to a Pareto-efficient allocation through mutually beneficial trade.
76
+
77
+ #### 6. Utility Levels and Number of Indifference Curves (`Utility_Show`, `Num_ind`)
78
+
79
+ - **`Utility_Show`**: When `True`, displays utility levels on the indifference curves.
80
+ - **`Num_ind`**: Controls the number of indifference curves plotted for each consumer.
81
+ - **Economic Intuition**: More curves provide a detailed view of preferences but may clutter the graph; adjusting `Num_ind` balances detail and clarity.
82
+
83
+ #### 7. Other Parameters
84
+
85
+ - **Labels (`Xlab`, `Ylab`)**: Axis labels for clarity—here, they should be set to "Noodles" and "Cereal."
86
+ - **Colors (`colors`)**: Customize the appearance of the plot elements for better distinction.
87
+ - **Endowment (`e`)**: Number of steps used in calculations—higher values lead to smoother curves but increase computation time.
88
+
89
+ ---
90
+
91
+ ### Economic Intuition Behind the Code
92
+
93
+ #### Mutually Beneficial Trade
94
+
95
+ - **Starting Point**: Consumers begin with an initial allocation of Noodles and Cereal.
96
+ - **Objective**: Through trade, both aim to reach higher indifference curves, thus achieving higher utility levels.
97
+ - **Visualization**: The movement from the initial allocation point towards the contract curve represents this process.
98
+
99
+ #### Marginal Rate of Substitution (MRS)
100
+
101
+ - **Definition**: The rate at which a consumer is willing to trade one good for another while maintaining the same utility level.
102
+ - **Equal MRS**: At points on the contract curve, both consumers have equal MRS, meaning they value the trade-off between Noodles and Cereal equally.
103
+ - **Economic Intuition**: Equating MRS ensures that resources are allocated efficiently between the two consumers.
104
+
105
+ #### Pareto Efficiency
106
+
107
+ - **Definition**: An allocation is Pareto-efficient if no consumer can be made better off without making the other worse off.
108
+ - **Contract Curve**: All points along this curve are Pareto-efficient allocations.
109
+ - **Visualization**: The contract curve in the Edgeworth box shows all such allocations.
110
+
111
+ #### Utility Maximization
112
+
113
+ - **Consumers' Goal**: Each aims to reach the highest possible indifference curve given their budget constraints (the total available goods).
114
+ - **Constraints**: Limited by the total quantities of Noodles and Cereal in the economy.
115
+ - **Trade-Offs**: Consumers make choices based on their preferences, as depicted by the shapes of their indifference curves.
116
+
117
+
118
+ ### Interpreting the Graph
119
+
120
+ #### Axes
121
+
122
+ - **Horizontal Axis**: Quantity of Noodles consumed by Consumer 1 (Alice).
123
+ - **Vertical Axis**: Quantity of Cereal consumed by Alice.
124
+ - **Origin for Consumer 2 (Bob)**: Located at the top-right corner
125
+
126
+ ```python
127
+
128
+ def draw_Ed_Bow(U1,U2, Xmax, Ymax, Xmin=10**(-6), Ymin=10**(-6), Utility_Show = False, Num_ind = 10,Xlab ="X",Ylab="Y",e=200, Contract_draw=True,AlPoint = None,colors =["black","Orange", "blue","red"],Utility_draw = True):
129
+ """
130
+ Input :
131
+ U1: Utility of the 1st agent (must depend on 2 variables)
132
+ U2: Utility of the 2nd agent (must depend on 2 variables)
133
+ Xmax : the limit of the box
134
+ Ymax: the limit of the box
135
+ Xmin=10**(-6): the limit of the box (default: set to ~0 to avoid problems with log expressions)
136
+ Ymin=10**(-6): the box limit (default: set to ~0 to avoid problems with log expressions)
137
+ Utility_Show = False: Show utility levels on the Edgeworth box
138
+ Num_ind = 10 : Number of indifference curves per agent
139
+ e = 200 : Number of steps to compute the utility levels and the contract curve
140
+ Contract_draw = True: Draw the contract curve
141
+ AlPoint = None : show an allocation point and his 2 indifference curves. Should be a tuple/list (x,y)
142
+ colors = ["black","Orange", "blue","red"] : To choose the color of : [ContractCurve, endowment point, indifference curves Agent1, indifference curves agent2]
143
+ Utility_draw = True : Draw the indefrence curves
144
+ Output:
145
+ None (but draws the Edgeworth box)
146
+ """
147
+ delta = min((Xmax-Xmin)/e,(Ymax-Ymin)/e)
148
+
149
+ x = np.arange(Xmin, Xmax, delta) #Tomates
150
+ y = np.arange(Ymin, Ymax, delta) #courgettes
151
+ X, Y = np.meshgrid(x, y)
152
+ Z1 = lambda x,y : U1(x,y)
153
+ Z2 = lambda x,y : U2(Xmax-x,Ymax-y)
154
+
155
+ #the contract curve
156
+ Num_ind_1 = Num_ind
157
+ Num_ind_2 = Num_ind
158
+
159
+ if Contract_draw == True:
160
+ Z2grad = np.gradient(Z2(X,Y))
161
+ Z1grad = np.gradient(Z1(X,Y))
162
+
163
+ global out
164
+ out = (Z2grad[0]*Z1grad[1]-Z2grad[1]*Z1grad[0])
165
+
166
+ Cont = plt.contour(X,Y,out,colors=colors[0],levels=[0])
167
+ fmt = {}
168
+ strs = ["Contract curve"]
169
+ for l, s in zip(Cont.levels, strs):
170
+ fmt[l] = s
171
+ plt.clabel(Cont, Cont.levels, inline = True,
172
+ fmt = fmt, fontsize = 10)
173
+
174
+ C_curv = abs(pd.DataFrame(out ,index=y, columns=x))
175
+ C_curv = C_curv.index @ (C_curv == C_curv.apply(min))
176
+ xC_curv = np.arange(Xmin,Xmax,(Xmax-Xmin)/(Num_ind+1))
177
+ C_curv = np.interp(xC_curv,C_curv.index,C_curv)
178
+ Num_ind_1 = pd.Series(Z1(xC_curv,C_curv)).sort_values(ascending=True)
179
+ Num_ind_2 = pd.Series(Z2(xC_curv,C_curv)).sort_values(ascending=True)
180
+
181
+ #Draw the dotation point and his curves
182
+ if AlPoint != None:
183
+ plt.scatter(AlPoint[0],AlPoint[1],s=200,marker=".",color = colors[1],label="Allocation point")
184
+ Num_ind_1 = [Z1(AlPoint[0],AlPoint[1])]
185
+ Num_ind_2 = [Z2(AlPoint[0],AlPoint[1])]
186
+
187
+ #draw the indifference curve
188
+ if Utility_draw == True:
189
+ C1 = plt.contour(X, Y, Z1(X,Y),colors = colors[2],levels=Num_ind_1)
190
+ C2 = plt.contour(X, Y, Z2(X,Y),colors = colors[3],levels=Num_ind_2)
191
+ if Utility_Show == True:
192
+ fmt = {}
193
+ strs = round(pd.Series(C1.levels[:]),1)
194
+ for l, s in zip(C1.levels, strs):
195
+ fmt[l] = s
196
+ plt.clabel(C1, C1.levels, inline = True,
197
+ fmt = fmt, fontsize = 10)
198
+ #Utility level2
199
+
200
+ fmt = {}
201
+ strs = round(pd.Series(C2.levels[:]),1)
202
+ for l, s in zip(C2.levels, strs):
203
+ fmt[l] = s
204
+ plt.clabel(C2, C2.levels, inline = True,
205
+ fmt = fmt, fontsize = 10)
206
+
207
+
208
+ plt.title("Edgeworth box")
209
+ plt.xlabel(Xlab)
210
+ plt.ylabel(Ylab)
211
+ ```
212
+
213
+ ## We can then set the parameters for Alpha and Beta in the Cobb - Douglas formula
214
+
215
+ ## Let's consider the simpler case of a Utility function
216
+ - that has a Cobb-Douglas type formulation
217
+ - consists of consuming two goods $X1$ and $X2$
218
+
219
+ $ U = \cdot X1^{\alpha} \cdot X2^{1-\alpha}$
220
+
221
+ ```python
222
+ #Utility of 1st agent (depend on X,Y):
223
+ U1 = lambda c,n : c**0.5 * n**0.5
224
+ #Utility of 2nd agent (depend on X,Y):
225
+ U2 = lambda c,n : c**0.5 * n**0.5
226
+
227
+
228
+ draw_Ed_Bow(U1,U2,18,30,colors=["k","Orange", "lightblue","mistyrose"],Num_ind=3)
229
+ draw_Ed_Bow(U1,U2,18,30,Xlab="Cereal",Ylab="Noodles",AlPoint=(10,16),Contract_draw=False)
230
+ plt.show()
231
+ ```
232
+
233
+ ```python
234
+ #Utility of 1st agent (depend on X,Y):
235
+ U1 = lambda c,n : c**0.7 * n**0.3
236
+ #Utility of 2nd agent (depend on X,Y):
237
+ U2 = lambda c,n : c**0.5 * n**0.5
238
+
239
+
240
+ draw_Ed_Bow(U1,U2,18,30,colors=["k","Orange", "lightblue","mistyrose"],Num_ind=3)
241
+ draw_Ed_Bow(U1,U2,18,30,Xlab="Cereal",Ylab="Noodles",AlPoint=(11.5,13),Contract_draw=False)
242
+ plt.show()
243
+ ```
244
+
245
+ ## General parameters for $\alpha $ and $ \beta $
246
+
247
+ ```python
248
+ alpha1 = 0.5
249
+ beta1 = 0.5
250
+ alpha2 = 0.7
251
+ beta2 = 0.3
252
+ ```
253
+
254
+ ```python
255
+ #Utility of 1st agent (depend on X,Y):
256
+ U1 = lambda c,n :n**alpha1 * c**beta1
257
+ #Utility of 2nd agent (depend on X,Y):
258
+ U2 = lambda c,n : n**alpha2 * c**beta2
259
+
260
+
261
+ draw_Ed_Bow(U1,U2,30,18,colors=["k","Orange", "lightblue","mistyrose"],Num_ind=3)
262
+ draw_Ed_Bow(U1,U2,30,18,Xlab="Cereal",Ylab="Noodles",AlPoint=(18,7),Contract_draw=False)
263
+ plt.show()
264
+ ```
265
+
266
+ ```python
267
+
268
+ ```
269
+
@@ -0,0 +1,283 @@
1
+ ---
2
+ title: "7.1-inequality"
3
+ type: lecture-notebook
4
+ week: 7
5
+ source_path: "/Users/ericvandusen/Documents/Data88E-ForTraining/F24Lec_NBs/lec07/7.1-inequality.ipynb"
6
+ ---
7
+
8
+ <table style="width: 100%;" id="nb-header">
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 23<br>
13
+ Dr. Eric Van Dusen <br>
14
+ Akhil Venkatesh <br>
15
+ </table>
16
+
17
+ From the Textbook Chapter
18
+ https://data-88e.github.io/textbook/content/06-inequality/inequality.html
19
+
20
+ ```python
21
+ import pandas as pd
22
+ import numpy as np
23
+ import matplotlib.pyplot as plt
24
+ from datascience import *
25
+ %matplotlib inline
26
+ #plt.style.use('seaborn-muted')
27
+ ```
28
+
29
+ # Lec 7.1 Measurements of Inequality
30
+
31
+ ## The Lorenz Curve
32
+ The Lorenz Curve visually presents income inequality by plotting household income percentile on the $x$-axis, and the cumulative income share that the bottom $x$ percentile own on the $y$-axis. The households are sorted by income, so that the first household at the 0th percentile has the least amount of income, while the household at the 100th percentile has the greatest income.
33
+
34
+ For any point $(x,y)$ on the Lorenz curve, “the bottom x percent own y% of the income”. For example, if the $x$-axis reads 0.30 and $y$-axis reads 0.10, then it means that the bottom 30% of the population received 10% of the total population's income. This yields 2 implications for the Lorenz Curve:
35
+ - The points $(0,0)$ and $(1,1)$ are always on the curve. $(0,0)$ represents the 0% of the population owning 0% of the income and $(1,1)$ represents 100% of the population owning 100% of the income.
36
+ - The slope is always increasing. This is because households are sorted by income as percentiles: for a slight increase in $x$, households become richer and hence provide a larger share of total income.
37
+
38
+ ### Line of Perfect Equality
39
+ In a world of perfect equality, everyone would have the exact same income. In this case, the Lorenz curve would just be a 45-degree straight line that runs through $(0,0)$ and $(1,1)$, i.e. $y=x$. Mathematically, this is because the derivative is constant: for a slight increase in $x$, the total share of income increases at a constant rate. Another way to think about this is that the bottom 10% of the population will own 10% of the total income, the bottom 50% of the population will own 50% of the total income, and so on. This line is known as the *line of perfect equality*, and we typically display this line when plotting our Lorenz curves as a reference.
40
+
41
+ ### A Toy Example
42
+ Let's suppose country 1 has the following income distribution:
43
+ - The bottom 10% owns a cumulative 2% of total income
44
+ - The bottom 20% owns 5% of total income
45
+ - The bottom 30% owns 9% of total income
46
+ - The bottom 40% owns 15% of total income
47
+ - The bottom 50% owns 23% of total income
48
+ - The bottom 60% owns 33% of total income
49
+ - The bottom 70% with 45% of total income
50
+ - The bottom 80% with 59% of total income
51
+ - The bottom 90% with 75% of total income
52
+ - The bottom 100% with 100% of total income
53
+
54
+ We will create an array of income shares and call it `Country1`.
55
+
56
+ ```python
57
+ Country1 = make_array(0, 0.02, 0.05, 0.09, 0.15, 0.23, 0.33, 0.45, 0.59, 0.75, 1.0)
58
+ ```
59
+
60
+ To better see this information, we will create a table containing population percentage and cumulative income share.
61
+
62
+ ```python
63
+ income_distribution = Table().with_columns(
64
+ "Population Percentage (%)", np.arange(11) * 10,
65
+ "Cumulative Income Share (%)", Country1 * 100,
66
+ "Perfect Equality Income Share (%)", np.arange(11) * 10
67
+ )
68
+ income_distribution
69
+ ```
70
+
71
+ How will the Lorenz Curve for this income distribution look?
72
+
73
+ ```python
74
+ income_distribution.scatter(0, 1, width=11, height=7)
75
+ plt.plot([0,100], [0,100], color='k');
76
+ ```
77
+
78
+ ### Comparing Lorenz Curves
79
+ Now let's compare 2 countries' Lorenz curves. Suppose country 2 has the following income distribution:
80
+ - The bottom 10% owns a cumulative 3% of total income
81
+ - The bottom 20% owns 7% of total income
82
+ - The bottom 30% owns 13% of total income
83
+ - The bottom 40% owns 19% of total income
84
+ - The bottom 50% owns 27% of total income
85
+ - The bottom 60% owns 37% of total income
86
+ - The bottom 70% with 50% of total income
87
+ - The bottom 80% with 65% of total income
88
+ - The bottom 90% with 81% of total income
89
+ - The bottom 100% with 100% of total income
90
+
91
+ ```python
92
+ Country2 = make_array(0, 0.03, 0.07, 0.13, 0.19, 0.27, 0.37, 0.5, 0.65, 0.81, 1.0)
93
+ income_distribution2 = Table().with_columns(
94
+ "Population Percentage (%)", np.arange(11) * 10,
95
+ "Cumulative Income Share (%)", Country2 * 100,
96
+ "Perfect Equality Income Share (%)", np.arange(11) * 10
97
+ )
98
+ income_distribution2
99
+ ```
100
+
101
+ Comparing the 2 countries' income distributions side by side:
102
+
103
+ ```python
104
+ income_distribution.join(
105
+ ["Population Percentage (%)", "Perfect Equality Income Share (%)"],
106
+ income_distribution2, ["Population Percentage (%)", "Perfect Equality Income Share (%)"]
107
+ ).relabel(
108
+ "Cumulative Income Share (%)", "Country 1 Cumulative Income Share (%)"
109
+ ).relabel(
110
+ "Cumulative Income Share (%)_2", "Country 2 Cumulative Income Share (%)"
111
+ )
112
+ ```
113
+
114
+ Plotting both countries' Lorenz curves, can you tell which country has a higher level of income inequality?
115
+
116
+ ```python
117
+ plt.figure(figsize=[7,7])
118
+ plt.plot(income_distribution.column(0), income_distribution.column(1), "-o", c = 'b')
119
+ plt.plot(income_distribution.column(0), income_distribution2.column(1), "-o", c = 'r')
120
+ plt.legend(["Country 1", "Country 2"])
121
+ plt.plot([0,100], [0,100], color='k');
122
+ ```
123
+
124
+ In this case, we can see that country 2's Lorenz curve is closer to the line of equality than that of country 1, which intuitively would suggest that country 2 is more equal. If we were to look at the numbers, we see that the bottom percentiles own a higher % of total national income in country 2 than in country 1, while top percentiles own less in country 2 than in country 1. This would suggest that country 2 is more equal in income than country 1, so that country 1 has a higher level of income inequality.
125
+
126
+ But now let's consider a different case; suppose country 3 has the following distribution:
127
+
128
+ ```python
129
+ Country3 = make_array(0, 0.03, 0.07, 0.12, 0.18, 0.25, 0.33, 0.42, 0.54, 0.73, 1.0)
130
+ income_distribution3 = Table().with_columns(
131
+ "Population Percentage (%)", np.arange(11) * 10,
132
+ "Cumulative Income Share (%)", Country3 * 100,
133
+ "Perfect Equality Income Share (%)", np.arange(11) * 10
134
+ )
135
+ income_distribution.join(
136
+ ["Population Percentage (%)", "Perfect Equality Income Share (%)"],
137
+ income_distribution3, ["Population Percentage (%)", "Perfect Equality Income Share (%)"]
138
+ ).relabel(
139
+ "Cumulative Income Share (%)", "Country 1 Cumulative Income Share (%)"
140
+ ).relabel(
141
+ "Cumulative Income Share (%)_2", "Country 3 Cumulative Income Share (%)"
142
+ )
143
+ ```
144
+
145
+ ```python
146
+ plt.figure(figsize=[7,7])
147
+ plt.plot(income_distribution.column(0), income_distribution.column(1), "-o", c = 'b')
148
+ plt.plot(income_distribution.column(0), income_distribution3.column(1), "-o", c = 'r')
149
+ plt.legend(["Country 1", "Country 3"])
150
+ plt.plot([0,100], [0,100], color='k');
151
+ ```
152
+
153
+ Now, ambiguity arises; while bottom income percentiles earn a larger share of national income in country 3, top income percentiles also have a larger share. We can visualize this phenomenon by the 'crossing' of Lorenz curves on the plot. As a result, we do cannot easily tell which country has a higher level of income inequality.
154
+
155
+ As you may see, the Lorenz curve is not able to produce a 'quantitative' measure of income inequality, making the scenario above hard for us to compare the 2 countries. For this, we turn to the Gini coefficient.
156
+
157
+ ## The Gini Coefficient
158
+
159
+ We can use the Gini coefficeint to quantify the level of income inequality.
160
+
161
+ !<img src="Gini.png" />
162
+
163
+ The **Gini coefficient** is the ratio of the area between the line of equality and the Lorenz curve to the total area under the line of equality. Referring to $A$ and $B$ from {numref}`gini-coefficient`:
164
+
165
+ $$\text{Gini} = \frac{\text{Area between line of equality and Lorenz curve}}{\text{Area under line of equality}} = \frac{A}{A+B}$$
166
+
167
+ If we express the Lorenz curve as $L(x)$, we can use calculus to derive an equation for the Gini coefficient:
168
+
169
+ $$\text{Gini} = \frac{\frac{1}{2} - \int_0^1 L(x)\text{d}x}{\frac{1}{2}} = 1 - 2\int_0^1 L(x)\text{d}x$$
170
+ ```
171
+
172
+ Intuitively, the closer the Lorenz curve is to the line of equality, the lower income inequality exists. Hence, the smaller the area of A, the lower the inequality. **This means that the smaller the Gini coefficient, the lower the income inequality.** Also note that the Gini coefficient will always be between 0 and 1. Mathematically, since $A$ and $B$ are both positive, $0<\frac{A}{A+B}<1$.
173
+
174
+ ```python
175
+ # This function estimates the Gini coefficient. You don't have to understand how this code works below.
176
+ def gini(distribution):
177
+ sorted_distribution = sorted(distribution)
178
+ height = 0
179
+ area = 0
180
+ for i in sorted_distribution:
181
+ height += i
182
+ area += height - i / 2
183
+ fair_area = height * len(distribution) / 2.
184
+ return (fair_area - area) / fair_area
185
+ ```
186
+
187
+ When we use our population as the parameter to the `gini` function, we get:
188
+
189
+ ```python
190
+ gini_coefficient_country1 = gini(Country1)
191
+ gini_coefficient_country1
192
+ ```
193
+
194
+ ```python
195
+ gini_coefficient_country2 = gini(Country2)
196
+ gini_coefficient_country2
197
+ ```
198
+
199
+ ```python
200
+ gini_coefficient_country3 = gini(Country3)
201
+ gini_coefficient_country3
202
+ ```
203
+
204
+ These results confirm our intuition from the analysis we did previously via Lorenz curves. Previously, we concluded that country 1 had a higher level of income inequality than country 2, and this is supported by country 1's higher gini coefficient. On the other hand, we had trouble comparing levels of inequality between country 1 and country 3. Here, the gini coefficient would indicate that country 1 has a higher level of income inequality than country 3.
205
+
206
+ # Income Inequality Historically
207
+
208
+ <!-- Written by Amal Bhatnagar -->
209
+
210
+ In the last chart on the previous page, you may have noticed that income inequality was rising in the United States in the last few decades. We will examine this in more detail, and also observe global trends in inequality.
211
+
212
+ ## The United States
213
+
214
+ Let's look at historical trends of income inequality in the US over the last 100 years. The data has been collected from [The World Inequality Database](https://wid.world/), which is co-directed by Berkeley Economics professors Emanuel Saez and Gabriel Zucman. Specifically, we will observe income distributions for the bottom 50 percent, top 10 percent, and top 1 percent.
215
+
216
+ ```python
217
+ us_hist = Table.read_table("US_inequality.csv")
218
+ us_hist.show(5)
219
+ ```
220
+
221
+ ```python
222
+ us_hist.take(np.arange(100,105))
223
+ ```
224
+
225
+ Let's begin with some data cleaning: it seems like our 3 brackets are 'vertically stacked' on top of each other. Instead, we would like a table with 5 columns: `Year`, `bottom 50% income share`, `top 10% income share`, and `top 1% income share`.
226
+
227
+ ```python
228
+ bottom_50_us = us_hist.where("Percentile", "p0p50").drop("Percentile").relabeled("Income Share", "Bottom 50% Share")
229
+ top_10_us = us_hist.where("Percentile", "p90p100").drop("Percentile").relabeled("Income Share", "Top 10% Share")
230
+ top_1_us = us_hist.where("Percentile", "p99p100").drop("Percentile").relabeled("Income Share", "Top 1% Share")
231
+ us_hist_joined = bottom_50_us.join("Year", top_10_us).join("Year", top_1_us)
232
+ us_hist_joined
233
+ ```
234
+
235
+ Oh no, there are some `nan` values! NaN (not a number) values are very common in real world datasets: often, we may not have some observations simply because no data was collected, or perhaps the data collected was faulty. Sometimes, we can try to impute or replace NaN values in order to avoid having gaps in our data, but for now let's ignore NaNs and when plotting to see what's going on:
236
+
237
+ ```python
238
+ # mpl.rcParams['figure.dpi'] = 120
239
+ us_hist_joined.plot("Year", width=11, height=7)
240
+ plt.title("Income Share over Time", fontsize = 16)
241
+ plt.ylabel("Proportion", fontsize = 14)
242
+ plt.xlabel("Year", fontsize = 14)
243
+ plt.show()
244
+ ```
245
+
246
+ # Income Inequality for the Rest of the World
247
+
248
+ Now let's examine the trends of income inequality in other parts of the world.
249
+
250
+ ```python
251
+ world_hist = Table.read_table("World_Inequality.csv")
252
+ bottom_50_world = world_hist.where("Percentile", "p0p50").drop("Percentile")
253
+ top_10_world = world_hist.where("Percentile", "p90p100").drop("Percentile")
254
+ top_1_world = world_hist.where("Percentile", "p99p100").drop("Percentile")
255
+ top_10_world
256
+ ```
257
+
258
+ ```python
259
+ top_10_world.plot("Year", width=11, height=7)
260
+ plt.ylabel("Gini Coefficient", fontsize=14)
261
+ plt.xlabel("Year", fontsize=14)
262
+ plt.title("Income Inequality over Time", fontsize=18);
263
+ ```
264
+
265
+ Just like the US, it seems global inequality has been rising around the world, especially in China, India, Russia, and across Europe. However, in absolute terms, the level of income inequality in Europe is much lower than that in the United States.
266
+
267
+ Also look at Russia: income inequality spiked up around 1991. This was likely caused by the fall of the USSR: the failing Soviet state left the ownership of state assets uncontested, which allowed former USSR officials to acquire state property through informal deals. This led to the rise of many Russian oligarchs - those who rapidly accumulated wealth during the era of Russian privatization directly follwing the dissolution of the Soviet Union.
268
+
269
+ ```python
270
+ top_10_world.select("Year", "USA", "Europe").plot("Year", width=11, height=7)
271
+ plt.ylabel("Gini Coefficient", fontsize=14)
272
+ plt.xlabel("Year", fontsize=14)
273
+ plt.title("Income Inequality over Time", fontsize=18);
274
+ ```
275
+
276
+ ```python
277
+
278
+ ```
279
+
280
+ ```python
281
+
282
+ ```
283
+