YouTube2Text

Large Datasets: Claude Code for Economists with Paul Goldsmith-Pinkham | Markus' Academy | Ep. 162-4 — Transcript

by Markus' Academy · 10,308 words · 1,604 segments · language en · Watch on YouTube

Full transcript

  1. 0:08Welcome back everybody.
  2. 0:10For another video of the mini video
  3. 0:12series with Paul Goldsmith Pinkham on
  4. 0:16Cloud Code for applied economists.
  5. 0:19Hi Paul. Good to be back.
  6. 0:20>> Hi and Marcus.
  7. 0:22I'm looking forward to this. This is
  8. 0:23fun. So we're kind of
  9. 0:26taking off the training wheels a little
  10. 0:28bit for
  11. 0:30today was in the sense that we got
  12. 0:31started last last three videos we got
  13. 0:33started. We sort of learned how how
  14. 0:35Cloud works. We've done some basic
  15. 0:37things making figures. Last time we did
  16. 0:39a little bit of work
  17. 0:40thinking about a database and
  18. 0:42downloading Edgar files. Today we're
  19. 0:44going to do a lot more with kind of big
  20. 0:47data in a structured fashion.
  21. 0:50We're going to do mainly stuff from
  22. 0:51Cloud Code in the command line.
  23. 0:54And my hope is that what this is really
  24. 0:56useful for is that
  25. 0:59we many applied economists work with
  26. 1:01really big data sets.
  27. 1:03You know, it's
  28. 1:05we have now the access to these big
  29. 1:07administrative data sets either through
  30. 1:09the web or somewhere else where you have
  31. 1:10many many observations, right? Like the
  32. 1:13one that we're going to do today is
  33. 1:14going to be what's called the HMDA data
  34. 1:16set. So this is the Home Mortgage
  35. 1:18Disclosure Act data set. It's a public
  36. 1:19data set. Everyone has it has access to
  37. 1:22it. And it has you know, the whole thing
  38. 1:25together when you get the CSVs is
  39. 1:27something like 70 gigabytes. Really
  40. 1:29large files. You can get much more, but
  41. 1:31that's quite big. And
  42. 1:34often when we work with these files,
  43. 1:37you know, none of us are trained as data
  44. 1:39engineers. We end up working with a lot
  45. 1:40of flat CSVs. We maybe make a bunch of
  46. 1:43different copies. We end up just
  47. 1:44constructing a lot of stuff. And I want
  48. 1:46to kind of show that one thing that is
  49. 1:48really nice about working with these
  50. 1:49agents in Cloud Code is that
  51. 1:52you can kind of more easily integrate
  52. 1:54into better practices for storing data
  53. 1:56and working with things in ways that
  54. 1:58actually like open up a lot of new
  55. 2:00interesting work and kind of improve
  56. 2:03replication and other things. So that's
  57. 2:05what we're going to do today.
  58. 2:07What I'm going to do is I'm just going
  59. 2:08to go straight to the command line. So
  60. 2:11we're going to
  61. 2:13go to the command line and I will show
  62. 2:17you here. Are you able to see this? So
  63. 2:18this is let me quickly. So I'm in a
  64. 2:20command line here.
  65. 2:23Where
  66. 2:25this is inside a folder that I have for
  67. 2:27you and I just want to kind of show you
  68. 2:29like that I have I've kind of
  69. 2:31established
  70. 2:32I made some prompts beforehand and I
  71. 2:34want to kind of describe what the
  72. 2:35project is that we're going to do in
  73. 2:38detail. Are you able to read this okay?
  74. 2:39So we're not doing anything with Cloud
  75. 2:41Code yet. I just want to read it
  76. 2:42together so I can tell you kind of the
  77. 2:44goal. And I tell you there's a little
  78. 2:47bit of preprocessing here just because I
  79. 2:48knew the task and I I got this set up. I
  80. 2:51set up a prompt. I could have very
  81. 2:52easily done this inside of Cloud Code,
  82. 2:55but just for the purposes of getting
  83. 2:57started I wanted to do this. So
  84. 2:59first what we're going to be doing today
  85. 3:01is we're going to be trying to
  86. 3:03download and kind of harmonize a large
  87. 3:06administrative data set that's referred
  88. 3:08to as HMDA. It stands for the Home
  89. 3:09Mortgage Disclosure Act, which is a data
  90. 3:12set that's now produced every year that
  91. 3:14basically has near universal coverage of
  92. 3:16all mortgages in the United States when
  93. 3:18they were originated. Both originated
  94. 3:20and actually denied. So this is this
  95. 3:22data was originally constructed in order
  96. 3:24to
  97. 3:26deal with potential racial
  98. 3:27discrimination in mortgage origination.
  99. 3:30So the data for this we're going to
  100. 3:31build a panel
  101. 3:33that uses original data. So what I've
  102. 3:36done in this prompt, I set up a prompt
  103. 3:37to say I want to build a panel data set
  104. 3:39of mortgage lending in the US from 2007
  105. 3:42to 2024 using HMDA data. The goal is to
  106. 3:45study the geographic expansion of
  107. 3:46fintech mortgage lenders over time.
  108. 3:49Right? So a pretty reasonable
  109. 3:51pretty reasonable problem.
  110. 3:53And
  111. 3:56I'm going to this is something I knew a
  112. 3:58little bit more of, but of course you
  113. 3:59might iterate on is that there's two
  114. 4:01sources for this data. I didn't want to
  115. 4:03have a ton of time for
  116. 4:06Cloud to have to worry about this. So
  117. 4:08the first one is 2007 to 2017. The CFPB
  118. 4:11has these zip files that are online.
  119. 4:14Mhm. And from 2018 to 2024 there's
  120. 4:18additional data that's stored here. Um
  121. 4:21these you're able to get access to both
  122. 4:23of them are publicly available. I'm kind
  123. 4:26of describing them and they change over
  124. 4:27time. So what I'm going to tell it is
  125. 4:30that these are really big data sets.
  126. 4:32These have like each the whole thing is
  127. 4:34going to have 250 million rows. So it's
  128. 4:36a big data set. This is not going to fit
  129. 4:38inside of memory, right? So if you you
  130. 4:41Stata or something like this, you could
  131. 4:43it's quite costly load this all into
  132. 4:46into Stata or to Python or any of these
  133. 4:48ones. So
  134. 4:49you wouldn't want to directly load this
  135. 4:51into memory. And so what I'm going to
  136. 4:52ask it to do is I want it to write a
  137. 4:54script that is going to pull this data
  138. 4:57down. I want to make it so that you
  139. 5:00know, it's so what I'm telling it here
  140. 5:01was include resume capability. That way
  141. 5:04in case something gets broken. So that
  142. 5:06could happen to you, right? You're
  143. 5:07downloading something and your computer
  144. 5:09turns off or reboots. You want to have
  145. 5:11it so that it downloads correctly.
  146. 5:13Mhm.
  147. 5:14This is a a user agent header. So this
  148. 5:16is just the same thing that we had last
  149. 5:18time in that when you when you talk to
  150. 5:20things on the internet, it wants to know
  151. 5:21who you are. If you do it without this,
  152. 5:23it it it will sometimes block you.
  153. 5:26Then I want to
  154. 5:29take this data and convert into just
  155. 5:31Parquets to make it more efficient. And
  156. 5:33I'm going to set up something called a
  157. 5:34DuckDB database. So we briefly talked
  158. 5:36about this last time, but Marcus, I
  159. 5:38didn't kind of give you all the details
  160. 5:39on this. What this is is really if if
  161. 5:41you've heard of a relational database or
  162. 5:43something with SQL, so SQL,
  163. 5:47these are ways of storing data that keep
  164. 5:50track of relationships between data. So
  165. 5:52you might imagine, right, that I have a
  166. 5:54table where I have different I have one
  167. 5:56table that stores who are all the
  168. 5:58lenders.
  169. 5:59And then another table that has the
  170. 6:00loans. And of course in a database that
  171. 6:03has stuff about
  172. 6:04loans is going to be a lender identifier
  173. 6:07there. And you might say, "Oh, I want to
  174. 6:08take all the lenders in here
  175. 6:10who have more than a hundred million
  176. 6:12dollars in assets and I want to link
  177. 6:14these over and only pull their loans."
  178. 6:17And so these types of relational
  179. 6:18databases are very good at this kind of
  180. 6:20information.
  181. 6:21And what's really good is it has
  182. 6:23metadata in it. So metadata means
  183. 6:26like additional information about the
  184. 6:28data sets that is about all the data
  185. 6:31that's in there. So it's things like
  186. 6:33what the name is, a description, the
  187. 6:34type of data it is, kind of what's valid
  188. 6:37about it. And what's really nice is that
  189. 6:39the metadata
  190. 6:41is going to give information to Cloud or
  191. 6:45any other LLM that you use with it in
  192. 6:47the future so that it doesn't have to
  193. 6:49kind of figure out what's going on,
  194. 6:51right? So you imagine if I give you a
  195. 6:52data set, Marcus, I
  196. 6:55the benefit of it is like there's a
  197. 6:57difference between a data set where
  198. 6:58somebody gives you names that have
  199. 7:00really good labels, right? Versus one
  200. 7:02that is totally indecipherable.
  201. 7:05Right? Does that make sense?
  202. 7:07So it's like but metadata is labels are
  203. 7:09metadata as well. Exactly. A label So if
  204. 7:12you've ever used in Stata, sometimes
  205. 7:13people talk about like value labels and
  206. 7:15other things. There's there's or
  207. 7:17variable labels. Those are often kind of
  208. 7:19additional meta information that's there
  209. 7:21that makes it kind of more useful to
  210. 7:23understand what's going on.
  211. 7:25Um
  212. 7:26an important thing here is that there
  213. 7:27was a big change in the data from in
  214. 7:302018.
  215. 7:31There were different column names and
  216. 7:33encoding schemes. And so I'm going to
  217. 7:34ask it to build a crosswalk and
  218. 7:35harmonize across this. All right. And so
  219. 7:38I'm telling it kind of the things I care
  220. 7:39about. And so I'm going to ask it to
  221. 7:41always use DuckDB in here. It can't kind
  222. 7:43of load everything and do anything. So
  223. 7:45it really needs to do everything kind of
  224. 7:46using SQL.
  225. 7:48So that's what we're going to do.
  226. 7:51We're going to start with that.
  227. 7:52>> DuckDB is the only provider? It's a
  228. 7:54particular provider like
  229. 7:55>> No, no, no. So there could be any So you
  230. 7:57can use lots of things. So DuckDB is
  231. 7:58what's very nice about DuckDB is it will
  232. 8:00be a way of it's a program that sits on
  233. 8:02top of um
  234. 8:05what are called Parquet files. So I'll
  235. 8:07briefly just explain if you don't A
  236. 8:09Parquet file is just another way to
  237. 8:11store data just like a CSV. CSV, right,
  238. 8:13stands for comma separated values. Mhm.
  239. 8:16Parquets are ones that are actually
  240. 8:19column They basically focus on things in
  241. 8:21So you think about a CSV, a CSV what it
  242. 8:24does is every line is kind of a piece of
  243. 8:27data, right? So you have a line, each
  244. 8:30each piece of information is separated
  245. 8:31by commas and then you have a new line
  246. 8:33and then you you keep you kind of cycle
  247. 8:35through it. Parquets are stored that
  248. 8:37what it does is that a whole column is
  249. 8:39stored and you kind of look through a
  250. 8:41column and there's information about the
  251. 8:43column stored at the beginning. And so
  252. 8:45it can be much more efficient and kind
  253. 8:46of compressed a lot more compactly. They
  254. 8:49tend to be more efficient ways of
  255. 8:50storing data um directly.
  256. 8:54And DuckDB sits on top of it and is very
  257. 8:56very fast. It's kind of one of the
  258. 8:57fastest ways of working with data. In
  259. 9:00Pandas there's something called Polars,
  260. 9:01which is similar.
  261. 9:04But DuckDB is a really nice one. I kind
  262. 9:06of encourage researchers to use it.
  263. 9:07There's also you could use something
  264. 9:09called SQLite. The main reason I'm
  265. 9:11encouraging this is that if often
  266. 9:13relational databases you have to do all
  267. 9:15this work to set up a server. Mhm. The
  268. 9:18SQLite and DuckDB are both ways of
  269. 9:20getting the benefits of relational
  270. 9:22databases without having to do anything
  271. 9:24complicated like set up a server. So
  272. 9:26that's why we're going to do this.
  273. 9:27>> up a server. It's everything on No, you
  274. 9:28don't have to do anything. Yeah, yeah,
  275. 9:29it's just a file that sits there and
  276. 9:31you'll work with it and Python or R
  277. 9:34can both directly query it without
  278. 9:36anything special. So it's just a really
  279. 9:38nice way of being able to work with big
  280. 9:40data sets very efficiently. Mhm.
  281. 9:43So what we're going to do now is
  282. 9:48we are going to split this screen here.
  283. 9:51If you remember we talked about one of
  284. 9:53the benefits of um
  285. 9:56having these
  286. 9:59this type go this is called ghosty. So
  287. 10:01this is a terminal that we're using. If
  288. 10:03you remember Marcus, we talked about
  289. 10:04this and one of the things I told you
  290. 10:06was that it can be very nice to have
  291. 10:07these things so you can have things side
  292. 10:08by side for example. And you'll see that
  293. 10:11if you can see that now I have two
  294. 10:13terminals side by side and so one thing
  295. 10:15I can do is I can look at the prompt
  296. 10:17here that I was going to do and on the
  297. 10:20other one what I'll do is I'll make a a
  298. 10:22folder
  299. 10:24um
  300. 10:25and we'll go into it. Yes. And we'll say
  301. 10:27okay now we're going to log load Claude.
  302. 10:31So here we So here we're going to load
  303. 10:32Claude
  304. 10:33and
  305. 10:35now we have it. So here we're inside it
  306. 10:37says welcome back and I'm going to take
  307. 10:39this prompt over here and I'm going to
  308. 10:42copy it.
  309. 10:44The only complication that we're going
  310. 10:46to do run into is so okay so it doesn't
  311. 10:50want me to
  312. 10:51do that.
  313. 10:52This is the problem with the slightly
  314. 10:54big size. So I'm just going to make it
  315. 10:55smaller so I can copy it all at once.
  316. 10:58And
  317. 11:00going to copy this and we'll make it
  318. 11:02bigger again.
  319. 11:03And I'll go over here and I'm going to
  320. 11:04paste it in. And the one thing I'm going
  321. 11:06to say is focus only on this
  322. 11:09subdirectory.
  323. 11:11Don't scout in the folder above. So one
  324. 11:14thing that it will do is
  325. 11:16it will start looking at other folders
  326. 11:19in this directory and so of course I've
  327. 11:20built these videos to sort of
  328. 11:24do here but of course if it starts
  329. 11:25looking up above it'll say oh this is
  330. 11:27part of a broader educational series and
  331. 11:29so I'm going to say let's focus just
  332. 11:31here. Don't go scouting everywhere else.
  333. 11:34Um
  334. 11:35the
  335. 11:38you could do more things to kind of
  336. 11:39prevent it from knowing what's going on.
  337. 11:41That's called sandboxing but I don't
  338. 11:42want to kind of deal with all those
  339. 11:44issues. So I'm going to do this so I've
  340. 11:45pasted this prompt over and now I am
  341. 11:47going to
  342. 11:49um
  343. 11:50uh
  344. 11:52run it here. So it's going to do this.
  345. 11:55So it I I want to build a country level
  346. 11:57data set that looks like this blah blah
  347. 11:58blah. So now we can read what it's
  348. 12:00saying and I'll even make it a little
  349. 12:02bit bigger so we can focus on this part.
  350. 12:05So it says let me start by exploring the
  351. 12:07existing
  352. 12:08things. So it didn't listen to me.
  353. 12:10So it's very annoying. I'm going to say
  354. 12:11no you can't read the other folders. So
  355. 12:14it's going to get very annoying. So I'm
  356. 12:16going to say no don't read these. Yes
  357. 12:19you can do web search commands and no
  358. 12:21you can't read in there and
  359. 12:23no you can't read it. So now it's useful
  360. 12:26to look at um
  361. 12:28uh
  362. 12:29what's going on. So it's doing two
  363. 12:31things. So it's trying to understand
  364. 12:32what's going on in here. It's it's
  365. 12:35Let me just pause before I let it run
  366. 12:36more which is that it says let me
  367. 12:38explore begin by exploring the project
  368. 12:40structure and any related files and then
  369. 12:41research the data formats to build a
  370. 12:43plan. So what's interesting about this
  371. 12:45is that it's launched two agents. So if
  372. 12:47you remember we talked about this last
  373. 12:49time that agents are kind of sub agents
  374. 12:51where it sends out to do things. And so
  375. 12:53what it's done here is it's launched two
  376. 12:55things. One a bunch of scouts to figure
  377. 12:58out what's going on in here and then the
  378. 13:00other is to research the data formats.
  379. 13:02And it's doing these in parallel. So
  380. 13:04these are two different kind of agents
  381. 13:06that have been sent out. And so I'm
  382. 13:08going to say yes you So this one is
  383. 13:10going to be allowed to search and I am
  384. 13:12not going to allow it to look here and
  385. 13:16no it's going to not be allowed to find
  386. 13:18anything in the previous one and then
  387. 13:20I'll allow it to look more. I'm going to
  388. 13:21I'm allowing it to kind of see here it
  389. 13:23it's really really wants to. So what I'm
  390. 13:26going to do
  391. 13:28I think if it keeps asking me so okay so
  392. 13:30now what's useful is let me describe
  393. 13:32you. So if you look here this is what it
  394. 13:34does. Remember we talked about how
  395. 13:35agents work. They have their own prompt.
  396. 13:38Part of the reason they use agents is so
  397. 13:39that it doesn't use up your own context
  398. 13:42window. So this one it's saying explore
  399. 13:44project structure says explore this and
  400. 13:46parent directory to understand what
  401. 13:48files are there. What related files are
  402. 13:49there. Any existing things. Be thorough.
  403. 13:52Report the full content of key files. So
  404. 13:54it's looking
  405. 13:55and I'm not letting it do a lot of these
  406. 13:56things. And
  407. 13:58>> makes a big difference?
  408. 14:00I'm sorry. Say again. If you say be
  409. 14:02thorough
  410. 14:03Yes so I didn't tell it to do this.
  411. 14:05Claude wrote this prompt. Oh.
  412. 14:08And it's probably
  413. 14:10it's probably
  414. 14:11Anthropic has sort of learned that this
  415. 14:13is a really useful thing to do to say
  416. 14:16like be thorough. So yes telling it to
  417. 14:17be thorough is good so that it double
  418. 14:19checked itself. And then this one to
  419. 14:21research the format it says research the
  420. 14:22Home Mortgage Disclosure Act data
  421. 14:24formats for both pre-2018 and post-2018
  422. 14:27eras. I need to understand the format of
  423. 14:30the data structure how to create a
  424. 14:31crosswalk. What are the key differences?
  425. 14:34Focus on these variables. Search the web
  426. 14:35for data dictionary. So it's searching
  427. 14:37and it's downloading information and
  428. 14:39it's looking through that. And
  429. 14:42um
  430. 14:44so I'm going to continue to not allow it
  431. 14:47to do this and I'm going to allow it to
  432. 14:48fetch this content. It's searching the
  433. 14:50Fed and other places to do this.
  434. 14:52Um
  435. 14:54and I'm going to say yes you can look at
  436. 14:55the the get repository.
  437. 14:58Um
  438. 14:59it's really
  439. 15:01aggressively trying to do this. So what
  440. 15:03I'm going to do is I'm going to say
  441. 15:07Oh interesting. So this one is actually
  442. 15:10um
  443. 15:11I need to find I need So I'm going to
  444. 15:12say
  445. 15:13um
  446. 15:16you should not look in the parent
  447. 15:19directory. So this is useful. So here it
  448. 15:21gave me three options but I want to tell
  449. 15:23it more. So it I can press tab
  450. 15:27and then it will let me add additional
  451. 15:30information. I'm saying no don't look in
  452. 15:32the parent directory.
  453. 15:34And so now it will continue to search
  454. 15:35the web
  455. 15:37and it will continue to search the web.
  456. 15:38So it's doing kind of what you and I
  457. 15:39would ever do if we were running a
  458. 15:41project. And so now you notice so here
  459. 15:43it says it's done exploring the project
  460. 15:45structure. I said no you don't need to
  461. 15:46look at the parent directory.
  462. 15:48Um
  463. 15:50And by the way this is a good example of
  464. 15:53how persistent these agents will be
  465. 15:56unless you kind of directly tell them to
  466. 15:57stop. I kept saying no
  467. 16:00but then it just kept trying new ways to
  468. 16:01look in the parent directory. So I had
  469. 16:03to say no you like you know don't do
  470. 16:06that thing anymore. But why is it so
  471. 16:08persistent? It doesn't make sense.
  472. 16:10Um because when I said no I didn't tell
  473. 16:13it why it shouldn't be doing that. I
  474. 16:16see. And the problem is that that
  475. 16:17explore agent got written its own
  476. 16:19prompt. So it's really interesting. I
  477. 16:21mean it's a very interesting problem. So
  478. 16:23that remember this one here it doesn't
  479. 16:25see anything that I told it. So when I
  480. 16:26wrote that prompt for the what would you
  481. 16:28call the the head agent Yes. uh the
  482. 16:31director
  483. 16:32I told it hey don't look only focus on
  484. 16:35this subdirectory. But then when it went
  485. 16:36to this one it said hey you should look
  486. 16:38in this directory and also look in the
  487. 16:39parent directory. It sort of screwed up
  488. 16:41this prompt. And so the sub agent says
  489. 16:43hey I got to I got to find here.
  490. 16:46So then it says so when it tried to look
  491. 16:49in the bigger
  492. 16:50the parent directory I said permission
  493. 16:52for this tool I denied it remember and
  494. 16:54it says the tool use was rejected. Try a
  495. 16:57different approach. And so it's like oh
  496. 16:59well how am I going to look in there? So
  497. 17:00now it's trying all sorts of ways to do
  498. 17:03it because it's smart. And so it keeps
  499. 17:06saying hey it didn't work try something
  500. 17:07else. And so it's saying like all right
  501. 17:10well there's many ways to skin a cat and
  502. 17:12so it keeps trying new things until I
  503. 17:15said eventually I said
  504. 17:18um
  505. 17:20no
  506. 17:22uh you should not the user said you
  507. 17:24should not look in the parent directory.
  508. 17:26I see their access restrictions. The
  509. 17:28settings indicate this is a constrained
  510. 17:29environment. Based on what I can access
  511. 17:31and restriction in place here is my
  512. 17:32summary.
  513. 17:33So there's really nothing in here.
  514. 17:35The directory is currently empty.
  515. 17:37There's these restrictions. You're
  516. 17:39allowed to do these things. So it's a
  517. 17:40little confused because it doesn't
  518. 17:43understand why I'm making these
  519. 17:45restrictions.
  520. 17:46It's saying that I want to keep this
  521. 17:48isolated and to only focus on external
  522. 17:50data sources.
  523. 17:51So it's going to report this back to the
  524. 17:53head agent.
  525. 17:55And And now we're we have this other one
  526. 17:57that's doing
  527. 17:58this other information. So remember the
  528. 18:00way that I'm toggling back and forth.
  529. 18:01You can't see me doing this Marcus but
  530. 18:03I'm pressing control O to to do things
  531. 18:05back and forth.
  532. 18:06And so now I'm going to continue to let
  533. 18:08it
  534. 18:10see this information.
  535. 18:12So it's still searching the web. You can
  536. 18:13see that it's done 33 different tool
  537. 18:16calls. So it's searching the web in lots
  538. 18:17of different ways and it's reading lots
  539. 18:19of information there.
  540. 18:21>> [snorts]
  541. 18:22>> And that's going to What it's do trying
  542. 18:24to do is it's trying to build
  543. 18:25information
  544. 18:27to then
  545. 18:28construct a crosswalk in a database. So
  546. 18:31now it said excellent I have a thorough
  547. 18:33understanding of both data formats. Let
  548. 18:35me verify the actual column names by
  549. 18:37sampling the real data files and then
  550. 18:39design the plan. So it's going to What
  551. 18:40it's going to do is it's going to kind
  552. 18:41of take a little bit from the data just
  553. 18:44to understand this. So I'm going to say
  554. 18:45yes you can look at this information.
  555. 18:47Now it's
  556. 18:48Now it's doing it again and I'm going to
  557. 18:50say now we've learned how to fix this
  558. 18:52and so I'm going to say no do not look
  559. 18:55in the parent directory.
  560. 18:57Mhm. Stay So why does it So first it
  561. 19:00makes a plan and then it experiments
  562. 19:01with the plan and then only it
  563. 19:03implements step by step.
  564. 19:04>> Exactly. So it's kind of like what you
  565. 19:06would do if you were going to work
  566. 19:08uh
  567. 19:09on on something right? You might say
  568. 19:11uh I'm an One of the key things that
  569. 19:13plan mode does that's a kind of an
  570. 19:15important thing to keep in mind is that
  571. 19:17plan mode will not edit things. So one
  572. 19:20thing remember we're talking about how
  573. 19:21these agents will kind of run wild
  574. 19:23sometimes if you give it the wrong ideas
  575. 19:26is that
  576. 19:29it will
  577. 19:31um
  578. 19:32it will in plan mode it will
  579. 19:33specifically not edit anything which it
  580. 19:35turns the Claude code actually turns
  581. 19:36that ability off.
  582. 19:38And so that can be very nice. If you're
  583. 19:40saying look I know I just want to build
  584. 19:41a plan with you what to do. Let's go
  585. 19:43into plan mode.
  586. 19:45And
  587. 19:46you can actually turn that on directly
  588. 19:47by pressing shift and then tab. And
  589. 19:50that's very important but it will
  590. 19:51automatically
  591. 19:53go into plan mode as well if it
  592. 19:54understands that it's a complicated
  593. 19:55project. So here this is a relatively
  594. 19:57complicated project and so it knows that
  595. 19:59it needs to look up a bunch of
  596. 20:01information about what this looks like.
  597. 20:03So it's looking up resources of what the
  598. 20:05columns look like.
  599. 20:07And it's going to go in there. So it's
  600. 20:09building this up and it's continuing to
  601. 20:11look. You can see that this one is in
  602. 20:13white and that means that it's stopped
  603. 20:15doing this particular sub-agent. This
  604. 20:17plan agent is design designing an
  605. 20:20implementation plan and so it's doing a
  606. 20:22lot of work here by looking what the
  607. 20:23data is. And we can actually read what
  608. 20:25the prompt is that it wrote for it. It
  609. 20:26says, "Designing a system to build a
  610. 20:28county-level panel data set of US
  611. 20:30mortgage lending from HMDA data. Here's
  612. 20:32the context." And tells a bunch of
  613. 20:33information. Downloads Here's what the
  614. 20:36requirements are. Here's the things that
  615. 20:38you need to do and you should use
  616. 20:39DuckDB.
  617. 20:41Here design the architecture for this
  618. 20:43system. File organization, download
  619. 20:45approach, CSV to Parquet conversion
  620. 20:47strategy using DuckDB.
  621. 20:50Harmonization approach. Should we create
  622. 20:53harmonized Parquet files or use DuckDB
  623. 20:54views?
  624. 20:56So what this means is that should I make
  625. 20:57all the files the same or should I do
  626. 20:59that afterwards within DuckDB to make
  627. 21:01them similar?
  628. 21:03Add metadata and then how should I
  629. 21:05handle the lender crosswalk and then
  630. 21:07finally kind of a crosswalk mapping for
  631. 21:10state [snorts] FIPS codes versus state
  632. 21:11>> So can you say again the harmonization
  633. 21:13approach is What what's the
  634. 21:15harmonization approach?
  635. 21:16>> Uh so I think what it's asking so I
  636. 21:19asked it to harmonize the variables if
  637. 21:21you remember that. So I wanted these
  638. 21:22things so that I could have a kind of
  639. 21:23consistent variable across years. They
  640. 21:25change in the data sets themselves. I
  641. 21:28just happen to know that from my own
  642. 21:30work with it. Um
  643. 21:32So what it's asking is, "Well, should I
  644. 21:34change the files themselves or should
  645. 21:37what I do is just store the raw data in
  646. 21:39there and then make a view on top of it
  647. 21:41which is like kind of a renaming
  648. 21:43restructuring." So those are slightly
  649. 21:45different approaches on how you might
  650. 21:46want to harmonize something.
  651. 21:48So it's still thinking very hard right
  652. 21:50now which is kind of interesting. So
  653. 21:51it's it's doing some work here. You can
  654. 21:53see that it's it's searching for
  655. 21:55information about how to do stuff.
  656. 21:57Um
  657. 21:59and
  658. 22:01I have a solid understanding of both. So
  659. 22:04let's read through what it's going to
  660. 22:04say just briefly.
  661. 22:07Um here's the goal. This is gives it the
  662. 22:09context. Goes, "This is the thing it's
  663. 22:11going to write to a file.
  664. 22:13Um build a harmonized data set of US
  665. 22:15mortgage lending. Data spans two
  666. 22:17different formats, pre-2018, post-2018
  667. 22:20with different column names, coding
  668. 22:21schemes, and lender identification
  669. 22:22systems. 250 million rows across 18
  670. 22:25years. All processing uses DuckDB and
  671. 22:28and Parquet."
  672. 22:29So it's going to write a bunch of code
  673. 22:30here. It's going to have six different
  674. 22:32Python files. Um one is for configuring
  675. 22:36things. This is how to download. This is
  676. 22:37the conversion. This is the raw Parquet
  677. 22:40to harmonize Parquet then assemble a
  678. 22:42database. And then this is the thing
  679. 22:44that's going to run all the different
  680. 22:45pieces of the pipeline.
  681. 22:47So this Parquet again is is like a
  682. 22:49column summarized.
  683. 22:50>> Yeah, Parquet think of it as just a
  684. 22:51different version. It's like CSVs, but
  685. 22:53it's column-based. It's just a more
  686. 22:55efficient way of storing the data. And
  687. 22:57it's what DuckDB uses underneath it. So
  688. 23:00now it's going to go through what are
  689. 23:01all the different files, the
  690. 23:02configuration. So here is the template
  691. 23:05um for where the data is. Here is the
  692. 23:08data dictionary of how you map between
  693. 23:09FIPS codes and states, column name
  694. 23:12mappings. So this is how you're going to
  695. 23:14map between columns,
  696. 23:16the schema, and then variation of the
  697. 23:18columns.
  698. 23:21Um
  699. 23:22So then there's this download um this is
  700. 23:25the download procedure. This is how it's
  701. 23:27going to do the downloads. Um
  702. 23:31and then here's the conversion. So I
  703. 23:32think the kind of most of this is just,
  704. 23:34you know, programming to download data
  705. 23:36correctly. Here is how it's going to
  706. 23:38harmonize the schema. So what it's going
  707. 23:40to do is it's going to have years. It's
  708. 23:42going to have a lender identifier. It's
  709. 23:44going to have a lender name. It's going
  710. 23:46to have the county and state code state
  711. 23:48code. It's going to have um
  712. 23:51the loan type, the loan purpose, the
  713. 23:53action taken, and the loan amount, and
  714. 23:55then the the race and income.
  715. 23:57So this is really going to kind of um
  716. 24:00convert this down. Um we could kind of
  717. 24:04We're going to have the raw data. So
  718. 24:06this is going to be a view that it's
  719. 24:07going to create. There's many other
  720. 24:08things we could do as well.
  721. 24:09So one of the things it's going to have
  722. 24:11to do, it's going to have to construct
  723. 24:13some different variable names depending
  724. 24:14on what things look like.
  725. 24:17It's also going to need to do some
  726. 24:18conversions to make things harmonize. Um
  727. 24:21it's going to drop rows where it have
  728. 24:23doesn't information about the county or
  729. 24:24state code. And then it's going to build
  730. 24:26the database based off of this. And so
  731. 24:28this is going to create a kind of a view
  732. 24:30with all the data and then it's going to
  733. 24:32create this metadata and then we're
  734. 24:35going to create this kind of harmonized
  735. 24:37version and the run pipeline is going to
  736. 24:39do all these pieces.
  737. 24:41So after we've done the coding, we're
  738. 24:43going to just run this to download the
  739. 24:44years. This is the different steps it's
  740. 24:46going to try and do. And then you can
  741. 24:48query the data to take a look at it. And
  742. 24:50so this is going to be the things that
  743. 24:51it's going to do. And so now if we're
  744. 24:53comfortable with this, we can say yes
  745. 24:55and auto accept the edits. So now I'm
  746. 24:57going to say
  747. 24:59So one thing that is useful is that this
  748. 25:00will save it into a folder
  749. 25:03um on your computer elsewhere. So in dot
  750. 25:06Claude's if you go to tilde dot Claude
  751. 25:09plans, it will save the plan here if you
  752. 25:11want to look at it later.
  753. 25:14Um
  754. 25:16I'm going to make two That's all. I'm
  755. 25:19going to do this.
  756. 25:21Um
  757. 25:21I'm going to say yes. And so now what it
  758. 25:24will do is it's cleared my whole
  759. 25:26context. So what I've done is I've said,
  760. 25:29"Hey, um
  761. 25:32just get rid of all the work that you
  762. 25:33did before. Just take the plan." So
  763. 25:34remember we talked about context window
  764. 25:36management in the first video? It's
  765. 25:38exactly that. It's saying, "Hey, take
  766. 25:40the plan, read it, and let's start from
  767. 25:41the beginning." And so now it's starting
  768. 25:44from a clean directory. It's going to
  769. 25:45write the seven files.
  770. 25:48Um
  771. 25:49and it's going to create these seven
  772. 25:51ones. Here's a summary of what was
  773. 25:53built. All these different files. So
  774. 25:55config, download, convert, harmonize,
  775. 25:58build, run. A git ignore. So this is if
  776. 26:02you use git. Um this is a way of
  777. 26:04ignoring things that are kind of um not
  778. 26:07important. So now it's telling you you
  779. 26:09should run this. Now
  780. 26:11I could tell it so I could run this
  781. 26:13separately on the command line over
  782. 26:14here.
  783. 26:16Honestly, once you're already doing it
  784. 26:17in here, you can just tell it. You say,
  785. 26:19"Hey, just run it yourself." Um now it's
  786. 26:21going to look at the data. So it's
  787. 26:22saying, "Great, we have all of this
  788. 26:23data. Before we run the full pipeline,
  789. 26:24let's verify the column names in one
  790. 26:27pre-2018 and one post-2018 to make sure
  791. 26:29it's correct." We're going to say um
  792. 26:31yes.
  793. 26:33One thing I want to kind of just say
  794. 26:35quickly here uh Marcus is you know,
  795. 26:38often if I kind of know what's going on
  796. 26:40in these things, there's this meme about
  797. 26:43you know these uh these drinking birds
  798. 26:45that kind of they tip back and forth.
  799. 26:46There's this joke about people who use
  800. 26:48this. You know, you're just hitting yes
  801. 26:50every time it kind of does this. Um so
  802. 26:54there's a there's a joke there too of
  803. 26:57like
  804. 26:58it's good to be reading carefully, but
  805. 27:00if you kind of trust that most of the
  806. 27:02time it's working reasonably well, you
  807. 27:03can kind of you could either kind of
  808. 27:05move very quickly if this can be very
  809. 27:07quick.
  810. 27:11In future videos
  811. 27:13um
  812. 27:14in future videos we'll talk about ways
  813. 27:16in which you can actually do this in
  814. 27:17which you don't have to give any input
  815. 27:19and you can kind of let it make
  816. 27:20decisions on its own, but then of course
  817. 27:21you have to check the work. And that's
  818. 27:23called that's called like um
  819. 27:26What's called YOLO mode. Um so now it's
  820. 27:28going to try and convert everything.
  821. 27:30YOLO mode. Yeah, you only live once. So
  822. 27:32now I'm going to let it convert one of
  823. 27:34the files
  824. 27:35into a Parquet.
  825. 27:37So it's going to try and do this.
  826. 27:39>> [snorts]
  827. 27:53>> So now it says, "2017 converted
  828. 27:55successfully. 14 million rows, 114
  829. 27:58megabyte Parquet." So just as a a sense,
  830. 28:01right? So remember I was talking about
  831. 28:02how 2017 is 1.7 gigs as a CSV. When it's
  832. 28:06a Parquet file,
  833. 28:08um it turns it's ends up being 100 megs.
  834. 28:12I see.
  835. 28:12>> So this is a much more efficient ways of
  836. 28:13storing data.
  837. 28:16So it somehow compresses it.
  838. 28:18Yeah, because it ends up not needing as
  839. 28:21much um
  840. 28:23space [snorts]
  841. 28:24for a lot of the things.
  842. 28:25>> same information content.
  843. 28:27Exactly. It's just compressed much more
  844. 28:30um efficiently.
  845. 28:31So now it's going to try and harmonize
  846. 28:33for 2017. It's going to run the
  847. 28:34harmonization.
  848. 28:38And so it says, "Looks like there's an
  849. 28:39issue. Works. The respondent name
  850. 28:41warning is expected because it's not in
  851. 28:43these files. It'll be null. Now we're
  852. 28:45going to test a post-2018 year. Let me
  853. 28:47use 2024 because it's smaller."
  854. 28:51So now it's going to run this again.
  855. 28:52This is the one that converts it to a
  856. 28:54Parquet.
  857. 29:07So this one
  858. 29:092014 is a 4.3 gigabyte file and now it's
  859. 29:12450 megabytes.
  860. 29:14And I noticed the column I noticed the
  861. 29:16column names for post-2018. It converted
  862. 29:18hyphens to nothing, not underscores.
  863. 29:20This is different than I expected. The
  864. 29:23actual thing is this. I need to update
  865. 29:24this to make it work. So this is what's
  866. 29:26called thinking. This is it's basically
  867. 29:28it's figuring stuff out in the
  868. 29:30background.
  869. 29:31Uh it's now going to kind of try and
  870. 29:34make these consistent. So it now is
  871. 29:38verifying these. It's created kind of
  872. 29:40two tables. It has two years. It's
  873. 29:42building a database and the data looks
  874. 29:43correct.
  875. 29:45Okay. Los Angeles, Maricopa, Cook
  876. 29:48County, and Harris County are the top
  877. 29:50counties as expected. So, Cook County is
  878. 29:52in Chicago. I don't know where Harris
  879. 29:54County is. I think Maricopa is in
  880. 29:55California. I don't know where Harris
  881. 29:57County is. Um
  882. 30:00Let me remain that
  883. 30:01Let me run the remaining 16 years
  884. 30:05through convert and harmonize. I'll kick
  885. 30:06these off as a background task
  886. 30:08and I'll check these periodically. So,
  887. 30:10what it's saying is that it's going to
  888. 30:12um run these.
  889. 30:14But, um it can just run right this is
  890. 30:17the same thing as if you ran it in
  891. 30:18Python. So, it doesn't need to stop
  892. 30:20Claude per se. So, that what happens
  893. 30:22here is what's funny is it's
  894. 30:24to make it so that it will just pause
  895. 30:27and sit here. What it's done is it's
  896. 30:29it's said, "I'm going to wait 60 seconds
  897. 30:31and then look at the output." Okay. So,
  898. 30:35this is fine. You will just leave this
  899. 30:37so that way it could keep working.
  900. 30:39Um
  901. 30:41What I want to kind of show you while
  902. 30:42that's running is you can see
  903. 30:46what the DuckDB database will look like.
  904. 30:48So, in the database
  905. 30:50here
  906. 30:52on the left, this home panel DuckDB
  907. 30:55is sort of stored here.
  908. 30:58This is this file that it's going to try
  909. 30:59and make. It's and it's going through
  910. 31:01now and it is
  911. 31:05making parquet files.
  912. 31:11It's going to slowly doing these all in
  913. 31:13parallel.
  914. 31:15They're almost done.
  915. 31:17But, you can see that this has gone from
  916. 31:18a 70 GB
  917. 31:20process to
  918. 31:22um
  919. 31:24just a basically this is going to end up
  920. 31:26being a GB Mhm. just because it's much
  921. 31:28more efficiently stored. All right. So,
  922. 31:30now it's all done. So, we have all 18
  923. 31:33years converted. We're going to run
  924. 31:35harmonize on the remaining 16 years cuz
  925. 31:38we already did two. So, it's going to
  926. 31:39run this. It's doing this task.
  927. 31:42It's [snorts] just going to um basically
  928. 31:44convert these in the background
  929. 31:46and then it's going to make a basically
  930. 31:48make a a database out of it. So, it's
  931. 31:49going to harmonize all of these.
  932. 31:52It has the same
  933. 31:55It's basically moving these ones. All it
  934. 31:57all 18 years harmonize successfully.
  935. 31:59Now, let's build the final database.
  936. 32:02So, it has 291 million rows across 18
  937. 32:05years. Let me find run the full
  938. 32:07verification query. So, a nice thing
  939. 32:08here you can see if you
  940. 32:10you know, we all did a bunch on
  941. 32:11mortgages is the peak of mortgage
  942. 32:13origination 2007 and then of course
  943. 32:16things fell off tremendously. Yes. Here
  944. 32:18during COVID, this is when interest
  945. 32:20rates fell. So, that's why we had this
  946. 32:21massive increase because there was a ton
  947. 32:23of refinancing.
  948. 32:25And then we've had um
  949. 32:27a bunch of a fall off because interest
  950. 32:29rates have gone up and there's been a
  951. 32:30very kind of little little origination.
  952. 32:32So, now it's all done and we have this
  953. 32:34final database here. So, we can read
  954. 32:37through what it says. Here's the
  955. 32:38pipeline.
  956. 32:39Um one single database. One thing I
  957. 32:41noticed is that these purpose codes
  958. 32:44appear in the 2018 database. These are
  959. 32:47pre-2018 encodings for refinancing and
  960. 32:49home improvement respectively. The
  961. 32:50harmonization maps the raw values
  962. 32:52directly. If you want to recode these
  963. 32:54for this year, I can add that
  964. 32:55transformation. Otherwise, it is um
  965. 33:00it is clean and ready to query. If I
  966. 33:02were doing this myself, I would it but I
  967. 33:04would do it. But, now we're all set. So,
  968. 33:06we can the last thing that we can do
  969. 33:08kind of now now we have the stuff. So,
  970. 33:10let's look at what we have. We built
  971. 33:12this whole pipeline to download the data
  972. 33:14and harmonize thing.
  973. 33:16And now I want to just say, "Okay, well,
  974. 33:17what's something we could do with this?"
  975. 33:19So,
  976. 33:20you know, a nice part of this is we
  977. 33:22could say, "I want to build some
  978. 33:24aggregated data where what we're going
  979. 33:26to do is
  980. 33:28I want to let's just for the purposes of
  981. 33:31this
  982. 33:32I want to build some views. So, this is
  983. 33:34what it's what it means is I want to
  984. 33:35take the data
  985. 33:36and I want to construct the amount of
  986. 33:39origination by county year. Mhm.
  987. 33:42And I can I want to basically build two
  988. 33:44aggregated databases. So, the challenge
  989. 33:46I wanted to do this by lender by year,
  990. 33:49but we'd have to do kind of more work on
  991. 33:50this um cuz I want to classify things by
  992. 33:54um fintech and non-fintech.
  993. 33:56Um
  994. 33:58I think the challenge given what was set
  995. 34:00up is I would need to do more work on
  996. 34:02here. So, what I want to do instead is I
  997. 34:05want to just build out an aggregate
  998. 34:07database where I'm going to say, "What
  999. 34:09are Here's what I'm going to do. I want
  1000. 34:10to build out aggregate database where
  1001. 34:12what I'm going to be getting is county
  1002. 34:14by year, total originations, dollar
  1003. 34:16value, number of active lenders, the HHI
  1004. 34:19which is like the market concentration,
  1005. 34:21the denial rate, and the median loan
  1006. 34:22amount."
  1007. 34:23So, I'm going to
  1008. 34:25um I'm going to ask it to do that.
  1009. 34:29And so, this should be very quick. So,
  1010. 34:31it will just
  1011. 34:33um do this in a few and kind of one very
  1012. 34:36natural thing that we can do and I'll
  1013. 34:38post about this online just to kind of
  1014. 34:40keep this from getting longer is
  1015. 34:42um now we can also do things for example
  1016. 34:44where we could crosswalk on um a
  1017. 34:47question of
  1018. 34:49um
  1019. 34:50shadow banks versus non-shadow banks.
  1020. 34:52This is a big question in the finance
  1021. 34:54literature about how much lending is
  1022. 34:55happening in mortgages among shadow
  1023. 34:57banks. And so, we could very easily try
  1024. 34:59to have this classify things
  1025. 35:02following others um in this approach.
  1026. 35:04So, after we do this one and I show this
  1027. 35:07in the director's cut, we can show the
  1028. 35:09longer version of this. But, I want to
  1029. 35:10kind of show you an example of how this
  1030. 35:12can be done. It's going to say, "Let me
  1031. 35:13create a a function for the build DB
  1032. 35:16Python code which is going to create HHI
  1033. 35:20and then collapse it down."
  1034. 35:24So, it's going to do this. It's going to
  1035. 35:25create a new little function here. So,
  1036. 35:27that's what Claude proposed that, no? Or
  1037. 35:30Yes, it I told it I just want to make
  1038. 35:32this table and it's saying, "Here's how
  1039. 35:34I would do it." And so, I'm letting it
  1040. 35:36go go to town. It's going to run that.
  1041. 35:38It's going to rebuild the database with
  1042. 35:40the new table.
  1043. 35:43So, now it's you'll notice it's found an
  1044. 35:44error here. It says, "2018 LA County
  1045. 35:46must have many fragmented rows instead
  1046. 35:48of one.
  1047. 35:49There must be format variation. Let me
  1048. 35:51investigate." So, it looks like it's run
  1049. 35:53into a problem here in which
  1050. 35:55there are some issues.
  1051. 35:58So, it looks like it found a FIPS code
  1052. 36:00which is inconsistent in some of the
  1053. 36:01post-2018.
  1054. 36:04So, it's going to try and
  1055. 36:06Sorry for No, no, go ahead. Yeah, yeah.
  1056. 36:09>> What are FIPS codes?
  1057. 36:10Mhm.
  1058. 36:11FIPS, what does FIPS stand for?
  1059. 36:14Oh, FIPS, good question. It stands for
  1060. 36:16Federal
  1061. 36:19Good question. I don't actually know.
  1062. 36:21It's a Federal Information Processing
  1063. 36:23something. It's a So, FIPS is a way of
  1064. 36:26you would get these long codes. Um so,
  1065. 36:29state it's going to be a two-digit code.
  1066. 36:31County is it's the state plus a
  1067. 36:33three-digit county code. And then you
  1068. 36:35can actually aggregate it to the
  1069. 36:38This is the same code that gets used for
  1070. 36:39example for census blocks and census
  1071. 36:41tracts. It's a long um multi-numeric
  1072. 36:45thing. And so, what it's done here is
  1073. 36:46it's figured out what the problem was.
  1074. 36:49The group by here
  1075. 36:51um
  1076. 36:52we need to derive the state FIPS code
  1077. 36:55correctly. It looks like there were some
  1078. 36:56errors there. So, now it is done this
  1079. 36:58correctly.
  1080. 37:00And it has one row per county year. LA
  1081. 37:03County shows a clean time series across
  1082. 37:05all 18 years. Tells a nice story. So, it
  1083. 37:08looks like it's constructed this. And
  1084. 37:09so, now what I'm going to ask it to do
  1085. 37:11is to make a histogram of HHI for across
  1086. 37:13counties for 2007, 2015, 2021,
  1087. 37:18and 2024 and uh make a four-panel graph.
  1088. 37:22Okay. Um
  1089. 37:25Um
  1090. 37:28The reason I'm going to do this uh
  1091. 37:30make this H uh histogram
  1092. 37:34uh dollar weighted.
  1093. 37:36Mhm.
  1094. 37:38So,
  1095. 37:40the reason I might be interested in this
  1096. 37:41is I want to understand kind of how
  1097. 37:42changing
  1098. 37:44um lender concentration has varied over
  1099. 37:46time. So, um HHIs that are that are much
  1100. 37:49larger are going to reflect counties
  1101. 37:51where there's much more concentration
  1102. 37:53for a single lender. What is HHI?
  1103. 37:55Herfindahl Index? Herfindahl Index,
  1104. 37:57exactly. It stands for that. I forget
  1105. 37:59the Herfindahl-Hirschman Index.
  1106. 38:02Um that's right. Hirschman always gets
  1107. 38:04the short shrift when people describe
  1108. 38:06it. Mhm. Um
  1109. 38:08Which one is
  1110. 38:10>> and it does that very, very quickly. So,
  1111. 38:11you'll see it's already constructed
  1112. 38:13this.
  1113. 38:14And
  1114. 38:15um
  1115. 38:17Once it's done here, it's going to have
  1116. 38:19its own opinion. Um
  1117. 38:23It's going to say, "It's remarkably low
  1118. 38:26across all four years.
  1119. 38:28Um the weighted mean ranges from 308 to
  1120. 38:31356.
  1121. 38:33Um
  1122. 38:34The big dollar counties have hundreds of
  1123. 38:36competing ones. It's very right skewed.
  1124. 38:38So, that you know, the rural counties
  1125. 38:39tend to be um
  1126. 38:41very concentrated. This was the most
  1127. 38:43competitive, whereas these two are tied.
  1128. 38:47So, I'm going to What I'm going to do
  1129. 38:48So, the last thing that I want to do um
  1130. 38:52All right. So, the last thing So, this
  1131. 38:53is kind of uh
  1132. 38:54I I'm going to
  1133. 38:56Let me actually
  1134. 38:58show you here. Marcus, if it's okay, I
  1135. 39:00want to
  1136. 39:00>> up the the PNG file here?
  1137. 39:02>> Yes. So, I want to open it so you can
  1138. 39:04see it. So, I'm going to share this now.
  1139. 39:05I'm going to switch my screen for a
  1140. 39:06second and share it. So, I want to be
  1141. 39:08able to show you what that looks like.
  1142. 39:10Um
  1143. 39:12So, now
  1144. 39:13um
  1145. 39:15Where did it save it? Saved it under
  1146. 39:16data. So, now we can look at this
  1147. 39:18figure.
  1148. 39:21Now, it's very funny to me that it used
  1149. 39:23that um
  1150. 39:28So, here is
  1151. 39:30what it looks like. So, it made this
  1152. 39:32one.
  1153. 39:33If you remember
  1154. 39:35I didn't tell it anything of what the
  1155. 39:36figure to look like. This is all
  1156. 39:37defaults.
  1157. 39:39I frankly think it would have been very
  1158. 39:40ugly. Um
  1159. 39:43I think the one thing that would be
  1160. 39:44interesting here if you could do for
  1161. 39:45example is you could also ask now you
  1162. 39:47could say like let's compare across
  1163. 39:49counties. So you could do a scatter
  1164. 39:50plot. You could say how has this kind of
  1165. 39:52changed over time? Kind of the real
  1166. 39:54thing that's interesting though is is
  1167. 39:56that the mean concentration has gone up
  1168. 39:59but I would say that it hasn't
  1169. 40:00dramatically shifted across these
  1170. 40:02hugely. Um it's a relatively competitive
  1171. 40:05industry although who are the major
  1172. 40:07players here maybe have changed a little
  1173. 40:09bit.
  1174. 40:10Um
  1175. 40:12As a kind of the key benefit here that I
  1176. 40:14just want to describe to you is
  1177. 40:16um
  1178. 40:17what I'm going to do now is I'll just go
  1179. 40:18back to the the the um
  1180. 40:21the command line
  1181. 40:23is to tell you
  1182. 40:28I just want to kind of show you very
  1183. 40:30quickly
  1184. 40:31um
  1185. 40:33how you could use this DuckDB. So like
  1186. 40:34just to give you a sense of what this
  1187. 40:36looks like. So in the data set um
  1188. 40:39we are
  1189. 40:41um here
  1190. 40:43and we take the the data
  1191. 40:47Mhm. and we look at the DuckDB file we
  1192. 40:49can run DuckDB in and
  1193. 40:51um
  1194. 40:53we can take a look at what's inside of
  1195. 40:55it. So I mentioned that this is a great
  1196. 40:57program. This is independent of looking
  1197. 40:58at this is so on the left here I'll make
  1198. 41:00it bigger so you can see it. This is I'm
  1199. 41:02now inside I've run DuckDB to look at
  1200. 41:05this thing and I can say show me the
  1201. 41:06tables um in here. And so now what I
  1202. 41:08have is a bunch of different tables. So
  1203. 41:10I have the main data here. I have the
  1204. 41:12metadata. This is what my um
  1205. 41:15my LLM would use and then I've made this
  1206. 41:17new thing called county year. So if you
  1207. 41:20describe county year
  1208. 41:22this is a a
  1209. 41:23uh this is this thing that I just made.
  1210. 41:26Um so I have all this information. I can
  1211. 41:28also describe the underlying raw data.
  1212. 41:32And you can see that this is kind of
  1213. 41:34what useful about it is it it gets
  1214. 41:35stored very efficiently. It has the the
  1215. 41:38strings. It has the loan type and it has
  1216. 41:40the loan purpose, the amount, the
  1217. 41:42origination, different pieces. I've
  1218. 41:44selected to a subset of things so I
  1219. 41:46could incorporate and do more if I
  1220. 41:48wanted um in the raw data but this is
  1221. 41:51just a very useful way of structuring
  1222. 41:53data. Now I have one file that I just
  1223. 41:55point the LLM to if I'm going to do
  1224. 41:57something.
  1225. 41:58So what I'm going to do now as a last um
  1226. 42:01exercise is
  1227. 42:03um what we're going to do is we are
  1228. 42:06going to ask um
  1229. 42:09we're going to ask the LLM to
  1230. 42:16um try and replicate some some um
  1231. 42:19labeling that comes from the finance
  1232. 42:22literature. So there's
  1233. 42:24been work of people trying to label what
  1234. 42:25are fintechs or shadow banks in the
  1235. 42:27mortgage literature. So what I'm going
  1236. 42:29to do is I'm going to say um I want to
  1237. 42:31classify lenders as fintech or shadow
  1238. 42:34banks versus traditional banks. Let's
  1239. 42:36start with the lending classification
  1240. 42:38from Fooster, Placer, Schnabl and
  1241. 42:40Victory which is a paper uh
  1242. 42:42in the Review of Financial Studies. They
  1243. 42:44have a list in that paper. I'm going to
  1244. 42:46use that as a base and then I want to
  1245. 42:47extend the classification to cover these
  1246. 42:49other names. So store it in a lender
  1247. 42:51classification and document what's going
  1248. 42:53on here. So
  1249. 42:54I'm what I'm going to do is I'm going to
  1250. 42:55say this and then I'm going to ask
  1251. 42:58tell me what it would take to do this
  1252. 43:03task before you um try anything
  1253. 43:08complicated.
  1254. 43:10Is this feasible?
  1255. 43:12What might be missing?
  1256. 43:15So we're going to we're going to ask it
  1257. 43:16to do this now and we'll see kind of
  1258. 43:18what it's able to do.
  1259. 43:20Good question to ask before diving in.
  1260. 43:22So this is very sycophantic. Let me
  1261. 43:24check what we actually have to work
  1262. 43:26with.
  1263. 43:29So it's reading the DuckDB database. So
  1264. 43:33underneath here it's looking it's
  1265. 43:34looking at the names and so it sees that
  1266. 43:36there's no names. So that's a big
  1267. 43:37problem. Yes. And that was why I was
  1268. 43:41telling you earlier that it will see
  1269. 43:42kind of how doable it is um and it might
  1270. 43:45need to kind of construct
  1271. 43:48I see. So it's going to go back to the
  1272. 43:50original data. What?
  1273. 43:51Yeah, exactly. So it's going to look to
  1274. 43:53see what's in there.
  1275. 43:55Um
  1276. 43:56and it's going to figure it out for me.
  1277. 43:57This is a little bit like you might ask
  1278. 43:59an RA, right? You might say hey
  1279. 44:01can you I want to do this. What is that
  1280. 44:03going to entail?
  1281. 44:07So it's looking at different uh
  1282. 44:09different files. My recollection here is
  1283. 44:11that what it needs to do is it needs to
  1284. 44:15um
  1285. 44:17figure out what the names are in here.
  1286. 44:20And so there's a crosswalk in this data.
  1287. 44:23Mhm. We would need to download this
  1288. 44:25data. This is a panel data set where
  1289. 44:27we'd need to do the here. And so it's
  1290. 44:29say it's going to say well, here's
  1291. 44:31what's missing. We have all the lender
  1292. 44:33identifiers but we have no names and no
  1293. 44:35institution type.
  1294. 44:37So what do we need? We need these HMDA
  1295. 44:39panel or trans middle sheet transmission
  1296. 44:41trans middle sheet files. Mhm. They are
  1297. 44:44going to have a bunch of information
  1298. 44:45that links across the two of these.
  1299. 44:48So
  1300. 44:50how can we do that?
  1301. 44:52We need a name we need the names to do
  1302. 44:54this. And so what's feasible? So we
  1303. 44:56could do an additional download to get
  1304. 44:58this. So should I download the panel
  1305. 45:00files? And so do like see if it is
  1306. 45:05feasible to download panel files.
  1307. 45:09And so we can ask.
  1308. 45:13And if it's easy these are tiny files it
  1309. 45:15looks like.
  1310. 45:16And it's going to try and figure out
  1311. 45:18what it's doing.
  1312. 45:19So it's looking it's going to it's
  1313. 45:21thinking about it and so now it's doing
  1314. 45:23it's how to download these files.
  1315. 45:25And so it's it's remember this is a an
  1316. 45:28agent that it's spun out now to look for
  1317. 45:30this and it's researched how to do this.
  1318. 45:33Look for these sources.
  1319. 45:35And now try and figure out if it's
  1320. 45:37doable.
  1321. 45:39So it's looking.
  1322. 45:41And it looks like it's done and now or
  1323. 45:42it's it's researching this right now.
  1324. 45:44It's not done.
  1325. 45:45And it's downloaded a bunch. It sees
  1326. 45:47that it looks like it has found one of
  1327. 45:49the data sources. So CFPB has it there
  1328. 45:52for a bunch of these files and I'm going
  1329. 45:53to say yes. So what it's trying to do
  1330. 45:55now is trying to download it. So curl is
  1331. 45:56a command to download data and it's
  1332. 45:58going to download and look at the
  1333. 46:00header.
  1334. 46:01And we're going to say yeah, go ahead.
  1335. 46:04All right. So that took a little while
  1336. 46:06to do this but um just to give you a
  1337. 46:08sense this it did a ton of work
  1338. 46:11basically a huge number uh it it ended
  1339. 46:14up using something like 75,000 tokens to
  1340. 46:16really research on this. And now it has
  1341. 46:18a new plan of what it wants to do. It
  1342. 46:20says all right, here's what we're going
  1343. 46:21to do. We're going to reconstruct this
  1344. 46:23plan. We're going to redo this plan and
  1345. 46:25we're going to deal
  1346. 46:27um
  1347. 46:28Sorry, we're going to basically
  1348. 46:30here's what I found. So it did 75,000
  1349. 46:33tokens
  1350. 46:34to figure out what was going on. It says
  1351. 46:36yes, it's available for all of these
  1352. 46:37years.
  1353. 46:392024 has not been published yet. Um
  1354. 46:43each file is about one it's not there
  1355. 46:45for 2024. That's fine. It's going to use
  1356. 46:48something else but it won't have an
  1357. 46:49other lender code. So let's do it. So it
  1358. 46:52took a while took 7 minutes and 41
  1359. 46:54seconds to figure it out but now it
  1360. 46:56knows how to do it. So we'll say yes, go
  1361. 46:58ahead
  1362. 46:59and implement.
  1363. 47:01So it's going to try and implement this.
  1364. 47:02It's going to download 18 small files.
  1365. 47:04It's going to merge these on to lender
  1366. 47:06ID and then it will have names and then
  1367. 47:08it will subclassify based off of this
  1368. 47:10from the paper. And so it's going to
  1369. 47:13it's going to try and do this.
  1370. 47:15Um
  1371. 47:17and what you'll see so just to give you
  1372. 47:19a sense of how this data set works is
  1373. 47:20that there's a file that's just about
  1374. 47:22the institutions that are there and it
  1375. 47:23has a name and lender codes. And so what
  1376. 47:27you know, these one of the useful ways
  1377. 47:28is that you can kind of classify banks
  1378. 47:30based off of what they look like um in
  1379. 47:32this information.
  1380. 47:34So it's going to try and implement the
  1381. 47:35code. So
  1382. 47:37we'll let this we'll let this run for a
  1383. 47:38second.
  1384. 47:40And so it's made some decisions
  1385. 47:42on what are the core list. So this it
  1386. 47:44knows from Fooster et al. Here's all the
  1387. 47:47Mhm. Names. The names and then it's made
  1388. 47:49it's made some decisions on what are
  1389. 47:51additional fintech loans. So we may or
  1390. 47:53may not agree with these but these are
  1391. 47:55certainly reasonable place to start.
  1392. 47:57Better Mortgage and better.com and SoFi
  1393. 47:59are good place to start.
  1394. 48:01Um [snorts] and now it's going to it
  1395. 48:03basically uh downloaded this data.
  1396. 48:08Um it actually didn't So this is
  1397. 48:10something I didn't wouldn't really like
  1398. 48:12and we didn't specify this so this is
  1399. 48:14why it's doing it. These are small files
  1400. 48:16and so it's just actually just running
  1401. 48:18it from the command it's basically
  1402. 48:19writing it out itself. This is not
  1403. 48:21replicable though. You would you know,
  1404. 48:23this would not be good if you were
  1405. 48:24trying to have a pipeline where you
  1406. 48:26could run it from scratch.
  1407. 48:28So I wouldn't traditionally like that. I
  1408. 48:29would go back and I'd change that. I
  1409. 48:31would say actually no, write a script to
  1410. 48:32download it. Now it's going to load it
  1411. 48:34in.
  1412. 48:35It's got all of these it's understanding
  1413. 48:37the data. Data looks great. We've got
  1414. 48:39this. Got a nonbank.
  1415. 48:42Now it's going to rebuild the database.
  1416. 48:46And now it has its first error.
  1417. 48:49Mhm.
  1418. 48:51Exit code one.
  1419. 48:54So we could see what it says. It's it's
  1420. 48:56kind of
  1421. 48:58How do you look at this? Or adjust?
  1422. 49:01Uh it's the same way as it's I would say
  1423. 49:03press control O and so there was some
  1424. 49:05error that happened there and so we'll
  1425. 49:06say
  1426. 49:07what happened? Oh, they have Windows
  1427. 49:09line ending. So this is the sort of
  1428. 49:10thing I would never know. It says
  1429. 49:12Windows line endings and fixed width
  1430. 49:13paddings. Let me fix the reading
  1431. 49:15options.
  1432. 49:16So I need to add this for these messy
  1433. 49:18pre-2018. This is the kind of thing
  1434. 49:19that's awful when you work with data. Um
  1435. 49:24and so it's updating the code to address
  1436. 49:26this. It's going to rerun it now.
  1437. 49:32Looks like it's excellent. 26 fintech
  1438. 49:34lenders identified all loans all years.
  1439. 49:37Let me verify that these look
  1440. 49:38reasonable.
  1441. 49:43And now it has market share over time.
  1442. 49:46And so what you can see is here's an LA
  1443. 49:48County
  1444. 49:49kind of grown substantially and of
  1445. 49:51course as of 2020 went up to 70%
  1446. 49:54and now it's around 60. And so this is
  1447. 49:56kind of very here's Rocket Mortgage
  1448. 49:58which is a huge lender. It's kind of the
  1449. 49:59largest lender.
  1450. 50:00Um
  1451. 50:02and it looks like it's great. So it's
  1452. 50:04basically created everything exactly
  1453. 50:05from this this classification.
  1454. 50:08Um and now what we could do is I'm going
  1455. 50:10to say, "Please make a figure of the
  1456. 50:13trend in um
  1457. 50:15raw in fintech origination share over
  1458. 50:20time
  1459. 50:21in the data set
  1460. 50:24uh
  1461. 50:25using Kieran Healy styling
  1462. 50:28for um
  1463. 50:30plotting."
  1464. 50:33So now it's going to make a figure.
  1465. 50:35And then we'll look at it and we will
  1466. 50:39summarize.
  1467. 50:40So while this is running
  1468. 50:44So let me kind of while this is running,
  1469. 50:46let me start by summarizing kind of what
  1470. 50:48we did at a high level.
  1471. 50:50I think there's a lot of stuff we did.
  1472. 50:51This was a ended up being really long.
  1473. 50:53I'm sorry for everybody who stuck with
  1474. 50:54us. Appreciate it.
  1475. 50:56The thing that this did was we took big
  1476. 50:59data sets. We kind of worked with Claude
  1477. 51:02code to
  1478. 51:03down write a script to download them, to
  1479. 51:05kind of put them all in the pipeline,
  1480. 51:07and then clean them up and work in a
  1481. 51:08framework that is
  1482. 51:11um
  1483. 51:12kind of
  1484. 51:14lets us work with it very efficiently.
  1485. 51:16So DuckDB is the thing that I was
  1486. 51:17arguing you should use. There are other
  1487. 51:19things like SQLite that you can do, but
  1488. 51:21they don't require a server or anything
  1489. 51:23else and they have a lot of metadata. So
  1490. 51:24now you could take that data set and you
  1491. 51:26could always heart go back to it and
  1492. 51:28then the LLM would kind of understand
  1493. 51:29what's going on.
  1494. 51:31We then did a crosswalk where we unders-
  1495. 51:33we basically mapped information about
  1496. 51:35the lenders directly from the literature
  1497. 51:37and we were able to kind of pull that
  1498. 51:39data in and harmonize a lot of the
  1499. 51:41information there. And that lets us do a
  1500. 51:44lot. This is this data set is actually
  1501. 51:46for a lot of researchers in finance it's
  1502. 51:48kind of one of the main things that
  1503. 51:49you'll start with um when you're working
  1504. 51:50with it. So let me end by kind of
  1505. 51:52showing you what you can see in this
  1506. 51:54data final data set. So I'm going to
  1507. 51:55share it with you. And now it'll look a
  1508. 51:57little nicer than our other figure.
  1509. 52:01So
  1510. 52:02here.
  1511. 52:03So here
  1512. 52:05is you know, it decided to do like this.
  1513. 52:10So this is the
  1514. 52:13um
  1515. 52:14that.
  1516. 52:18It's interesting in that
  1517. 52:20this is basically non-bank lenders,
  1518. 52:22right? So the the light blue here and
  1519. 52:26actually I'll read you what it says
  1520. 52:28here. It's so there's a
  1521. 52:30light blue band is
  1522. 52:32non-mor- non-bank lenders. So there are
  1523. 52:34a lot of non-bank lenders in the United
  1524. 52:36States that make loans and they've
  1525. 52:39always done that. They've always kind of
  1526. 52:40been on the outside. Um this was kind of
  1527. 52:43a bit they were a lot of the ones who
  1528. 52:44were doing securitization and other
  1529. 52:45things. This blue band is non-bank
  1530. 52:47lenders who Fooster and co-authors
  1531. 52:50classify as fintech. And what you can
  1532. 52:52see is that they've just grown as a
  1533. 52:54proportion of overall lending by quite a
  1534. 52:56bit during this period. Now, whether or
  1535. 52:58not these other places are non-fintech
  1536. 53:00is a is a big question, but this is
  1537. 53:02right around when Quicken became big and
  1538. 53:03you can see that they've just grown as
  1539. 53:04an overall share. And more generally,
  1540. 53:07this is the collapse in traditional bank
  1541. 53:09lending overall. They're the residual
  1542. 53:12and they've gone down. They now make up
  1543. 53:14only 40% of all lending relative to
  1544. 53:17um during the crisis and what we
  1545. 53:19>> of the dark blue?
  1546. 53:21Yes. Okay.
  1547. 53:23Um Rocket Mortgage is that's sort of in
  1548. 53:27here and they they kind of consist in
  1549. 53:28here.
  1550. 53:29Um
  1551. 53:31so it's kind of very cool. There's a lot
  1552. 53:33of other things you could do. You could
  1553. 53:34work with Claude to kind of clean this
  1554. 53:35stuff up. All the slow stuff we kind of
  1555. 53:37already done now. And so, you know, I I
  1556. 53:40think I'd really encourage you. There's
  1557. 53:42a lot of really cool big data sets um
  1558. 53:45out there. I've kind of um I've posted
  1559. 53:48online about this, but I just want to
  1560. 53:49tell you like
  1561. 53:50I've done stuff with uh we're not going
  1562. 53:52to make anyone have to watch us download
  1563. 53:55a bunch of big data sets again, but kind
  1564. 53:57of the there's stuff
  1565. 53:59from what's called IPEDS which is
  1566. 54:02information about post-secondary
  1567. 54:03institutions. So if you're interested in
  1568. 54:05colleges or universities the federal
  1569. 54:07government posts a huge amount of
  1570. 54:08information about that that is all
  1571. 54:10structured and I've posted code on how
  1572. 54:12can you harmonize that and put this all
  1573. 54:13into a one big DuckDB database. If
  1574. 54:16you're interested in studying um
  1575. 54:17universities
  1576. 54:18same thing is true for a lot of other
  1577. 54:19databases. And so I think the kind of
  1578. 54:22the world's your oyster if you're
  1579. 54:23interested in working with data, if
  1580. 54:24you're a graduate student, if you're a
  1581. 54:25junior researcher and you want to kind
  1582. 54:27of learn about new data, I think it's
  1583. 54:28become a lot easier to work with these
  1584. 54:30big data sets and kind of cleanly clean
  1585. 54:32and work with them. So hopefully this
  1586. 54:34was useful. Thank you for sticking with
  1587. 54:35us for this long video and um
  1588. 54:38next time I think Marcus we're going to
  1589. 54:40talk about writing and kind of the
  1590. 54:42general ways in which you can use LLMs
  1591. 54:43for those sorts of tasks, writing
  1592. 54:45reports, kind of iterating on proofs and
  1593. 54:48other things, yeah?
  1594. 54:49Very good. Thanks a lot, Paul. Uh so
  1595. 54:52next time we're looking forward how to
  1596. 54:53write your referee report for this
  1597. 54:55project we started today.
  1598. 54:57Exactly. Exactly. All right. Thanks so
  1599. 54:59much, Marcus. Thanks a lot. Thanks to
  1600. 55:01everybody and uh see you soon again
  1601. 55:04for the next mini video.
  1602. 55:08Bye-bye.
  1603. 55:09Bye.
  1604. 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.