# Economist's doing dynamic programming and structural estimation

**URL:** <https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171>\
**Category:** General Usage\
**Created:** [March 29, 2021, 4:43pm UTC](https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171 "2021-03-29T16:43:57Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jovansam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jovansam/32/15023_2.png) [@jovansam](https://discourse.julialang.org/u/jovansam)\
**Post date:** [March 29, 2021, 4:43pm UTC](https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171/1 "2021-03-29T16:43:57Z")

</div>

I love discourse because you get to learn from experts across fields. This is really nice!.

At the same time, I would like to learn from people with closely aligned work as mine. Thus, I was wondering whether some economists here who solve for value functions, policy functions, and undertake full solution structural model estimation in Julia could post links to their code. Ideally complete code for an article for instance, or that simply illustrates a single complete concept.

Thanks. This could also serve as a beginners guide for others too.

PS: I have googled around for this code, some of this is on my Github page. But it just seems to take forever to find this code. I have so have found only three/four academic articles.

---

<div class="post-metadata">

**Author:** ![austinbean](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@austinbean](https://discourse.julialang.org/u/austinbean)\
**Post date:** [March 29, 2021, 5:17pm UTC](https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171/2 "2021-03-29T17:17:33Z")

</div>

> [@jovansam](#):
>
> Thanks. This could also serve as a beginners guide for others too.

You will find a lot to work with here: [QuantEcon.jl – QuantEcon](https://quantecon.org/quantecon-jl/) or here: [https://julia.quantecon.org/](https://julia.quantecon.org/) especially if you want to work on macro questions.

---

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [March 29, 2021, 5:33pm UTC](https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171/3 "2021-03-29T17:33:22Z")

</div>

> **[GitHub - UBCECON567/BLPDemand.jl](https://github.com/UBCECON567/BLPDemand.jl)**
>
> Contribute to UBCECON567/BLPDemand.jl development by creating an account on GitHub.

> **[BenConnault - Repositories](https://github.com/BenConnault?tab=repositories)**
>
> BenConnault has 5 repositories available. Follow their code on GitHub.

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [March 29, 2021, 5:44pm UTC](https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171/4 "2021-03-29T17:44:02Z")

</div>

@jlperla has some code available for his papers, hopefully he doesn’t mind me sharing

> **[jlperla - Overview](https://github.com/jlperla)**
>
> Associate Professor of Economics. jlperla has 36 repositories available. Follow their code on GitHub.

There is also more work related to continuous time models here:

> **[GitHub - matthieugomez/EconPDEs.jl: Solve forward-looking PDEs (e.g. HJB...](https://github.com/matthieugomez/EconPDEs.jl)**
>
> Solve forward-looking PDEs (e.g. HJB equations). Contribute to matthieugomez/EconPDEs.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![jlperla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlperla/32/34332_2.png) [@jlperla](https://discourse.julialang.org/u/jlperla)\
**Post date:** [March 29, 2021, 5:52pm UTC](https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171/5 "2021-03-29T17:52:52Z")

</div>

Don’t mind at all, but not entirely sure how useful it would me. My papers are all a little weird! Since “dynamic programming” and “structural estimation” are so brought, I think you need to narrow it down a bit. There are a buzzilion methods and models, with different approaches depending on what field you are working on, whether it is continuous or discrete time, etc.

---

<div class="post-metadata">

**Author:** ![jovansam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jovansam/32/15023_2.png) [@jovansam](https://discourse.julialang.org/u/jovansam)\
**Post date:** [March 30, 2021, 10:30am UTC](https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171/6 "2021-03-30T10:30:14Z")

</div>

Thanks everybody. @jlperla, I tend to read anything really to see what I can learn and incorporate into my own stuff. Now I am looking to introduce financial intermediation, financial frictions, and innnovation into my macro-climate models, and also structurally estimate models of electricity generation and wholesale power market clearing.

Other stuff I have found around the web that others may also find useful:

A paper by @aaowens using Julia that I came across: [Does redistribution increase output? The centrality of labor supply | Athreya | Quantitative Economics](https://qeconomics.org/ojs/index.php/qe/article/view/533)

Another by @floswald [GitHub - floswald/migration: Replication Kit for Oswald, Quantitative Economics (2019)](https://github.com/floswald/migration)

And another by @sglyon [GitHub - sglyon/CLMMJuliaPythonMatlab: Codes to accompany the paper "Matlab, Python, Julia: What to Choose in Economics?" by Chase Coleman, Spencer Lyon, Lilia Maliar, and Serguei Maliar](https://github.com/sglyon/CLMMJuliaPythonMatlab)

---

<div class="post-metadata">

**Author:** ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)\
**Post date:** [March 30, 2021, 11:24am UTC](https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171/7 "2021-03-30T11:24:48Z")

</div>

my stuff is legacy at this point (julia 0.6). on v0.6 it still runs though 🙂

for climate model stuff, make sure to have @davidanthoff on your radar, eg. [GitHub - fund-model/MimiFUND.jl: FUND - Climate Framework for Uncertainty, Negotiation and Distribution](https://github.com/fund-model/MimiFUND.jl) and a ton of other stuff.

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [March 30, 2021, 2:26pm UTC](https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171/8 "2021-03-30T14:26:15Z")

</div>

Ben Moll has some code on his website for the HANK models (mostly Python but there were some Julia too)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 31, 2021, 7:00am UTC](https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171/9 "2021-03-31T07:00:26Z")

</div>

Having a complete codebase for an article or working paper is useful for replication, but may not be ideal for learning. By the time of publication, code for structural empirical work usually contains a lot of accretion (changes to the model, semi-random requests by referees that enrich your appendix in the end, etc) that happened under time pressure and no one had the time or inclination for a clean refactoring (as usual, respect to those who do it anyway).

I usually find solving functional equations (HJB/Euler) the easiest part, and also the least computationally intensive. I use my own library, which is undergoing a refactoring right now (check back in a month or so, I am integrating Smolyak code that I used in a paper):

> **[GitHub - tpapp/SpectralKit.jl: Building blocks of spectral methods for Julia.](https://github.com/tpapp/SpectralKit.jl/)**
>
> Building blocks of spectral methods for Julia. Contribute to tpapp/SpectralKit.jl development by creating an account on GitHub.

It is

1. solving for general equilibrium objects, and
2. dealing with distributions of heterogeneous agents

that I find tricky. (1) usually requires a good initial guess, homotopy methods, and gradual refinement of crude solutions. I find

> **[GitHub - bifurcationkit/BifurcationKit.jl: A Julia package to perform...](https://github.com/bifurcationkit/BifurcationKit.jl)**
>
> A Julia package to perform Bifurcation Analysis. Contribute to bifurcationkit/BifurcationKit.jl development by creating an account on GitHub.

useful for homotopy. Keeping the solution for policy functions automatically differentiable from the beginning (and unit testing for this) is very useful.

Dealing with distributions as states usually involves some ad hoc method that I construct based on the properties of the problem (ie I want a good approximation where the mass is). I usually try to get away with a rectangular grid, but when I can’t, I found

> **[GitHub - KristofferC/NearestNeighbors.jl: High performance nearest neighbor...](https://github.com/KristofferC/NearestNeighbors.jl)**
>
> High performance nearest neighbor data structures and algorithms for Julia. - GitHub - KristofferC/NearestNeighbors.jl: High performance nearest neighbor data structures and algorithms for Julia.

useful.

Generally, if you can keep your code automatically differentiable all the way up to a distance metric between simulated and actual data or a log posterior, it is a big win. But for complex models it requires some practice and refactoring.

---

<div class="post-metadata">

**Author:** ![mcreel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcreel/32/30088_2.png) [@mcreel](https://discourse.julialang.org/u/mcreel)\
**Post date:** [March 31, 2021, 8:29am UTC](https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171/10 "2021-03-31T08:29:59Z")

</div>

[https://github.com/mcreel/SNM/tree/master/examples/Auction](https://github.com/mcreel/SNM/tree/master/examples/Auction) has code for Tong Li’s auction model from the paper [Indirect inference in structural econometric models - ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S0304407609002802)

---

<div class="post-metadata">

**Author:** ![pierre-haessig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pierre-haessig/32/217129_2.png) [@pierre-haessig](https://discourse.julialang.org/u/pierre-haessig)\
**Post date:** [April 2, 2021, 7:21am UTC](https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171/11 "2021-04-02T07:21:07Z")

</div>

I know of (but never used) [Dolo.jl](http://www.econforge.org/Dolo.jl/latest/index.html) by @albop ([http://www.mosphere.fr/](http://www.mosphere.fr/), [albop (Pablo Winant) · GitHub](https://github.com/albop)) which implements value iteration for economics. I once took his multilinear interpolation routine for my own dynamic programming Python package (because dolo was at first a Python package).

---

<div class="post-metadata">

**Author:** ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)\
**Post date:** [April 5, 2021, 8:25pm UTC](https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171/12 "2021-04-05T20:25:47Z")

</div>

I have quite a lot of code for discrete choice dynamic programming ala Rust (the code for [Solving dynamic discrete choice models using smoothing and sieve methods - ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S0304407620303298) is only for solving for the value function and is not public but I could clean it up…), but it doesn’t appear to be what you’re after.

---

<div class="post-metadata">

**Author:** ![jovansam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jovansam/32/15023_2.png) [@jovansam](https://discourse.julialang.org/u/jovansam)\
**Post date:** [April 6, 2021, 1:42am UTC](https://discourse.julialang.org/t/economists-doing-dynamic-programming-and-structural-estimation/58171/13 "2021-04-06T01:42:33Z")

</div>

@pkofod. I am certain the code would be very helpful. For instance when modelling powerplant operations in my case. The code could also be helpful in other ways and to other people. So you if you have time please clean it up and post.
