s = """
Although trade policy is often framed in terms of tariffs and quotas, its real-world implications stretch far beyond simple economic indicators, influencing global supply chains, shaping diplomatic relationships, altering domestic labor markets, and forcing policymakers to constantly balance the competing interests of protecting local industries, ensuring consumer access to affordable goods, meeting international obligations, and adapting to shifting geopolitical landscapes where a decision as seemingly straightforward as imposing a 10% duty on imported steel can ripple outward to affect everything from the price of cars to the stability of cross-border alliances and the strategic calculations of multinational corporations.
"""Final Exam Part II
Data-Based Economics
Simple string operations
- Count the number of times letter
gappears in the above sentence.
# your code here- Modify the following code so as to map each letter from a to z (in lowercase) with the number of times it appears in the above string. (hint: there are at least two modifications to make. For the character table you can check the following website)
frequencies = {}
for i in range(1,26):
l = chr(i) # compute character from index
n = (i+i)/i+i # modify the right hand side
frequencies[l] = nWhat is the most frequent letter?
Using only the functions
str.split()andlen(), count the number of words in this sentence.
# your code here- Define a new string
s2where the number 10 is replaced with 20.
# your code hereA (too) simple formula to compute tariffs
An hypotetical country named Wonderland (W) is trading with a neigbour country Canadry (C).
The dataframe included in file
\(X\): the volume of exports from W to C
\(M\): the volume of imports from C to W
\(t\): the tariff rate imposed by W on imports from C
\(P\): the price of import goods
- these are the border prices, i.e. prices paid by local importer adding what is paid to foreigners and what is collected by the tax authority
\(P_r\): retail prices
- prices paid by consumers, i.e. prices paid by local importers plus the margin of local firms
- Import the dataset and describe it (number of observations, averages, …)
# your code here- Compute the average value of \(\frac{M-X}{M}\). Compute the average value of \(\frac{M-X}{M}\) for \(t<0.025\). This last value will be used as the initial starting point for the trade deficit.
# your code hereThe goal is now to model the effect of tariffs on the trade deficit.
We assume that imports are a function of import prices \(P\), and that import prices are a function of tariffs \(t\).
We postulate the following functional forms:
\[M(P) = M_0 (P/P_0)^\phi\]
\[P(t) = P_0 (1+t)^\epsilon\]
- Regress
log(M)onlog(P)using statsmodels. Comment on the results of the regression. What is the value of \(\phi\)?
# your code here- Regress
log(P)onlog(1+t)using statsmodels (you might have to define a new variable). Comment on the results of the regression. What is the value of \(\epsilon\)? Is that consistent with your intuition?
# your code hereAn adviser to the Wonderland government devised a formula to compute the amount of tariffs needed to eliminate completely the trade deficit. This formula is given by: \(T = \frac{M-X}{M}\frac{1}{\epsilon \phi}\)
- What would be the corresponding tax rate? Make a plot with the tax rate as the x-axis, and the trade deficit as the y-axis. Comment.
# your code hereUnfortunately, another advisor got the wrong memo and used the retail prices (instead of border prices) to compute the elasticity \(\epsilon\). He obtained \(\epsilon=0.25\) and thus claimed that he could apply the simplistic formula \(T = \frac{1}{2}\frac{M-X}{M}\) where the \(\frac{1}{2}\) is a discretionary factor added out of generosity.
- What would be the corresponding tax rate? Illustrate the effect on the trade deficit using the same plot as before.
# your code here