spatial models update and stanning for github copilot

I wanted to start off by saying that Github Co-Pilot is amazing. I’m not super sure about the specifics of what it trains on but it has to somehow look at my git tracked code and give suggestions based on my coding style which is just spectacular. Often times the most demoralizing part of doing a coding project is typing out tedious code that one knows how to write but just takes effort and unnessary mental energy (especially if there are some unintended bugs). Co-Pilot bypasses all of that with just one keystroke; more often than not the code that Co-Pilot writes is not buggy (especially if it’s something not particularly complicated). The greatest thing is that sure you can ask write out a detailed prompt in the chat window for AI to interpret and answer, but Co-Pilot also has an autocomplete feature where you can only write out the name of the function and it does the rest for you (sometimes it even knows what function you want to write next before you type out the name).

Then also, before I get into the spatial stuff, one update on TidyTuesday. The code is still a work in progress; I still need to get it to a state where I’m satisfied enough to not touch it for a while. That being said, it is currently functional. Meaning I can go on with my TidyTuesday blog series plans but there’s still a little to be done to make it fully automated and also include data from more than just Fred.

With those two things out of the way, I want to talk a little about spatial econ. I’m not really sure what it is about spatial models that really captures me. If I were to guess, I know I have had somewhat of an interest in the movement of peoples and how they organize in the context of a city for a while since highschool and it was this interest that leaned me towards doing something spatial related for my senior thesis which has then kept me interested in the field.

Before I learned a lot of macro, however, I used to think that there was something intrinsically different between the model written in the spatial literature and those in the general macro setting. This may be just from ignorance of not knowing the general questions that a macro model uses to motivate itself, but in my involvement in the spatial literature thus far I have realized that the inherent motivation is very similar: households making a selection from some choice set to maximize their utility given some budget constraints that introduce unique mechanics. There are few key components of a spatial general equilibrium models that I’ve found are the key marked differences between the two:

  • The choice set for households (also firms as well for models that include those) is expanded to choosing places to live (and work). Models can differ vastly in terms of when these choices are made or restrictions on how such a choice is made but the commuting costs of households and goods is what gives birth to the rich spatial dynamics that relate the model to reality.
  • Location (blocks) have unique characteristics (which can be anything from natural landmarks to the vibes of a neighborhood) that are incorporated into the model in various ways
    • Household preferences for these characteristics
    • local productivity shocks and spillover effects

These two differences are what drive the unique analysis that we can do with spatial models. For example, we can look at how the migration flows (either people moving their residence or working location) change in response to a local productivity shock, or we can see the extent of the effect that local spillovers have on the composition of households in a location. This may seem a bit abstract to those non-macroeconomics readers in terms of the mechanics of the math, so let’s dive into some more specifics.

At its core, a structural macro model is built on connecting the optimization problems of various groups of different types of agents. For the toy model we are building now:

  • There is a discount factor \(\beta \in (0,1)\) and capital depreciation rate \(\delta \in [0,1]\).
  • Let there be \(N\) many location blocks in which households choose to live and work. Each location also has a living amenity rate \(A_i\) which factors into a household’s utility function.
  • A household is an agent who lives forever and faces the main problem of choosing how much of a good to consume at each point in time \(c_t\), how much time to spend on leisure \(l_t\) instead of working, and which location blocks \(i\) and \(j\) to live and work in respectively (they have to pay a commuting fee \(d_{i,j}\) for every time period based on the chosen \(i\) and \(j\)). Households also have the ability to save from time period to time period and these savings affect (this very nebulous and confusing concept to those not in econ that we call) capital \(k_t\).
  • There are no firms in this world; rather, households “make money” using a production function \(Z_{i_t}\cdot F(k_t, 1 - l_t)\) which uses some function \(F\) to relate how much a household produces based on how much capital they possess and how much time they spend working instead of as leisure time. The \(Z_{i_t}\) is a location-specific random process that all have different means and variances that the households are not sure about, so that one’s working location has an effect on how much they are able to produce: since the process is different for each location, each location has different shocks as well.
    • This is where I’m making the spatial model “interesting”. The model isn’t just incorporating the spatial component by making households choose where they want to live and work based on which is the best place to live in terms of the amenities and distance to work but also which has good future prospects for location productivity.

Specifically, the households solve the following optimization problem \(\max_{c_t, l_t, i_t, j_t} \sum_{t=0}^\infty \beta^t u(c_t, l_t, A_{i_t})\) subject to constraints \(c_t + d_{i_t, j_t} + s_t \leq Z_{i_t}\cdot F(k_t, 1 - l_t)\) to dictate the production/saving and \(k_{t+1} = \delta k_t + s_t\) to dictate the capital.

It took me a bit of training to be able to do this, but from the problem statement above you can already paint a qualitative picture of the push and pull that affects the households. They want to choose a location to live in with high location amenities, but they also want it to be close to their work, and they also want to choose a place to work that they think has good prospects for its productivity that factors into the households’ production function (their way of making money). They can also turn the levers of how they make money by saving money for the future to build up their capital. There’s a lot going on already without adding too much complexity; don’t get me started on how to solve and estimate these models.

There are plenty more features we can build into this to make it more interesting or realistic, such as introducing firms, government agents, or some intrinsic heterogeneity between households; for example, some households can have low levels of education while others can have higher, which affects their respective production functions and may influence their migratory decisions. My NSF proposal will likely tinker with a couple of these “bonus” features and study them in the context of government policy and their spatial implications.

Of course, not even I would say that the model we built above is consistent with reality, and even if we were to relax a few assumptions, we would still be nowhere close. This brings me to a point of economic maturity that I’ve come to learn over the past year. Very rarely in econ are people who are doing these structural models caught up with trying to replicate reality; it is more about exploring the relative effects of some channels on others that is what is interesting in monetary policy research. As always, my blog posts are very stream-of-consciousness and more so a personal outlet for me to espouse some thoughts, so I’m not sure how coherent any of the above is to an outside reader. If you want to know more or are confused (most people reading probably know me in real life, so texting is also good 😊).

So to close off, the NSF application is coming along and will help me a lot with the spatial sims package that has been a work in progress for such a long time. As a recap and update on that, my plans for the package had started almost a year ago around this time but I soon postponed it after realizing how much more I had to learn to get to a position to understand how exactly I could accomplish my goals with the package. I’m not currently at a level of economic maturity where I can just sit down and write all the code myself in a month, but I definitely understand what is going on and I know a lot more than before (understanding DSGE.jl, SMC.jl, and ModelConstructors.jl has helped an incredible amount). I’ll still probably need to find people to help me out with it, but the current plan is to get back into writing out the models for the package and coding it up once PhD applications are all submitted (sometime in the beginning of 2025).




More Posts:

  • automated mouse movement
  • TidyTuesday Week 40
  • TidyTuesday Week 39
  • airplane networks pt. 1
  • TidyTuesday Week 38