class: center, middle, inverse, title-slide .title[ # Lecture 11 ] .subtitle[ ## Spatial Models ] .author[ ### Ivan Rudik ] .date[ ### AEM 7130 ] --- exclude: true ```r if (!require("pacman")) install.packages("pacman") pacman::p_load( xaringanExtra, JuliaCall ) options(htmltools.dir.version = FALSE) library(knitr) opts_chunk$set( prompt = T, ## See hook below. I basically want a "$" prompt for every bash command in this lecture. fig.align = "center", fig.width=10, fig.height=6, out.width="748px", out.length="520.75px", dpi = 300, #fig.path='Figs/', cache = F#, echo=F, warning=F, message=F ) ## Next hook based on this SO answer: https://stackoverflow.com/a/39025054 knit_hooks$set( prompt = function(before, options, envir) { options( prompt = if (options$engine %in% c('sh','bash')) '$ ' else ' ', continue = if (options$engine %in% c('sh','bash')) '$ ' else ' ' ) }) julia_setup(JULIA_HOME = "/Applications/Julia-1.8.app/Contents/Resources/julia/bin") ``` --- # Roadmap 1. Spatial models: Armington 2. Exact hat algebra 3. Dynamic spatial models: Armington + migration 4. Dynamic hat algebra --- # Spatial models So far we have been focusing on .hi[dynamics] -- Now we are going to look at the other dimension: .hi[space] -- To start, we will work with static models -- But we will introduce multiple regions across space, and frictions inhibiting mobility of goods and factors of production --- class: inverse, center, middle name: armington # The Armington model <html><div style='float:left'></div><hr color='#EB811B' size=1px width=796px></html> --- # Armington and gravity Classic trade theory (e.g. Ricardo) highlights economic forces driving trade of goods - Comparative advantage -- Empirical work has long used the .hi[gravity model:] `$$X_{ij} = \alpha \frac{Y_i Y_j}{D_{ij}}$$` --- # Armington and gravity `$$X_{ij} = \alpha \frac{Y_i Y_j}{D_{ij}}$$` `\(X_{ij}\)` trade flow from i to j `\(Y_i\)` GDP of origin `\(Y_j\)` GDP of destination `\(D_{ij}\)` distance and other frictions affecting trade flows --- # Armington and gravity `$$X_{ij} = \alpha \frac{Y_i Y_j}{D_{ij}}$$` The gravity model is widely used and empirically matches the data, but no real theoretical foundation, can't do counterfactuals -- The .hi[Armington] model provides a simple theoretical foundation for gravity with two key ingredients: 1. Spatially differentiated products 2. Love-of-variety preferences --- # Armington The set up: `\(N\)` regions -- Each region produces a differentiated product -- Representative household in each region can purchase goods from all locations -- Trade frictions (e.g. distance) result in different prices offered by different producers --- # Armington: preferences The representative household in region `\(j\)` has CES preferences across goods: `$$U_j = \left(\sum_{i \in N} a_{ij}^{1 \over \sigma} q_{ij}^{\sigma-1 \over \sigma}\right)^{\sigma \over \sigma-1}$$` `\(\sigma\)` is the elasticity of substitution with `\(\sigma > 1\)` `\(a_{ij}\)` is an exogenous taste parameter `\(q_{ij}\)` is the quantity of goods imported from `\(i\)` to `\(j\)` --- # Armington: demand The consumer maximizes utility subject to a budget: `$$\max_{\{q_{ij}\}_{i \in N}} \left(\sum_{i \in N} a_{ij}^{1 \over \sigma} q_{ij}^{\sigma-1 \over \sigma}\right)^{\sigma \over \sigma-1} \quad \text{subject to:} \quad \sum_{i \in N} q_{ij} p_{ij} \leq Y_j$$` -- Standard result gives demand for goods from `\(i\)` by `\(j\)`: `$$q_{ij} = a_{ij} p_{ij}^{-\sigma} Y_j P_j^{\sigma-1} \quad \text{where} \quad P_j = \left(\sum_{k \in N} a_{kj} p_{kj}^{1-\sigma}\right)^{1 \over 1-\sigma}$$` `\(P_j\)` is the usual Dixit-Stiglitz price index --- # Armington: demand `$$q_{ij} = a_{ij} p_{ij}^{-\sigma} Y_j P_j^{\sigma-1} \quad \text{where} \quad P_j = \left(\sum_{k \in N} a_{kj} p_{kj}^{1-\sigma}\right)^{1 \over 1-\sigma}$$` Multiply by prices to get trade flows in dollar terms: `$$X_{ij} = q_{ij} p_{ij} = a_{ij} p_{ij}^{1-\sigma} Y_j P_j^{\sigma-1}$$` Trade flows .hi-red[decrease] in bilateral prices, .hi-blue[increase] in the local price index, and .hi-blue[increase] in local size/GDP --- # Armington: supply .hi[Armington assumption:] each region produces a distinct variety of a good -- There are .hi[iceberg trade costs] `\(\tau_{ij} \geq 1\)`: for 1 unit of `\(q_{ij}\)` to arrive at `\(j\)` from `\(i\)` you need to ship `\(\tau_{ij}\)` units -- Market structure: - Producers compete in perfect competition - Regions are endowed with `\(L_i\)` workers supplying 1 unit of labor - Each unit of labor can produce `\(A_i\)` units so total output is `\(A_i L_i\)` - Workers are paid a wage `\(w_i\)` so that `\(Y_i = w_i L_i\)` --- # Armington: supply Given a labor endowment `\(L_i\)` and productivity `\(A_i\)` the marginal cost of production is `\(w_i \over A_i\)` -- Perfect competition means the factory-door price is marginal cost: `\(w_i \over A_i\)` -- The price in `\(j\)` to buy a unit of the good from `\(i\)` is then: `$$p_{ij} = \tau_{ij} {w_i \over A_i}$$` Plug back into demand to get: `$$X_{ij} = a_{ij} \tau_{ij}^{1-\sigma} \left(w_i \over A_i\right)^{1-\sigma} Y_j P_j^{\sigma-1}$$` --- # Armington: market clearing `$$X_{ij} = a_{ij} \tau_{ij}^{1-\sigma} \left(w_i \over A_i\right)^{1-\sigma} Y_j P_j^{\sigma-1}$$` Define .hi[expenditure shares] as the expenditures on `\(i\)` by `\(j\)` relative to `\(j\)`s total expenditures: `\begin{align} \lambda_{ij} &= {X_{ij} \over \sum_{k \in N} X_{kj}} \end{align}` --- # Armington: market clearing `\begin{align} \lambda_{ij} &= {X_{ij} \over \sum_{k \in N} X_{kj}} \\ & = \frac{a_{ij} \tau_{ij}^{1-\sigma} \left(w_i \over A_i\right)^{1-\sigma} Y_j P_j^{\sigma-1}}{\sum_{k \in N} a_{kj} \tau_{kj}^{1-\sigma} \left(w_k \over A_k\right)^{1-\sigma} Y_j P_j^{\sigma-1}} \\ & = \frac{a_{ij} \left(\tau_{ij} w_i \over A_i\right)^{1-\sigma} }{\sum_{k \in N} a_{kj} \left(\tau_{kj} w_k \over A_k\right)^{1-\sigma} } \end{align}` --- # Armington: market clearing `$$\lambda_{ij} = \frac{a_{ij} \left(\tau_{ij} w_i \over A_i\right)^{1-\sigma} }{\sum_{k \in N} a_{kj} \left(\tau_{kj} w_k \over A_k\right)^{1-\sigma}}$$` `\(j\)` spends more on `\(i\)` relative to other places if `\(i\)` has lower wages, higher productivity, or lower trade costs relative to other locations --- # Armington: market clearing In perfect competition the expenditures on inputs in `\(j\)` need to match the spending by other locations `\(i\)` on `\(j\)`s goods: `$$w_j L_j = \sum_{i \in N} \lambda_{ji} w_i L_i$$` Perfect competition `\(\rightarrow\)` labor costs = revenues --- # Armington: equilibrium Our equilibrium is then defined by two sets of equations: `$$\lambda_{ij} = \frac{a_{ij} \left(\tau_{ij} w_i \over A_i\right)^{1-\sigma} }{\sum_{k \in N} a_{kj} \left(\tau_{kj} w_k \over A_k\right)^{1-\sigma}} \qquad w_j L_j = \sum_{i \in N} \lambda_{ji} w_i L_i$$` where the endogenous variables are the `\(N^2\)` `\(\lambda_{ij}\)` terms and the `\(N\)` `\(w_j\)` terms --- # Armington: equilibrium `$$\lambda_{ij} = \frac{a_{ij} \left(\tau_{ij} w_i \over A_i\right)^{1-\sigma} }{\sum_{k \in N} a_{kj} \left(\tau_{kj} w_k \over A_k\right)^{1-\sigma}} \qquad w_j L_j = \sum_{i \in N} \lambda_{ji} w_i L_i$$` Given the exogenous parameters `\(a_{ij}, \tau_{ij}, A_i, L_i, \sigma\)`, how do we solve for the equilibrium? -- We can use function iteration after substituting in for `\(\lambda{ij}\)` in market clearing: `$$w_j L_j = \sum_{i \in N} \frac{a_{ji} \left(\tau_{ji} w_j \over A_j\right)^{1-\sigma} }{\sum_{k \in N} a_{ki} \left(\tau_{ki} w_k \over A_k\right)^{1-\sigma}} w_i L_i$$` --- # Armington: equilibrium `$$w_j L_j = \sum_{i \in N} \frac{a_{ij} \left(\tau_{ij} w_i \over A_i\right)^{1-\sigma} }{\sum_{k \in N} a_{kj} \left(\tau_{kj} w_k \over A_k\right)^{1-\sigma}} w_i L_i$$` We have `\(N\)` market clearing conditions and `\(N\)` unknown `\(w_i\)` terms -- Write up a function `solve_armington_eq(sigma, tau, A, L, a, tol, damp)` that solves for the equilibrium wages and expenditure shares --- # Armington: equilibrium ```julia function solve_armington_eq(σ, τ, A, L, a, tol = 1e-5, damp = .1) w, λ = ones(size(A)), zeros(size(a)) wage_error = 1e5 while wage_error > tol denominator, wL = zeros(size(A)), zeros(size(A)) for k in eachindex(A) denominator .+= a[k,:] .* (τ[k,:] * w[k] / A[k]).^(1 .- σ) end for i in eachindex(A) wL .+= a[:,i] .* (τ[:,i] .* w ./ A).^(1 .- σ) .* w[i] .* L[i] ./ denominator[i] end wnew = wL ./ L wage_error = maximum(abs.(wnew .- w)./w) w = damp .* wnew .+ (1 - damp) .* w end for o in eachindex(A), d in eachindex(A) λ[o,d] = a[o,d] * (τ[o,d] * w[o] / A[o])^(1 - σ) / sum(a[:,d] .* (τ[:,d] .* w[:] ./ A[:]).^(1 .- σ)) end return w, λ end ``` ``` ## solve_armington_eq (generic function with 3 methods) ``` --- # Symmetric + cross-region trade costs of 5 ```julia τ = [1. 5; 5. 1.]; a = [1. 1.; 1. 1.]; A = [1., 1.]; L = [1., 1.]; σ = 2.; w, λ = solve_armington_eq(σ, τ, A, L, a); display(w) ``` ``` ## 2-element Vector{Float64}: ## 1.0 ## 1.0 ``` ```julia display(λ) ``` ``` ## 2×2 Matrix{Float64}: ## 0.833333 0.166667 ## 0.166667 0.833333 ``` --- # Productivity shock to region 1 ```julia τ = [1. 5; 5. 1.]; a = [1. 1.; 1. 1.]; A = [10., 1.]; L = [1., 1.]; σ = 2.; w, λ = solve_armington_eq(σ, τ, A, L, a); display(w) ``` ``` ## 2-element Vector{Float64}: ## 1.6143181095745787 ## 0.38568189042542783 ``` ```julia display(λ) ``` ``` ## 2×2 Matrix{Float64}: ## 0.922754 0.323331 ## 0.077246 0.676669 ``` --- # Increased labor supply in region 1 ```julia τ = [1. 5; 5. 1.]; a = [1. 1.; 1. 1.]; A = [1., 1.]; L = [5., 1.]; σ = 2.; w, λ = solve_armington_eq(σ, τ, A, L, a); display(w) ``` ``` ## 2-element Vector{Float64}: ## 0.8780637781792023 ## 1.6096811091040044 ``` ```julia display(λ) ``` ``` ## 2×2 Matrix{Float64}: ## 0.901634 0.26828 ## 0.0983663 0.73172 ``` --- # Return to autarky ```julia τ = [1. 1e9; 1e9 1.]; a = [1. 1.; 1. 1.]; A = [1., 1.]; L = [1., 1.]; σ = 2.; w, λ = solve_armington_eq(σ, τ, A, L, a); display(w) ``` ``` ## 2-element Vector{Float64}: ## 1.0 ## 1.0 ``` ```julia display(λ) ``` ``` ## 2×2 Matrix{Float64}: ## 1.0 1.0e-9 ## 1.0e-9 1.0 ``` --- # Free trade ```julia τ = [1. 1.0001; 1.0001 1.]; a = [1. 1.; 1. 1.]; A = [1., 1.]; L = [1., 1.]; σ = 2.; w, λ = solve_armington_eq(σ, τ, A, L, a); display(w) ``` ``` ## 2-element Vector{Float64}: ## 1.0 ## 1.0 ``` ```julia display(λ) ``` ``` ## 2×2 Matrix{Float64}: ## 0.500025 0.499975 ## 0.499975 0.500025 ``` --- # New trading partner ```julia τ = [1. 2. 3.; 3. 1. 2.; 1e9 5. 1.]; a = [1. 1. 1.; 1. 1. 1.; 1. 1. 1.]; A = [1., 1., 1.]; L = [1., 1., 1.]; σ = 2.; w, λ = solve_armington_eq(σ, τ, A, L, a); display(w) ``` ``` ## 3-element Vector{Float64}: ## 1.2539609132194725 ## 1.095427131707213 ## 0.6506119550733213 ``` ```julia display(λ) ``` ``` ## 3×3 Matrix{Float64}: ## 0.723812 0.246282 0.117659 ## 0.276188 0.563849 0.20203 ## 1.39504e-9 0.189869 0.680311 ``` --- # Solving Armington We solved for the Armington equilibrium -- If we have values for all the exogenous parameters, we can then perform counterfactuals where we explore the equilibrium effects of changes in trade costs, productivity, etc -- This is a bit unsatisfying: we'd like to not have to take a stand on numerous region-specific and bilateral parameters --- class: inverse, center, middle name: exacthat # Exact hat algebra <html><div style='float:left'></div><hr color='#EB811B' size=1px width=796px></html> --- # Exact hat algebra A workhorse method for solving for counterfactual is .hi[exact hat algebra], you can think of it as a structural differences estimator -- There are two key pieces to it: 1. Real world data (wages, trade flows) are essentially sufficient statistics for unobservable parameters (productivity, trade costs) 2. Spatial models are built in a way where we can express a counterfactual equilibrium in terms of changes relative to the factual -- Going forward, primes will indicate counterfactual quantities `\((w'_i)\)`, hats will indicate relative quantities `\((\hat{w}_i = {w'_i \over w_i})\)` --- # Exact hat algebra In our working example, our factual equilibrium will be the real world -- We observe the data for this equilibrium (wages, trade flows, etc) -- We want to understand the equilibrium effects of some arbitrary changes in the distribution of productivity: `\(\{\hat{A}_1, \hat{A}_2, \dots \}\)` -- Assume no other exogenous variables are changing: `\(\hat{\tau}_{ij} = 1, \hat{a}_{ij} = 1, \hat{\sigma} = 1, \hat{L} = 1\)` --- # Exact hat algebra Recall our equilibrium conditions were: `$$\lambda_{ij} = \frac{a_{ij} \left(\tau_{ij} w_i \over A_i\right)^{1-\sigma} }{\sum_{k \in N} a_{kj} \left(\tau_{kj} w_k \over A_k\right)^{1-\sigma}} \qquad w_j L_j = \sum_{i \in N} \lambda_{ji} w_i L_i$$` Let's start by manipulating the market clearing condition which holds in the factual and counterfactual equilibria: -- `$$w_j L_j = \sum_{i \in N} \lambda_{ji} w_i L_i \qquad w'_j L'_j = \sum_{i \in N} \lambda'_{ji} w'_i L_i'$$` --- # Exact hat algebra First by definition: `\(\lambda_{ji} w_i L_i = X_{ji}\)` so that `$$w_j' L_j' = \sum_{i \in N} \lambda_{ji}' w_i' L_i' = \sum_{i \in N} X'_{ji}$$` -- Next, put the left hand side into hat form by dividing both sides by `\(w_j L_j\)`: `$$\hat{w}_j \underbrace{\hat{L}_j}_{=1} = \sum_{i \in N} \frac{X'_{ji}}{w_j L_j}$$` --- # Exact hat algebra `$$\hat{w}_j = \sum_{i \in N} \frac{X'_{ji}}{w_j L_j}$$` Multiply and divide the right and side by `\(X_{ji}\)` to put it into hat form: `$$\hat{w}_j = \sum_{i \in N} \frac{X_{ji}}{w_j L_j}\hat{X}_{ji}$$` --- # Exact hat algebra Finally, we know that `\(X_{ji} = \lambda_{ji} w_i L_i\)` so that `\(\hat{X}_{ji} = \hat{\lambda}_{ji} \hat{w}_i \hat{L}_i\)` and `$$\hat{w}_j = \sum_{i \in N} \frac{X_{ji}}{w_j L_j}\hat{\lambda}_{ji} \hat{w}_i$$` The change in wages depends on the change in endogenous wages and expenditure shares, and the observed factual bilateral expenditures, wages, and labor --- # Exact hat algebra Now let's go to the gravity equation: `$$\lambda'_{ij} = \frac{a_{ij} \left(\tau_{ij} w'_i \over A'_i\right)^{1-\sigma} }{\sum_{k \in N} a_{kj} \left(\tau_{kj} w'_k \over A'_k\right)^{1-\sigma}}$$` -- Put this into hat form: `$$\lambda'_{ij} / \lambda_{ij} = \left[\frac{a_{ij} \left(\tau_{ij} w'_i \over A'_i\right)^{1-\sigma} }{\sum_{k \in N} a_{kj} \left(\tau_{kj} w'_k \over A'_k\right)^{1-\sigma}}\right] \Bigg/ \left[\frac{a_{ij} \left(\tau_{ij} w_i \over A_i\right)^{1-\sigma} }{\sum_{l \in N} a_{lj} \left(\tau_{lj} w_l \over A_l\right)^{1-\sigma}}\right]$$` --- # Exact hat algebra The numerator goes into hats easily, the denominator is trickier: `$$\hat{\lambda}_{ij} = \frac{\left(\hat{w}_i \over \hat{A}_i\right)^{1-\sigma} }{ \left[\frac{\sum_{k \in N} a_{kj} \left(\tau_{kj} w'_k \over A'_k\right)^{1-\sigma}}{\sum_{l \in N} a_{lj} \left(\tau_{lj} w_l \over A_l\right)^{1-\sigma}}\right]}$$` Next, bring the bottom sum inside the top sum since it is a function of `\(j\)` and does not depend on k --- # Exact hat algebra `$$\hat{\lambda}_{ij} = \frac{\left(\hat{w}_i \over \hat{A}_i\right)^{1-\sigma} }{\sum_{k \in N} \left[\frac{ a_{kj} \left(\tau_{kj} w'_k \over A'_k\right)^{1-\sigma}}{\sum_{l \in N} a_{lj} \left(\tau_{lj} w_l \over A_l\right)^{1-\sigma}}\right]}$$` -- Inside the square brackets, multiply and divide by `\(a_{kj} \left(\tau_{kj} w_k \over A_k\right)^{1-\sigma}\)` --- # Exact hat algebra `$$\hat{\lambda}_{ij} = \frac{\left(\hat{w}_i \over \hat{A}_i\right)^{1-\sigma} }{\sum_{k \in N} \left[ \underbrace{\frac{ a_{kj} \left(\tau_{kj} w'_k \over A'_k\right)^{1-\sigma}}{a_{kj} \left(\tau_{kj} w_k \over A_k\right)^{1-\sigma}}}_{\left(\hat{w}_k \over \hat{A}_k\right)^{1-\sigma}} \underbrace{\frac{a_{kj} \left(\tau_{kj} w_k \over A_k\right)^{1-\sigma}}{\sum_{l \in N} a_{lj} \left(\tau_{lj} w_l \over A_l\right)^{1-\sigma}}}_{\lambda_{kj}}\right]}$$` --- # Exact hat algebra This finally gives us that: `$$\hat{\lambda}_{ij} = \frac{\left(\hat{w}_i \over \hat{A}_i\right)^{1-\sigma} }{\sum_{k \in N}\lambda_{kj} \left(\hat{w}_k \over \hat{A}_k\right)^{1-\sigma}}$$` The change in expenditure shares depends on the change in exogenous productivity, endogenous wages, and the observed factual expenditure shares --- # Exact hat algebra We now have our two equilibrium conditions in changes: `$$\hat{\lambda}_{ij} = \frac{\left(\hat{w}_i \over \hat{A}_i\right)^{1-\sigma} }{\sum_{k \in N}\lambda_{kj} \left(\hat{w}_k \over \hat{A}_k\right)^{1-\sigma}} \qquad \hat{w}_j = \sum_{i \in N} \frac{X_{ji}}{w_j L_j}\hat{\lambda}_{ji} \hat{w}_i$$` and can combine them into a single equilibrium condition in changes: `$$\hat{w}_j = \sum_{i \in N} \frac{\frac{X_{ji}}{w_j L_j} \left(\hat{w}_j \over \hat{A}_j\right)^{1-\sigma} \hat{w}_i}{\sum_{k \in N}\lambda_{ki} \left(\hat{w}_k \over \hat{A}_k\right)^{1-\sigma}}$$` --- # Exact hat algebra `$$\hat{w}_j = \sum_{i \in N} \frac{\frac{X_{ji}}{w_j L_j} \left(\hat{w}_j \over \hat{A}_j\right)^{1-\sigma} \hat{w}_i}{\sum_{k \in N}\lambda_{ki} \left(\hat{w}_k \over \hat{A}_k\right)^{1-\sigma}}$$` Notice that it does not depend on any structural parameters except for `\(\sigma\)` --- # Exact hat algebra `$$\hat{w}_j = \sum_{i \in N} \frac{\frac{X_{ji}}{w_j L_j} \left(\hat{w}_j \over \hat{A}_j\right)^{1-\sigma} \hat{w}_i}{\sum_{k \in N}\lambda_{ki} \left(\hat{w}_k \over \hat{A}_k\right)^{1-\sigma}}$$` `\(\lambda_{ij}, X_{ij}, w_i, L_i\)` are all observable data: -- `\(\hat{A}_i\)` is a chosen counterfactual -- `\(\hat{w}_i\)` are unknown but can be solved through function iteration -- We also will want to solve for `\(\hat{P}_i\)` to understand how the price index is changing --- # Exact hat algebra Recall: `$$P_j = \left(\sum_{k \in N} a_{kj} p_{kj}^{1-\sigma}\right)^{1 \over 1-\sigma} = \left(\sum_{k \in N} a_{kj} \left(\tau_{kj} {w_k \over A_k}\right)^{1-\sigma}\right)^{1 \over 1-\sigma}$$` `$$\hat{P}_j^{1-\sigma} = \frac{\sum_{k \in N} a_{kj} \left(\tau_{kj} {w'_k \over A'_k}\right)^{1-\sigma} }{\sum_{l \in N} a_{lj} \left(\tau_{lj} {w_l \over A_l}\right)^{1-\sigma}}$$` Like before, bring the denominator inside the numerator sum --- # Exact hat algebra `$$\hat{P}_j^{1-\sigma} = \sum_{k \in N}\frac{ a_{kj} \left(\tau_{kj} {w'_k \over A'_k}\right)^{1-\sigma}}{\sum_{l \in N} a_{lj} \left(\tau_{lj} {w_l \over A_l}\right)^{1-\sigma}}$$` multiply and divide by `\(a_{kj} \left(\tau_{kj} {w_k \over A_k}\right)^{1-\sigma}\)` to get: `$$\hat{P}_j^{1-\sigma} = \sum_{k \in N}\frac{ a_{kj} \left(\tau_{kj} {w'_k \over A'_k}\right)^{1-\sigma}}{a_{kj} \left(\tau_{kj} {w_k \over A_k}\right)^{1-\sigma}} \frac{a_{kj} \left(\tau_{kj} {w_k \over A_k}\right)^{1-\sigma}}{\sum_{l \in N} a_{lj} \left(\tau_{lj} {w_l \over A_l}\right)^{1-\sigma}}$$` --- # Exact hat algebra `$$\hat{P}_j^{1-\sigma} = \sum_{k \in N} \left( {\hat{w}_k \over \hat{A}_k}\right)^{1-\sigma} \underbrace{\frac{a_{kj} \left(\tau_{kj} {w_k \over A_k}\right)^{1-\sigma}}{\sum_{l \in N} a_{lj} \left(\tau_{lj} {w_l \over A_l}\right)^{1-\sigma}}}_{\lambda_{kj}}$$` `$$\hat{P}_j = \left(\sum_{k \in N} \left( {\hat{w}_k \over \hat{A}_k}\right)^{1-\sigma} \lambda_{kj}\right)^{1 \over 1-\sigma}$$` --- # Exact hat algebra `$$\hat{w}_j = \sum_{i \in N} \frac{\frac{X_{ji}}{w_j L_j} \left(\hat{w}_j \over \hat{A}_j\right)^{1-\sigma} \hat{w}_i}{\sum_{k \in N}\lambda_{ki} \left(\hat{w}_k \over \hat{A}_k\right)^{1-\sigma}}$$` We have `\(N\)` market clearing conditions and `\(N\)` unknown `\(\hat{w}_i\)` terms -- Write up a function `solve_armington_exact_hat(X, lambda, w, L, Ahat, sigma, tol, damp)` that solves for the new equilibrium in changes -- .hi[Key thing to keep in mind:] we haven't defined a numeraire yet, use the consumption price index --- # Exact hat algebra Here are the data to use: ```julia w = [1., 1.]; L = [1., 1.]; λ = [.8 .2; .2 .8]; X = (w .* L)' .* λ; Ahat = [10., 1.]; σ = 2.; ``` Columns of `\(\lambda\)` should sum to 1, `\(X\)` is generated to be consistent with `\(w, L, \lambda\)` --- # Exact hat algebra ```julia function solve_armington_exact_hat(X, λ, w, L, Ahat, σ, tol = 1e-5, damp = .1) what = ones(size(Ahat)) wage_error = 1e5 while wage_error > tol denominator, what_new = zeros(size(Ahat)), zeros(size(Ahat)) for k in eachindex(Ahat) denominator .+= λ[k,:] .* (what[k] / Ahat[k]).^(1 .- σ) end for i in eachindex(Ahat) what_new .+= (X[:,i] ./ (w .* L) ) .* (what ./ Ahat).^(1 .- σ) .* what[i] ./ denominator[i] end wage_error = maximum(abs.(what_new .- what)./what) what = damp .* what_new .+ (1 - damp) .* what end λhat = (what ./ Ahat).^(1 .- σ) ./ sum(λ .* (what ./ Ahat).^(1 .- σ), dims = 1) Phat = vec((sum(λ .* (what ./ Ahat).^(1 .- σ), dims = 1)).^(1 ./ (1 .- σ))) return what, λhat, Phat end ``` ``` ## solve_armington_exact_hat (generic function with 3 methods) ``` --- # Exact hat algebra ```julia Ahat = [10., 1.]; what, λhat, Phat = solve_armington_exact_hat(X, λ, w, L, Ahat, σ); what ./ Phat ``` ``` ## 2-element Vector{Float64}: ## 8.817954095849839 ## 1.289024997893565 ``` When region 1 becomes more productive: their real wages increase > 800%, region 2's real wages increase 30% --- # Exact hat algebra ```julia λhat ``` ``` ## 2×2 Matrix{Float64}: ## 1.13405 1.89688 ## 0.4638 0.77578 ``` Both region's expenditures tilt toward region 1 --- # Exact hat algebra There was nothing special about productivity here -- We could have looked at changes in trade costs, preference parameters, labor endowments, or any combination of them --- class: inverse, center, middle name: migration # Armington with dynamic migration <html><div style='float:left'></div><hr color='#EB811B' size=1px width=796px></html> --- # Dynamics in spatial models Introducing meaningful dynamics in spatial models is difficult -- The intuition is that when we introduce additional regions, the state space grows dramatically -- This is then exacerbated by introducing meaningful notions of time -- How can we begin to introduce some dynamics into spatial models? -- One way is to essentially layer a separate, tractable dynamic model onto our static Armington model --- # Dynamics in spatial models How we will do this is by introducing dynamic migration decisions of households -- First we will introduce static migration to get a sense of how it works --- # Armington + migration The set up: `\(N\)` regions with a measure `\(L = 1\)` total households across all regions -- Each region produces a differentiated product -- Representative household in each region can purchase goods from all locations -- Trade frictions result in different prices offered by different producers -- Households frictionlessly choose where to live to maximize their utility --- # Armington + migration: indirect utility The household makes two choices: 1. Which region `\(j\)` to live in subject 2. How to allocate their budget across the menu of possible `\(N\)` goods -- We make two additional tweaks to the model: 1. Adding a .hi[type 1 extreme value], destination-specific idiosyncratic shock `\(\varepsilon_j\)` observed by the households 2. Adding log utility over the CES aggregator --- # Armington + migration: indirect utility The consumer maximizes utility subject to their wage `\(w_j\)`: `$$\max_{\{q_{ij}\}_{i \in N}} \log \left[\left(\sum_{i \in N} a_{ij}^{1 \over \sigma} q_{ij}^{\sigma-1 \over \sigma}\right)^{\sigma \over \sigma-1}\right] + \varepsilon_j \quad \text{subject to:} \quad \sum_{i \in N} q_{ij} p_{ij} \leq w_j$$` --- # Armington + migration: indirect utility We get the standard result for their real wage `\(C_j\)` under CES preferences: `$$C_j = w_j / P_j \quad \text{where} \quad P_j = \left(\sum_{k \in N} a_{kj} p_{kj}^{1-\sigma}\right)^{1 \over 1-\sigma}$$` `\(P_j\)` is the usual Dixit-Stiglitz price index -- We now have the households' real wage conditional on choosing `\(j\)`, we can now solve for the households' optimal choice of `\(j\)`: `$$\max_{j \in N} \log C_j + \varepsilon_j$$` --- # Armington + migration: labor supply `$$\max_{j \in N} \log C_j + \varepsilon_j$$` The household just chooses the location with the highest combination of real wages `\(C_j\)` -- How many households choose each location? The Frechet assumption on `\(\varepsilon_j\)` buys us a closed form solution (see any treatment on discrete choice models) --- # Armington + migration: labor supply If `\(\varepsilon_j \sim T1EV\)`, with mean 0 variance 1, the share of the `\(L=1\)` households choosing to live in region `\(j\)` is: `$$L_j = \frac{\exp \log C_j}{\sum_{k \in N} \exp \log C_k} = \frac{{w_j \over P_j}}{\sum_{k \in N} {w_k \over P_k}}$$` where `\(\sum_{j \in N} L_j = 1\)` -- This is essentially our extensive margin of labor supply -- Higher wages or lower prices in `\(j\)` relative to other locations attracts more workers --- # Armington + migration: equilibrium We now have two equilibrium conditions, labor supply and joint market clearing: `$$L_j = \frac{\exp {w_j \over P_j}}{\sum_{k \in N} \exp {w_k \over P_k}} \qquad w_j L_j = \sum_{i \in N} \frac{a_{ij} \left(\tau_{ij} w_i \over A_i\right)^{1-\sigma} }{\sum_{k \in N} a_{kj} \left(\tau_{kj} w_k \over A_k\right)^{1-\sigma}} w_i L_i$$` where: - `\(P_j = \left(\sum_{k \in N} a_{kj} \left(\tau_{kj} {w_k \over A_k}\right)^{1-\sigma}\right)^{1 \over 1-\sigma}\)` - `\(\sum_{j \in N} L_j = 1\)` --- # Armington + migration: exact hat algebra Now let's solve the model using exact hat algebra -- Since labor is endogenous, we now need to account for it in the market clearing condition: `$$\hat{w}_j \hat{L}_j = \sum_{i \in N} \frac{\frac{X_{ji}}{w_j L_j} \left(\hat{w}_j \over \hat{A}_j\right)^{1-\sigma} \hat{w}_i \hat{L}_i}{\sum_{k \in N}\lambda_{ki} \left(\hat{w}_k \over \hat{A}_k\right)^{1-\sigma}}$$` You can prove to yourself that this is the correct expression --- # Armington + migration: exact hat algebra Next we need to put labor supply in hat terms: `$$L_j = \frac{{w_j \over P_j}}{\sum_{k \in N} {w_k \over P_k}}$$` `$$\hat{L}_j = \frac{ {\hat{w}_j \over \hat{P}_j}}{ \frac{\sum_{k \in N} {w'_k \over P'_k} }{\sum_{l \in N} {w_l \over P_l}} }$$` Next, use a similar multiply and divide by `\({w_j \over P_j}\)` trick as for `\(\lambda\)` --- # Armington + migration: exact hat algebra `\begin{align} \hat{L}_j &= \frac{ {\hat{w}_j \over \hat{P}_j}}{ \left[\frac{\sum_{k \in N} {w'_k \over P'_k} \frac{{w_k \over P_k}}{{w_k \over P_k}} }{\sum_{l \in N} {w_l \over P_l}} \right] } = \frac{ {\hat{w}_j \over \hat{P}_j}}{ \left[\frac{\sum_{k \in N} {\hat{w}_k \over \hat{P}_k} {w_k \over P_k} }{\sum_{l \in N} {w_l \over P_l}} \right] } = \frac{ {\hat{w}_j \over \hat{P}_j}}{\sum_{k \in N}{\hat{w}_k \over \hat{P}_k} \underbrace{\left[\frac{ {w_k \over P_k} }{\sum_{l \in N} {w_l \over P_l}} \right]}_{L_k} } \\ \hat{L}_j &= \frac{ {\hat{w}_j \over \hat{P}_j}}{\sum_{k \in N} L_k{\hat{w}_k \over \hat{P}_k} } \end{align}` The change in labor depends on the change in real wages but also the initial labor allocation --- # Armington + migration: exact hat algebra `$$\hat{w}_j \hat{L}_j = \sum_{i \in N} \frac{\frac{X_{ji}}{w_j L_j} \left(\hat{w}_j \over \hat{A}_j\right)^{1-\sigma} \hat{w}_i \hat{L}_i}{\sum_{k \in N}\lambda_{ki} \left(\hat{w}_k \over \hat{A}_k\right)^{1-\sigma}} \qquad \hat{L}_j = \frac{ {\hat{w}_j \over \hat{P}_j}}{\sum_{k \in N} L_k{\hat{w}_k \over \hat{P}_k} }$$` We now have our two equilibrium conditions in changes that we can iterate on to recover `\(\hat{w}_j, \hat{L}_j\)` Write up a function `solve_armington_mig_exact_hat(X, lambda, w, L, Ahat, sigma, tol, damp)` that solves for the new equilibrium in changes --- # Armington + migration: exact hat algebra Here are the data to use: ```julia w = [6., 3.]; L = [.3, .7]; λ = [.8 .2; .2 .8]; X = (w .* L)' .* λ ``` ``` ## 2×2 Matrix{Float64}: ## 1.44 0.42 ## 0.36 1.68 ``` ```julia Ahat = [.5, 1.]; σ = 2.; ``` Columns of `\(\lambda\)` should sum to 1, L should sum to 1, `\(X\)` is generated to be consistent with `\(w, L, \lambda\)` --- # Exact hat algebra ```julia function solve_armington_mig_exact_hat(X, λ, w, L, Ahat, σ, tol = 1e-5, damp = .1) what, Lhat, labor_error, wage_error = ones(size(Ahat)), ones(size(Ahat)), 1e5, 1e5 while max(labor_error, wage_error) > tol denominator, what_new, Lhat_new = zeros(size(Ahat)), zeros(size(Ahat)), zeros(size(Ahat)) for k in eachindex(Ahat) denominator .+= λ[k,:] .* (what[k] / Ahat[k]).^(1 .- σ) end for i in eachindex(Ahat) what_new .+= (X[:,i] ./ (w .* L) ) .* (what ./ Ahat).^(1 .- σ) .* what[i] .* Lhat[i] ./ denominator[i] ./ Lhat end Phat = vec((sum(λ .* (what_new ./ Ahat).^(1 .- σ), dims = 1)).^(1 ./ (1 .- σ))) Lhat_new = what ./ Phat ./ sum(L .* what ./ Phat) wage_error, labor_error = maximum(abs.(what_new .- what)./what), maximum(abs.(Lhat_new .- Lhat)./Lhat) what = damp .* what_new .+ (1 - damp) .* what Lhat = damp .* Lhat_new .+ (1 - damp) .* Lhat end λhat = (what ./ Ahat).^(1 .- σ) ./ sum(λ .* (what ./ Ahat).^(1 .- σ), dims = 1) Phat = vec((sum(λ .* (what ./ Ahat).^(1 .- σ), dims = 1)).^(1 ./ (1 .- σ))) return what, λhat, Phat, Lhat end ``` ``` ## solve_armington_mig_exact_hat (generic function with 3 methods) ``` --- # Exact hat algebra ```julia Ahat = [.5, 1.]; what, λhat, Phat, Lhat = solve_armington_mig_exact_hat(X, λ, w, L, Ahat, σ) ``` ``` ## ([0.9051035127985965, 1.0832507504862192], [0.8816650787044907 0.6506730472117545; 1.4733396851820366 1.0873317381970613], [1.595996319694571, 1.177852921429452], [0.6967741048725734, 1.1299539550546118]) ``` ```julia what ./ Phat ``` ``` ## 2-element Vector{Float64}: ## 0.5671087718872735 ## 0.9196825263816277 ``` When region 1 becomes less productive by 50%: their real wages fall by about the same amount, region 2s real wages fall as well --- # Exact hat algebra ```julia Lhat ``` ``` ## 2-element Vector{Float64}: ## 0.6967741048725734 ## 1.1299539550546118 ``` Decreasing productivity in region 1 leads to reallocation of workers to region 2 as workers search for higher real wages --- # Armington with dynamic migration Now let's introduce dynamics in the migration decision: - Time `\(t = 0, \dots, T\)` - Same static goods market in each period `\(t\)` - Each region `\(j\)` is populated with `\(L_{jt}\)` households where `\(\sum_{j \in N} L_{jt} = 1\)` - Productivity in each time is `\(A_{jt}\)` - Households are forward-looking and have perfect information - Households discount the future at `\(\beta \in (0,1)\)` - Moving from `\(i\)` to `\(j\)` has a multiplicative utility cost `\(\mu_{ij} \in (0,1]\)` - Households work and consume at the beginning of the period, migrate at the end of the period --- # Armington with dynamic migration We can write the household's objective as: `$$v_{jt} = \max_{i \in N} \log {w_{jt} \over P_{jt}} + \beta \mathbb{E}[v_{it+1}] - \mu_{ji} + \varepsilon_{it}$$` where the idiosyncratic shock is destination-specific -- The share of households migrating from `\(j\)` to `\(i\)` at time `\(t\)` is: `$$\pi_{jit} = \frac{\exp\left(\beta\mathbb{E}[v_{it+1}]- \mu_{ji}\right)}{\sum_{k \in N} \exp\left(\beta\mathbb{E}[v_{kt+1}]- \mu_{jk}\right)}$$` The share of households in `\(j\)` at time `\(t\)` is still `\(L_j\)` --- # Armington with dynamic migration: labor supply `$$\pi_{jit} = \frac{\exp\left(\beta\mathbb{E}[v_{it+1}]- \mu_{ji}\right)}{\sum_{k \in N} \exp\left(\beta\mathbb{E}[v_{kt+1}]- \mu_{jk}\right)}$$` We now have our .hi[dynamic] labor supply equation which depends on expected future payoffs and migration costs --- class: inverse, center, middle name: dynamichat # Dynamic hat algebra <html><div style='float:left'></div><hr color='#EB811B' size=1px width=796px></html> --- # Armington: dynamic hat algebra Now that our problem is dynamic we need to make one additional notational tweak: .hi[dots/time changes] `$$\dot{Z}_{jt+1} \equiv Z_{jt+1} / Z_{jt}$$` The dot version of a variable is the relative time change between two periods -- Then, the .hi[dynamic hat] variable is the counterfactual relative to the factual in time changes: `$$\hat{Z}_{jt+1} \equiv \dot{Z}'_{jt+1} / \dot{Z}_{jt+1} = {Z'_{jt+1}/Z'_{jt} \over Z_{jt+1}/Z_{jt}}$$` --- # Armington: dynamic hat algebra `$$\hat{Z}_{jt+1} \equiv \dot{Z}'_{jt+1} / \dot{Z}_{jt+1} = {Z'_{jt+1}/Z'_{jt} \over Z_{jt+1}/Z_{jt}}$$` In the static model using hat variables let us get around knowing the levels of most exogenous variables -- In the dynamic model using dynamic hat variables will let us get around knowing the levels of time-varying exogenous (common) variables: this is like a structural difference-in-differences -- Lets put our equilibrium conditions in dynamic hat notation starting with the labor supply equation --- # Armington: dynamic hat algebra `$$\pi_{jit} = \frac{\exp\left(\beta\mathbb{E}[v_{it+1}]- \mu_{ji}\right)}{\sum_{k \in N} \exp\left(\beta\mathbb{E}[v_{kt+1}]- \mu_{jk}\right)}$$` `$$\dot{\pi}_{jit+1} = \frac{ \frac{\exp\left(\beta\mathbb{E}[v_{it+2}]- \mu_{ji}\right)}{\exp\left(\beta\mathbb{E}[v_{it+1}]- \mu_{ji}\right)} }{\frac{\sum_{k \in N} \exp\left(\beta\mathbb{E}[v_{kt+2}]- \mu_{jk}\right)}{\sum_{l \in N} \exp\left(\beta\mathbb{E}[v_{lt+1}]- \mu_{jl}\right)} }$$` Next, let `\(u_{it} \equiv \exp\left(\mathbb{E}\left[v_{it}\right]\right)\)` to keep notation simple later, and use the multiply and divide trick to put into dot terms --- # Armington: dynamic hat algebra `$$\dot{\pi}_{jit+1} = \frac{ \frac{\exp\left(\beta\mathbb{E}[v_{it+2}]- \mu_{ji}\right)}{\exp\left(\beta\mathbb{E}[v_{it+1}]- \mu_{ji}\right)} }{\frac{\sum_{k \in N} \exp\left(\beta\mathbb{E}[v_{kt+2}]- \mu_{jk}\right)}{\sum_{l \in N} \exp\left(\beta\mathbb{E}[v_{lt+1}]- \mu_{jl}\right)} }$$` `\begin{align} \dot{\pi}_{jit+1} &= \frac{ \dot{u}_{it+2}^\beta }{\frac{\sum_{k \in N} \exp\left(\beta\mathbb{E}[v_{kt+2}]- \mu_{jk}\right)}{\sum_{l \in N} \exp\left(\beta\mathbb{E}[v_{lt+1}]- \mu_{jl}\right)} } = \frac{ \dot{u}_{it+2}^\beta}{ \frac{\sum_{k \in N} \exp\left(\beta\mathbb{E}[v_{kt+2}]- \mu_{jk}\right) \frac{\exp\left(\beta\mathbb{E}[v_{kt+1}]- \mu_{jk}\right)}{ \exp\left(\beta\mathbb{E}[v_{kt+1}]- \mu_{jk}\right) } }{\sum_{l \in N} \exp\left(\beta\mathbb{E}[v_{lt+1}]- \mu_{jl}\right)}} \\ \dot{\pi}_{jit+1} &= \frac{ \dot{u}_{it+2}^\beta}{\sum_{k \in N} \dot{u}_{kt+2}^\beta\frac{ \exp\left(\beta\mathbb{E}[v_{kt+2}]- \mu_{jk}\right)}{\sum_{l \in N} \exp\left(\beta\mathbb{E}[v_{lt+1}]- \mu_{jl}\right)} } = \frac{ \dot{u}_{it+2}^\beta }{\sum_{k \in N} \pi_{jkt} \dot{u}_{kt+2}^\beta } \end{align}` --- # Armington: dynamic hat algebra `$$\dot{\pi}_{jit+1} = \frac{ \dot{u}_{it+2}^\beta }{\sum_{k \in N} \pi_{jkt} \dot{u}_{kt+2}^\beta }$$` By putting migration into time changes, we differenced out time-invariant migration costs -- But now we have time changes in another endogenous variable `\({u_{it+2} = \exp(\mathbb{E}[v_{it+2}])}\)` so we need another equilibrium condition (in time changes) --- # Armington: dynamic hat algebra We will use the T1EV version of the Bellman: `$$\mathbb{E}[v_{jt}] = \log u_{jt} = \log {w_{jt} \over P_{jt}} + \log\left(\sum_{i \in N} \exp \left(\beta v_{it+1} - \mu_{ji} \right) \right)$$` -- Exponentiate both sides and then take time differences: `$$\dot{u}_{jt+1} = \frac{\dot{w}_{jt+1}}{\dot{P}_{jt+1}} \frac{\sum_{i \in N} \exp \left(\beta v_{it+2} - \mu_{ji} \right)}{\sum_{l \in N} \exp \left(\beta v_{lt+1} - \mu_{jl} \right)}$$` Next use the multiply and divide trick --- # Armington: dynamic hat algebra `\begin{align} \dot{u}_{jt+1} &= \frac{\dot{w}_{jt+1}}{\dot{P}_{jt+1}} \frac{\sum_{i \in N} \exp \left(\beta v_{it+2} - \mu_{ji} \right) \frac{\exp \left(\beta v_{it+1} - \mu_{ji} \right)}{\exp \left(\beta v_{it+1} - \mu_{ji} \right)}}{\sum_{l \in N} \exp \left(\beta v_{lt+1} - \mu_{jl} \right)} \\ &= \frac{\dot{w}_{jt+1}}{\dot{P}_{jt+1}} \sum_{i \in N} \frac{\exp \left(\beta v_{it+2} - \mu_{ji} \right)}{\exp \left(\beta v_{it+1} - \mu_{ji} \right)} \frac{ \exp \left(\beta v_{it+1} - \mu_{ji} \right)}{\sum_{l \in N} \exp \left(\beta v_{lt+1} - \mu_{jl} \right)} \\ \dot{u}_{jt+1} &= \frac{\dot{w}_{jt+1}}{\dot{P}_{jt+1}} \sum_{i \in N} \dot{u}_{it+2}^\beta \pi_{jit} \end{align}` Now we have `\(\dot{u}\)` as a function of itself and other dot variables --- # Armington: dynamic hat algebra Next, do the same for the market clearing condition `$$w_{jt} L_{jt} = \sum_{i \in N} \frac{a_{ij} \left(\tau_{ij} w_{it} \over A_{it} \right)^{1-\sigma} }{\sum_{k \in N} a_{kj} \left(\tau_{kj} w_{kt} \over A_{kt}\right)^{1-\sigma}} w_{it} L_{it}$$` -- You can prove to yourself that it is: `$$\dot{w}_{jt+1} \dot{L}_{jt+1} = \sum_{i \in N} \frac{\frac{X_{jit}}{w_{jt} L_{jt}} \left(\dot{w}_{jt+1} \over \dot{A}_{jt+1}\right)^{1-\sigma} \dot{w}_{it+1} \dot{L}_{it+1}}{\sum_{k \in N}\lambda_{kit} \left(\dot{w}_{kt+1} \over \dot{A}_{kt+1}\right)^{1-\sigma}}$$` --- # Armington: dynamic hat algebra We have our three equilibrium conditions in time changes Along with the labor transition `\(L_{jt+1} = \sum_{i \in N} \pi_{ijt} L_{it}\)`, and changes in prices that are easy to solve for `\(\dot{P}_{jt+1}\)`, we can then solve for the dynamic equilibrium of the economy given some sequence of .hi[changes] in productivity `\(\dot{A}_{jt+1}\)` --- # Armington: dynamic hat algebra `\begin{gather} \dot{w}_{jt+1} \dot{L}_{jt+1} = \sum_{i \in N} \frac{\frac{X_{jit}}{w_{jt} L_{jt}} \left(\dot{w}_{jt+1} \over \dot{A}_{jt+1}\right)^{1-\sigma} \dot{w}_{it+1} \dot{L}_{it+1}}{\sum_{k \in N}\lambda_{kit} \left(\dot{w}_{kt+1} \over \dot{A}_{kt+1}\right)^{1-\sigma}} \\ \dot{\pi}_{jit+1} = \frac{ \dot{u}_{it+2}^\beta }{\sum_{k \in N} \pi_{jkt} \dot{u}_{kt+2}^\beta } \qquad \dot{u}_{jt+1} = \frac{\dot{w}_{jt+1}}{\dot{P}_{jt+1}} \sum_{i \in N} \dot{u}_{it+2}^\beta \pi_{jit} \\ L_{jt+1} = \sum_{i \in N} \pi_{ijt} L_{it} \qquad \dot{P}_{jt+1} = \left(\sum_{k \in N} \left( {\dot{w}_{kt+1} \over \dot{A}_{kt+1}}\right)^{1-\sigma} \lambda_{kjt}\right)^{1 \over 1-\sigma} \end{gather}` We also impose `\(\dot{u}_{it}\)` converges to 1 (else can't solve the problem) --- # Armington: dynamic hat algebra How do we solve it? -- We essentially have two nested problems: 1. A static market-clearing problem at each time `\(t\)` (conditional on the labor allocation) 2. A dynamic migration problem (conditional on the sequence of wages and prices) --- # Armington: dynamic hat algebra Pseudocode might look like this: ``` while error > tolerance (outer loop) compute sequence of migration shares given initial conditions and expected values compute sequence of labor given initial conditions and migration shares for each time t (inner loop) solve for wages and prices that clear the goods market end compute the sequence of expected values compute error in expected values since last iteration end ``` `solve_arm_dyn_mig(X, lambda, w, L, pi, Ahat, sigma, beta, tol, damp)`