Large Datasets: Claude Code for Economists with Paul Goldsmith-Pinkham | Markus' Academy | Ep. 162-4 — Transcript
Full transcript
- 0:08Welcome back everybody.
- 0:10For another video of the mini video
- 0:12series with Paul Goldsmith Pinkham on
- 0:16Cloud Code for applied economists.
- 0:19Hi Paul. Good to be back.
- 0:20>> Hi and Marcus.
- 0:22I'm looking forward to this. This is
- 0:23fun. So we're kind of
- 0:26taking off the training wheels a little
- 0:28bit for
- 0:30today was in the sense that we got
- 0:31started last last three videos we got
- 0:33started. We sort of learned how how
- 0:35Cloud works. We've done some basic
- 0:37things making figures. Last time we did
- 0:39a little bit of work
- 0:40thinking about a database and
- 0:42downloading Edgar files. Today we're
- 0:44going to do a lot more with kind of big
- 0:47data in a structured fashion.
- 0:50We're going to do mainly stuff from
- 0:51Cloud Code in the command line.
- 0:54And my hope is that what this is really
- 0:56useful for is that
- 0:59we many applied economists work with
- 1:01really big data sets.
- 1:03You know, it's
- 1:05we have now the access to these big
- 1:07administrative data sets either through
- 1:09the web or somewhere else where you have
- 1:10many many observations, right? Like the
- 1:13one that we're going to do today is
- 1:14going to be what's called the HMDA data
- 1:16set. So this is the Home Mortgage
- 1:18Disclosure Act data set. It's a public
- 1:19data set. Everyone has it has access to
- 1:22it. And it has you know, the whole thing
- 1:25together when you get the CSVs is
- 1:27something like 70 gigabytes. Really
- 1:29large files. You can get much more, but
- 1:31that's quite big. And
- 1:34often when we work with these files,
- 1:37you know, none of us are trained as data
- 1:39engineers. We end up working with a lot
- 1:40of flat CSVs. We maybe make a bunch of
- 1:43different copies. We end up just
- 1:44constructing a lot of stuff. And I want
- 1:46to kind of show that one thing that is
- 1:48really nice about working with these
- 1:49agents in Cloud Code is that
- 1:52you can kind of more easily integrate
- 1:54into better practices for storing data
- 1:56and working with things in ways that
- 1:58actually like open up a lot of new
- 2:00interesting work and kind of improve
- 2:03replication and other things. So that's
- 2:05what we're going to do today.
- 2:07What I'm going to do is I'm just going
- 2:08to go straight to the command line. So
- 2:11we're going to
- 2:13go to the command line and I will show
- 2:17you here. Are you able to see this? So
- 2:18this is let me quickly. So I'm in a
- 2:20command line here.
- 2:23Where
- 2:25this is inside a folder that I have for
- 2:27you and I just want to kind of show you
- 2:29like that I have I've kind of
- 2:31established
- 2:32I made some prompts beforehand and I
- 2:34want to kind of describe what the
- 2:35project is that we're going to do in
- 2:38detail. Are you able to read this okay?
- 2:39So we're not doing anything with Cloud
- 2:41Code yet. I just want to read it
- 2:42together so I can tell you kind of the
- 2:44goal. And I tell you there's a little
- 2:47bit of preprocessing here just because I
- 2:48knew the task and I I got this set up. I
- 2:51set up a prompt. I could have very
- 2:52easily done this inside of Cloud Code,
- 2:55but just for the purposes of getting
- 2:57started I wanted to do this. So
- 2:59first what we're going to be doing today
- 3:01is we're going to be trying to
- 3:03download and kind of harmonize a large
- 3:06administrative data set that's referred
- 3:08to as HMDA. It stands for the Home
- 3:09Mortgage Disclosure Act, which is a data
- 3:12set that's now produced every year that
- 3:14basically has near universal coverage of
- 3:16all mortgages in the United States when
- 3:18they were originated. Both originated
- 3:20and actually denied. So this is this
- 3:22data was originally constructed in order
- 3:24to
- 3:26deal with potential racial
- 3:27discrimination in mortgage origination.
- 3:30So the data for this we're going to
- 3:31build a panel
- 3:33that uses original data. So what I've
- 3:36done in this prompt, I set up a prompt
- 3:37to say I want to build a panel data set
- 3:39of mortgage lending in the US from 2007
- 3:42to 2024 using HMDA data. The goal is to
- 3:45study the geographic expansion of
- 3:46fintech mortgage lenders over time.
- 3:49Right? So a pretty reasonable
- 3:51pretty reasonable problem.
- 3:53And
- 3:56I'm going to this is something I knew a
- 3:58little bit more of, but of course you
- 3:59might iterate on is that there's two
- 4:01sources for this data. I didn't want to
- 4:03have a ton of time for
- 4:06Cloud to have to worry about this. So
- 4:08the first one is 2007 to 2017. The CFPB
- 4:11has these zip files that are online.
- 4:14Mhm. And from 2018 to 2024 there's
- 4:18additional data that's stored here. Um
- 4:21these you're able to get access to both
- 4:23of them are publicly available. I'm kind
- 4:26of describing them and they change over
- 4:27time. So what I'm going to tell it is
- 4:30that these are really big data sets.
- 4:32These have like each the whole thing is
- 4:34going to have 250 million rows. So it's
- 4:36a big data set. This is not going to fit
- 4:38inside of memory, right? So if you you
- 4:41Stata or something like this, you could
- 4:43it's quite costly load this all into
- 4:46into Stata or to Python or any of these
- 4:48ones. So
- 4:49you wouldn't want to directly load this
- 4:51into memory. And so what I'm going to
- 4:52ask it to do is I want it to write a
- 4:54script that is going to pull this data
- 4:57down. I want to make it so that you
- 5:00know, it's so what I'm telling it here
- 5:01was include resume capability. That way
- 5:04in case something gets broken. So that
- 5:06could happen to you, right? You're
- 5:07downloading something and your computer
- 5:09turns off or reboots. You want to have
- 5:11it so that it downloads correctly.
- 5:13Mhm.
- 5:14This is a a user agent header. So this
- 5:16is just the same thing that we had last
- 5:18time in that when you when you talk to
- 5:20things on the internet, it wants to know
- 5:21who you are. If you do it without this,
- 5:23it it it will sometimes block you.
- 5:26Then I want to
- 5:29take this data and convert into just
- 5:31Parquets to make it more efficient. And
- 5:33I'm going to set up something called a
- 5:34DuckDB database. So we briefly talked
- 5:36about this last time, but Marcus, I
- 5:38didn't kind of give you all the details
- 5:39on this. What this is is really if if
- 5:41you've heard of a relational database or
- 5:43something with SQL, so SQL,
- 5:47these are ways of storing data that keep
- 5:50track of relationships between data. So
- 5:52you might imagine, right, that I have a
- 5:54table where I have different I have one
- 5:56table that stores who are all the
- 5:58lenders.
- 5:59And then another table that has the
- 6:00loans. And of course in a database that
- 6:03has stuff about
- 6:04loans is going to be a lender identifier
- 6:07there. And you might say, "Oh, I want to
- 6:08take all the lenders in here
- 6:10who have more than a hundred million
- 6:12dollars in assets and I want to link
- 6:14these over and only pull their loans."
- 6:17And so these types of relational
- 6:18databases are very good at this kind of
- 6:20information.
- 6:21And what's really good is it has
- 6:23metadata in it. So metadata means
- 6:26like additional information about the
- 6:28data sets that is about all the data
- 6:31that's in there. So it's things like
- 6:33what the name is, a description, the
- 6:34type of data it is, kind of what's valid
- 6:37about it. And what's really nice is that
- 6:39the metadata
- 6:41is going to give information to Cloud or
- 6:45any other LLM that you use with it in
- 6:47the future so that it doesn't have to
- 6:49kind of figure out what's going on,
- 6:51right? So you imagine if I give you a
- 6:52data set, Marcus, I
- 6:55the benefit of it is like there's a
- 6:57difference between a data set where
- 6:58somebody gives you names that have
- 7:00really good labels, right? Versus one
- 7:02that is totally indecipherable.
- 7:05Right? Does that make sense?
- 7:07So it's like but metadata is labels are
- 7:09metadata as well. Exactly. A label So if
- 7:12you've ever used in Stata, sometimes
- 7:13people talk about like value labels and
- 7:15other things. There's there's or
- 7:17variable labels. Those are often kind of
- 7:19additional meta information that's there
- 7:21that makes it kind of more useful to
- 7:23understand what's going on.
- 7:25Um
- 7:26an important thing here is that there
- 7:27was a big change in the data from in
- 7:302018.
- 7:31There were different column names and
- 7:33encoding schemes. And so I'm going to
- 7:34ask it to build a crosswalk and
- 7:35harmonize across this. All right. And so
- 7:38I'm telling it kind of the things I care
- 7:39about. And so I'm going to ask it to
- 7:41always use DuckDB in here. It can't kind
- 7:43of load everything and do anything. So
- 7:45it really needs to do everything kind of
- 7:46using SQL.
- 7:48So that's what we're going to do.
- 7:51We're going to start with that.
- 7:52>> DuckDB is the only provider? It's a
- 7:54particular provider like
- 7:55>> No, no, no. So there could be any So you
- 7:57can use lots of things. So DuckDB is
- 7:58what's very nice about DuckDB is it will
- 8:00be a way of it's a program that sits on
- 8:02top of um
- 8:05what are called Parquet files. So I'll
- 8:07briefly just explain if you don't A
- 8:09Parquet file is just another way to
- 8:11store data just like a CSV. CSV, right,
- 8:13stands for comma separated values. Mhm.
- 8:16Parquets are ones that are actually
- 8:19column They basically focus on things in
- 8:21So you think about a CSV, a CSV what it
- 8:24does is every line is kind of a piece of
- 8:27data, right? So you have a line, each
- 8:30each piece of information is separated
- 8:31by commas and then you have a new line
- 8:33and then you you keep you kind of cycle
- 8:35through it. Parquets are stored that
- 8:37what it does is that a whole column is
- 8:39stored and you kind of look through a
- 8:41column and there's information about the
- 8:43column stored at the beginning. And so
- 8:45it can be much more efficient and kind
- 8:46of compressed a lot more compactly. They
- 8:49tend to be more efficient ways of
- 8:50storing data um directly.
- 8:54And DuckDB sits on top of it and is very
- 8:56very fast. It's kind of one of the
- 8:57fastest ways of working with data. In
- 9:00Pandas there's something called Polars,
- 9:01which is similar.
- 9:04But DuckDB is a really nice one. I kind
- 9:06of encourage researchers to use it.
- 9:07There's also you could use something
- 9:09called SQLite. The main reason I'm
- 9:11encouraging this is that if often
- 9:13relational databases you have to do all
- 9:15this work to set up a server. Mhm. The
- 9:18SQLite and DuckDB are both ways of
- 9:20getting the benefits of relational
- 9:22databases without having to do anything
- 9:24complicated like set up a server. So
- 9:26that's why we're going to do this.
- 9:27>> up a server. It's everything on No, you
- 9:28don't have to do anything. Yeah, yeah,
- 9:29it's just a file that sits there and
- 9:31you'll work with it and Python or R
- 9:34can both directly query it without
- 9:36anything special. So it's just a really
- 9:38nice way of being able to work with big
- 9:40data sets very efficiently. Mhm.
- 9:43So what we're going to do now is
- 9:48we are going to split this screen here.
- 9:51If you remember we talked about one of
- 9:53the benefits of um
- 9:56having these
- 9:59this type go this is called ghosty. So
- 10:01this is a terminal that we're using. If
- 10:03you remember Marcus, we talked about
- 10:04this and one of the things I told you
- 10:06was that it can be very nice to have
- 10:07these things so you can have things side
- 10:08by side for example. And you'll see that
- 10:11if you can see that now I have two
- 10:13terminals side by side and so one thing
- 10:15I can do is I can look at the prompt
- 10:17here that I was going to do and on the
- 10:20other one what I'll do is I'll make a a
- 10:22folder
- 10:24um
- 10:25and we'll go into it. Yes. And we'll say
- 10:27okay now we're going to log load Claude.
- 10:31So here we So here we're going to load
- 10:32Claude
- 10:33and
- 10:35now we have it. So here we're inside it
- 10:37says welcome back and I'm going to take
- 10:39this prompt over here and I'm going to
- 10:42copy it.
- 10:44The only complication that we're going
- 10:46to do run into is so okay so it doesn't
- 10:50want me to
- 10:51do that.
- 10:52This is the problem with the slightly
- 10:54big size. So I'm just going to make it
- 10:55smaller so I can copy it all at once.
- 10:58And
- 11:00going to copy this and we'll make it
- 11:02bigger again.
- 11:03And I'll go over here and I'm going to
- 11:04paste it in. And the one thing I'm going
- 11:06to say is focus only on this
- 11:09subdirectory.
- 11:11Don't scout in the folder above. So one
- 11:14thing that it will do is
- 11:16it will start looking at other folders
- 11:19in this directory and so of course I've
- 11:20built these videos to sort of
- 11:24do here but of course if it starts
- 11:25looking up above it'll say oh this is
- 11:27part of a broader educational series and
- 11:29so I'm going to say let's focus just
- 11:31here. Don't go scouting everywhere else.
- 11:34Um
- 11:35the
- 11:38you could do more things to kind of
- 11:39prevent it from knowing what's going on.
- 11:41That's called sandboxing but I don't
- 11:42want to kind of deal with all those
- 11:44issues. So I'm going to do this so I've
- 11:45pasted this prompt over and now I am
- 11:47going to
- 11:49um
- 11:50uh
- 11:52run it here. So it's going to do this.
- 11:55So it I I want to build a country level
- 11:57data set that looks like this blah blah
- 11:58blah. So now we can read what it's
- 12:00saying and I'll even make it a little
- 12:02bit bigger so we can focus on this part.
- 12:05So it says let me start by exploring the
- 12:07existing
- 12:08things. So it didn't listen to me.
- 12:10So it's very annoying. I'm going to say
- 12:11no you can't read the other folders. So
- 12:14it's going to get very annoying. So I'm
- 12:16going to say no don't read these. Yes
- 12:19you can do web search commands and no
- 12:21you can't read in there and
- 12:23no you can't read it. So now it's useful
- 12:26to look at um
- 12:28uh
- 12:29what's going on. So it's doing two
- 12:31things. So it's trying to understand
- 12:32what's going on in here. It's it's
- 12:35Let me just pause before I let it run
- 12:36more which is that it says let me
- 12:38explore begin by exploring the project
- 12:40structure and any related files and then
- 12:41research the data formats to build a
- 12:43plan. So what's interesting about this
- 12:45is that it's launched two agents. So if
- 12:47you remember we talked about this last
- 12:49time that agents are kind of sub agents
- 12:51where it sends out to do things. And so
- 12:53what it's done here is it's launched two
- 12:55things. One a bunch of scouts to figure
- 12:58out what's going on in here and then the
- 13:00other is to research the data formats.
- 13:02And it's doing these in parallel. So
- 13:04these are two different kind of agents
- 13:06that have been sent out. And so I'm
- 13:08going to say yes you So this one is
- 13:10going to be allowed to search and I am
- 13:12not going to allow it to look here and
- 13:16no it's going to not be allowed to find
- 13:18anything in the previous one and then
- 13:20I'll allow it to look more. I'm going to
- 13:21I'm allowing it to kind of see here it
- 13:23it's really really wants to. So what I'm
- 13:26going to do
- 13:28I think if it keeps asking me so okay so
- 13:30now what's useful is let me describe
- 13:32you. So if you look here this is what it
- 13:34does. Remember we talked about how
- 13:35agents work. They have their own prompt.
- 13:38Part of the reason they use agents is so
- 13:39that it doesn't use up your own context
- 13:42window. So this one it's saying explore
- 13:44project structure says explore this and
- 13:46parent directory to understand what
- 13:48files are there. What related files are
- 13:49there. Any existing things. Be thorough.
- 13:52Report the full content of key files. So
- 13:54it's looking
- 13:55and I'm not letting it do a lot of these
- 13:56things. And
- 13:58>> makes a big difference?
- 14:00I'm sorry. Say again. If you say be
- 14:02thorough
- 14:03Yes so I didn't tell it to do this.
- 14:05Claude wrote this prompt. Oh.
- 14:08And it's probably
- 14:10it's probably
- 14:11Anthropic has sort of learned that this
- 14:13is a really useful thing to do to say
- 14:16like be thorough. So yes telling it to
- 14:17be thorough is good so that it double
- 14:19checked itself. And then this one to
- 14:21research the format it says research the
- 14:22Home Mortgage Disclosure Act data
- 14:24formats for both pre-2018 and post-2018
- 14:27eras. I need to understand the format of
- 14:30the data structure how to create a
- 14:31crosswalk. What are the key differences?
- 14:34Focus on these variables. Search the web
- 14:35for data dictionary. So it's searching
- 14:37and it's downloading information and
- 14:39it's looking through that. And
- 14:42um
- 14:44so I'm going to continue to not allow it
- 14:47to do this and I'm going to allow it to
- 14:48fetch this content. It's searching the
- 14:50Fed and other places to do this.
- 14:52Um
- 14:54and I'm going to say yes you can look at
- 14:55the the get repository.
- 14:58Um
- 14:59it's really
- 15:01aggressively trying to do this. So what
- 15:03I'm going to do is I'm going to say
- 15:07Oh interesting. So this one is actually
- 15:10um
- 15:11I need to find I need So I'm going to
- 15:12say
- 15:13um
- 15:16you should not look in the parent
- 15:19directory. So this is useful. So here it
- 15:21gave me three options but I want to tell
- 15:23it more. So it I can press tab
- 15:27and then it will let me add additional
- 15:30information. I'm saying no don't look in
- 15:32the parent directory.
- 15:34And so now it will continue to search
- 15:35the web
- 15:37and it will continue to search the web.
- 15:38So it's doing kind of what you and I
- 15:39would ever do if we were running a
- 15:41project. And so now you notice so here
- 15:43it says it's done exploring the project
- 15:45structure. I said no you don't need to
- 15:46look at the parent directory.
- 15:48Um
- 15:50And by the way this is a good example of
- 15:53how persistent these agents will be
- 15:56unless you kind of directly tell them to
- 15:57stop. I kept saying no
- 16:00but then it just kept trying new ways to
- 16:01look in the parent directory. So I had
- 16:03to say no you like you know don't do
- 16:06that thing anymore. But why is it so
- 16:08persistent? It doesn't make sense.
- 16:10Um because when I said no I didn't tell
- 16:13it why it shouldn't be doing that. I
- 16:16see. And the problem is that that
- 16:17explore agent got written its own
- 16:19prompt. So it's really interesting. I
- 16:21mean it's a very interesting problem. So
- 16:23that remember this one here it doesn't
- 16:25see anything that I told it. So when I
- 16:26wrote that prompt for the what would you
- 16:28call the the head agent Yes. uh the
- 16:31director
- 16:32I told it hey don't look only focus on
- 16:35this subdirectory. But then when it went
- 16:36to this one it said hey you should look
- 16:38in this directory and also look in the
- 16:39parent directory. It sort of screwed up
- 16:41this prompt. And so the sub agent says
- 16:43hey I got to I got to find here.
- 16:46So then it says so when it tried to look
- 16:49in the bigger
- 16:50the parent directory I said permission
- 16:52for this tool I denied it remember and
- 16:54it says the tool use was rejected. Try a
- 16:57different approach. And so it's like oh
- 16:59well how am I going to look in there? So
- 17:00now it's trying all sorts of ways to do
- 17:03it because it's smart. And so it keeps
- 17:06saying hey it didn't work try something
- 17:07else. And so it's saying like all right
- 17:10well there's many ways to skin a cat and
- 17:12so it keeps trying new things until I
- 17:15said eventually I said
- 17:18um
- 17:20no
- 17:22uh you should not the user said you
- 17:24should not look in the parent directory.
- 17:26I see their access restrictions. The
- 17:28settings indicate this is a constrained
- 17:29environment. Based on what I can access
- 17:31and restriction in place here is my
- 17:32summary.
- 17:33So there's really nothing in here.
- 17:35The directory is currently empty.
- 17:37There's these restrictions. You're
- 17:39allowed to do these things. So it's a
- 17:40little confused because it doesn't
- 17:43understand why I'm making these
- 17:45restrictions.
- 17:46It's saying that I want to keep this
- 17:48isolated and to only focus on external
- 17:50data sources.
- 17:51So it's going to report this back to the
- 17:53head agent.
- 17:55And And now we're we have this other one
- 17:57that's doing
- 17:58this other information. So remember the
- 18:00way that I'm toggling back and forth.
- 18:01You can't see me doing this Marcus but
- 18:03I'm pressing control O to to do things
- 18:05back and forth.
- 18:06And so now I'm going to continue to let
- 18:08it
- 18:10see this information.
- 18:12So it's still searching the web. You can
- 18:13see that it's done 33 different tool
- 18:16calls. So it's searching the web in lots
- 18:17of different ways and it's reading lots
- 18:19of information there.
- 18:21>> [snorts]
- 18:22>> And that's going to What it's do trying
- 18:24to do is it's trying to build
- 18:25information
- 18:27to then
- 18:28construct a crosswalk in a database. So
- 18:31now it said excellent I have a thorough
- 18:33understanding of both data formats. Let
- 18:35me verify the actual column names by
- 18:37sampling the real data files and then
- 18:39design the plan. So it's going to What
- 18:40it's going to do is it's going to kind
- 18:41of take a little bit from the data just
- 18:44to understand this. So I'm going to say
- 18:45yes you can look at this information.
- 18:47Now it's
- 18:48Now it's doing it again and I'm going to
- 18:50say now we've learned how to fix this
- 18:52and so I'm going to say no do not look
- 18:55in the parent directory.
- 18:57Mhm. Stay So why does it So first it
- 19:00makes a plan and then it experiments
- 19:01with the plan and then only it
- 19:03implements step by step.
- 19:04>> Exactly. So it's kind of like what you
- 19:06would do if you were going to work
- 19:08uh
- 19:09on on something right? You might say
- 19:11uh I'm an One of the key things that
- 19:13plan mode does that's a kind of an
- 19:15important thing to keep in mind is that
- 19:17plan mode will not edit things. So one
- 19:20thing remember we're talking about how
- 19:21these agents will kind of run wild
- 19:23sometimes if you give it the wrong ideas
- 19:26is that
- 19:29it will
- 19:31um
- 19:32it will in plan mode it will
- 19:33specifically not edit anything which it
- 19:35turns the Claude code actually turns
- 19:36that ability off.
- 19:38And so that can be very nice. If you're
- 19:40saying look I know I just want to build
- 19:41a plan with you what to do. Let's go
- 19:43into plan mode.
- 19:45And
- 19:46you can actually turn that on directly
- 19:47by pressing shift and then tab. And
- 19:50that's very important but it will
- 19:51automatically
- 19:53go into plan mode as well if it
- 19:54understands that it's a complicated
- 19:55project. So here this is a relatively
- 19:57complicated project and so it knows that
- 19:59it needs to look up a bunch of
- 20:01information about what this looks like.
- 20:03So it's looking up resources of what the
- 20:05columns look like.
- 20:07And it's going to go in there. So it's
- 20:09building this up and it's continuing to
- 20:11look. You can see that this one is in
- 20:13white and that means that it's stopped
- 20:15doing this particular sub-agent. This
- 20:17plan agent is design designing an
- 20:20implementation plan and so it's doing a
- 20:22lot of work here by looking what the
- 20:23data is. And we can actually read what
- 20:25the prompt is that it wrote for it. It
- 20:26says, "Designing a system to build a
- 20:28county-level panel data set of US
- 20:30mortgage lending from HMDA data. Here's
- 20:32the context." And tells a bunch of
- 20:33information. Downloads Here's what the
- 20:36requirements are. Here's the things that
- 20:38you need to do and you should use
- 20:39DuckDB.
- 20:41Here design the architecture for this
- 20:43system. File organization, download
- 20:45approach, CSV to Parquet conversion
- 20:47strategy using DuckDB.
- 20:50Harmonization approach. Should we create
- 20:53harmonized Parquet files or use DuckDB
- 20:54views?
- 20:56So what this means is that should I make
- 20:57all the files the same or should I do
- 20:59that afterwards within DuckDB to make
- 21:01them similar?
- 21:03Add metadata and then how should I
- 21:05handle the lender crosswalk and then
- 21:07finally kind of a crosswalk mapping for
- 21:10state [snorts] FIPS codes versus state
- 21:11>> So can you say again the harmonization
- 21:13approach is What what's the
- 21:15harmonization approach?
- 21:16>> Uh so I think what it's asking so I
- 21:19asked it to harmonize the variables if
- 21:21you remember that. So I wanted these
- 21:22things so that I could have a kind of
- 21:23consistent variable across years. They
- 21:25change in the data sets themselves. I
- 21:28just happen to know that from my own
- 21:30work with it. Um
- 21:32So what it's asking is, "Well, should I
- 21:34change the files themselves or should
- 21:37what I do is just store the raw data in
- 21:39there and then make a view on top of it
- 21:41which is like kind of a renaming
- 21:43restructuring." So those are slightly
- 21:45different approaches on how you might
- 21:46want to harmonize something.
- 21:48So it's still thinking very hard right
- 21:50now which is kind of interesting. So
- 21:51it's it's doing some work here. You can
- 21:53see that it's it's searching for
- 21:55information about how to do stuff.
- 21:57Um
- 21:59and
- 22:01I have a solid understanding of both. So
- 22:04let's read through what it's going to
- 22:04say just briefly.
- 22:07Um here's the goal. This is gives it the
- 22:09context. Goes, "This is the thing it's
- 22:11going to write to a file.
- 22:13Um build a harmonized data set of US
- 22:15mortgage lending. Data spans two
- 22:17different formats, pre-2018, post-2018
- 22:20with different column names, coding
- 22:21schemes, and lender identification
- 22:22systems. 250 million rows across 18
- 22:25years. All processing uses DuckDB and
- 22:28and Parquet."
- 22:29So it's going to write a bunch of code
- 22:30here. It's going to have six different
- 22:32Python files. Um one is for configuring
- 22:36things. This is how to download. This is
- 22:37the conversion. This is the raw Parquet
- 22:40to harmonize Parquet then assemble a
- 22:42database. And then this is the thing
- 22:44that's going to run all the different
- 22:45pieces of the pipeline.
- 22:47So this Parquet again is is like a
- 22:49column summarized.
- 22:50>> Yeah, Parquet think of it as just a
- 22:51different version. It's like CSVs, but
- 22:53it's column-based. It's just a more
- 22:55efficient way of storing the data. And
- 22:57it's what DuckDB uses underneath it. So
- 23:00now it's going to go through what are
- 23:01all the different files, the
- 23:02configuration. So here is the template
- 23:05um for where the data is. Here is the
- 23:08data dictionary of how you map between
- 23:09FIPS codes and states, column name
- 23:12mappings. So this is how you're going to
- 23:14map between columns,
- 23:16the schema, and then variation of the
- 23:18columns.
- 23:21Um
- 23:22So then there's this download um this is
- 23:25the download procedure. This is how it's
- 23:27going to do the downloads. Um
- 23:31and then here's the conversion. So I
- 23:32think the kind of most of this is just,
- 23:34you know, programming to download data
- 23:36correctly. Here is how it's going to
- 23:38harmonize the schema. So what it's going
- 23:40to do is it's going to have years. It's
- 23:42going to have a lender identifier. It's
- 23:44going to have a lender name. It's going
- 23:46to have the county and state code state
- 23:48code. It's going to have um
- 23:51the loan type, the loan purpose, the
- 23:53action taken, and the loan amount, and
- 23:55then the the race and income.
- 23:57So this is really going to kind of um
- 24:00convert this down. Um we could kind of
- 24:04We're going to have the raw data. So
- 24:06this is going to be a view that it's
- 24:07going to create. There's many other
- 24:08things we could do as well.
- 24:09So one of the things it's going to have
- 24:11to do, it's going to have to construct
- 24:13some different variable names depending
- 24:14on what things look like.
- 24:17It's also going to need to do some
- 24:18conversions to make things harmonize. Um
- 24:21it's going to drop rows where it have
- 24:23doesn't information about the county or
- 24:24state code. And then it's going to build
- 24:26the database based off of this. And so
- 24:28this is going to create a kind of a view
- 24:30with all the data and then it's going to
- 24:32create this metadata and then we're
- 24:35going to create this kind of harmonized
- 24:37version and the run pipeline is going to
- 24:39do all these pieces.
- 24:41So after we've done the coding, we're
- 24:43going to just run this to download the
- 24:44years. This is the different steps it's
- 24:46going to try and do. And then you can
- 24:48query the data to take a look at it. And
- 24:50so this is going to be the things that
- 24:51it's going to do. And so now if we're
- 24:53comfortable with this, we can say yes
- 24:55and auto accept the edits. So now I'm
- 24:57going to say
- 24:59So one thing that is useful is that this
- 25:00will save it into a folder
- 25:03um on your computer elsewhere. So in dot
- 25:06Claude's if you go to tilde dot Claude
- 25:09plans, it will save the plan here if you
- 25:11want to look at it later.
- 25:14Um
- 25:16I'm going to make two That's all. I'm
- 25:19going to do this.
- 25:21Um
- 25:21I'm going to say yes. And so now what it
- 25:24will do is it's cleared my whole
- 25:26context. So what I've done is I've said,
- 25:29"Hey, um
- 25:32just get rid of all the work that you
- 25:33did before. Just take the plan." So
- 25:34remember we talked about context window
- 25:36management in the first video? It's
- 25:38exactly that. It's saying, "Hey, take
- 25:40the plan, read it, and let's start from
- 25:41the beginning." And so now it's starting
- 25:44from a clean directory. It's going to
- 25:45write the seven files.
- 25:48Um
- 25:49and it's going to create these seven
- 25:51ones. Here's a summary of what was
- 25:53built. All these different files. So
- 25:55config, download, convert, harmonize,
- 25:58build, run. A git ignore. So this is if
- 26:02you use git. Um this is a way of
- 26:04ignoring things that are kind of um not
- 26:07important. So now it's telling you you
- 26:09should run this. Now
- 26:11I could tell it so I could run this
- 26:13separately on the command line over
- 26:14here.
- 26:16Honestly, once you're already doing it
- 26:17in here, you can just tell it. You say,
- 26:19"Hey, just run it yourself." Um now it's
- 26:21going to look at the data. So it's
- 26:22saying, "Great, we have all of this
- 26:23data. Before we run the full pipeline,
- 26:24let's verify the column names in one
- 26:27pre-2018 and one post-2018 to make sure
- 26:29it's correct." We're going to say um
- 26:31yes.
- 26:33One thing I want to kind of just say
- 26:35quickly here uh Marcus is you know,
- 26:38often if I kind of know what's going on
- 26:40in these things, there's this meme about
- 26:43you know these uh these drinking birds
- 26:45that kind of they tip back and forth.
- 26:46There's this joke about people who use
- 26:48this. You know, you're just hitting yes
- 26:50every time it kind of does this. Um so
- 26:54there's a there's a joke there too of
- 26:57like
- 26:58it's good to be reading carefully, but
- 27:00if you kind of trust that most of the
- 27:02time it's working reasonably well, you
- 27:03can kind of you could either kind of
- 27:05move very quickly if this can be very
- 27:07quick.
- 27:11In future videos
- 27:13um
- 27:14in future videos we'll talk about ways
- 27:16in which you can actually do this in
- 27:17which you don't have to give any input
- 27:19and you can kind of let it make
- 27:20decisions on its own, but then of course
- 27:21you have to check the work. And that's
- 27:23called that's called like um
- 27:26What's called YOLO mode. Um so now it's
- 27:28going to try and convert everything.
- 27:30YOLO mode. Yeah, you only live once. So
- 27:32now I'm going to let it convert one of
- 27:34the files
- 27:35into a Parquet.
- 27:37So it's going to try and do this.
- 27:39>> [snorts]
- 27:53>> So now it says, "2017 converted
- 27:55successfully. 14 million rows, 114
- 27:58megabyte Parquet." So just as a a sense,
- 28:01right? So remember I was talking about
- 28:02how 2017 is 1.7 gigs as a CSV. When it's
- 28:06a Parquet file,
- 28:08um it turns it's ends up being 100 megs.
- 28:12I see.
- 28:12>> So this is a much more efficient ways of
- 28:13storing data.
- 28:16So it somehow compresses it.
- 28:18Yeah, because it ends up not needing as
- 28:21much um
- 28:23space [snorts]
- 28:24for a lot of the things.
- 28:25>> same information content.
- 28:27Exactly. It's just compressed much more
- 28:30um efficiently.
- 28:31So now it's going to try and harmonize
- 28:33for 2017. It's going to run the
- 28:34harmonization.
- 28:38And so it says, "Looks like there's an
- 28:39issue. Works. The respondent name
- 28:41warning is expected because it's not in
- 28:43these files. It'll be null. Now we're
- 28:45going to test a post-2018 year. Let me
- 28:47use 2024 because it's smaller."
- 28:51So now it's going to run this again.
- 28:52This is the one that converts it to a
- 28:54Parquet.
- 29:07So this one
- 29:092014 is a 4.3 gigabyte file and now it's
- 29:12450 megabytes.
- 29:14And I noticed the column I noticed the
- 29:16column names for post-2018. It converted
- 29:18hyphens to nothing, not underscores.
- 29:20This is different than I expected. The
- 29:23actual thing is this. I need to update
- 29:24this to make it work. So this is what's
- 29:26called thinking. This is it's basically
- 29:28it's figuring stuff out in the
- 29:30background.
- 29:31Uh it's now going to kind of try and
- 29:34make these consistent. So it now is
- 29:38verifying these. It's created kind of
- 29:40two tables. It has two years. It's
- 29:42building a database and the data looks
- 29:43correct.
- 29:45Okay. Los Angeles, Maricopa, Cook
- 29:48County, and Harris County are the top
- 29:50counties as expected. So, Cook County is
- 29:52in Chicago. I don't know where Harris
- 29:54County is. I think Maricopa is in
- 29:55California. I don't know where Harris
- 29:57County is. Um
- 30:00Let me remain that
- 30:01Let me run the remaining 16 years
- 30:05through convert and harmonize. I'll kick
- 30:06these off as a background task
- 30:08and I'll check these periodically. So,
- 30:10what it's saying is that it's going to
- 30:12um run these.
- 30:14But, um it can just run right this is
- 30:17the same thing as if you ran it in
- 30:18Python. So, it doesn't need to stop
- 30:20Claude per se. So, that what happens
- 30:22here is what's funny is it's
- 30:24to make it so that it will just pause
- 30:27and sit here. What it's done is it's
- 30:29it's said, "I'm going to wait 60 seconds
- 30:31and then look at the output." Okay. So,
- 30:35this is fine. You will just leave this
- 30:37so that way it could keep working.
- 30:39Um
- 30:41What I want to kind of show you while
- 30:42that's running is you can see
- 30:46what the DuckDB database will look like.
- 30:48So, in the database
- 30:50here
- 30:52on the left, this home panel DuckDB
- 30:55is sort of stored here.
- 30:58This is this file that it's going to try
- 30:59and make. It's and it's going through
- 31:01now and it is
- 31:05making parquet files.
- 31:11It's going to slowly doing these all in
- 31:13parallel.
- 31:15They're almost done.
- 31:17But, you can see that this has gone from
- 31:18a 70 GB
- 31:20process to
- 31:22um
- 31:24just a basically this is going to end up
- 31:26being a GB Mhm. just because it's much
- 31:28more efficiently stored. All right. So,
- 31:30now it's all done. So, we have all 18
- 31:33years converted. We're going to run
- 31:35harmonize on the remaining 16 years cuz
- 31:38we already did two. So, it's going to
- 31:39run this. It's doing this task.
- 31:42It's [snorts] just going to um basically
- 31:44convert these in the background
- 31:46and then it's going to make a basically
- 31:48make a a database out of it. So, it's
- 31:49going to harmonize all of these.
- 31:52It has the same
- 31:55It's basically moving these ones. All it
- 31:57all 18 years harmonize successfully.
- 31:59Now, let's build the final database.
- 32:02So, it has 291 million rows across 18
- 32:05years. Let me find run the full
- 32:07verification query. So, a nice thing
- 32:08here you can see if you
- 32:10you know, we all did a bunch on
- 32:11mortgages is the peak of mortgage
- 32:13origination 2007 and then of course
- 32:16things fell off tremendously. Yes. Here
- 32:18during COVID, this is when interest
- 32:20rates fell. So, that's why we had this
- 32:21massive increase because there was a ton
- 32:23of refinancing.
- 32:25And then we've had um
- 32:27a bunch of a fall off because interest
- 32:29rates have gone up and there's been a
- 32:30very kind of little little origination.
- 32:32So, now it's all done and we have this
- 32:34final database here. So, we can read
- 32:37through what it says. Here's the
- 32:38pipeline.
- 32:39Um one single database. One thing I
- 32:41noticed is that these purpose codes
- 32:44appear in the 2018 database. These are
- 32:47pre-2018 encodings for refinancing and
- 32:49home improvement respectively. The
- 32:50harmonization maps the raw values
- 32:52directly. If you want to recode these
- 32:54for this year, I can add that
- 32:55transformation. Otherwise, it is um
- 33:00it is clean and ready to query. If I
- 33:02were doing this myself, I would it but I
- 33:04would do it. But, now we're all set. So,
- 33:06we can the last thing that we can do
- 33:08kind of now now we have the stuff. So,
- 33:10let's look at what we have. We built
- 33:12this whole pipeline to download the data
- 33:14and harmonize thing.
- 33:16And now I want to just say, "Okay, well,
- 33:17what's something we could do with this?"
- 33:19So,
- 33:20you know, a nice part of this is we
- 33:22could say, "I want to build some
- 33:24aggregated data where what we're going
- 33:26to do is
- 33:28I want to let's just for the purposes of
- 33:31this
- 33:32I want to build some views. So, this is
- 33:34what it's what it means is I want to
- 33:35take the data
- 33:36and I want to construct the amount of
- 33:39origination by county year. Mhm.
- 33:42And I can I want to basically build two
- 33:44aggregated databases. So, the challenge
- 33:46I wanted to do this by lender by year,
- 33:49but we'd have to do kind of more work on
- 33:50this um cuz I want to classify things by
- 33:54um fintech and non-fintech.
- 33:56Um
- 33:58I think the challenge given what was set
- 34:00up is I would need to do more work on
- 34:02here. So, what I want to do instead is I
- 34:05want to just build out an aggregate
- 34:07database where I'm going to say, "What
- 34:09are Here's what I'm going to do. I want
- 34:10to build out aggregate database where
- 34:12what I'm going to be getting is county
- 34:14by year, total originations, dollar
- 34:16value, number of active lenders, the HHI
- 34:19which is like the market concentration,
- 34:21the denial rate, and the median loan
- 34:22amount."
- 34:23So, I'm going to
- 34:25um I'm going to ask it to do that.
- 34:29And so, this should be very quick. So,
- 34:31it will just
- 34:33um do this in a few and kind of one very
- 34:36natural thing that we can do and I'll
- 34:38post about this online just to kind of
- 34:40keep this from getting longer is
- 34:42um now we can also do things for example
- 34:44where we could crosswalk on um a
- 34:47question of
- 34:49um
- 34:50shadow banks versus non-shadow banks.
- 34:52This is a big question in the finance
- 34:54literature about how much lending is
- 34:55happening in mortgages among shadow
- 34:57banks. And so, we could very easily try
- 34:59to have this classify things
- 35:02following others um in this approach.
- 35:04So, after we do this one and I show this
- 35:07in the director's cut, we can show the
- 35:09longer version of this. But, I want to
- 35:10kind of show you an example of how this
- 35:12can be done. It's going to say, "Let me
- 35:13create a a function for the build DB
- 35:16Python code which is going to create HHI
- 35:20and then collapse it down."
- 35:24So, it's going to do this. It's going to
- 35:25create a new little function here. So,
- 35:27that's what Claude proposed that, no? Or
- 35:30Yes, it I told it I just want to make
- 35:32this table and it's saying, "Here's how
- 35:34I would do it." And so, I'm letting it
- 35:36go go to town. It's going to run that.
- 35:38It's going to rebuild the database with
- 35:40the new table.
- 35:43So, now it's you'll notice it's found an
- 35:44error here. It says, "2018 LA County
- 35:46must have many fragmented rows instead
- 35:48of one.
- 35:49There must be format variation. Let me
- 35:51investigate." So, it looks like it's run
- 35:53into a problem here in which
- 35:55there are some issues.
- 35:58So, it looks like it found a FIPS code
- 36:00which is inconsistent in some of the
- 36:01post-2018.
- 36:04So, it's going to try and
- 36:06Sorry for No, no, go ahead. Yeah, yeah.
- 36:09>> What are FIPS codes?
- 36:10Mhm.
- 36:11FIPS, what does FIPS stand for?
- 36:14Oh, FIPS, good question. It stands for
- 36:16Federal
- 36:19Good question. I don't actually know.
- 36:21It's a Federal Information Processing
- 36:23something. It's a So, FIPS is a way of
- 36:26you would get these long codes. Um so,
- 36:29state it's going to be a two-digit code.
- 36:31County is it's the state plus a
- 36:33three-digit county code. And then you
- 36:35can actually aggregate it to the
- 36:38This is the same code that gets used for
- 36:39example for census blocks and census
- 36:41tracts. It's a long um multi-numeric
- 36:45thing. And so, what it's done here is
- 36:46it's figured out what the problem was.
- 36:49The group by here
- 36:51um
- 36:52we need to derive the state FIPS code
- 36:55correctly. It looks like there were some
- 36:56errors there. So, now it is done this
- 36:58correctly.
- 37:00And it has one row per county year. LA
- 37:03County shows a clean time series across
- 37:05all 18 years. Tells a nice story. So, it
- 37:08looks like it's constructed this. And
- 37:09so, now what I'm going to ask it to do
- 37:11is to make a histogram of HHI for across
- 37:13counties for 2007, 2015, 2021,
- 37:18and 2024 and uh make a four-panel graph.
- 37:22Okay. Um
- 37:25Um
- 37:28The reason I'm going to do this uh
- 37:30make this H uh histogram
- 37:34uh dollar weighted.
- 37:36Mhm.
- 37:38So,
- 37:40the reason I might be interested in this
- 37:41is I want to understand kind of how
- 37:42changing
- 37:44um lender concentration has varied over
- 37:46time. So, um HHIs that are that are much
- 37:49larger are going to reflect counties
- 37:51where there's much more concentration
- 37:53for a single lender. What is HHI?
- 37:55Herfindahl Index? Herfindahl Index,
- 37:57exactly. It stands for that. I forget
- 37:59the Herfindahl-Hirschman Index.
- 38:02Um that's right. Hirschman always gets
- 38:04the short shrift when people describe
- 38:06it. Mhm. Um
- 38:08Which one is
- 38:10>> and it does that very, very quickly. So,
- 38:11you'll see it's already constructed
- 38:13this.
- 38:14And
- 38:15um
- 38:17Once it's done here, it's going to have
- 38:19its own opinion. Um
- 38:23It's going to say, "It's remarkably low
- 38:26across all four years.
- 38:28Um the weighted mean ranges from 308 to
- 38:31356.
- 38:33Um
- 38:34The big dollar counties have hundreds of
- 38:36competing ones. It's very right skewed.
- 38:38So, that you know, the rural counties
- 38:39tend to be um
- 38:41very concentrated. This was the most
- 38:43competitive, whereas these two are tied.
- 38:47So, I'm going to What I'm going to do
- 38:48So, the last thing that I want to do um
- 38:52All right. So, the last thing So, this
- 38:53is kind of uh
- 38:54I I'm going to
- 38:56Let me actually
- 38:58show you here. Marcus, if it's okay, I
- 39:00want to
- 39:00>> up the the PNG file here?
- 39:02>> Yes. So, I want to open it so you can
- 39:04see it. So, I'm going to share this now.
- 39:05I'm going to switch my screen for a
- 39:06second and share it. So, I want to be
- 39:08able to show you what that looks like.
- 39:10Um
- 39:12So, now
- 39:13um
- 39:15Where did it save it? Saved it under
- 39:16data. So, now we can look at this
- 39:18figure.
- 39:21Now, it's very funny to me that it used
- 39:23that um
- 39:28So, here is
- 39:30what it looks like. So, it made this
- 39:32one.
- 39:33If you remember
- 39:35I didn't tell it anything of what the
- 39:36figure to look like. This is all
- 39:37defaults.
- 39:39I frankly think it would have been very
- 39:40ugly. Um
- 39:43I think the one thing that would be
- 39:44interesting here if you could do for
- 39:45example is you could also ask now you
- 39:47could say like let's compare across
- 39:49counties. So you could do a scatter
- 39:50plot. You could say how has this kind of
- 39:52changed over time? Kind of the real
- 39:54thing that's interesting though is is
- 39:56that the mean concentration has gone up
- 39:59but I would say that it hasn't
- 40:00dramatically shifted across these
- 40:02hugely. Um it's a relatively competitive
- 40:05industry although who are the major
- 40:07players here maybe have changed a little
- 40:09bit.
- 40:10Um
- 40:12As a kind of the key benefit here that I
- 40:14just want to describe to you is
- 40:16um
- 40:17what I'm going to do now is I'll just go
- 40:18back to the the the um
- 40:21the command line
- 40:23is to tell you
- 40:28I just want to kind of show you very
- 40:30quickly
- 40:31um
- 40:33how you could use this DuckDB. So like
- 40:34just to give you a sense of what this
- 40:36looks like. So in the data set um
- 40:39we are
- 40:41um here
- 40:43and we take the the data
- 40:47Mhm. and we look at the DuckDB file we
- 40:49can run DuckDB in and
- 40:51um
- 40:53we can take a look at what's inside of
- 40:55it. So I mentioned that this is a great
- 40:57program. This is independent of looking
- 40:58at this is so on the left here I'll make
- 41:00it bigger so you can see it. This is I'm
- 41:02now inside I've run DuckDB to look at
- 41:05this thing and I can say show me the
- 41:06tables um in here. And so now what I
- 41:08have is a bunch of different tables. So
- 41:10I have the main data here. I have the
- 41:12metadata. This is what my um
- 41:15my LLM would use and then I've made this
- 41:17new thing called county year. So if you
- 41:20describe county year
- 41:22this is a a
- 41:23uh this is this thing that I just made.
- 41:26Um so I have all this information. I can
- 41:28also describe the underlying raw data.
- 41:32And you can see that this is kind of
- 41:34what useful about it is it it gets
- 41:35stored very efficiently. It has the the
- 41:38strings. It has the loan type and it has
- 41:40the loan purpose, the amount, the
- 41:42origination, different pieces. I've
- 41:44selected to a subset of things so I
- 41:46could incorporate and do more if I
- 41:48wanted um in the raw data but this is
- 41:51just a very useful way of structuring
- 41:53data. Now I have one file that I just
- 41:55point the LLM to if I'm going to do
- 41:57something.
- 41:58So what I'm going to do now as a last um
- 42:01exercise is
- 42:03um what we're going to do is we are
- 42:06going to ask um
- 42:09we're going to ask the LLM to
- 42:16um try and replicate some some um
- 42:19labeling that comes from the finance
- 42:22literature. So there's
- 42:24been work of people trying to label what
- 42:25are fintechs or shadow banks in the
- 42:27mortgage literature. So what I'm going
- 42:29to do is I'm going to say um I want to
- 42:31classify lenders as fintech or shadow
- 42:34banks versus traditional banks. Let's
- 42:36start with the lending classification
- 42:38from Fooster, Placer, Schnabl and
- 42:40Victory which is a paper uh
- 42:42in the Review of Financial Studies. They
- 42:44have a list in that paper. I'm going to
- 42:46use that as a base and then I want to
- 42:47extend the classification to cover these
- 42:49other names. So store it in a lender
- 42:51classification and document what's going
- 42:53on here. So
- 42:54I'm what I'm going to do is I'm going to
- 42:55say this and then I'm going to ask
- 42:58tell me what it would take to do this
- 43:03task before you um try anything
- 43:08complicated.
- 43:10Is this feasible?
- 43:12What might be missing?
- 43:15So we're going to we're going to ask it
- 43:16to do this now and we'll see kind of
- 43:18what it's able to do.
- 43:20Good question to ask before diving in.
- 43:22So this is very sycophantic. Let me
- 43:24check what we actually have to work
- 43:26with.
- 43:29So it's reading the DuckDB database. So
- 43:33underneath here it's looking it's
- 43:34looking at the names and so it sees that
- 43:36there's no names. So that's a big
- 43:37problem. Yes. And that was why I was
- 43:41telling you earlier that it will see
- 43:42kind of how doable it is um and it might
- 43:45need to kind of construct
- 43:48I see. So it's going to go back to the
- 43:50original data. What?
- 43:51Yeah, exactly. So it's going to look to
- 43:53see what's in there.
- 43:55Um
- 43:56and it's going to figure it out for me.
- 43:57This is a little bit like you might ask
- 43:59an RA, right? You might say hey
- 44:01can you I want to do this. What is that
- 44:03going to entail?
- 44:07So it's looking at different uh
- 44:09different files. My recollection here is
- 44:11that what it needs to do is it needs to
- 44:15um
- 44:17figure out what the names are in here.
- 44:20And so there's a crosswalk in this data.
- 44:23Mhm. We would need to download this
- 44:25data. This is a panel data set where
- 44:27we'd need to do the here. And so it's
- 44:29say it's going to say well, here's
- 44:31what's missing. We have all the lender
- 44:33identifiers but we have no names and no
- 44:35institution type.
- 44:37So what do we need? We need these HMDA
- 44:39panel or trans middle sheet transmission
- 44:41trans middle sheet files. Mhm. They are
- 44:44going to have a bunch of information
- 44:45that links across the two of these.
- 44:48So
- 44:50how can we do that?
- 44:52We need a name we need the names to do
- 44:54this. And so what's feasible? So we
- 44:56could do an additional download to get
- 44:58this. So should I download the panel
- 45:00files? And so do like see if it is
- 45:05feasible to download panel files.
- 45:09And so we can ask.
- 45:13And if it's easy these are tiny files it
- 45:15looks like.
- 45:16And it's going to try and figure out
- 45:18what it's doing.
- 45:19So it's looking it's going to it's
- 45:21thinking about it and so now it's doing
- 45:23it's how to download these files.
- 45:25And so it's it's remember this is a an
- 45:28agent that it's spun out now to look for
- 45:30this and it's researched how to do this.
- 45:33Look for these sources.
- 45:35And now try and figure out if it's
- 45:37doable.
- 45:39So it's looking.
- 45:41And it looks like it's done and now or
- 45:42it's it's researching this right now.
- 45:44It's not done.
- 45:45And it's downloaded a bunch. It sees
- 45:47that it looks like it has found one of
- 45:49the data sources. So CFPB has it there
- 45:52for a bunch of these files and I'm going
- 45:53to say yes. So what it's trying to do
- 45:55now is trying to download it. So curl is
- 45:56a command to download data and it's
- 45:58going to download and look at the
- 46:00header.
- 46:01And we're going to say yeah, go ahead.
- 46:04All right. So that took a little while
- 46:06to do this but um just to give you a
- 46:08sense this it did a ton of work
- 46:11basically a huge number uh it it ended
- 46:14up using something like 75,000 tokens to
- 46:16really research on this. And now it has
- 46:18a new plan of what it wants to do. It
- 46:20says all right, here's what we're going
- 46:21to do. We're going to reconstruct this
- 46:23plan. We're going to redo this plan and
- 46:25we're going to deal
- 46:27um
- 46:28Sorry, we're going to basically
- 46:30here's what I found. So it did 75,000
- 46:33tokens
- 46:34to figure out what was going on. It says
- 46:36yes, it's available for all of these
- 46:37years.
- 46:392024 has not been published yet. Um
- 46:43each file is about one it's not there
- 46:45for 2024. That's fine. It's going to use
- 46:48something else but it won't have an
- 46:49other lender code. So let's do it. So it
- 46:52took a while took 7 minutes and 41
- 46:54seconds to figure it out but now it
- 46:56knows how to do it. So we'll say yes, go
- 46:58ahead
- 46:59and implement.
- 47:01So it's going to try and implement this.
- 47:02It's going to download 18 small files.
- 47:04It's going to merge these on to lender
- 47:06ID and then it will have names and then
- 47:08it will subclassify based off of this
- 47:10from the paper. And so it's going to
- 47:13it's going to try and do this.
- 47:15Um
- 47:17and what you'll see so just to give you
- 47:19a sense of how this data set works is
- 47:20that there's a file that's just about
- 47:22the institutions that are there and it
- 47:23has a name and lender codes. And so what
- 47:27you know, these one of the useful ways
- 47:28is that you can kind of classify banks
- 47:30based off of what they look like um in
- 47:32this information.
- 47:34So it's going to try and implement the
- 47:35code. So
- 47:37we'll let this we'll let this run for a
- 47:38second.
- 47:40And so it's made some decisions
- 47:42on what are the core list. So this it
- 47:44knows from Fooster et al. Here's all the
- 47:47Mhm. Names. The names and then it's made
- 47:49it's made some decisions on what are
- 47:51additional fintech loans. So we may or
- 47:53may not agree with these but these are
- 47:55certainly reasonable place to start.
- 47:57Better Mortgage and better.com and SoFi
- 47:59are good place to start.
- 48:01Um [snorts] and now it's going to it
- 48:03basically uh downloaded this data.
- 48:08Um it actually didn't So this is
- 48:10something I didn't wouldn't really like
- 48:12and we didn't specify this so this is
- 48:14why it's doing it. These are small files
- 48:16and so it's just actually just running
- 48:18it from the command it's basically
- 48:19writing it out itself. This is not
- 48:21replicable though. You would you know,
- 48:23this would not be good if you were
- 48:24trying to have a pipeline where you
- 48:26could run it from scratch.
- 48:28So I wouldn't traditionally like that. I
- 48:29would go back and I'd change that. I
- 48:31would say actually no, write a script to
- 48:32download it. Now it's going to load it
- 48:34in.
- 48:35It's got all of these it's understanding
- 48:37the data. Data looks great. We've got
- 48:39this. Got a nonbank.
- 48:42Now it's going to rebuild the database.
- 48:46And now it has its first error.
- 48:49Mhm.
- 48:51Exit code one.
- 48:54So we could see what it says. It's it's
- 48:56kind of
- 48:58How do you look at this? Or adjust?
- 49:01Uh it's the same way as it's I would say
- 49:03press control O and so there was some
- 49:05error that happened there and so we'll
- 49:06say
- 49:07what happened? Oh, they have Windows
- 49:09line ending. So this is the sort of
- 49:10thing I would never know. It says
- 49:12Windows line endings and fixed width
- 49:13paddings. Let me fix the reading
- 49:15options.
- 49:16So I need to add this for these messy
- 49:18pre-2018. This is the kind of thing
- 49:19that's awful when you work with data. Um
- 49:24and so it's updating the code to address
- 49:26this. It's going to rerun it now.
- 49:32Looks like it's excellent. 26 fintech
- 49:34lenders identified all loans all years.
- 49:37Let me verify that these look
- 49:38reasonable.
- 49:43And now it has market share over time.
- 49:46And so what you can see is here's an LA
- 49:48County
- 49:49kind of grown substantially and of
- 49:51course as of 2020 went up to 70%
- 49:54and now it's around 60. And so this is
- 49:56kind of very here's Rocket Mortgage
- 49:58which is a huge lender. It's kind of the
- 49:59largest lender.
- 50:00Um
- 50:02and it looks like it's great. So it's
- 50:04basically created everything exactly
- 50:05from this this classification.
- 50:08Um and now what we could do is I'm going
- 50:10to say, "Please make a figure of the
- 50:13trend in um
- 50:15raw in fintech origination share over
- 50:20time
- 50:21in the data set
- 50:24uh
- 50:25using Kieran Healy styling
- 50:28for um
- 50:30plotting."
- 50:33So now it's going to make a figure.
- 50:35And then we'll look at it and we will
- 50:39summarize.
- 50:40So while this is running
- 50:44So let me kind of while this is running,
- 50:46let me start by summarizing kind of what
- 50:48we did at a high level.
- 50:50I think there's a lot of stuff we did.
- 50:51This was a ended up being really long.
- 50:53I'm sorry for everybody who stuck with
- 50:54us. Appreciate it.
- 50:56The thing that this did was we took big
- 50:59data sets. We kind of worked with Claude
- 51:02code to
- 51:03down write a script to download them, to
- 51:05kind of put them all in the pipeline,
- 51:07and then clean them up and work in a
- 51:08framework that is
- 51:11um
- 51:12kind of
- 51:14lets us work with it very efficiently.
- 51:16So DuckDB is the thing that I was
- 51:17arguing you should use. There are other
- 51:19things like SQLite that you can do, but
- 51:21they don't require a server or anything
- 51:23else and they have a lot of metadata. So
- 51:24now you could take that data set and you
- 51:26could always heart go back to it and
- 51:28then the LLM would kind of understand
- 51:29what's going on.
- 51:31We then did a crosswalk where we unders-
- 51:33we basically mapped information about
- 51:35the lenders directly from the literature
- 51:37and we were able to kind of pull that
- 51:39data in and harmonize a lot of the
- 51:41information there. And that lets us do a
- 51:44lot. This is this data set is actually
- 51:46for a lot of researchers in finance it's
- 51:48kind of one of the main things that
- 51:49you'll start with um when you're working
- 51:50with it. So let me end by kind of
- 51:52showing you what you can see in this
- 51:54data final data set. So I'm going to
- 51:55share it with you. And now it'll look a
- 51:57little nicer than our other figure.
- 52:01So
- 52:02here.
- 52:03So here
- 52:05is you know, it decided to do like this.
- 52:10So this is the
- 52:13um
- 52:14that.
- 52:18It's interesting in that
- 52:20this is basically non-bank lenders,
- 52:22right? So the the light blue here and
- 52:26actually I'll read you what it says
- 52:28here. It's so there's a
- 52:30light blue band is
- 52:32non-mor- non-bank lenders. So there are
- 52:34a lot of non-bank lenders in the United
- 52:36States that make loans and they've
- 52:39always done that. They've always kind of
- 52:40been on the outside. Um this was kind of
- 52:43a bit they were a lot of the ones who
- 52:44were doing securitization and other
- 52:45things. This blue band is non-bank
- 52:47lenders who Fooster and co-authors
- 52:50classify as fintech. And what you can
- 52:52see is that they've just grown as a
- 52:54proportion of overall lending by quite a
- 52:56bit during this period. Now, whether or
- 52:58not these other places are non-fintech
- 53:00is a is a big question, but this is
- 53:02right around when Quicken became big and
- 53:03you can see that they've just grown as
- 53:04an overall share. And more generally,
- 53:07this is the collapse in traditional bank
- 53:09lending overall. They're the residual
- 53:12and they've gone down. They now make up
- 53:14only 40% of all lending relative to
- 53:17um during the crisis and what we
- 53:19>> of the dark blue?
- 53:21Yes. Okay.
- 53:23Um Rocket Mortgage is that's sort of in
- 53:27here and they they kind of consist in
- 53:28here.
- 53:29Um
- 53:31so it's kind of very cool. There's a lot
- 53:33of other things you could do. You could
- 53:34work with Claude to kind of clean this
- 53:35stuff up. All the slow stuff we kind of
- 53:37already done now. And so, you know, I I
- 53:40think I'd really encourage you. There's
- 53:42a lot of really cool big data sets um
- 53:45out there. I've kind of um I've posted
- 53:48online about this, but I just want to
- 53:49tell you like
- 53:50I've done stuff with uh we're not going
- 53:52to make anyone have to watch us download
- 53:55a bunch of big data sets again, but kind
- 53:57of the there's stuff
- 53:59from what's called IPEDS which is
- 54:02information about post-secondary
- 54:03institutions. So if you're interested in
- 54:05colleges or universities the federal
- 54:07government posts a huge amount of
- 54:08information about that that is all
- 54:10structured and I've posted code on how
- 54:12can you harmonize that and put this all
- 54:13into a one big DuckDB database. If
- 54:16you're interested in studying um
- 54:17universities
- 54:18same thing is true for a lot of other
- 54:19databases. And so I think the kind of
- 54:22the world's your oyster if you're
- 54:23interested in working with data, if
- 54:24you're a graduate student, if you're a
- 54:25junior researcher and you want to kind
- 54:27of learn about new data, I think it's
- 54:28become a lot easier to work with these
- 54:30big data sets and kind of cleanly clean
- 54:32and work with them. So hopefully this
- 54:34was useful. Thank you for sticking with
- 54:35us for this long video and um
- 54:38next time I think Marcus we're going to
- 54:40talk about writing and kind of the
- 54:42general ways in which you can use LLMs
- 54:43for those sorts of tasks, writing
- 54:45reports, kind of iterating on proofs and
- 54:48other things, yeah?
- 54:49Very good. Thanks a lot, Paul. Uh so
- 54:52next time we're looking forward how to
- 54:53write your referee report for this
- 54:55project we started today.
- 54:57Exactly. Exactly. All right. Thanks so
- 54:59much, Marcus. Thanks a lot. Thanks to
- 55:01everybody and uh see you soon again
- 55:04for the next mini video.
- 55:08Bye-bye.
- 55:09Bye.
- 55:11All right.
About this transcript
This page contains the full transcript of Large Datasets: Claude Code for Economists with Paul Goldsmith-Pinkham | Markus' Academy | Ep. 162-4 by Markus' Academy, generated from the public captions YouTube serves with the video. The transcript has 10,308 words across 1,604 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.