Data Analysis: Claude Code for Economists with Paul Goldsmith-Pinkham | Markus' Academy | Ep. 162-2 — Transcript
Full transcript
- 0:09Welcome back everybody for another
- 0:11session of the mini video series with
- 0:13Paul Goldsmith income on cloud code for
- 0:15applied economists.
- 0:17Today we go to the second video.
- 0:20And um
- 0:22We talked last time we talked about how
- 0:24to get started with cloud code we talked
- 0:26about the difference between cloud code
- 0:28and cloud code works and how the
- 0:30difference things are to how to install
- 0:33it and set up the terminal.
- 0:35Today we do part two which is about data
- 0:37analysis workflow and some simple
- 0:39examples before we then move on to data
- 0:41collections, web scraping and many many
- 0:44other tasks coming down the road for
- 0:46different videos. Paul
- 0:48great to have you here with us again and
- 0:50uh let's start with part two.
- 0:52>> Great, thanks so much. I'm really
- 0:54looking forward to this one. So this was
- 0:55fun. So like like you said Marcus, you
- 0:58know, last time we really started with
- 1:00the idea of a um basically a
- 1:06Let me open this up here. We we really
- 1:08were kind of focused on the idea of just
- 1:09installation and we didn't really kind
- 1:10of see
- 1:12what could actually be done. And so what
- 1:14I want to show you now is I want to show
- 1:16you just actually kind of a simple very
- 1:18simple task. So in some ways this is not
- 1:20going to be um
- 1:22This is not going to be a kind of
- 1:23complicated one. This is I think a
- 1:25pretty trivial example. But then we'll
- 1:27kind of get into more complicated ones.
- 1:29So if you're not familiar with things,
- 1:30this might be a good entry point. This
- 1:32is
- 1:33you know
- 1:34Often when we do analyses you kind of
- 1:36assume you have the data. Well and so
- 1:38what I'm going to do is I just want to
- 1:39kind of come in. Often I have these very
- 1:41fun data tasks where I kind of want to
- 1:44just you have a research idea. So like I
- 1:46think Marcus you would be the same as
- 1:47this if you're somebody who
- 1:49you want to have a you have an empirical
- 1:51question. It's a non-trivial question.
- 1:53It's maybe not totally set up in in data
- 1:55set. Like it's not a perfect graph. You
- 1:57maybe Google it. It's you know, they
- 1:58haven't made it yet.
- 2:00You say, "Okay, well, how do I I want to
- 2:01just see that?" You might ask an RA if
- 2:03you're lucky enough to have an RA or you
- 2:04might spend an hour doing it yourself. I
- 2:06want to kind of just show you that this
- 2:08is very easy way to do to do this. So,
- 2:10the question that I kind of want to pose
- 2:12is you know, let's make a graph and I've
- 2:14actually posted this recently on social
- 2:16media to show this
- 2:17is what is the age distribution of
- 2:19homeowners in the United States change
- 2:21over the last 50 years. This is
- 2:22something I've worked on with Kelly Shue
- 2:24and other projects.
- 2:26You know, and we all know kind of
- 2:27inherently there's been this discussion
- 2:29about there's a shift. Younger folks are
- 2:31not owning homes as much as as older
- 2:34folks. So, what I'm going to start with
- 2:36is I'm going to have Claude get the
- 2:37data.
- 2:38And I'm not actually
- 2:40when I started this, I've done it now
- 2:41once as a test project. I don't really
- 2:44remember exactly how to get it and I
- 2:45don't really remember. It's kind of just
- 2:47like you'd ask an RA to do something.
- 2:49So, I'm going to say, "Look, I'm
- 2:50starting a project from scratch. I want
- 2:53to analyze how the age distribution of
- 2:55homeowners in the United States has
- 2:56changed over the last 50 years. I think
- 2:58the Census Bureau publishes
- 3:00homeownership rates by age of
- 3:01homeowners. Potentially the data could
- 3:03be on the Census website or it could be
- 3:05on FRED. So, what I want you to do is
- 3:07download the homeownership rates by age
- 3:08going back as far as possible. Write
- 3:10this as a as a script and then save the
- 3:13raw data as a CSV. Okay? So, it's just a
- 3:15data collection task. So, let's actually
- 3:18just
- 3:19Yeah.
- 3:19>> work on code the same way.
- 3:21>> You could do this in either of these.
- 3:22Yeah, or you could honestly even do this
- 3:24on the website. So, this is the benefit
- 3:26here is I'm going to kind of just do
- 3:27this locally on a
- 3:29I will have this on my laptop after it's
- 3:31done and I kind of don't have to worry
- 3:32about downloading and moving it around.
- 3:34It's just something that will run
- 3:35locally. Co-work, it would be the same
- 3:36exercise.
- 3:37Um
- 3:38I'm going to do this when we when we do
- 3:40it here, I'm going to write this this
- 3:42example here. So, what I'll do now is
- 3:44I'm going to share my screen with the
- 3:46terminal just so that you can have an
- 3:48example of what that looks like. We'll
- 3:49open this up.
- 3:50We have this from last time, so remember
- 3:53I like often to what I'm going to be
- 3:55doing is I'm going to run Claude Claude,
- 3:57so I'm going to run this here.
- 3:59Um
- 4:01and so you you're um we're in this
- 4:03folder here. This is a So, this is a
- 4:05folder I'm already in here. So, I made a
- 4:08test
- 4:09I written this once before, but now
- 4:10we're going to write make a new
- 4:12uh folder in here. We're going to call
- 4:13it test two, which is the same idea.
- 4:16And this is a folder inside this um
- 4:20Basically, I have a set of folders about
- 4:23um these video series that I made a test
- 4:25two. There's nothing in it.
- 4:27And so, I'm just going to launch Claude
- 4:28inside of it.
- 4:30And it says, "Okay."
- 4:32>> actually have to launch Claude again.
- 4:34>> Yeah, so I've you know, so I just run
- 4:36the program and it launches it it
- 4:38launches it up here, you know, when I
- 4:40when I quit. So, I can quit by hitting
- 4:42control C control C.
- 4:44>> Okay.
- 4:45>> And what happens? So, a great example of
- 4:46this would be I'd say So, I I started
- 4:49every time I want to be in the right
- 4:50folder just so that I'm doing this. I
- 4:51just don't want it to kind of look at
- 4:53the other stuff necessarily. I'm going
- 4:55to start from here. So, I'm going to say
- 4:57um
- 4:58So, I can copy and paste or I can just
- 5:00write it myself, but the way that I'm
- 5:01going to do is I'm going to copy and
- 5:02paste. So, it's not actually going to
- 5:04show it. I'll say
- 5:06It will show it once I once I do this
- 5:08here and I'll say, "I'm starting a new
- 5:10project from scratch, blah blah blah
- 5:11blah blah."
- 5:12So, now it's saying So, ignore this
- 5:14warning thing. That's just a skill that
- 5:16I have installed and it says, "Let me
- 5:17research what data is available and then
- 5:18write the download script." So, now it's
- 5:20doing a bunch of calls that we talked
- 5:22about. Remember how we talked about that
- 5:24Claude can use tools. So, it is now
- 5:26using
- 5:28an agent to run tools, which are these
- 5:31web search things. It's searching for
- 5:32these things.
- 5:33And it's asking me if I if it's allowed
- 5:36to do this. Remember we talked about its
- 5:37ability to do things.
- 5:39It wants to go search the web. It's not
- 5:41allowed to until I give it permissions.
- 5:43So, it's going to do a lot of searching.
- 5:45So, rather than say yes a bunch of
- 5:47times, I'm just going to say yes, you
- 5:48can always use web searches. So, this is
- 5:51this is I'm giving it permission to
- 5:52search for anything now.
- 5:54Um in this in this particular folder.
- 5:58And so, it's now searching for all these
- 5:59things. It's thinking.
- 6:01So, this prestidigitating, this is just
- 6:03nonsense that it puts when it's working.
- 6:05If you want to see what it's doing, you
- 6:07can hit control O.
- 6:10And it will show what it's thinking.
- 6:11It's saying, "Okay, I ran an agent." So,
- 6:14an agent um we haven't talked about this
- 6:16yet, Marcus, but um when you asked about
- 6:19cursor, for example, what an LLM will
- 6:22often do is it will spawn
- 6:24a an agent, a sub agent, which has its
- 6:28own context window.
- 6:31And so, what that agent is doing is it's
- 6:32running on its own. It's also a Claude
- 6:34LLM. But, our main agent has said to it,
- 6:37"Hey, you need to go look for census
- 6:39home ownership data." And so, the prompt
- 6:40it gives it is, "Research how to
- 6:42download this by age." This is the kind
- 6:44of thing I should have said
- 6:46originally. It says, "I need to find
- 6:47this. What is available?" and so forth.
- 6:49You should search for all these things,
- 6:51and here's how you're going to do it.
- 6:53And so now, it wants to
- 6:55um look at this content. It's going to
- 6:58fetch data from this. So, it's going to
- 7:00actually try and download stuff from
- 7:01here. And I'm going to say, "Yes, you
- 7:03can download things." So, it's thinking.
- 7:05So, you think about the task that we
- 7:06just gave it, right? The first thing we
- 7:07said is, "Go find this data." So, that
- 7:10was a task that I let it do. I'm letting
- 7:12it do all these things. I'm going to let
- 7:14it do it so that I don't have to keep
- 7:15hitting enter. I'm going to say, "Yes,
- 7:17you can look at stuff on Fred."
- 7:19So, it's doing lots of tool use. So,
- 7:20you'll see it's continuing. It's
- 7:22searching. It's searching.
- 7:24It's looking for this, home ownership
- 7:25rate under 35 by home ownership tables,
- 7:28and so forth. There's a lot of things
- 7:29you can see that it's doing this. And
- 7:31remember we talked about
- 7:33what's an LLM doing, these tokens you
- 7:36are basically its way of saying how much
- 7:38up and down thinking is going on
- 7:40in what's going on. And so, yes, I'm Now
- 7:42it's you notice it switched gears. It
- 7:44said, "Well,
- 7:47it looks like it looks like it switched
- 7:49gears from Fred." So, it says, "Okay,
- 7:50let's look at Let's look at the census."
- 7:52So, we're now going to look at the
- 7:54census. Yeah.
- 7:55>> Can't you have one agent doing Fred and
- 7:56the other one doing
- 7:57>> Yes, so it's not very efficient. So, we
- 7:59could have if we were really in a hurry,
- 8:01>> Okay.
- 8:01>> we could have said
- 8:03"Spawn one agent that searches in one
- 8:05and spawn one agent that searches" That
- 8:06would have been faster. Instead, it's
- 8:08doing it in sequence. That's exactly
- 8:10right. So, often you might have
- 8:11>> in parallel, you have to tell it to do
- 8:14it in
- 8:14>> You don't always. Sometimes it will know
- 8:15to do that, but this I was so vague, I
- 8:18sort of said, "Well, look through Fred,
- 8:20look through this."
- 8:21Often it can be better to do this. So,
- 8:23like the more specific you are in your
- 8:25um query, often the better it will do on
- 8:27these types of tasks.
- 8:29Um
- 8:30So, you can see here it's continuing to
- 8:32search. It's trying a bunch of different
- 8:33things. Um
- 8:35but it really isn't sure kind of what's
- 8:38going on. So, the fact that we were very
- 8:39vague has made this a little slower. Of
- 8:41course, if I knew where the data was and
- 8:42I knew what data I wanted to do even if
- 8:44it wasn't clean,
- 8:46it wouldn't take this long. I just want
- 8:47to kind of give you an example of
- 8:49Sometimes you have an idea of what you
- 8:50want to do. So, now it's found the right
- 8:52data set. So, this is the housing
- 8:53vacancy survey.
- 8:55Um and it's pulling it from in. It says,
- 8:58"Oh, I finally You know, it's finally
- 8:59found some examples of what it's looking
- 9:01for." But, this is the kind of thing
- 9:02that if you just let it go, this is the
- 9:04same thing when you use a research
- 9:05function or something else on Cohort,
- 9:07there's no reason you couldn't have
- 9:08inherently um
- 9:10done this uh
- 9:13for you know, on the web, too, right?
- 9:15These are just This is just the same
- 9:17idea of what's going on. So, we're
- 9:19letting it search. We're letting it
- 9:20search. It takes a little while.
- 9:23Um
- 9:25and then we say, "Yes, don't ask again."
- 9:27It's basically almost found it all.
- 9:31So, what's beneficial here, right, is
- 9:32that if you do this on the web and you
- 9:33gave it kind of permissions, it would
- 9:35just search and then come back to you
- 9:37and you wouldn't have to keep kind of
- 9:38mon- There's no reason we have to
- 9:39monitor this beyond telling it it's okay
- 9:41to search for stuff.
- 9:43>> So, here there's no reasoning going on
- 9:45in a sense. Because it's not like
- 9:46>> There's reasoning going on in the sense
- 9:47that what it does is once it fetches
- 9:49stuff, it's it's basically trying to
- 9:51find something that satisfies the
- 9:53prompt.
- 9:54>> Okay.
- 9:54>> And then it's going to eventually get to
- 9:55a point where it's going to say, "Okay,
- 9:57I found all the data that's relevant.
- 9:58Now we're going to download it and write
- 10:00it down like write a research script."
- 10:01So, the agent is really doing a lot of
- 10:04tool searching to kind of search the
- 10:05web. And this could be faster if you
- 10:07were using other skills. This is the
- 10:09we're really like living in kind of the
- 10:10bare-bones version of this. Um
- 10:13>> Have you done this repeatedly the same
- 10:15thing and it will come up with the same
- 10:16data or at every time or it comes up
- 10:19with different data sources?
- 10:20>> It Well, we'll see cuz this is going to
- 10:22be the second time. My guess is there is
- 10:24really one very good answer for this.
- 10:28It's There's one answer. So, really it
- 10:30should be using the Housing Vacancy
- 10:32Survey, which is in the It's basically
- 10:34the Census has data broken down at the
- 10:36national level by Um in fact, I can show
- 10:39you the picture of what this should look
- 10:41like. There's one video like there's one
- 10:43data set that kind of gets you the gist
- 10:45of what you want it to look like. It
- 10:46will look like
- 10:48this.
- 10:49Um
- 10:51So, I'll just show you while we're
- 10:52waiting while we're waiting in the
- 10:53background we can I can show you what
- 10:54this looks like.
- 10:56Um it will look like this.
- 10:59So, this is the final product. This is
- 11:01what I you know, I used a
- 11:03I did this on my own to make sure that
- 11:05it would work and this is the kind of
- 11:07thing that you get. This comes from the
- 11:08Housing Vacancy Survey. This is kind of
- 11:10the right answer of what it looks like.
- 11:12>> Okay.
- 11:12>> Um
- 11:14So, this is the end result.
- 11:15And you know, what we'll get if we just
- 11:19let it let it cruise for a little bit.
- 11:21>> Well, that's then done the the figure is
- 11:24done also with Claude?
- 11:25>> Yeah, I run all of it. It was done with
- 11:27Claude. So, I mean it uses I used R in
- 11:29the background cuz I'm I tend to use R,
- 11:31but it wrote the R code for everything
- 11:34to do this. I basically just told it
- 11:36what I wanted it to look like they like
- 11:38roughly speaking and it did everything
- 11:40else.
- 11:40>> What are what are the gray
- 11:42things doing?
- 11:44>> What are the gray things? You mean the
- 11:45lines?
- 11:46>> Yes.
- 11:47>> So in this data there is annual data
- 11:50every year of what things look like.
- 11:52But of course that's sort of there's
- 11:53different ways to show what's going on.
- 11:55So what it did was it just showed all
- 11:56the years but then it's it showed that
- 11:58basically the every decade what the what
- 12:00the relative change was you could see
- 12:02that it's kind of shifting
- 12:03discontinuously or not continuously
- 12:05rather.
- 12:06>> And you told it to do it this way.
- 12:08>> Yeah, you know, I kind of I kind of
- 12:10hinted at it. It's kind of a natural way
- 12:11to make that graph but I would be a
- 12:13stretch to say that I told it to make it
- 12:14look exactly like that. That's that
- 12:16would be too much. So you see so now
- 12:18it's done. So what it says is it found
- 12:21two good sources.
- 12:22>> Mhm.
- 12:22>> Um it says
- 12:24So it had a lot of thinking. It says two
- 12:26good sources.
- 12:27One is the Census Bureau table 19
- 12:29quarterly home ownership rates by age
- 12:31from 1994 to the present. I'll use the
- 12:33Census Bureau data since it's the
- 12:34standard home ownership rate measure.
- 12:36Let me first check the environment and
- 12:37check the file um Excel file structure.
- 12:40So now it's doing stuff. So now it's
- 12:42it's basically wants to write um
- 12:45this Python command that's basically
- 12:48checking a bunch of things. It's
- 12:50basically checking versions to kind of
- 12:51understand what's going on. I'm going to
- 12:52say yes you can do that.
- 12:54So that took it about three or four
- 12:56minutes. It found the data. It found
- 12:57some examples. If I wanted I could tell
- 12:59it to use Fred
- 13:01um but it would use a totally different
- 13:02survey. So now it's just going to start
- 13:04inspecting the data. It's running code
- 13:06to kind of look at one of the the files.
- 13:08This is this file here which is an Excel
- 13:10file. It's reading it in Python.
- 13:13And I'm going to say yes you can do that
- 13:15and now it's going to um
- 13:17it basically uh ran into an error.
- 13:21So likely what you need to do
- 13:24So the Census doesn't like what it's
- 13:26doing cuz I'm I'm just querying it and
- 13:28trying to pull it and so it throws
- 13:29something called a 403 error.
- 13:32A 403 error is basically Census wants
- 13:35you to pretend to be a person. Like you
- 13:37can't just it doesn't want just bots
- 13:39that are doing it. So I'm saying, "Hey,
- 13:41I'm a user." It puts a little header on
- 13:43it and now it should and now it should
- 13:45um be able to do this using the requests
- 13:47package.
- 13:48Um this becomes an issue as you start to
- 13:50scrape stuff. If you're a person who's
- 13:52interested in scraping, you have to be
- 13:54very um careful and diligent about the
- 13:57way that you interact with websites
- 13:58because
- 14:00um a lot of websites set stuff up so
- 14:02that they aren't just basically
- 14:04bombarded by requests from
- 14:06uh LLMs or just from web scraping
- 14:09programs.
- 14:10>> That's what we do in the next video, no?
- 14:12>> Yes, exactly. And so we'll talk about
- 14:13that for here and so you can see here is
- 14:15it's printing out stuff from the data.
- 14:17It's saying, "Here is what you know, it
- 14:19wrote this code. It pulled the data." It
- 14:21basically pulled this data from these
- 14:23various places. Here's 1994 the first
- 14:26has quarterly data on home ownership
- 14:27rates
- 14:29at the national level and so now it's
- 14:31going
- 14:32um
- 14:33to
- 14:37It's also going to check FRED now. So
- 14:40it's checking FRED as well.
- 14:42FRED is only has I think previous data
- 14:44has only a little bit of data.
- 14:47It's not great. So it's basically trying
- 14:48out all the different It's exactly what
- 14:50you'd want an RA to do.
- 14:52And now it's going to say, "Oh, let's
- 14:53see if there's older Census data."
- 14:55Cuz we only got back to 1994 and
- 14:57actually we'd like to have more data. So
- 14:59what it's going to do is let's table
- 15:00seven might have annual data by age
- 15:02going back further. So this is the kind
- 15:04of thing you'd exactly want your RA to I
- 15:06didn't as you can see I didn't tell it
- 15:08to do any of this. No, I just said go
- 15:09back as far as you can.
- 15:12So
- 15:13>> Cool work. It will put the same. It does
- 15:15It does not ask you to prompt. It's the
- 15:17same as
- 15:17>> So what we can do, why don't we do that
- 15:19while Let me just uh quickly copy that
- 15:21over so that we can do it in parallel.
- 15:23Um very quickly, let me just move this
- 15:25over while we're here. 1 second.
- 15:28Um I'm just going to copy this again.
- 15:30We'll go to Cogram.
- 15:32Um since just so for you people who
- 15:35weren't with us on the last video, let
- 15:37me just show you on Cogram what this
- 15:39would look like, what Marcus is asking.
- 15:41So it would be here.
- 15:43So here's Cogram, which is an
- 15:44application that's kind of doing a
- 15:46similar thing.
- 15:47I'm going to make a new folder for this
- 15:49to work in just very quickly so that we
- 15:51have a space for it. I'm going to call
- 15:53that um
- 15:56um we'll call it temp three in there.
- 16:00And if we go here, we'll tell it to work
- 16:03in a folder. We'll say work in the
- 16:06Marcus folder for video two in temp
- 16:08three.
- 16:10Um and we'll say yes, you can work you
- 16:12can change things in here. And then
- 16:14we'll say let's go. So we'll just let it
- 16:17run and we'll see what it does. Um I
- 16:20don't work in nothing.
- 16:21>> same amount of time. It's not faster or
- 16:22slower.
- 16:23>> No, it shouldn't be. I mean, the only
- 16:25way that it would be any faster or
- 16:26slower. So it's you know, we'll just let
- 16:28it go here and we'll see. It may
- 16:29actually be faster in some ways because
- 16:31you know, there's kind of
- 16:33uh with the terminal, we've kind of
- 16:37we may have a could there may have to be
- 16:39more things that are approved. But um so
- 16:42here we're going to just say yes, you
- 16:44can do this. I could have made this much
- 16:45faster by the way. If I had just said,
- 16:47"Yes, you can run Python things." and it
- 16:48would do this faster.
- 16:50So you can see it's basically reading
- 16:51through the code. It's trying to see
- 16:52what's going on here. Um this is just a
- 16:55bunch of data. It basically is parsing
- 16:57all the data that's in this structure.
- 16:59>> Mhm.
- 16:59>> Table 12 has household counts by age so
- 17:02I can compute rates from that. Um so
- 17:04it's really gotten a lot of
- 17:07it understands the structure of the data
- 17:08really, really well. Um
- 17:11so I'll keep you apprised of what's
- 17:13going on with Cogram at the same time
- 17:14this is going on. Cogram is searching
- 17:16the web just like with the the other
- 17:18one. So, it should be very similar.
- 17:19There's no reason that it shouldn't be
- 17:21um
- 17:22So, I'm just going to say yes, you can
- 17:23run all the Python scripts that you
- 17:24desire.
- 17:26That way it will I don't have to keep
- 17:27saying yes. So, now it's just trying to
- 17:30basically see the structure of the data
- 17:32and part Now, it's the same way that you
- 17:35if you were working with this, Marcus,
- 17:37you would kind of look at each file and
- 17:38you try to understand what the structure
- 17:39is and then you'd write a little script
- 17:41that kind of
- 17:42>> Nice.
- 17:43>> parses everything carefully, right?
- 17:46>> But, it takes it takes 6 minutes, 21
- 17:48seconds to start.
- 17:49>> Yeah, it's I mean it's So, now it says,
- 17:51"Okay, I have a clear picture of both
- 17:53data sources. Let me write the script."
- 17:54So, this is, you know, faster than I
- 17:56would have done it, for sure.
- 17:57>> Yes.
- 17:58>> Um
- 17:59So, for
- 18:01uh
- 18:02Interestingly, Claude uh Claude Co-work
- 18:05really struggled because it
- 18:08it uh
- 18:09it ran into that same user agent
- 18:11problem.
- 18:12>> Mhm.
- 18:13>> So, it struggled with this idea that,
- 18:16you know, it couldn't log in.
- 18:18Um
- 18:19>> Do you want to go back to the Co-work or
- 18:20>> Yeah, let me just let me quickly just
- 18:22show you what it's doing here. So, it
- 18:23wrote it wrote the script. So, now it
- 18:25understands the data.
- 18:26So, remember just, Marcus, the way we
- 18:28talked about the context windows, it has
- 18:29all that information. It's kind of like
- 18:31it can keep all of that in its memory
- 18:33and now it's like, "All right, let me
- 18:34write a script that parses stuff that
- 18:36looks like this." And so, it says,
- 18:37"Okay." And so, it's going to write this
- 18:39file
- 18:40in here.
- 18:41Um it's going to write a file that
- 18:42pretends to be a user agent. It's going
- 18:44to pull from these age groups. It's
- 18:46going to have these age patterns. It's
- 18:47going to download files. It's going to
- 18:48parse them.
- 18:50And it's even it's going to parse two
- 18:52different tables.
- 18:53And then it's going to download the data
- 18:55and then it's going to construct these
- 18:56files and then it's and then it's done
- 18:58and you'll say, "Yes."
- 18:59And so, then
- 19:01um Oops, sorry. Then, I'll just go into
- 19:06uh
- 19:06>> Just to make sure that I understand.
- 19:08>> Yeah.
- 19:08>> So, you already downloaded already, but
- 19:10then is it all right a script and
- 19:11download it again?
- 19:13>> No, cuz it didn't really download all of
- 19:15it. I mean, it did a little bit, but
- 19:16really what it did was it downloaded and
- 19:18just read a little bit of it cuz it
- 19:19doesn't want to download and look at
- 19:21everything because that will blow out
- 19:22its context window. So, often these
- 19:24things are It's the same way that you
- 19:25might not, you know, imagine you had a
- 19:26perfect memory, Marcus. You wouldn't
- 19:28like take a thing and then look at every
- 19:30row and then be like, "Okay, I'm now
- 19:31going to look at the every row." It's
- 19:32going to say, "Let me just understand
- 19:34It kind of knows it. And so, what it did
- 19:36So, you notice here is
- 19:39um
- 19:39on the right you can see what the file
- 19:40is. It wrote the It wrote the code in my
- 19:42thing. So, I could just rerun that code
- 19:44any one time I want, and it made a file,
- 19:46which is called home ownership age uh by
- 19:48age annual.
- 19:50And it made a CSV file that has
- 19:52everything here. Every year has what the
- 19:54home ownership rate is.
- 19:55So, they both They all come from this
- 19:57and they do this. So, now
- 19:59that's great. So, you were asking So,
- 20:01that just downloaded the data. The thing
- 20:03that I would typically do here is
- 20:06um
- 20:07So, just to give you a sense of what I
- 20:08would do next is I would typically um
- 20:13you know, take this. And this is just a
- 20:15discussion here. So, it does this, clean
- 20:17data, blah blah blah. So, now
- 20:20um
- 20:22what I'm going to do is I want to make
- 20:23this graph. So, I'm going to I want to
- 20:25sort of show you how you would make this
- 20:27graph. So,
- 20:28I'm going to do it in the following way.
- 20:30And so, by the way, like actually let's
- 20:31quickly check in on um
- 20:33So, what's kind of interesting here is
- 20:35it will kind of tell you the different
- 20:36setups, what the different data Wait,
- 20:38for example, given that there's
- 20:39quarterly data, you could do a quarterly
- 20:42version of the graph that we're going to
- 20:43talk about if you wanted to study that.
- 20:45I'm going to focus on the annual one
- 20:46just for the purposes there.
- 20:49Let's check in very quickly on um
- 20:53what
- 20:54uh the co-work is doing just since you
- 20:57asked about that.
- 20:58Um co-work is here.
- 21:01And it's still struggling because mainly
- 21:04because
- 21:06it's still doing the search process.
- 21:07Now, struggling is the wrong word, but
- 21:10>> What kind of data do
- 21:10>> It's it's working on the data question.
- 21:12So, it says, "Okay, here
- 21:15um
- 21:16let's do it." So, it's doing all the
- 21:17exercise, same thing as before. It's
- 21:19really It can't get to the census is one
- 21:21of the big problems here.
- 21:23So, now it's going to say, "Let me try
- 21:25and find this."
- 21:27Um
- 21:28So, it's still doing basically the same
- 21:30exercise. I'm trying to find this. It
- 21:32has historical data. And so, what it's
- 21:34doing is it's going to try and download
- 21:36directly.
- 21:38And so, then it It would The problem
- 21:40with it is is that
- 21:42it's running into the same issue that
- 21:44happened in the other one. So, it's the
- 21:45same type of issues, which is that the
- 21:46census doesn't let you go there unless
- 21:48you write a script where you have a user
- 21:50agent. It doesn't seem like Co-work
- 21:52wants to do that. And so, it seems like
- 21:53it they're kind of having slightly
- 21:55different approaches. We'll see where
- 21:56this one gets to. Um
- 21:59Yeah, you can see
- 22:00>> doing never get into the census data.
- 22:02>> Well, we'll see we'll see what happens.
- 22:03I don't usually use Co-work for this
- 22:04reason. So, it looks like he it might.
- 22:09So, let's see if it can get there. Let's
- 22:11see if it gets there. Let's give it the
- 22:13benefit of the doubt. While I While we
- 22:14make this figure, we'll see if it can
- 22:15get to the same place.
- 22:16>> Okay.
- 22:17>> Um
- 22:19So, what we're going to do now is This
- 22:21is going to be very fast by comparison.
- 22:23So, we're going to say, "All right,
- 22:25um we have these two data sets. We're
- 22:26going to say
- 22:28um please make a graph that plots the
- 22:33um
- 22:34distribution of home ownership
- 22:36of home ownership
- 22:40um by age um
- 22:43for each year in the So, I'm going to
- 22:48tell it what file I want It It doesn't
- 22:49really need this, but I want to say that
- 22:51I want to use the annual. So, here you
- 22:52can say at home ownership by age
- 22:55annual.csv just to tell it I mean this
- 22:57file.
- 22:59Um
- 23:00Um
- 23:01>> tell it that you want to use all?
- 23:03>> I'm going to in just a second. Yes. So,
- 23:05please
- 23:06make a script to generate a figure in R
- 23:11with this data.
- 23:13Um
- 23:14And then so this is my cheat. So,
- 23:16Marcus, you're now getting the number
- 23:18one cheat that I have found that has
- 23:19been very helpful. So, there is a a
- 23:22professor of sociology, his name is
- 23:24Kieran Healy. He has a really wonderful
- 23:26book that I will um
- 23:28pitch here that's called data
- 23:29visualization in R.
- 23:32It makes beautiful graphs. And so, what
- 23:35you can do, you can say, "Please follow
- 23:38the best practices
- 23:41of making figures from
- 23:44Kieran Healy."
- 23:46>> Okay.
- 23:46>> And so now, we can tell it to do that.
- 23:49Um
- 23:50>> The fact that you use "please" all the
- 23:52time, does it make a difference?
- 23:53>> I don't know. Maybe I'm just very
- 23:54polite. I So, you know, I It's hard for
- 23:58me not to say please. I know that there
- 24:00are people who
- 24:01There is literature that talks about
- 24:03ways in terms of um So, here now, by the
- 24:05way, it's asking like what R scripts it
- 24:07is and what's available and so on. And
- 24:09it says, "Good, everything's available.
- 24:10Let's write this following Healy's
- 24:12principles: clean ggplot2, direct
- 24:14labeling, minimal chart junk, thoughtful
- 24:16color, and clear typography."
- 24:18Um
- 24:19So, I say "please" a lot, mainly cuz I
- 24:22just say I'm overly polite probably
- 24:24anyway. And then um
- 24:27>> I'm sorry.
- 24:27>> There is literature about the extent to
- 24:29which being polite or rude or
- 24:31threatening these LLMs can potentially
- 24:34change behavior. I guess I It's very
- 24:37hard for me to not just be polite. So,
- 24:40>> Okay.
- 24:40>> I I don't know how much it will affect
- 24:42your results. So, um So, now I wrote
- 24:45this, you know, 77 lines of this. And
- 24:47then I'm telling it to run it. It will
- 24:49also run it for me. So, I said, "Yes,
- 24:50you can run it." And
- 24:53>> Wait, it was 77 lines? Wow, okay.
- 24:56>> Um Well, cuz there's a lot of preambles.
- 24:59So here you can see what it looks like.
- 25:00This is it on the right. So here you
- 25:03have it just makes this nice It's this
- 25:05long plot.
- 25:06Um
- 25:08Cairo is an Oh, yes. So
- 25:11So it's running into this problem of it
- 25:13So this is very funny in that it's
- 25:15really struggling with um
- 25:17fonts.
- 25:18Because because
- 25:21um
- 25:23it So Kieran Healy has very preferences
- 25:25for fonts.
- 25:27>> Mhm.
- 25:27>> And so it's trying to do his fonts. And
- 25:29so now it's debugging this issue that
- 25:31comes up for the way that it's tried to
- 25:32structure it. And it looks like it
- 25:33should work. Which is kind of amazing.
- 25:36This [snorts] is always a huge issue.
- 25:37There's a whole blog post from
- 25:39Kieran Healy about this. So now it looks
- 25:42like
- 25:43it should be done. So what we can do it
- 25:45looks good. I see there's a one Unicode
- 25:48isn't supported well. So we'll fix that
- 25:50very quickly. Um
- 25:53and then we'll run it again.
- 25:55And once it's done we can see
- 25:58how happy it is or if it's happy.
- 26:02>> So all this doing get defying and all
- 26:04this things
- 26:06these are all well known terms or they
- 26:08just made it up?
- 26:09>> Which which terms? The
- 26:11>> The cogitating
- 26:13or
- 26:13>> Oh, cogitating. Yes, these are just like
- 26:15it's
- 26:16I think there's a You can actually
- 26:17change that. So you can
- 26:19cogitated just means to to have thought,
- 26:21but it uses all these ridiculous terms
- 26:22and you can change those. They're kind
- 26:24of meaningless. They're not No, they
- 26:25they're meaningless. They're kind of
- 26:26nonsense words. So now we can open this.
- 26:29So um let me open this file. So I'll say
- 26:32open home ownership by age
- 26:34um dot PDF. And let's see if it did
- 26:37exactly the same thing. It should be
- 26:38similar. So I'll open it. Oh, no, it
- 26:41didn't do that. Okay, very interesting.
- 26:43Um
- 26:45So and you know the reason for that it's
- 26:47actually kind of interesting. So it did
- 26:48a different graph. So here I'll I'll you
- 26:50what it looks like. This is what it did.
- 26:52Um
- 26:55it did this one.
- 26:57So
- 26:58Oh.
- 26:59>> That's a different one. That's very
- 27:00different.
- 27:00>> Yeah, sorry. Let me just It opened the
- 27:02wrong one for me. One sec. It's It looks
- 27:04very different. And part of the reason
- 27:06for that is it
- 27:09it only has these bucketed ones. So it's
- 27:12it clearly doesn't have as many um
- 27:13subcategories in terms of age. Well, now
- 27:15this is still very helpful. You can kind
- 27:17of see the relative home ownership rate,
- 27:19but it's not the same kind of graph. So
- 27:20now we could ask the question of um
- 27:25how can we get something that looks
- 27:27closer to these other these other ones?
- 27:29Um
- 27:30It's interesting in that this is sort of
- 27:32more aggregated.
- 27:34>> x axis. You want the timeline on the x
- 27:35axis.
- 27:35>> Yeah, exactly. So let's let's let's kind
- 27:38of change that and see if we can get
- 27:39there. And it what it might say is um
- 27:43you know, it might say, "Hey,
- 27:45uh
- 27:47you know, the data doesn't work for
- 27:48this." And then so then we'd have to be
- 27:49like, "Okay, well, you need to go back
- 27:50and figure it out." Um I
- 27:53So I have a tendency of being polite
- 27:55here. I say, "This is great, but I want
- 27:58a graph where age
- 28:02is on the x axis and the death
- 28:06distribution
- 28:08on the y axis
- 28:10and there are different
- 28:14lines for each year.
- 28:17Do you have sufficiently fine-grained
- 28:20age data for this?
- 28:22Can you go back and find something
- 28:26with age buckets?
- 28:28If not
- 28:33So we'll see if this kind of
- 28:36Of course, it is kind of cool to look at
- 28:37that graph in the sense that it kind of
- 28:39exactly explains
- 28:41what has happened during this period,
- 28:43right? So if we while we wait for this
- 28:44to kind of run, it's thinking. So it
- 28:47says, "Oh, yes, good news. It actually
- 28:49all There are finer age buckets. We only
- 28:50got the five big ones."
- 28:52So, this time it didn't do the big ones.
- 28:54I wanted more. And so, now it's going to
- 28:56re-download the data.
- 28:59Now, refactor this
- 29:00>> it will re-download it? The CSV file
- 29:03probably has it already or not?
- 29:05>> No, cuz I think when it parsed There's a
- 29:06large much larger Excel file that it
- 29:10kind of read.
- 29:11Now, I think it just downloads and then
- 29:13kind of gets it it pulls directly from
- 29:15that. So, what it's doing is it's
- 29:16downloading, reading into memory, and
- 29:18then parsing it. Think if this was a
- 29:19bigger file. These are pretty small
- 29:21files. If they were bigger files, we'd
- 29:23have a raw folder where we download all
- 29:25this stuff, and then we wouldn't have to
- 29:26re-download. These are tiny by, you
- 29:28know,
- 29:29Um so, now it's going to rerun it.
- 29:32And
- 29:35um
- 29:36And you notice, by the way, Marcus, this
- 29:38is like
- 29:39This obviously it's a little strange to
- 29:40be working in the command line and
- 29:42everything else. For the most part, this
- 29:44is all
- 29:45um pretty straightforward English. Yeah,
- 29:48and you can just It's the same thing
- 29:49you'd say for talking to someone like
- 29:51you and I both here. Let me quickly I'll
- 29:53show you what co-worker is doing. Yeah,
- 29:56co-worker is doing something very
- 29:57similar.
- 29:58It looks like it has managed to find a
- 30:00data set. So, it says,
- 30:03"It looks like" So, it's writing the
- 30:06download.api download.data.py.
- 30:09I'm curious which data set it's going to
- 30:10use.
- 30:11Um
- 30:13It's been a bunch of time thinking about
- 30:15this, and now it is finally the script.
- 30:18So, we'll see what it's doing. So, it
- 30:20looks like it's writing it here. So,
- 30:22what
- 30:23uh it's a interesting question of what
- 30:25file. So, download fr- Oh, so it found
- 30:26the same one.
- 30:28So, it's doing the same one here,
- 30:30but it's only doing it from table 19.
- 30:34Um
- 30:35Oh, no, and here's 17 as well. So, it
- 30:37found exactly the same one. So, you
- 30:39know, co-
- 30:41um
- 30:43So, oh, this is interesting. So, the
- 30:44challenge here, and so I didn't quite
- 30:46realize this about co-work. So, if you
- 30:48look at this here,
- 30:49it's the same thing that would happen on
- 30:50the website often. So, it wrote a it
- 30:52wrote a script,
- 30:54but the script,
- 30:56um
- 30:57basically, it's not able to write it and
- 30:59then query something because it's in
- 31:01something called a sandbox. So, it's
- 31:03really working just within this one
- 31:05sandbox, which is something we'll talk
- 31:06about for Claude code going forward.
- 31:08We let Claude go nuts, right? We said,
- 31:11"Hey, yeah, Claude, go access the web,
- 31:13do whatever you want."
- 31:15>> Yeah.
- 31:15>> Um
- 31:17And so, it's struggling inside Claude
- 31:19co-work to kind of work in the way that
- 31:21you would if you ran your own script. It
- 31:23can't really act like you, per se, if
- 31:25that makes sense. So, there's it's
- 31:27getting
- 31:28>> in the sandbox.
- 31:29>> It's really much more sandbox, which of
- 31:31course then removes a lot of the privacy
- 31:33and other concerns that you might have,
- 31:35right? So, there's there's kind of, um a
- 31:38lot of
- 31:39um pluses and minuses. Um So, let me
- 31:43kind of, to finish this up and then
- 31:46we can wrap up, is so here now we fix
- 31:48this, we've told it all the things, it's
- 31:49kind of working.
- 31:52Um let's run this again.
- 31:55And we'll see if it's kind of
- 31:58fixed.
- 32:02This looks like it's it's reading this,
- 32:03da da da.
- 32:09So,
- 32:11it's still working. So, gesticulating
- 32:13just means it's working. It doesn't mean
- 32:14anything else. And so, now it's going to
- 32:16do a little bit more. The year it says
- 32:19the shape is right, but the year labels
- 32:20are overlapping. Let me use this thing
- 32:22to fine-tune the spacing. So, it really
- 32:24is like like a good RA in the sense that
- 32:26it looks to make nice graphs for you.
- 32:28Um
- 32:30>> So, it even discovers problems.
- 32:32>> Yeah. I mean, it tries. It doesn't
- 32:34always. Sometimes you have to tell it to
- 32:36go look. This is a pretty
- 32:37straightforward problem that I've asked
- 32:39it to do. On more complicated things,
- 32:41like if you were writing a macro model
- 32:42and you wanted to code it up, you might
- 32:44say, "Okay, now make sure you go review
- 32:46that code and make sure like, you know,
- 32:48everything makes sense. Are the
- 32:49intertemporal constraints being
- 32:51satisfied, etc., etc."
- 32:54>> So, what's what's done on your computer
- 32:56and what's done in the cloud or
- 32:59>> So, in the cloud is anything that has to
- 33:01do with text in terms of what it's
- 33:02writing. Like it's writing stuff like
- 33:04writing a like telling you what script
- 33:06to do. The program being run, the
- 33:09commands are coming from the cloud, but
- 33:11the the actual execution of the R script
- 33:14is being done on my computer. So,
- 33:16>> So, you have R on your computer. If you
- 33:18don't have R on your computer, it
- 33:19wouldn't work.
- 33:20>> No, and then you could ask it to install
- 33:22it if you wanted or you use Python or
- 33:24something else. That's right. But that's
- 33:25true. Um yes, that's right. That's like
- 33:28basically you need to have the same um
- 33:29thing here. So, let's look at what it
- 33:31does. So, just to give you a sense,
- 33:32you'll notice um
- 33:36This is what it's gotten to so far,
- 33:37although it you notice it keeps thinking
- 33:39and it keeps wanting to do stuff. I just
- 33:40want to show you what this picture looks
- 33:42like.
- 33:42>> So, all this software you have to have
- 33:44on your local computer essentially.
- 33:45>> Yeah, but that's true. I think of yes,
- 33:47but that's right. So, here's what it's
- 33:48made now, but it doesn't love what it's
- 33:50done yet. So, very similar, but still
- 33:53not identical. So, this is what it's
- 33:54made.
- 33:56Um and now it will let it we'll see what
- 33:59it
- 34:00um
- 34:01We'll just kind of last thing here.
- 34:04We'll just let it do one more piece,
- 34:07which is to say, "Okay, you want to do a
- 34:08little bit more." It's going to change
- 34:10the colors. It has lots of strong
- 34:11feelings right now about what things
- 34:12need to look like.
- 34:14And
- 34:16hopefully
- 34:17This is because I I really gave it a
- 34:19very dogmatic viewpoint on it. If I had
- 34:21said, "Just make a graph," it would have
- 34:23said, "Great. Here's a graph." But
- 34:25instead I said, "You need to make, you
- 34:26know, follow these very particular
- 34:28protocols of how to do things." It's
- 34:30it's iterating to kind of make sure it
- 34:32looks kind of nice. So, now it's done.
- 34:34Says, "Great. It looks to this.
- 34:37It's using this data. Here's some
- 34:39features of it."
- 34:41Um of what's going on. And now let's
- 34:43just look at that graph and we'll be
- 34:45done. So, it didn't do the gray lines
- 34:46and like in the one that I showed you.
- 34:49Um and I'll but I'll show you this and
- 34:51then we'll be done. So, here it is.
- 34:55So, this is the version of it. It didn't
- 34:56do the gray lines, but you can kind of
- 34:58see it goes I see. See the different
- 35:01versions. I kind of prefer the other one
- 35:02that was made, but this is kind of
- 35:04getting you a sense of what it looks
- 35:05like. Um you have kind of this is the
- 35:08time series of what it looks like. You
- 35:10have the kind of the peak. I think
- 35:12there's different ways you could make
- 35:12this, but this is kind of a This is a
- 35:14pretty good start. You can kind of
- 35:15clearly see like this is what it looked
- 35:17like at certain points. I would say the
- 35:19crisis looks very similar to 2024 and 20
- 35:22you know, 2004 is when obviously
- 35:24homeownership was the highest across the
- 35:25board. There are better ways to do this,
- 35:27but you know, we could iterate here
- 35:28forever kind of of what it would look
- 35:30like.
- 35:31Um so, that's kind of Yeah. So, that's
- 35:33kind of just to kind of sum up on this
- 35:35cuz I don't I think like you could do a
- 35:36lot of ideas here if you wanted. Is
- 35:41you know, the idea here is that when you
- 35:43work um sorry, not this one. We'll do if
- 35:47we think about
- 35:49um
- 35:52you know, if we could make this graph,
- 35:53you get a lot of really nice things
- 35:55here. Kind of what's nice before is that
- 35:56you had to kind of run a lot of things
- 35:58and go back and forth. Instead, you can
- 35:59kind of just tell it what you want the
- 36:01graph to look like and it will do it
- 36:02yourself. That's really kind of lovely
- 36:04part of it.
- 36:05And then you can just iterate
- 36:06accordingly. You can add different
- 36:08things. You can add stylings if you want
- 36:10it to be satisfying certain
- 36:12requirements. And in the end, you know,
- 36:14now we have all this stuff in one folder
- 36:16where we can kind of it creates a kind
- 36:18of repository that looks like a project,
- 36:20right? You started to actually make
- 36:22stuff that looks like code for a
- 36:23project. And that's kind of the key
- 36:25benefit is like you have Claude do these
- 36:28things. It works with you to do the data
- 36:30acquisition. You can talk about what you
- 36:31want to look like. You always are
- 36:33generating scripts so that you have can
- 36:35actually do it yourself and you can look
- 36:36at the code later.
- 36:38And then you can kind of do judgment on
- 36:40what you need things to look like. So
- 36:42that's kind of the key thing and I think
- 36:46next time what we'll do is we'll try to
- 36:47do something a lot more complicated and
- 36:48it'll kind of be more clear of why you
- 36:50need to be what kind of what what really
- 36:52unlocks.
- 36:55>> Fantastic. Okay.
- 36:58So that concludes this video but uh
- 37:01don't hold off to go to the next one.
- 37:03It's coming. We're ready to full force
- 37:06data scrapping.
- 37:07>> Perfect. All right. Thank Thanks so
- 37:10much.
About this transcript
This page contains the full transcript of Data Analysis: Claude Code for Economists with Paul Goldsmith-Pinkham | Markus' Academy | Ep. 162-2 by Markus' Academy, generated from the public captions YouTube serves with the video. The transcript has 7,688 words across 1,177 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.