<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>Finn O'Keeffe</title><description>Statistics, data, python, and art.</description><link>https://www.finnokeeffe.nz/</link><image><url>https://www.finnokeeffe.nz/content/images/2026/03/Icon_hu_994f876b6476b3fd.png</url><title>Finn O'Keeffe</title><link>https://www.finnokeeffe.nz/</link></image><generator>Hugo</generator><lastBuildDate>Mon, 18 May 2026 06:46:41 GMT</lastBuildDate><atom:link href="https://www.finnokeeffe.nz/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title>Exploring instrumental variables with synthetic data</title><description>In my work I'm regularly dealing with questions that have a causal nature. These are questions like, Can investing in employee training increase a business's profitability or production?</description><link>https://www.finnokeeffe.nz/exploring-instrumental-variables-with-synthetic-data/</link><guid isPermaLink="false">69febca70ae834000140b659</guid><dc:creator>Finn O'Keeffe</dc:creator><pubDate>Mon, 18 May 2026 06:46:41 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1556379118-7034d926d258?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=M3wxMTc3M3wwfDF8c2VhcmNofDF8fEluc3RydW1lbnRzfGVufDB8fHx8MTc3ODM2NzI3MXww&amp;ixlib=rb-4.1.0&amp;q=80&amp;w=2000" medium="image"/><content:encoded><![CDATA[<p>In my work I'm regularly dealing with questions that have a causal nature. These are questions like,</p>
<ul>
<li>Can investing in employee training increase a business's profitability or production?</li>
<li>In a university or polytech, what are the effects of first year support programmes on overall qualification completion rates?</li>
</ul>
<p>Through sources such as the Stats NZ IDI we can sometimes get data describing these situations, but establishing a causal link is difficult. Confounders can enhance or reduce correlations between the predictors and the outcome through pathways that aren't the intended causal link. For example, take the example of how employee education affects business profits. Theoretically a more trained employee might be more productive because of their training, which could improve profits. But a person who is particularly motivated may also improve profits and have higher education, but in part because motivation is causally influences both of these.</p>
<p>This can be an issue when forecasting the effects of interventions. If we simply took a regression between years of education and business profits, we might be overestimating the effects of interventions which fund training. If these interventions cause random uptake of training rather than uptake being depending on the employee's motivation, the actual effect of the intervention will be less than we forecast.</p>
<p>If we could somehow measure motivation we could try to control for it. And while that might be possible with latent factor analysis, that's only one confounder. We not only have to contend with the known unknowns, but the <a href="https://en.wikipedia.org/wiki/There_are_unknown_unknowns">unknown unknowns</a>.</p>
<h1 id="backgroundinstrumental-variables">Background - Instrumental variables</h1>
<p>One possibility to help with this is instrumental variables. The idea is that we introduce a variable which is causally linked to our outcome only through our predictor of interest. Thus, any correlation between the instrumental variable and the outcome is solely due to the causal link of interest.</p>
<div class="mermaid">
flowchart LR
pred[Predictor]
outc[Outcome]
conf((Confounder))
instr[Instrumental Variable]

instr --&gt; pred --&gt; outc
conf --&gt; pred
conf --&gt; outc
</div>
<p>This instrumental variable needs to satisfy the following rules in order to make our regression analysis actually get at the causal link:</p>
<ol>
<li><strong>Relevance</strong>; the instrumental variable must have a strong relationship with the predictor.</li>
<li><strong>Exogeneity</strong>; the instrumental variable must be uncorrelated with the residual in our outcome. Effectively, this means the instrumental variable must only be causally linked to the outcome through our parameter of interest.</li>
</ol>
<p>The second condition is usually much hard to meet; it is hard to test for, so tends to rely on arguments made by the author. Ideally, the instrumental variable would be assigned at random.</p>
<p>In our example of the effect of education on business profitability, we might examine proximity to a tertiary education institution. We satisfy relevance as someone living close to a university will be more likely to attend that university, and so have more years of education. An argument for exogeneity might be that within a city with multiple tertiary education providers, proximity to them is somewhat randomly assigned, so we may expect it to be independent of our residual term.</p>
<div class="kg-card kg-callout-card kg-callout-card-blue"><div class="kg-callout-emoji">❗</div><div class="kg-callout-text">This is not a particularly strong argument for exogeneity. For example, university professors have a strong incentive to live close to their university. So a student who lives close to a university is more likely to be a child of a professor, which will have implications for confounders such as socioeconomic status.<br>
This isn't the end for using this instrumental variable, we could use it as long as we are able to control for the confounding pathways such as this one. But we need to know and measure these confounding effects, or we're back where we started.</div>
</div>

<div class="mermaid">
flowchart LR

dtp[Distance to provider]
motivation((Motivation))
yoe[Years of education]
busprof[Business profitability]
r((Residual))

dtp --&gt; yoe
motivation --&gt; yoe
yoe --&gt; busprof
motivation --&gt; r --&gt; busprof
</div>
<p>If we believe this argument for relevance and exogeneity, then two-stage least squares can give an unbiased estimation of the causal effect of education on business profitability. The instrumental variable forms a natural experiment of sorts which can even help control for the unknown unknowns.</p>
<h1 id="exploration-with-synthetic-data">Exploration with synthetic data</h1>
<figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://github.com/finn-okeeffe/instrumental-variables-notebook"><div class="kg-bookmark-content"><div class="kg-bookmark-title">GitHub - finn-okeeffe/instrumental-variables-notebook: An exploration of instrumental variables and two stage least squares using synthetic data.</div><div class="kg-bookmark-description">An exploration of instrumental variables and two stage least squares using synthetic data. - finn-okeeffe/instrumental-variables-notebook</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://www.finnokeeffe.nz/content/images/icon/pinned-octocat-093da3e6fa40-2.svg" alt=""><span class="kg-bookmark-author">GitHub</span><span class="kg-bookmark-publisher">finn-okeeffe</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://www.finnokeeffe.nz/content/images/thumbnail/instrumental-variables-notebook.png" alt="" loading="lazy"></div></a></figure>

<p>In the above repo, I explore instrumental variables using some synthetic data with the years of education example we've been exploring so far.</p>
<figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://www.finnokeeffe.nz/content/images/2026/05/scatter-naive-regression-1.png" class="kg-image" alt="" width="1200" height="400" loading="lazy">
<figcaption>The confounder motivation affects both years of education and profitability, making the causal effect of interest difficult to estimate.</figcaption></figure><p>I generated synthetic data following the example before, generating a latent motivation factor using a standard normal and similarly generating years of education and residual effects. Years of education and profitability was generated following the model, with a true effect size of</p>
<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>β</mi><mo>=</mo><mi mathvariant="normal">$</mi><mn>500</mn><mi mathvariant="normal">/</mi><mtext>year</mtext></mrow><annotation encoding="application/x-tex">\beta = \$500 / \text{year} </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="katex-base"><span class="katex-strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.0528em;">β</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="katex-base"><span class="katex-strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">$500/</span><span class="mord text"><span class="mord">year</span></span></span></span></span></span><p>However, if we naively apply OLS to estimate the effect, we get <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>β</mi><mo>^</mo></mover><mo>=</mo><mi mathvariant="normal">$</mi><mn>668</mn><mi mathvariant="normal">/</mi><mtext>year</mtext></mrow><annotation encoding="application/x-tex">\hat{\beta} = \$668 / \text{year}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="katex-base"><span class="katex-strut" style="height:1.1523em;vertical-align:-0.1944em;"></span><span class="mord katex-accent"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.9579em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mathnormal" style="margin-right:0.0528em;">β</span></span><span style="top:-3.2634em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.1667em;"><span class="mord">^</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.1944em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="katex-base"><span class="katex-strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">$668/</span><span class="mord text"><span class="mord">year</span></span></span></span></span> with a 95% confidence interval of <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mi mathvariant="normal">$</mi><mn>646</mn><mi mathvariant="normal">/</mi><mtext>year</mtext><mo separator="true">,</mo><mi mathvariant="normal">$</mi><mn>691</mn><mi mathvariant="normal">/</mi><mtext>year</mtext><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">(\$646 / \text{year}, \$691 / \text{year})</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="katex-base"><span class="katex-strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord">$646/</span><span class="mord text"><span class="mord">year</span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord">$691/</span><span class="mord text"><span class="mord">year</span></span><span class="mclose">)</span></span></span></span>. We're overestimating the causal effect.</p>
<figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/content/images/2026/05/OLS-fit-screenshot.png" class="kg-image" alt="" width="464" height="548" loading="lazy">
</figure><p>So let's try again with our instrumental variable.</p>
<figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://www.finnokeeffe.nz/content/images/2026/05/scatter-instrumental-variable-1.png" class="kg-image" alt="" width="1200" height="400" loading="lazy">
<figcaption>The instrumental variable <em>Distance to provider</em> is correlated with years of education, but not with our confounder, meaning that it's effect on distance to college must purely be through the variable of interest. In reality we wouldn't be able to look at these correlations. Not just because we might not be able to measure motivation, but also because we might not know what the confounders even are!</figcaption></figure><p>Using 2SLS (I used the <a href="https://www.statsmodels.org/stable/generated/statsmodels.sandbox.regression.gmm.IV2SLS.html">statsmodels implementation</a>), we estimate <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>β</mi><mo>^</mo></mover><mo>=</mo><mi mathvariant="normal">$</mi><mn>516</mn><mi mathvariant="normal">/</mi><mtext>year</mtext></mrow><annotation encoding="application/x-tex">\hat{\beta} = \$516/\text{year}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="katex-base"><span class="katex-strut" style="height:1.1523em;vertical-align:-0.1944em;"></span><span class="mord katex-accent"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.9579em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mathnormal" style="margin-right:0.0528em;">β</span></span><span style="top:-3.2634em;"><span class="pstrut" style="height:3em;"></span><span class="accent-body" style="left:-0.1667em;"><span class="mord">^</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.1944em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="katex-base"><span class="katex-strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">$516/</span><span class="mord text"><span class="mord">year</span></span></span></span></span> with a 95% confidence interval of <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mi mathvariant="normal">$</mi><mn>443</mn><mi mathvariant="normal">/</mi><mtext>year</mtext><mo separator="true">,</mo><mi mathvariant="normal">$</mi><mn>589</mn><mi mathvariant="normal">/</mi><mtext>year</mtext><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">(\$443 / \text{year}, \$589 / \text{year})</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="katex-base"><span class="katex-strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord">$443/</span><span class="mord text"><span class="mord">year</span></span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord">$589/</span><span class="mord text"><span class="mord">year</span></span><span class="mclose">)</span></span></span></span>. Much better!</p>
<figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/content/images/2026/05/2SLS-fit-screenshot.png" class="kg-image" alt="" width="455" height="559" loading="lazy">
</figure><p>I plotted this naive slope and actual slope on a single plot below to get an idea of the difference. Note that the red line using the 2SLS slope isn't meant to be an accurate prediction for profitability, since we've purposely removed the effect of motivation. This is purely just to demonstrate the difference in our slope estimates.</p>
<figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/content/images/2026/05/regression-comparison.png" class="kg-image" alt="" width="640" height="480" loading="lazy">
</figure><h1 id="caveats-for-real-world-application">Caveats for real world application</h1>
<p>Finding instrumental variables which satisfy the exogeneity question can be difficult, and the strength of your resulting causal inference will depend on the strength of the argument for exogeneity. And these are very hard to find, and very hard to justify.</p>
<blockquote>
<p><strong>Patrick Curran:</strong> I actually saw an instrumental variable. It was riding a unicorn, and it was licking a rainbow.</p>
</blockquote>
<p><a href="https://open.spotify.com/episode/3k8MXmocl478aj9Eud4sQx?si=12905ef2149745c6"><em>Quantitude — S6E10 Instrumental Variables (Dad)Rock!</em></a></p>
]]></content:encoded></item><item><title>Recipe Website Analysis - Streamlit Dashboard</title><description>Back in 2023, as a capstone to learning SQL, I scraped a recipe website and designed a PostgreSQL database to store and query data about that site.</description><link>https://www.finnokeeffe.nz/recipe-website-analysis-streamlit-dashboard/</link><guid isPermaLink="false">69b61f1363fc660001f460d9</guid><dc:creator>Finn O'Keeffe</dc:creator><pubDate>Sun, 15 Mar 2026 03:34:35 GMT</pubDate><media:content url="https://www.finnokeeffe.nz/content/images/2026/03/the-doctors-kitchen-dashboard-screenshot-2.png" medium="image"/><content:encoded><![CDATA[<div class="kg-card kg-button-card kg-align-center"><a href="#embedded-dashboard" class="kg-btn kg-btn-accent">Skip the post and jump straight to the dashboard</a></div>

<p>Back in 2023, as a capstone to learning SQL, I scraped a recipe website and designed a PostgreSQL database to store and query data about that site. It was a really great way to finish my SQL learning spring, particularly since it gave me practical experience about how SQL databases need to work in the wild. I would encourage anyone learning from videos or a book to give something like this a go. It was also my first experience with dashboarding, <a href="https://streamlit.io/">Streamlit</a> was such a good way to get into it. I'm not sure what it's like now, but you should check it out.</p>
<p>The website I scraped was <a href="https://www.thedoctorskitchen.com/">The Doctor's Kitchen</a>, and at the time it was a pretty simple website. One of my goals with the project was to be able to search the recipes by ingredients to see how I could use what was in my pantry, but now the website has it's own search functionality. It's such a good search too, letting you filter not just by ingredients or keywords, but also filter out allergens, select common dietary requirements, or filter to a handful of other useful categories.</p>
<p>I briefly tried to refresh the database behind the dashboard, and rerun my scraper. The classical techniques of web scraping (e.g., using tools like <a href="https://www.crummy.com/software/BeautifulSoup/">Beautiful Soup</a>) are pretty fragile, so the scraper had completely broken because of website changes. But nowadays after you view a few recipes on their website, the rest of them get locked behind requiring a log in. That's fair enough, given the masses of bots on the internet nowadays. This was only mean to be a simple refresh for my new site, so I ended up just migrating the database from its old host on neon.tech to a simple JSON and converted the dashboard to a static site. That means this doesn't use streamlit anymore.</p>
<p>Anyways, here's the dashboard. It also has a dedicated page on this site <a href="https://www.finnokeeffe.nz/the-doctors-kitchen-dashboard/">here</a>.</p>
<div class="dk" id="embedded-dashboard" data-src="https://www.finnokeeffe.nz/data/the-doctors-kitchen.fc7c34d2dba1a3c7492e41012e7a00336a526a62b7308cc1c93b8a2bd6f9f63c.json">
    <h2 class="dk-title">The Doctors Kitchen Dashboard</h2>
    <p class="dk-intro">An analysis of 108 recipes from <a href="https://thedoctorskitchen.com/">The Doctor's Kitchen</a>, scraped in August 2023.</p>

    <div class="dk-app" data-pagefind-ignore>
        <div class="dk-filters">
            <fieldset class="dk-tags">
                <legend>Meals</legend>
                <label class="dk-chip"><input type="checkbox" value="Dinner" checked> Dinner</label>
                <label class="dk-chip"><input type="checkbox" value="Lunch" checked> Lunch</label>
                <label class="dk-chip"><input type="checkbox" value="Breakfast" checked> Breakfast</label>
                <label class="dk-chip"><input type="checkbox" value="Snack" checked> Snack</label>
                <label class="dk-chip"><input type="checkbox" value="Unspecified Meals" checked> Unspecified Meals</label>
            </fieldset>
            <fieldset class="dk-tags">
                <legend>Diets</legend>
                <label class="dk-chip"><input type="checkbox" value="Vegan" checked> Vegan</label>
                <label class="dk-chip"><input type="checkbox" value="Vegetarian" checked> Vegetarian</label>
                <label class="dk-chip"><input type="checkbox" value="Pescatarian" checked> Pescatarian</label>
                <label class="dk-chip"><input type="checkbox" value="No diet" checked> No diet</label>
            </fieldset>
        </div>
        <p class="dk-count" aria-live="polite"><strong>108</strong> recipes selected</p>

        <div class="dk-tabs" role="tablist" aria-label="Charts">
            <button type="button" role="tab" id="dk1-tab-ingredients" aria-controls="dk1-panel-ingredients" aria-selected="true">Ingredients</button>
            <button type="button" role="tab" id="dk1-tab-equipment" aria-controls="dk1-panel-equipment" aria-selected="false" tabindex="-1">Equipment</button>
            <button type="button" role="tab" id="dk1-tab-time" aria-controls="dk1-panel-time" aria-selected="false" tabindex="-1">Preparation and cooking time</button>
        </div>
        <div class="dk-panel" role="tabpanel" id="dk1-panel-ingredients" aria-labelledby="dk1-tab-ingredients">
            <figure class="dk-chart"><figcaption>What are the most used ingredients?</figcaption><div class="dk-plot" data-chart="ingredients"></div></figure>
        </div>
        <div class="dk-panel" role="tabpanel" id="dk1-panel-equipment" aria-labelledby="dk1-tab-equipment" hidden>
            <figure class="dk-chart"><figcaption>What are the most used equipment?</figcaption><div class="dk-plot" data-chart="equipment"></div></figure>
        </div>
        <div class="dk-panel dk-panel-time" role="tabpanel" id="dk1-panel-time" aria-labelledby="dk1-tab-time" hidden>
            <figure class="dk-chart"><figcaption>Distribution of preparation time</figcaption><div class="dk-plot" data-chart="prep"></div></figure>
            <figure class="dk-chart"><figcaption>Distribution of cooking time</figcaption><div class="dk-plot" data-chart="cook"></div><p class="dk-note" data-note="cook"></p></figure>
        </div>

        <h3 class="dk-search-title">Search for recipes by ingredients</h3>
        <label class="dk-search-label" for="dk1-search">Enter ingredients separated by commas</label>
        <input class="dk-search" id="dk1-search" type="search" placeholder="e.g. olive oil, coriander, bean" maxlength="200" autocomplete="off" spellcheck="false">
        <p class="dk-results-count" aria-live="polite"></p>
        <ol class="dk-results"></ol>
        <nav class="dk-pager" aria-label="Search result pages"></nav>
        <noscript><p class="dk-note">The charts and the search need JavaScript.</p></noscript>
    </div>
</div>

<figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://github.com/finn-okeeffe/the_doctors_kitchen_project"><div class="kg-bookmark-content"><div class="kg-bookmark-title">GitHub - finn-okeeffe/the_doctors_kitchen_project</div><div class="kg-bookmark-description">Contribute to finn-okeeffe/the_doctors_kitchen_project development by creating an account on GitHub.</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://www.finnokeeffe.nz/content/images/icon/pinned-octocat-093da3e6fa40.svg" alt=""><span class="kg-bookmark-author">GitHub</span><span class="kg-bookmark-publisher">finn-okeeffe</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://www.finnokeeffe.nz/content/images/thumbnail/the_doctors_kitchen_project.png" alt="" loading="lazy"></div></a></figure>

]]></content:encoded></item><item><title>Excel: Aggregating and Cleaning Chord data from Rock Songs</title><description>This project uses data from A Corpus Study of Rock Music, by Trevor de Clerq and David Temperley. This project analysed the top 200 songs from the Rolling Stone magazine's list of the "500 Greatest Songs of All Time", providing a transcription of the melody and a harmonic analysis.</description><link>https://www.finnokeeffe.nz/excel-aggregating-and-cleaning-chord-data-from-rock-songs/</link><guid isPermaLink="false">69b12870f91cf700011e7ce5</guid><dc:creator>Finn O'Keeffe</dc:creator><pubDate>Wed, 11 Mar 2026 08:47:33 GMT</pubDate><media:content url="https://www.finnokeeffe.nz/content/images/2026/03/dancing_queen_progression.png" medium="image"/><content:encoded><![CDATA[<div class="kg-card kg-callout-card kg-callout-card-green"><div class="kg-callout-text"><em>This is an older post that I've brought over from my previous portfolio site - which I'd hosted on GitHub pages. I would have made this after finishing my MSc, but before getting my offer at Scarlatti, which dates this to 2023.</em><br><br><em>It's interesting to look back at how I went about it back then - I've certainly come a long way (especially in graph styling, I'm not a huge fan of those default styled Excel graphs...). I've totally forgotten about that PowerQuery folder import option - every time I need to batch process data files, I reach for Python nowadays.</em><br><br><em>If (for some reason I can't fathom) you want to look at the spreadsheet, here's the link. But I warn you, there is no contents page, no nice narrative. Just raw tables, and pivot charts!</em></div>
</div>

<div class="kg-card kg-button-card kg-align-center"><a href="https://1drv.ms/x/s!AiwUeFDGVIfLg9Vs9tYdzq9BWXQWjg?e=Ve4Esq" class="kg-btn kg-btn-accent">Check out the Excel workbook</a></div>

<h1 id="data-source">Data source</h1>
<p>This project uses data from <a href="http://rockcorpus.midside.com/index.html"><em>A Corpus Study of Rock Music</em>, by Trevor de Clerq and David Temperley</a>. This project analysed the top 200 songs from the <a href="https://www.rollingstone.com/">Rolling Stone magazine's</a> list of the <a href="http://web.archive.org/web/20080622145429/www.rollingstone.com/news/coverstory/500songs">&quot;500 Greatest Songs of All Time&quot;</a>, providing a transcription of the melody and a harmonic analysis. I will be importing and cleaning this data into excel.</p>
<p>There are two main parts to the data:</p>
<ul>
<li>rs200.csv, which holds data about the songs such as the title and artist.</li>
<li>The harmonic analysis data. This holds the chord data, and each song has its own file.</li>
</ul>
<h1 id="rs200csv">RS200.csv</h1>
<p>Trevor and David have provided a csv file, <code>RS200.csv</code>, with data about the releases. This part of the data is very easy to clean, after importing with Power Query, all we need to do is set the column titles. I have removed the last column in the file, which stated if the song was present in a previous dataset. This isn't needed for our analysis. The before and after of this file can be seen below.</p>
<figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/content/images/2026/03/image.png" class="kg-image" alt="" width="800" height="604" loading="lazy">
</figure><h1 id="chord-data">Chord Data</h1>
<p>Trevor and David have provided the chord data a file for each song. There are two versions of each file, one ending in _dt, one ending in _tdc. This is because both Trevor and David did the harmonic analysis for each song. Since chord sequences can be subjective, there may be differences between their analysis.</p>
<figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/excel-aggregating-and-cleaning-chord-data-from-rock-songs/chord_data_folder.png" class="kg-image" alt="" width="500" height="385" loading="lazy">
</figure><p>Each file contains timing and harmonic data. For example, the first few lines of 1999_dt.clt are,</p>
<pre><code>18.774	7.00	I64	0	1	5	5
19.784	7.50	V11	7	5	5	0
20.795	8.00	I64	0	1	5	5
21.812	8.50	V11	7	5	5	0
22.830	9.00	I64	0	1	5	5
23.838	9.50	V11	7	5	5	0
24.847	10.00	I64	0	1	5	5</code></pre>
<p>To all this data from individual files by import each one would be a pain. Fortunately, Excel's PowerQuery has just the tool to deal with this:</p>
<h2 id="bulk-importing-in-power-query">Bulk importing in Power Query</h2>
<figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/content/images/2026/03/image-1.png" class="kg-image" alt="" width="458" height="546" loading="lazy">
</figure><p>This automates most of the hard work to import and merge all these files. Excel autodetects the data format perfectly in this case. And after a little renaming of columns, (and sorting to show that the data from each file has indeed been merged) we get the following,</p>
<figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/content/images/2026/03/image-2.png" class="kg-image" alt="" width="1012" height="375" loading="lazy">
</figure><h3 id="splitting-the-filename-into-its-components">Splitting the filename into its components</h3>
<p>There's one last thing to do before we can import this into the work sheet. The filename field effectively contains two fields worth of data: the song id as appears in RS200.csv, and the person who did the analysis.</p>
<p>Before parsing the filename text, I duplicated the column. This way I could be sure to keep the original filename data. Then, I split the column by the last &quot;_&quot; delimiter to separate the song id from the author initials. Finally, I removed the .clt extension by extracting the text before the delimiter. These operations can be found in PowerQuery in the transform tab, as seen below.</p>
<figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/excel-aggregating-and-cleaning-chord-data-from-rock-songs/split_column_by_delimiter.png" class="kg-image" alt="" width="400" height="276" loading="lazy">
</figure><figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/content/images/2026/03/image-3.png" class="kg-image" alt="" width="719" height="492" loading="lazy">
</figure><figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/content/images/2026/03/image-4.png" class="kg-image" alt="" width="368" height="256" loading="lazy">
</figure><figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/content/images/2026/03/image-5.png" class="kg-image" alt="" width="708" height="259" loading="lazy">
</figure><figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/content/images/2026/03/image-6.png" class="kg-image" alt="" width="529" height="204" loading="lazy">
</figure><p>In general, you need to be careful when parsing text like this. If the delimiters aren't exactly where you expect them, then the text won't split like you expect. In this case the filenames are structured enough that we can be sure of exactly how it will split.</p>
<p>There we go, we've successfully imported, aggregated, and cleaned our data. The final table of chord data has 36,970 rows. PowerQuery made that much easier than it had any right to be. With this data we can perform some analysis. For example, visualising the chords of a single song.</p>
<figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/excel-aggregating-and-cleaning-chord-data-from-rock-songs/dancing_queen_progression.png" class="kg-image" alt="" width="1005" height="452" loading="lazy">
</figure><figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/excel-aggregating-and-cleaning-chord-data-from-rock-songs/dancing_queen_chord_distribution.png" class="kg-image" alt="" width="1005" height="452" loading="lazy">
</figure><p>Or, analysing data from all songs to find trends in what chords or keys are popular.</p>
<figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/excel-aggregating-and-cleaning-chord-data-from-rock-songs/most-used-chords.png" class="kg-image" alt="" width="802" height="439" loading="lazy">
</figure><figure class="kg-card kg-image-card"><img src="https://www.finnokeeffe.nz/excel-aggregating-and-cleaning-chord-data-from-rock-songs/all_songs_key_distribution.png" class="kg-image" alt="" width="802" height="439" loading="lazy">
</figure><p>There's a lot of interesting stuff you could do with this data. But since this project was just about aggregating and cleaning data I'll leave it here. Perhaps in the future I'll come back and find patterns or insights in this data. Such as what cadences are popular, or how use of certain keys/chords change over time. If you want to have a play with the spreadsheet, you can find a link to it at the top of the page.</p>
]]></content:encoded></item></channel></rss>