<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Akio Yamazaki</title><link>https://a-yamazaki1028.github.io/</link><atom:link href="https://a-yamazaki1028.github.io/index.xml" rel="self" type="application/rss+xml"/><description>Akio Yamazaki</description><generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><copyright>© `2026`</copyright><lastBuildDate>Sat, 01 Jun 2030 13:00:00 +0000</lastBuildDate><image><url>img/map[gravatar:%!s(bool=false) shape:circle]</url><title>Akio Yamazaki</title><link>https://a-yamazaki1028.github.io/</link></image><item><title>Example Talk</title><link>https://a-yamazaki1028.github.io/talk/example/</link><pubDate>Sat, 01 Jun 2030 13:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/talk/example/</guid><description>&lt;div class="alert alert-note">
&lt;div>
Click on the &lt;strong>Slides&lt;/strong> button above to view the built-in slides feature.
&lt;/div>
&lt;/div>
&lt;p>Slides can be added in a few ways:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Create&lt;/strong> slides using Academic&amp;rsquo;s
&lt;a href="https://sourcethemes.com/academic/docs/managing-content/#create-slides" target="_blank" rel="noopener">&lt;em>Slides&lt;/em>&lt;/a> feature and link using &lt;code>slides&lt;/code> parameter in the front matter of the talk file&lt;/li>
&lt;li>&lt;strong>Upload&lt;/strong> an existing slide deck to &lt;code>static/&lt;/code> and link using &lt;code>url_slides&lt;/code> parameter in the front matter of the talk file&lt;/li>
&lt;li>&lt;strong>Embed&lt;/strong> your slides (e.g. Google Slides) or presentation video on this page using
&lt;a href="https://sourcethemes.com/academic/docs/writing-markdown-latex/" target="_blank" rel="noopener">shortcodes&lt;/a>.&lt;/li>
&lt;/ul>
&lt;p>Further talk details can easily be added to this page using &lt;em>Markdown&lt;/em> and $\rm \LaTeX$ math code.&lt;/p></description></item><item><title>Green Fiscal Reforms and the Demographic Squeeze: Lessons from Japan</title><link>https://a-yamazaki1028.github.io/publication/greenfiscal_carbone/</link><pubDate>Thu, 20 Nov 2025 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/publication/greenfiscal_carbone/</guid><description/></item><item><title>Innovating Towards Carbon Neutrality: The Long-Run Responses of Carbon Pricing Policies</title><link>https://a-yamazaki1028.github.io/publication/ctaxextensive/</link><pubDate>Sun, 08 Dec 2024 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/publication/ctaxextensive/</guid><description/></item><item><title>Do Carbon Taxes Kill Jobs? Firm-level Evidence from British Columbia</title><link>https://a-yamazaki1028.github.io/publication/ahy/</link><pubDate>Tue, 31 Jan 2023 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/publication/ahy/</guid><description/></item><item><title>How Do Carbon Taxes Affect Emissions? Plant-level Evidence from Manufacturing</title><link>https://a-yamazaki1028.github.io/publication/ahmadiyamazaki2020/</link><pubDate>Sun, 10 Apr 2022 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/publication/ahmadiyamazaki2020/</guid><description/></item><item><title>Environmental Taxes and Productivity: Lessons from Canadian Manufacturing</title><link>https://a-yamazaki1028.github.io/publication/ctaxproductivity/</link><pubDate>Sat, 01 Jan 2022 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/publication/ctaxproductivity/</guid><description/></item><item><title>Comparing applied general equilibrium and econometric estimates of the effect of an environmental policy shock</title><link>https://a-yamazaki1028.github.io/publication/carbone-et-al2020jaere/</link><pubDate>Fri, 15 May 2020 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/publication/carbone-et-al2020jaere/</guid><description/></item><item><title>Who Bears More Burdens of Carbon Taxes? Heterogeneous Employment Effects within Manufacturing Plants</title><link>https://a-yamazaki1028.github.io/publication/ctaxhetero/</link><pubDate>Mon, 01 Jul 2019 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/publication/ctaxhetero/</guid><description/></item><item><title>An example preprint / working paper</title><link>https://a-yamazaki1028.github.io/old-not-used/publication/preprint/</link><pubDate>Sun, 07 Apr 2019 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/old-not-used/publication/preprint/</guid><description>&lt;div class="alert alert-note">
&lt;div>
Click the &lt;em>Slides&lt;/em> button above to demo Academic&amp;rsquo;s Markdown slides feature.
&lt;/div>
&lt;/div>
&lt;p>Supplementary notes can be added here, including
&lt;a href="https://sourcethemes.com/academic/docs/writing-markdown-latex/" target="_blank" rel="noopener">code and math&lt;/a>.&lt;/p></description></item><item><title>Slides</title><link>https://a-yamazaki1028.github.io/slides/example/</link><pubDate>Tue, 05 Feb 2019 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/slides/example/</guid><description>&lt;h1 id="create-slides-in-markdown-with-academic">Create slides in Markdown with Academic&lt;/h1>
&lt;p>
&lt;a href="https://sourcethemes.com/academic/" target="_blank" rel="noopener">Academic&lt;/a> |
&lt;a href="https://sourcethemes.com/academic/docs/managing-content/#create-slides" target="_blank" rel="noopener">Documentation&lt;/a>&lt;/p>
&lt;hr>
&lt;h2 id="features">Features&lt;/h2>
&lt;ul>
&lt;li>Efficiently write slides in Markdown&lt;/li>
&lt;li>3-in-1: Create, Present, and Publish your slides&lt;/li>
&lt;li>Supports speaker notes&lt;/li>
&lt;li>Mobile friendly slides&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="controls">Controls&lt;/h2>
&lt;ul>
&lt;li>Next: &lt;code>Right Arrow&lt;/code> or &lt;code>Space&lt;/code>&lt;/li>
&lt;li>Previous: &lt;code>Left Arrow&lt;/code>&lt;/li>
&lt;li>Start: &lt;code>Home&lt;/code>&lt;/li>
&lt;li>Finish: &lt;code>End&lt;/code>&lt;/li>
&lt;li>Overview: &lt;code>Esc&lt;/code>&lt;/li>
&lt;li>Speaker notes: &lt;code>S&lt;/code>&lt;/li>
&lt;li>Fullscreen: &lt;code>F&lt;/code>&lt;/li>
&lt;li>Zoom: &lt;code>Alt + Click&lt;/code>&lt;/li>
&lt;li>
&lt;a href="https://github.com/hakimel/reveal.js#pdf-export" target="_blank" rel="noopener">PDF Export&lt;/a>: &lt;code>E&lt;/code>&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="code-highlighting">Code Highlighting&lt;/h2>
&lt;p>Inline code: &lt;code>variable&lt;/code>&lt;/p>
&lt;p>Code block:&lt;/p>
&lt;pre>&lt;code class="language-python">porridge = &amp;quot;blueberry&amp;quot;
if porridge == &amp;quot;blueberry&amp;quot;:
print(&amp;quot;Eating...&amp;quot;)
&lt;/code>&lt;/pre>
&lt;hr>
&lt;h2 id="math">Math&lt;/h2>
&lt;p>In-line math: $x + y = z$&lt;/p>
&lt;p>Block math:&lt;/p>
&lt;p>$$
f\left( x \right) = ;\frac{{2\left( {x + 4} \right)\left( {x - 4} \right)}}{{\left( {x + 4} \right)\left( {x + 1} \right)}}
$$&lt;/p>
&lt;hr>
&lt;h2 id="fragments">Fragments&lt;/h2>
&lt;p>Make content appear incrementally&lt;/p>
&lt;pre>&lt;code>{{% fragment %}} One {{% /fragment %}}
{{% fragment %}} **Two** {{% /fragment %}}
{{% fragment %}} Three {{% /fragment %}}
&lt;/code>&lt;/pre>
&lt;p>Press &lt;code>Space&lt;/code> to play!&lt;/p>
&lt;p>&lt;span class="fragment " >
One
&lt;/span>
&lt;span class="fragment " >
&lt;strong>Two&lt;/strong>
&lt;/span>
&lt;span class="fragment " >
Three
&lt;/span>&lt;/p>
&lt;hr>
&lt;p>A fragment can accept two optional parameters:&lt;/p>
&lt;ul>
&lt;li>&lt;code>class&lt;/code>: use a custom style (requires definition in custom CSS)&lt;/li>
&lt;li>&lt;code>weight&lt;/code>: sets the order in which a fragment appears&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="speaker-notes">Speaker Notes&lt;/h2>
&lt;p>Add speaker notes to your presentation&lt;/p>
&lt;pre>&lt;code class="language-markdown">{{% speaker_note %}}
- Only the speaker can read these notes
- Press `S` key to view
{{% /speaker_note %}}
&lt;/code>&lt;/pre>
&lt;p>Press the &lt;code>S&lt;/code> key to view the speaker notes!&lt;/p>
&lt;aside class="notes">
&lt;ul>
&lt;li>Only the speaker can read these notes&lt;/li>
&lt;li>Press &lt;code>S&lt;/code> key to view&lt;/li>
&lt;/ul>
&lt;/aside>
&lt;hr>
&lt;h2 id="themes">Themes&lt;/h2>
&lt;ul>
&lt;li>black: Black background, white text, blue links (default)&lt;/li>
&lt;li>white: White background, black text, blue links&lt;/li>
&lt;li>league: Gray background, white text, blue links&lt;/li>
&lt;li>beige: Beige background, dark text, brown links&lt;/li>
&lt;li>sky: Blue background, thin dark text, blue links&lt;/li>
&lt;/ul>
&lt;hr>
&lt;ul>
&lt;li>night: Black background, thick white text, orange links&lt;/li>
&lt;li>serif: Cappuccino background, gray text, brown links&lt;/li>
&lt;li>simple: White background, black text, blue links&lt;/li>
&lt;li>solarized: Cream-colored background, dark green text, blue links&lt;/li>
&lt;/ul>
&lt;hr>
&lt;section data-noprocess data-shortcode-slide
data-background-image="/img/boards.jpg"
>
&lt;h2 id="custom-slide">Custom Slide&lt;/h2>
&lt;p>Customize the slide style and background&lt;/p>
&lt;pre>&lt;code class="language-markdown">{{&amp;lt; slide background-image=&amp;quot;/img/boards.jpg&amp;quot; &amp;gt;}}
{{&amp;lt; slide background-color=&amp;quot;#0000FF&amp;quot; &amp;gt;}}
{{&amp;lt; slide class=&amp;quot;my-style&amp;quot; &amp;gt;}}
&lt;/code>&lt;/pre>
&lt;hr>
&lt;h2 id="custom-css-example">Custom CSS Example&lt;/h2>
&lt;p>Let&amp;rsquo;s make headers navy colored.&lt;/p>
&lt;p>Create &lt;code>assets/css/reveal_custom.css&lt;/code> with:&lt;/p>
&lt;pre>&lt;code class="language-css">.reveal section h1,
.reveal section h2,
.reveal section h3 {
color: navy;
}
&lt;/code>&lt;/pre>
&lt;hr>
&lt;h1 id="questions">Questions?&lt;/h1>
&lt;p>
&lt;a href="https://spectrum.chat/academic" target="_blank" rel="noopener">Ask&lt;/a>&lt;/p>
&lt;p>
&lt;a href="https://sourcethemes.com/academic/docs/managing-content/#create-slides" target="_blank" rel="noopener">Documentation&lt;/a>&lt;/p></description></item><item><title>Canada’s aging population</title><link>https://a-yamazaki1028.github.io/post/canada-s-aging-population/</link><pubDate>Mon, 28 Jan 2019 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/post/canada-s-aging-population/</guid><description>
&lt;p>Recently released data from Statistics Canada allows us to explore demographic trends in the age make-up of the Canadian population. The trend is clear: Canada is getting old.&lt;/p>
&lt;p>In this chart-blog, we will take a look at population by age group – both across regions and over time – and how median age has evolved. (Spoiler: It’s risen. A lot!)&lt;/p>
&lt;p>You can find the chart-blog &lt;a href="https://a-yamazaki1028.github.io/post/compiled/Population-pyramids.html">here&lt;/a>&lt;/p></description></item><item><title>Trucks! Trucks! Trucks!</title><link>https://a-yamazaki1028.github.io/post/trucks-trucks-trucks/</link><pubDate>Mon, 17 Dec 2018 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/post/trucks-trucks-trucks/</guid><description>
&lt;p>Quick post to show how easy it is to do quick data exploration using R. This post walks us through making a (nice!) chart of &lt;strong>new vehicle sales in Canada&lt;/strong>, breaking it down by vehicle type and region.&lt;/p>
&lt;div id="step-1-load-the-three-packages-we-will-use-for-this-plot" class="section level2">
&lt;h2>Step 1: Load the three packages we will use for this plot:&lt;/h2>
&lt;ul>
&lt;li>&lt;code>tidyverse&lt;/code> : because always tidyverse&lt;/li>
&lt;li>&lt;code>cansim&lt;/code> : great package to easily extract Statistics Canada data&lt;/li>
&lt;li>&lt;code>ggthemes&lt;/code> : not necessary, but a quick way to pretty up your ggplot&lt;/li>
&lt;/ul>
&lt;pre class="r">&lt;code>library(tidyverse)
library(cansim)
library(ggthemes)&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="step-2-data-wranglin" class="section level2">
&lt;h2>Step 2: Data wranglin’&lt;/h2>
&lt;ol style="list-style-type: decimal">
&lt;li>Pull in the data&lt;/li>
&lt;li>Filter to what we want in the data&lt;/li>
&lt;li>Fiddle with some labels&lt;/li>
&lt;/ol>
&lt;pre class="r">&lt;code>data &amp;lt;- get_cansim(20100001) %&amp;gt;% normalize_cansim_values()
plotdata &amp;lt;- data %&amp;gt;%
filter(GEO!=&amp;quot;Canada&amp;quot;,
Sales==&amp;quot;Units&amp;quot;,
`Vehicle type` %in% c(&amp;quot;Passenger cars&amp;quot;,&amp;quot;Trucks&amp;quot;),
`Origin of manufacture`==&amp;quot;Total, country of manufacture&amp;quot;)
# Change some GEO labels to shorten them
plotdata$GEO[plotdata$GEO==&amp;quot;Newfoundland and Labrador&amp;quot;] &amp;lt;- &amp;quot;Nfld &amp;amp; Lab.&amp;quot;
plotdata$GEO[plotdata$GEO==&amp;quot;British Columbia and the Territories&amp;quot;] &amp;lt;- &amp;quot;BC &amp;amp; Terr.&amp;quot;
plotdata$GEO[plotdata$GEO==&amp;quot;Prince Edward Island&amp;quot;] &amp;lt;- &amp;quot;PEI&amp;quot;
plotdata$GEO &amp;lt;- factor(plotdata$GEO, levels=c(&amp;quot;BC &amp;amp; Terr.&amp;quot;,&amp;quot;Alberta&amp;quot;,&amp;quot;Saskatchewan&amp;quot;,&amp;quot;Manitoba&amp;quot;,&amp;quot;Ontario&amp;quot;,&amp;quot;Quebec&amp;quot;,&amp;quot;New Brunswick&amp;quot;,&amp;quot;PEI&amp;quot;,&amp;quot;Nova Scotia&amp;quot;,&amp;quot;Nfld &amp;amp; Lab.&amp;quot;))
# Change &amp;quot;passenger cars&amp;quot; to &amp;quot;cars&amp;quot; for plot label
plotdata$`Vehicle type`[plotdata$`Vehicle type`==&amp;quot;Passenger cars&amp;quot;] &amp;lt;- &amp;quot;Cars&amp;quot;&lt;/code>&lt;/pre>
&lt;/div>
&lt;div id="step-3-plot-it" class="section level2">
&lt;h2>Step 3: Plot it!&lt;/h2>
&lt;pre class="r">&lt;code>ggplot(plotdata, aes(Date,VALUE,color=`Vehicle type`))+
geom_point(size=.1,alpha=.2)+
geom_smooth(se=F)+
facet_wrap(~GEO, scales=&amp;quot;free_y&amp;quot;, nrow=2)+
scale_color_ptol(name=&amp;quot;&amp;quot;)+ # nice color scheme from ggthemes package
scale_x_date(limits=c(as.Date(&amp;quot;1980-01-01&amp;quot;),as.Date(&amp;quot;2020-01-01&amp;quot;)),
breaks = c(as.Date(&amp;quot;1980-01-01&amp;quot;),as.Date(&amp;quot;2000-01-01&amp;quot;),as.Date(&amp;quot;2020-01-01&amp;quot;)),
date_labels = &amp;quot;%Y&amp;quot;)+
theme_tufte(12,&amp;quot;Shree Devanagari 714&amp;quot;)+ # font similar to &amp;#39;Avenir&amp;#39;
theme(legend.position = &amp;quot;top&amp;quot;,
title=element_text(face=&amp;quot;bold&amp;quot;),
plot.caption = element_text(face=&amp;quot;italic&amp;quot;),
legend.text = element_text(size=14))+
labs(x=&amp;quot;&amp;quot;, y=&amp;quot;&amp;quot;,
subtitle=&amp;quot;New vehicle sales (monthly)&amp;quot;,
title=&amp;quot;Trucks! Trucks! Trucks!&amp;quot;,
caption=&amp;quot;Fitted line through monthly (seasonally unadjusted) data.\nSource: Statscan NDM Table 20-10-0001.&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-17-trucks-trucks-trucks_files/figure-html/truckplot-1.png" width="864" />&lt;/p>
&lt;hr />
&lt;p>There you go. A nice quick plot showing a pretty stark shift in consumer preferences towards trucks across &lt;em>all regions&lt;/em> in Canada. An interesting extension of this data exploration would be to see what this means in terms of fleet-wide fuel economy. Are people switching from Civics to F-150s? Or Crown Vics to Subaru Crosstreks? The latter would mean a shift from cars to “trucks” is improving overall gas mileage… More data needed!&lt;/p>
&lt;p>&lt;em>Happy Charting!&lt;/em>&lt;/p>
&lt;p>&lt;em>-Blake&lt;/em>&lt;/p>
&lt;/div></description></item><item><title>Making animated charts with gganimate</title><link>https://a-yamazaki1028.github.io/post/making-animated-charts-with-gganimate/</link><pubDate>Fri, 14 Dec 2018 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/post/making-animated-charts-with-gganimate/</guid><description>
&lt;p>What’s better than making charts? Making them animated, of course! While animation isn’t always (ok, rarely) necessary, it can help tell a story static charts can’t.&lt;/p>
&lt;p>Recently there has been a lot of discussion in Canada related to &lt;em>equalization&lt;/em>. This is a federal program to transfer funds to provinces with below average fiscal capacity. What is “fiscal capacity”? Others can tell you a &lt;a href="https://ideas.repec.org/p/clg/wpaper/2018-13.html">&lt;strong>lot&lt;/strong>&lt;/a> more about it, but for simplicity, we can think of it like GDP.&lt;/p>
&lt;p>So I wanted to take a look at GDP per capita, by province, going back several years. A little learning, a lot of online digging, and I was able to create this nice chart:&lt;/p>
&lt;blockquote class="twitter-tweet" data-lang="en">
&lt;p lang="en" dir="ltr">
I made a chart. &lt;a href="https://twitter.com/hashtag/cdnecon?src=hash&amp;amp;ref_src=twsrc%5Etfw">#cdnecon&lt;/a> &lt;a href="https://twitter.com/hashtag/cdnpoli?src=hash&amp;amp;ref_src=twsrc%5Etfw">#cdnpoli&lt;/a> &lt;a href="https://t.co/Ks8o5E4qir">pic.twitter.com/Ks8o5E4qir&lt;/a>
&lt;/p>
— Blake Shaffer 📊 (&lt;span class="citation">@bcshaffer&lt;/span>) &lt;a href="https://twitter.com/bcshaffer/status/1073340073184296960?ref_src=twsrc%5Etfw">December 13, 2018&lt;/a>
&lt;/blockquote>
&lt;script async src="https://platform.twitter.com/widgets.js" charset="utf-8">&lt;/script>
&lt;p>People seemed to like it and some wanted to know more about how it was made. This post explains how to make an animated chart like the tweeted one above using &lt;code>gganimate&lt;/code>.&lt;/p>
&lt;p>##Let’s go!&lt;/p>
&lt;p>To begin, let’s load our usual packages, but add in the latest version of &lt;code>gganimate&lt;/code> from David Robinson which has been updated by Thomas Lin Pedersen. Thomas has added some new syntax which allows for &lt;em>really nice transitions&lt;/em> to the animation.&lt;/p>
&lt;pre class="r">&lt;code>library(tidyverse)
library(lubridate)
library(ggthemes)
library(ggrepel)
# Package to pull in cansim data, courtesy of Jens von Bergman and Dmitry Shkolnik
library(cansim)
# Now update to the newest gganimate version
#install.packages(&amp;quot;devtools&amp;quot;)
#devtools::install_github(&amp;#39;thomasp85/gganimate&amp;#39;)
library(gganimate)&lt;/code>&lt;/pre>
&lt;p>With packages loaded, it’s time to wrangle the data. I could probably do this cleaner, but meh - it works! I wrote a function below to change the full province names to their 2 character abbreviations that we will use in the plots.&lt;/p>
&lt;p>##Let’s start by pulling in annual GDP data by province and to test it’s working do a quick plot.&lt;/p>
&lt;pre class="r">&lt;code>provlist &amp;lt;- c(&amp;quot;British Columbia&amp;quot;,&amp;quot;Alberta&amp;quot;,&amp;quot;Saskatchewan&amp;quot;,&amp;quot;Manitoba&amp;quot;,&amp;quot;Ontario&amp;quot;,&amp;quot;Quebec&amp;quot;,&amp;quot;New Brunswick&amp;quot;,&amp;quot;Nova Scotia&amp;quot;,&amp;quot;Prince Edward Island&amp;quot;,&amp;quot;Newfoundland and Labrador&amp;quot;)
short_provs &amp;lt;- function(df){
df &amp;lt;- df %&amp;gt;%
filter(GEO %in% c(&amp;quot;British Columbia&amp;quot;,&amp;quot;Alberta&amp;quot;,&amp;quot;Saskatchewan&amp;quot;,&amp;quot;Manitoba&amp;quot;,&amp;quot;Ontario&amp;quot;,&amp;quot;Quebec&amp;quot;,&amp;quot;New Brunswick&amp;quot;,&amp;quot;Nova Scotia&amp;quot;,&amp;quot;Prince Edward Island&amp;quot;,&amp;quot;Newfoundland and Labrador&amp;quot;))
df &amp;lt;- df %&amp;gt;%
mutate(GEO.short = case_when(
GEO==&amp;quot;British Columbia&amp;quot; ~ &amp;quot;BC&amp;quot;,
GEO==&amp;quot;Alberta&amp;quot; ~ &amp;quot;AB&amp;quot;,
GEO==&amp;quot;Saskatchewan&amp;quot; ~ &amp;quot;SK&amp;quot;,
GEO==&amp;quot;Manitoba&amp;quot; ~ &amp;quot;MB&amp;quot;,
GEO==&amp;quot;Ontario&amp;quot; ~ &amp;quot;ON&amp;quot;,
GEO==&amp;quot;Quebec&amp;quot; ~ &amp;quot;QC&amp;quot;,
GEO==&amp;quot;New Brunswick&amp;quot; ~ &amp;quot;NB&amp;quot;,
GEO==&amp;quot;Prince Edward Island&amp;quot; ~ &amp;quot;PE&amp;quot;,
GEO==&amp;quot;Nova Scotia&amp;quot; ~ &amp;quot;NS&amp;quot;,
GEO==&amp;quot;Newfoundland and Labrador&amp;quot; ~ &amp;quot;NL&amp;quot;
))
df$GEO.short &amp;lt;- factor(df$GEO.short, levels=c(&amp;quot;BC&amp;quot;,&amp;quot;AB&amp;quot;,&amp;quot;SK&amp;quot;,&amp;quot;MB&amp;quot;,&amp;quot;ON&amp;quot;,&amp;quot;QC&amp;quot;,&amp;quot;NB&amp;quot;,&amp;quot;PE&amp;quot;,&amp;quot;NS&amp;quot;,&amp;quot;NL&amp;quot;))
}
GDP &amp;lt;- get_cansim(36100222) %&amp;gt;% normalize_cansim_values()
df.GDP &amp;lt;- GDP %&amp;gt;%
mutate(year=as.integer(REF_DATE)) %&amp;gt;%
filter(GEO %in% provlist,
Prices==&amp;quot;Chained (2012) dollars&amp;quot;,
Estimates==&amp;quot;Gross domestic product at market prices&amp;quot;) %&amp;gt;%
dplyr::select(GEO,year,GDP=VALUE)
df.GDP$GEO.short&amp;lt;-short_provs(df.GDP)
ggplot(df.GDP, aes(GEO.short, GDP/1e9, fill = GEO.short, label=GEO.short)) +
geom_col()+
geom_text(vjust=-.1)+
scale_fill_viridis_d(name=&amp;quot;&amp;quot;)+
scale_y_continuous(labels=scales::dollar)+
theme_tufte(14,&amp;quot;Avenir&amp;quot;)+
theme(legend.position = &amp;quot;none&amp;quot;,
axis.text.x = element_blank(),
axis.ticks = element_blank())+
# Here comes the gganimate specific bits
labs(title = &amp;quot;Year: {frame_time}&amp;quot;, x = &amp;quot;&amp;quot;, y = &amp;quot;GDP (2012$ billions&amp;quot;) +
transition_time(year) +
ease_aes(&amp;#39;linear&amp;#39;) &lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-14-making-animated-charts-with-gganimate_files/figure-html/GDP-1.gif" />&lt;!-- -->&lt;/p>
&lt;p>Ok. Good! We have an animated chart! But it’s not too informative given the BIG and small size of provinces. So to look at per capita GDP we need to pull in annual population data and merge it with our GDP data.&lt;/p>
&lt;pre class="r">&lt;code>pop &amp;lt;- get_cansim(17100005) %&amp;gt;% normalize_cansim_values()
df.pop &amp;lt;- pop %&amp;gt;%
mutate(year=as.integer(REF_DATE)) %&amp;gt;%
filter(GEO %in% provlist,
Sex==&amp;quot;Both sexes&amp;quot;,
`Age group`==&amp;quot;All ages&amp;quot;) %&amp;gt;%
dplyr::select(GEO,year,pop=VALUE)
df.GDPpercap &amp;lt;-left_join(df.GDP,df.pop, by=c(&amp;quot;year&amp;quot;,&amp;quot;GEO&amp;quot;)) %&amp;gt;%
mutate(GDPpercap=GDP/pop)
df.GDPpercap$GEO.short&amp;lt;-short_provs(df.GDPpercap)&lt;/code>&lt;/pre>
&lt;p>##Now, let’s create our plot.&lt;/p>
&lt;p>I’m going to use the &lt;code>animate&lt;/code> function here so that I can change the speed of the animation a bit, and add a pause at the end.&lt;/p>
&lt;pre class="r">&lt;code>p&amp;lt;-ggplot(df.GDPpercap, aes(GEO.short, GDPpercap, fill=GEO.short, label=GEO.short)) +
geom_col()+
geom_text(vjust=-.1)+
scale_fill_viridis_d(name=&amp;quot;&amp;quot;)+
theme_tufte(14,&amp;quot;Avenir&amp;quot;)+
theme(legend.position = &amp;quot;none&amp;quot;,
axis.text.x = element_blank(),
axis.ticks = element_blank())+
# Here comes the gganimate specific bits
labs(title = &amp;#39;Year: {frame_time}&amp;#39;, x = &amp;#39;&amp;#39;, y = &amp;#39;GDP per capita ($2012)&amp;#39;) +
transition_time(year) +
ease_aes(&amp;#39;linear&amp;#39;)
animate(p, fps=5, end_pause = 30) # Use anim_save(filename) to save the plot&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-14-making-animated-charts-with-gganimate_files/figure-html/gdppercap-1.gif" />&lt;!-- -->&lt;/p>
&lt;p>Not bad. But we can do better! It would be fun to get the provinces to rank themselves every frame. And let’s flip it horizontally too to look like they’re climbing over one another.&lt;/p>
&lt;p>A little digging on stackoverflow took me to this post by Jon Spring: &lt;a href="https://stackoverflow.com/questions/52623722/how-does-gganimate-order-an-ordered-bar-time-series">(https://stackoverflow.com/questions/52623722/how-does-gganimate-order-an-ordered-bar-time-series)&lt;/a>&lt;/p>
&lt;p>Basically, we add a rank variable, grouping first by year and ordering the provinces. We will use this as our x axis (vertical axis in the flipped coordinates). We will also use &lt;code>geom_tile&lt;/code> instead of &lt;code>geom_col&lt;/code> because this object creates smoother transitions in the size of the bars.&lt;/p>
&lt;div id="the-tweeted-chart" class="section level2">
&lt;h2>The tweeted chart!&lt;/h2>
&lt;pre class="r">&lt;code>plotdata &amp;lt;- df.GDPpercap %&amp;gt;%
group_by(year) %&amp;gt;%
mutate(ordering = rank(GDPpercap)) %&amp;gt;%
ungroup()
p&amp;lt;-ggplot(plotdata,
aes(ordering, group = GEO.short,color=GEO.short,fill=GEO.short)) +
geom_tile(aes(y = GDPpercap/2,
height = GDPpercap,
width = 0.9), alpha = 0.9) +
# text on top of bars
geom_text(aes(y = GDPpercap, label = GEO.short), hjust = -0.4) +
# text in x-axis (requires clip = &amp;quot;off&amp;quot; in coord_cartesian)
geom_text(aes(y = 0, label = GEO.short), hjust = 1.4) +
coord_flip(clip = &amp;quot;off&amp;quot;, expand = FALSE) +
scale_color_viridis_d(name=&amp;quot;&amp;quot;)+
scale_fill_viridis_d(name=&amp;quot;&amp;quot;)+
scale_y_continuous(labels=scales::dollar)+
theme_tufte(14,&amp;quot;Avenir&amp;quot;)+
guides(color=F,fill=F)+
labs(title=&amp;#39;{frame_time}&amp;#39;, x = &amp;quot;&amp;quot;,y=&amp;quot;GDP per capita ($2012)&amp;quot;) +
theme(plot.title = element_text(hjust = 1, size = 22),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
transition_time(year)+
ease_aes(&amp;#39;cubic-in-out&amp;#39;)
animate(p, nframes = 100, fps = 5, end_pause = 20) #again, use anim_save(filename) to save&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-14-making-animated-charts-with-gganimate_files/figure-html/GDPpercap_good_plot-1.gif" />&lt;!-- -->&lt;/p>
&lt;p>Cool. If i do say so myself :-)&lt;/p>
&lt;p>But wait, we can do more! Rather than bars, let’s plot points as in a scatter plot and watch them float over time. We can start by looking at the co-movement of &lt;strong>GDP per capita&lt;/strong> and &lt;strong>unemployment&lt;/strong> rates across provinces over time. I pull in the annual LFS data from &lt;code>NDM 14-10-0090&lt;/code>, merging the annual unemployment rate values with our GDP per capita data.&lt;/p>
&lt;/div>
&lt;div id="lets-chart-it" class="section level2">
&lt;h2>Let’s chart it!&lt;/h2>
&lt;pre class="r">&lt;code>p&amp;lt;-ggplot(df.full,
aes(GDPpercap,Unemp_Rate,
color=GEO.short, label=GEO.short)) +
geom_point(aes(size=pop))+
geom_text(hjust=-.2,vjust=-.2)+
scale_color_viridis_d(name=&amp;quot;&amp;quot;)+
scale_y_continuous(labels=scales::percent)+
scale_x_continuous(labels=scales::dollar)+
theme_tufte(14,&amp;quot;Avenir&amp;quot;)+
theme(legend.position = &amp;quot;none&amp;quot;,
plot.caption = element_text(size=9,face=&amp;quot;italic&amp;quot;))+
guides(size=F,color=F)+
# Here comes the gganimate specific bits
labs(title = &amp;#39;Year: {frame_time}&amp;#39;,
x = &amp;#39;GDP per capita ($2012)&amp;#39;,
y = &amp;quot;Unemployment Rate&amp;quot;,
caption=&amp;quot;Bubble size proportional to population\nChart by @bcshaffer&amp;quot;) +
transition_time(year) +
ease_aes(&amp;#39;linear&amp;#39;)
animate(p, nframes = 100, fps = 10, width = 600, height = 400, end_pause = 30)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-14-making-animated-charts-with-gganimate_files/figure-html/unemp-1.gif" />&lt;!-- -->&lt;/p>
&lt;p>Lastly, we can do the same with the &lt;strong>employment rate&lt;/strong>. This time leads add some bread crumbs behind our roving points to get some history.&lt;/p>
&lt;pre class="r">&lt;code>p&amp;lt;-ggplot(df.full,
aes(GDPpercap,Emp_Rate,
color=GEO.short, label=GEO.short)) +
geom_point(aes(size=pop))+
geom_text(hjust=-.2,vjust=-.2)+
scale_color_viridis_d(name=&amp;quot;&amp;quot;)+
scale_y_continuous(labels=scales::percent)+
scale_x_continuous(labels=scales::dollar)+
theme_tufte(14,&amp;quot;Avenir&amp;quot;)+
theme(legend.position = &amp;quot;none&amp;quot;,
plot.caption = element_text(size=9,face=&amp;quot;italic&amp;quot;))+
guides(size=F,color=F)+
# Here comes the gganimate specific bits
labs(title = &amp;#39;Year: {frame_time}&amp;#39;,
x = &amp;#39;GDP per capita ($2012)&amp;#39;,
y = &amp;quot;Employment Rate&amp;quot;,
caption=&amp;quot;Bubble size proportional to population\nChart by @bcshaffer&amp;quot;) +
transition_time(year) +
shadow_wake(wake_length = 1, exclude_layer = 2)+
ease_aes(&amp;#39;cubic-in-out&amp;#39;)
#ease_aes(&amp;#39;linear&amp;#39;)
animate(p, nframes = 100, fps = 10, width = 600, height = 400, end_pause = 30)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-14-making-animated-charts-with-gganimate_files/figure-html/emp-1.gif" />&lt;!-- -->&lt;/p>
&lt;p>&lt;strong>&lt;em>Happy charting!&lt;/em>&lt;/strong>&lt;/p>
&lt;p>-Blake&lt;/p>
&lt;/div></description></item><item><title>New Statscan data on victims of violent crime in Canada</title><link>https://a-yamazaki1028.github.io/post/new-statscan-data-on-victims-of-violent-crime/</link><pubDate>Thu, 06 Dec 2018 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/post/new-statscan-data-on-victims-of-violent-crime/</guid><description>
&lt;p>Statistics Canada recently released new data on victims of violent crime across Canada from 2009 to 2017. In this post, I explore trends in this data by region, age and gender.&lt;/p>
&lt;p>I find, unsurprisingly, big differences in incidence by gender. The rate of violent crime, notably sexual assaults, remains extremely skewed towards women. The rate of violent crime causing death and attempted murder is skewed towards men but remains relatively low in Canada. &lt;strong>Alarmingly, the rate of sexual assaults towards young girls is high and climbing.&lt;/strong> Regional splits also show concerning trends in certain regions.&lt;/p>
&lt;hr />
&lt;p>Let’s start by pulling in the data which can be found in NDM table 35-10-0051.&lt;/p>
&lt;pre class="r">&lt;code>library(tidyverse)
library(cansim)
library(ggthemes)
data &amp;lt;- get_cansim(35100051) %&amp;gt;% normalize_cansim_values() %&amp;gt;%
mutate(year = as.numeric(REF_DATE))
data$GEO &amp;lt;- factor(data$GEO, levels=c(&amp;quot;Canada&amp;quot;,
&amp;quot;British Columbia&amp;quot;,
&amp;quot;Alberta&amp;quot;,
&amp;quot;Saskatchewan&amp;quot;,
&amp;quot;Manitoba&amp;quot;,
&amp;quot;Ontario&amp;quot;,
&amp;quot;Quebec&amp;quot;,
&amp;quot;New Brunswick&amp;quot;,
&amp;quot;Prince Edward Island&amp;quot;,
&amp;quot;Nova Scotia&amp;quot;,
&amp;quot;Newfoundland and Labrador&amp;quot;,
&amp;quot;Yukon&amp;quot;,
&amp;quot;Northwest Territories&amp;quot;,
&amp;quot;Nunavut&amp;quot;))&lt;/code>&lt;/pre>
&lt;p>To start, let’s look at Canada-wide total violations, by gender:&lt;/p>
&lt;pre class="r">&lt;code>plotdata &amp;lt;- data %&amp;gt;%
filter( `Sex of victim`!=&amp;quot;Total, sex of victim&amp;quot;,
`Sex of victim`!=&amp;quot;Sex of victim unknown&amp;quot;,
`Age of victim`==&amp;quot;Total, age of victim&amp;quot;,
Statistics==&amp;quot;Rate per 100,000 population&amp;quot;,
GEO==&amp;quot;Canada&amp;quot;,
Violations==&amp;quot;Total, all violations&amp;quot;)
ggplot(plotdata,
aes(Date,VALUE, group=`Sex of victim`, color=`Sex of victim`))+
geom_line(size=1.5)+
theme_light(12,&amp;quot;Avenir&amp;quot;)+
scale_color_manual(name=&amp;quot;&amp;quot;,values=c(&amp;quot;#CC6677&amp;quot;,&amp;quot;#4477AA&amp;quot;))+
theme(legend.position = &amp;quot;top&amp;quot;)+
labs(x=&amp;quot;&amp;quot;,y=&amp;quot;Rate per 100,000 population&amp;quot;,
title=&amp;quot;Victims of police-reported violent crime&amp;quot;,
subtitle=&amp;quot;Total, all ages&amp;quot;,
caption=&amp;quot;Source: Statistics Canada NDM 35-10-0051\nChart by @bcshaffer&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-2-1.png" width="672" />&lt;/p>
&lt;p>We can dig a little deeper and see how this breaks down by age group:&lt;/p>
&lt;pre class="r">&lt;code># by age
plotdata &amp;lt;- data %&amp;gt;%
filter( `Sex of victim`!=&amp;quot;Total, sex of victim&amp;quot;,
`Sex of victim`!=&amp;quot;Sex of victim unknown&amp;quot;,
`Age of victim` %in% c(&amp;quot;Under 12 years&amp;quot;,
&amp;quot;12 to 17 years&amp;quot;,
&amp;quot;18 years and over&amp;quot;),
Statistics==&amp;quot;Rate per 100,000 population&amp;quot;,
GEO==&amp;quot;Canada&amp;quot;,
Violations==&amp;quot;Total, all violations&amp;quot;)
plotdata$`Age of victim` &amp;lt;- factor(plotdata$`Age of victim`,
levels=c(&amp;quot;Under 12 years&amp;quot;,
&amp;quot;12 to 17 years&amp;quot;,
&amp;quot;18 years and over&amp;quot;))
ggplot(plotdata,
aes(Date,VALUE, group=`Sex of victim`, color=`Sex of victim`))+
geom_line(size=1.5)+
theme_light(12,&amp;quot;Avenir&amp;quot;)+
facet_wrap(~ `Age of victim`,nrow=1)+
scale_color_manual(name=&amp;quot;&amp;quot;,values=c(&amp;quot;#CC6677&amp;quot;,&amp;quot;#4477AA&amp;quot;))+
theme(legend.position = &amp;quot;top&amp;quot;)+
labs(x=&amp;quot;&amp;quot;,y=&amp;quot;Rate per 100,000 population&amp;quot;,
title=&amp;quot;Victims of police-reported violent crime&amp;quot;,
subtitle=&amp;quot;Total, all ages&amp;quot;,
caption=&amp;quot;Source: Statistics Canada NDM 35-10-0051\nChart by @bcshaffer&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-3-1.png" width="672" />&lt;/p>
&lt;p>There is concerning growth in the rate of violent crimes against teens. For some perspective, let’s see the same data in numbers of victim rather than rate. The bulk of crimes remains in the greater than 18 category, although growth is larger for teens, especially on a per capita basis.
&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-4-1.png" width="672" />&lt;/p>
&lt;p>Now, let’s look at the rate of crime per 100,000 population by each violation type across each province. The list of violation types is:&lt;/p>
&lt;pre class="r">&lt;code>unique(data$Violations)&lt;/code>&lt;/pre>
&lt;pre>&lt;code>## [1] &amp;quot;Total, all violations&amp;quot;
## [2] &amp;quot;Violations causing death and attempted murder&amp;quot;
## [3] &amp;quot;Sexual assaults, levels 1, 2, 3&amp;quot;
## [4] &amp;quot;Sexual violations against children&amp;quot;
## [5] &amp;quot;Assaults&amp;quot;
## [6] &amp;quot;Other violent violations&amp;quot;
## [7] &amp;quot;Criminal Code traffic violations causing death or bodily harm&amp;quot;&lt;/code>&lt;/pre>
&lt;div id="breakdown-by-province" class="section level2">
&lt;h2>Breakdown by Province&lt;/h2>
&lt;p>We start by only looking at the provinces, because the territory values blow up the y-axis. I’ll come back to important data in the territories later. We aggregate across all ages, but split the data by sex.&lt;/p>
&lt;pre class="r">&lt;code># Function to plot by sex (all ages) with violation type as input
# Excludes territories due to much higher rate (y-axis issues)
plotbysex &amp;lt;- function(v){
plotdata &amp;lt;- data %&amp;gt;%
filter( Violations==v,
`Sex of victim`!=&amp;quot;Total, sex of victim&amp;quot;,
`Sex of victim`!=&amp;quot;Sex of victim unknown&amp;quot;,
`Age of victim`==&amp;quot;Total, age of victim&amp;quot;,
Statistics==&amp;quot;Rate per 100,000 population&amp;quot;,
!(GEO %in% c(&amp;quot;Canada&amp;quot;,&amp;quot;Northwest Territories&amp;quot;,&amp;quot;Nunavut&amp;quot;,&amp;quot;Yukon&amp;quot;))
)
ggplot(plotdata, aes(year,VALUE, group=`Sex of victim`, color=`Sex of victim`))+
geom_line(size=1.5)+
facet_wrap(~ GEO,nrow=2)+
theme_light(12,&amp;quot;Avenir&amp;quot;)+
scale_color_manual(name=&amp;quot;&amp;quot;,values=c(&amp;quot;#CC6677&amp;quot;,&amp;quot;#4477AA&amp;quot;))+
scale_x_continuous(breaks=c(2010,2016))+
theme(legend.position = &amp;quot;top&amp;quot;)+
labs(x=&amp;quot;&amp;quot;,y=&amp;quot;Rate per 100,000 population&amp;quot;,
title=&amp;quot;Victims of police-reported violent crime&amp;quot;,
subtitle=paste0(v,&amp;quot;, all ages&amp;quot;),
caption=&amp;quot;Source: Statistics Canada NDM 35-10-0051\nChart by @bcshaffer&amp;quot;)
}&lt;/code>&lt;/pre>
&lt;pre class="r">&lt;code>plotbysex(&amp;quot;Total, all violations&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-7-1.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbysex(&amp;quot;Violations causing death and attempted murder&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-7-2.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbysex(&amp;quot;Sexual assaults, levels 1, 2, 3&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-7-3.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbysex(&amp;quot;Sexual violations against children&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-7-4.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbysex(&amp;quot;Assaults&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-7-5.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbysex(&amp;quot;Other violent violations&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-7-6.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbysex(&amp;quot;Criminal Code traffic violations causing death or bodily harm&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-7-7.png" width="672" />&lt;/p>
&lt;/div>
&lt;div id="the-territories" class="section level2">
&lt;h2>The Territories&lt;/h2>
&lt;p>Now, let’s look at the same data, but filtering only on the 3 territories and Canada for reference.&lt;/p>
&lt;pre class="r">&lt;code>plotbysex.t(&amp;quot;Total, all violations&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-9-1.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbysex.t(&amp;quot;Violations causing death and attempted murder&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-9-2.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbysex.t(&amp;quot;Sexual assaults, levels 1, 2, 3&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-9-3.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbysex.t(&amp;quot;Sexual violations against children&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-9-4.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbysex.t(&amp;quot;Assaults&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-9-5.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbysex.t(&amp;quot;Other violent violations&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-9-6.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbysex.t(&amp;quot;Criminal Code traffic violations causing death or bodily harm&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-9-7.png" width="672" />&lt;/p>
&lt;/div>
&lt;div id="breakdown-by-age" class="section level2">
&lt;h2>Breakdown by Age&lt;/h2>
&lt;p>We can look at how the incidence of violent crime breaks down by age. Here we’ll look at the Canada-wide numbers. A massive table (facet_grid) splitting it by age and region is possible, but gets messy quickly. I hide the function code here, but it is similar to the above function, with the exception that faceting is done by age rather than province, and I filter on Canada-wide data only.&lt;/p>
&lt;pre class="r">&lt;code>plotbyage(&amp;quot;Total, all violations&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-11-1.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbyage(&amp;quot;Violations causing death and attempted murder&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-11-2.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbyage(&amp;quot;Sexual assaults, levels 1, 2, 3&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-11-3.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbyage(&amp;quot;Sexual violations against children&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-11-4.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbyage(&amp;quot;Assaults&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-11-5.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbyage(&amp;quot;Other violent violations&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-11-6.png" width="672" />&lt;/p>
&lt;pre class="r">&lt;code>plotbyage(&amp;quot;Criminal Code traffic violations causing death or bodily harm&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/unnamed-chunk-11-7.png" width="672" />&lt;/p>
&lt;hr />
&lt;/div>
&lt;div id="the-bottom-line" class="section level2">
&lt;h2>The Bottom Line:&lt;/h2>
&lt;ul>
&lt;li>The rate of violent crime, notably sexual assaults, remains extremely skewed towards women.&lt;/li>
&lt;li>The rate of violent crime causing death and attempted murder is skewed towards men but remains relatively low.&lt;/li>
&lt;li>&lt;strong>The rate of sexual assaults towards young girls is high and alarmingly climbing.&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-12-06-new-statscan-data-on-victims-of-violent-crime_files/figure-html/sexual_assault_teens-1.png" width="672" />&lt;/p>
&lt;/div></description></item><item><title>Gasoline demand: BC and the Rest of Canada</title><link>https://a-yamazaki1028.github.io/post/gasoline-demand-bc-and-the-rest-of-canada/</link><pubDate>Fri, 30 Nov 2018 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/post/gasoline-demand-bc-and-the-rest-of-canada/</guid><description>
&lt;p>This post looks at gasoline demand across the Canadian provinces and territories. It was prompted by this tweet by &lt;span class="citation">@sjmuir&lt;/span>, noting that gasoline demand per capita in BC is unchanged since 2008, the year of implementation of the BC carbon tax.&lt;/p>
&lt;blockquote class="twitter-tweet" data-lang="en">
&lt;p lang="en" dir="ltr">
It's taboo to point this out, but the fact is that British Columbia residents used as much gasoline in 2017 as they did in 2008. That's why I'm skeptical whenever it's stated that carbon pricing has led to some kind of revolution in fuel usage, because it hasn't. &lt;a href="https://t.co/3IPILHxnTw">pic.twitter.com/3IPILHxnTw&lt;/a>
&lt;/p>
— Stewart Muir (&lt;span class="citation">@sjmuir&lt;/span>) &lt;a href="https://twitter.com/sjmuir/status/1068523879331586048?ref_src=twsrc%5Etfw">November 30, 2018&lt;/a>
&lt;/blockquote>
&lt;script async src="https://platform.twitter.com/widgets.js" charset="utf-8">&lt;/script>
&lt;p>The data didn’t fit my prior as I had seen in a &lt;a href="https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2778868">recent paper&lt;/a> that shows BC gasoline demand per capita falling relative to the rest of Canada.&lt;/p>
&lt;p>So what gives?&lt;/p>
&lt;p>It turns out, a lot has changed since the above referenced paper. Namely, BC gasoline demand has risen quite a bit since 2015. Let’s dig in. I’ll first plot the change in total gasoline demand in each province since 2008:&lt;/p>
&lt;pre class="r">&lt;code>library(tidyverse)
library(lubridate)
library(cansim)
library(ggrepel)
library(ggthemes)
## GET EMPLOYMENT DATA
data.gas &amp;lt;- get_cansim(23100066) %&amp;gt;%
normalize_cansim_values() %&amp;gt;%
filter(`Type of fuel sales`==&amp;quot;Net sales of gasoline&amp;quot;,
GEO!=&amp;quot;Northwest Territories including Nunavut&amp;quot;) %&amp;gt;%
mutate(Year=as.numeric(REF_DATE),
Region = case_when(GEO %in% c(&amp;quot;British Columbia&amp;quot;,&amp;quot;Alberta&amp;quot;,&amp;quot;Saskatchewan&amp;quot;) ~ &amp;quot;West&amp;quot;,
GEO %in% c(&amp;quot;Manitoba&amp;quot;,&amp;quot;Ontario&amp;quot;,&amp;quot;Quebec&amp;quot;) ~ &amp;quot;Central&amp;quot;,
GEO %in% c(&amp;quot;New Brunswick&amp;quot;,&amp;quot;Nova Scotia&amp;quot;,&amp;quot;Prince Edward Island&amp;quot;,&amp;quot;Newfoundland and Labrador&amp;quot;) ~ &amp;quot;East&amp;quot;,
GEO %in% c(&amp;quot;Yukon&amp;quot;,&amp;quot;Northwest Territories&amp;quot;,&amp;quot;Nunavut&amp;quot;) ~ &amp;quot;Territories&amp;quot;,
GEO==&amp;quot;Canada&amp;quot; ~ &amp;quot;CANADA&amp;quot;),
GEO.abb = case_when(GEO==&amp;quot;British Columbia&amp;quot; ~ &amp;quot;BC&amp;quot;,
GEO==&amp;quot;Alberta&amp;quot; ~ &amp;quot;AB&amp;quot;,
GEO==&amp;quot;Saskatchewan&amp;quot; ~ &amp;quot;SK&amp;quot;,
GEO==&amp;quot;Manitoba&amp;quot; ~ &amp;quot;MB&amp;quot;,
GEO==&amp;quot;Ontario&amp;quot; ~ &amp;quot;ON&amp;quot;,
GEO==&amp;quot;Quebec&amp;quot; ~ &amp;quot;QC&amp;quot;,
GEO==&amp;quot;New Brunswick&amp;quot; ~ &amp;quot;NB&amp;quot;,
GEO==&amp;quot;Nova Scotia&amp;quot; ~ &amp;quot;NS&amp;quot;,
GEO==&amp;quot;Prince Edward Island&amp;quot; ~ &amp;quot;PE&amp;quot;,
GEO==&amp;quot;Newfoundland and Labrador&amp;quot; ~ &amp;quot;NL&amp;quot;,
GEO==&amp;quot;Yukon&amp;quot; ~ &amp;quot;YT&amp;quot;,
GEO==&amp;quot;Northwest Territories&amp;quot; ~ &amp;quot;NT&amp;quot;,
GEO==&amp;quot;Nunavut&amp;quot; ~ &amp;quot;NU&amp;quot;,
GEO==&amp;quot;Canada&amp;quot; ~ &amp;quot;CAN&amp;quot;)) %&amp;gt;%
group_by(GEO) %&amp;gt;%
mutate(Index=VALUE/VALUE[Year==2008]) %&amp;gt;%
dplyr::select(Year,Date,GEO,GEO.abb,Region,Index,&amp;quot;Gasoline&amp;quot;=VALUE)
data.gas$Region &amp;lt;- factor(data.gas$Region, levels=c(&amp;quot;CANADA&amp;quot;,&amp;quot;West&amp;quot;,&amp;quot;Central&amp;quot;,&amp;quot;East&amp;quot;,&amp;quot;Territories&amp;quot;))
ggplot()+
geom_line(data=data.gas %&amp;gt;% filter(GEO!=&amp;quot;Canada&amp;quot;,GEO!=&amp;quot;Nunavut&amp;quot;,GEO!=&amp;quot;British Columbia&amp;quot;),
aes(Year,Index,group=GEO,color=GEO),
size=1)+
geom_line(data=data.gas %&amp;gt;% filter(GEO==&amp;quot;British Columbia&amp;quot;),
aes(Year,Index),
size=2, color=&amp;quot;firebrick&amp;quot;)+
geom_label_repel(data=data.gas %&amp;gt;% filter(Year==2017,GEO!=&amp;quot;Canada&amp;quot;,GEO!=&amp;quot;Nunavut&amp;quot;,GEO!=&amp;quot;British Columbia&amp;quot;),
aes(Year, Index, color=GEO, label=GEO.abb),
nudge_x=.5)+
geom_label_repel(data=data.gas %&amp;gt;% filter(Year==2017,GEO==&amp;quot;British Columbia&amp;quot;),
aes(Year, Index, label=GEO.abb),
nudge_x=.5, color=&amp;quot;firebrick&amp;quot;)+
geom_hline(yintercept = 1,linetype=&amp;quot;dashed&amp;quot;)+
scale_y_continuous(labels=scales::percent)+
scale_x_continuous(breaks=seq(2008,2018,2),limits=c(2008,2018))+
coord_cartesian(ylim=c(.95,1.4))+
scale_color_viridis_d(name=&amp;quot;&amp;quot;)+
theme_classic(14,&amp;quot;Gill Sans&amp;quot;)+
theme(plot.caption=element_text(size=8,face=&amp;quot;italic&amp;quot;),
legend.position = &amp;quot;none&amp;quot;)+
labs(x=&amp;quot;&amp;quot;,y=&amp;quot;&amp;quot;,
subtitle=&amp;quot;Gasoline demand relative to 2008 (unadjusted for population)&amp;quot;,
caption=&amp;quot;Statistics Canada NDM Table 23-10-0066\nChart by @bcshaffer&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-11-30-gasoline-demand-bc-and-the-rest-of-canada_files/figure-html/gasoline_index-1.png" width="768" />&lt;/p>
&lt;p>It’s a busy chart but there’s a few things to note:&lt;/p>
&lt;ol style="list-style-type: decimal">
&lt;li>Sask is guzzling the stuff. This isn’t per capita yet, but still!&lt;/li>
&lt;li>Meanwhile, BC, which showed a big dip in 2011-2014 has come roaring back.&lt;/li>
&lt;/ol>
&lt;p>The above chart isn’t per capita. So let’s get quarterly population estimates, annualize them, and create a gasoline_per_capita variable:&lt;/p>
&lt;pre class="r">&lt;code>## GET POPULATION DATA
data.population &amp;lt;- get_cansim(0510005) %&amp;gt;%
normalize_cansim_values() %&amp;gt;%
mutate(Year=year(Date)) %&amp;gt;%
dplyr::select(Year,GEO,&amp;quot;Population&amp;quot;=VALUE) %&amp;gt;%
group_by(GEO,Year) %&amp;gt;%
summarise(Population=mean(Population))
## Merge and plot
plotdata &amp;lt;- left_join(data.gas,data.population,by=c(&amp;quot;Year&amp;quot;,&amp;quot;GEO&amp;quot;))
plotdata$gas_per_cap &amp;lt;- plotdata$Gasoline/plotdata$Population/365
ggplot(plotdata, aes(Year,gas_per_cap,group=GEO,color=GEO,label=GEO.abb))+
geom_line(size=1.5)+
geom_vline(xintercept = 2008,linetype=&amp;quot;dashed&amp;quot;)+
geom_label_repel(data=plotdata %&amp;gt;% filter(Year==2017),nudge_x=.5)+
facet_wrap(~Region,nrow=1)+
scale_x_continuous(breaks=seq(2008,2018,4),limits=c(2008,2019))+
scale_color_viridis_d(name=&amp;quot;&amp;quot;,option=&amp;quot;B&amp;quot;)+
theme_classic(14,&amp;quot;Gill Sans&amp;quot;)+
theme(plot.caption=element_text(size=8,face=&amp;quot;italic&amp;quot;),
legend.position = &amp;quot;none&amp;quot;)+
labs(x=&amp;quot;&amp;quot;,y=&amp;quot;Litres per day&amp;quot;,
subtitle=&amp;quot;Per capita gasoline demand&amp;quot;,
caption=&amp;quot;Statistics Canada NDM Table 23-10-0066 and 17-10-0009\nChart by @bcshaffer&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-11-30-gasoline-demand-bc-and-the-rest-of-canada_files/figure-html/per_capita-1.png" width="960" />&lt;/p>
&lt;p>Another question, is how different economic growth–rather than just population growth–across provinces impacts their gasoline demand. So here we look at &lt;em>gasoline intensity&lt;/em>, the ratio of annual gasoline demand (in litres) per thousand dollars of GDP. (Note: I drop the territories as their scale gets wonky. Sorry Territories…)&lt;/p>
&lt;pre class="r">&lt;code>## GET GDP DATA
data.GDP &amp;lt;- get_cansim(36100222) %&amp;gt;%
normalize_cansim_values() %&amp;gt;%
filter(Prices==&amp;quot;Chained (2012) dollars&amp;quot;,
Estimates==&amp;quot;Gross domestic product at market prices&amp;quot;) %&amp;gt;%
mutate(Year=year(Date)) %&amp;gt;%
dplyr::select(Year,GEO,&amp;quot;GDP&amp;quot;=VALUE)
plotdata &amp;lt;- left_join(plotdata,data.GDP, by=c(&amp;quot;Year&amp;quot;,&amp;quot;GEO&amp;quot;))
plotdata$gas_intensity &amp;lt;- plotdata$Gasoline / plotdata$GDP * 1000
plotdata &amp;lt;- plotdata %&amp;gt;% filter(Region!=&amp;quot;Territories&amp;quot;)
ggplot(plotdata, aes(Year,gas_intensity,group=GEO,color=GEO,label=GEO.abb))+
geom_line(size=1.5)+
geom_vline(xintercept = 2008,linetype=&amp;quot;dashed&amp;quot;)+
geom_label_repel(data=plotdata %&amp;gt;% filter(Year==2017),nudge_x=1)+
facet_wrap(~Region,nrow=1)+
scale_x_continuous(breaks=seq(1995,2015,10),limits=c(1994,2020))+
coord_cartesian(ylim=c(16,45))+
scale_color_viridis_d(name=&amp;quot;&amp;quot;,option=&amp;quot;B&amp;quot;)+
theme_classic(14,&amp;quot;Gill Sans&amp;quot;)+
theme(plot.caption=element_text(size=8,face=&amp;quot;italic&amp;quot;),
legend.position = &amp;quot;none&amp;quot;)+
labs(x=&amp;quot;&amp;quot;,y=&amp;quot;L per $1000 GDP&amp;quot;,
subtitle=&amp;quot;Gasoline intensity\n(Gas demand / GDP)&amp;quot;,
caption=&amp;quot;Statistics Canada NDM Table 23-10-0066 and 36-10-0222\nChart by @bcshaffer&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-11-30-gasoline-demand-bc-and-the-rest-of-canada_files/figure-html/gasoline_intensity-1.png" width="960" />&lt;/p>
&lt;p>It’s a little hard to tell in that graph, but in the &lt;strong>West&lt;/strong> plot, BC is the line that starts highest and is falling rapidly throughout the period. I’ll re-plot it on one panel here:&lt;/p>
&lt;pre class="r">&lt;code>ggplot()+
geom_line(data=plotdata %&amp;gt;% filter(GEO!=&amp;quot;Nunavut&amp;quot;,GEO!=&amp;quot;British Columbia&amp;quot;),
aes(Year,gas_intensity,group=GEO,color=GEO),
size=1)+
geom_line(data=plotdata %&amp;gt;% filter(GEO==&amp;quot;British Columbia&amp;quot;),
aes(Year,gas_intensity),
size=2, color=&amp;quot;firebrick&amp;quot;)+
geom_label_repel(data=plotdata %&amp;gt;% filter(Year==2017,GEO!=&amp;quot;Nunavut&amp;quot;,GEO!=&amp;quot;British Columbia&amp;quot;),
aes(Year, gas_intensity, color=GEO, label=GEO.abb),
nudge_x=1)+
geom_label_repel(data=plotdata %&amp;gt;% filter(Year==2017,GEO==&amp;quot;British Columbia&amp;quot;),
aes(Year, gas_intensity, label=GEO.abb),
nudge_x=.5, color=&amp;quot;firebrick&amp;quot;)+
geom_vline(xintercept = 2008,linetype=&amp;quot;dashed&amp;quot;)+
scale_x_continuous(breaks=seq(1995,2015,10),limits=c(1994,2020))+
coord_cartesian(ylim=c(16,48))+
scale_color_viridis_d(name=&amp;quot;&amp;quot;)+
theme_classic(14,&amp;quot;Gill Sans&amp;quot;)+
theme(plot.caption=element_text(size=8,face=&amp;quot;italic&amp;quot;),
legend.position = &amp;quot;none&amp;quot;)+
labs(x=&amp;quot;&amp;quot;,y=&amp;quot;L per $1000 GDP&amp;quot;,
subtitle=&amp;quot;Gasoline intensity\n(Gas demand / GDP)&amp;quot;,
caption=&amp;quot;Statistics Canada NDM Table 23-10-0066 and 36-10-0222\nChart by @bcshaffer&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-11-30-gasoline-demand-bc-and-the-rest-of-canada_files/figure-html/gas_intensity_one_chart-1.png" width="576" />&lt;/p>
&lt;p>To summarise, and make it clearer, let’s take a look at just BC and Canada side by side for both gasoline intensity and gasoline per capita:&lt;/p>
&lt;pre class="r">&lt;code>data.summary &amp;lt;- plotdata %&amp;gt;%
filter(GEO %in% c(&amp;quot;British Columbia&amp;quot;,&amp;quot;Canada&amp;quot;)) %&amp;gt;%
dplyr::select(Year,GEO,GEO.abb,gas_per_cap,gas_intensity) %&amp;gt;%
gather(key,value,gas_per_cap,gas_intensity)
ggplot(data.summary, aes(Year,value,group=GEO,color=GEO))+
geom_line(size=1.5)+
geom_vline(xintercept = 2008,linetype=&amp;quot;dashed&amp;quot;)+
facet_wrap(~key,scales=&amp;quot;free_y&amp;quot;)+
scale_x_continuous(breaks=seq(1995,2015,5))+
scale_color_manual(name=&amp;quot;&amp;quot;,values=c(&amp;quot;forestgreen&amp;quot;,&amp;quot;red&amp;quot;))+
theme_classic(12,&amp;quot;Gill Sans&amp;quot;)+
theme(plot.caption=element_text(size=8,face=&amp;quot;italic&amp;quot;),
legend.position = &amp;quot;top&amp;quot;,
legend.text = element_text(size=14),
strip.text = element_text(size=12))+
labs(x=&amp;quot;&amp;quot;,y=&amp;quot;&amp;quot;,
subtitle=&amp;quot;gas_intensity: L/GDP ($&amp;#39;000s)\ngas_per_cap: L/capita/day&amp;quot;,
title=&amp;quot;BC vs the Rest of Canada&amp;quot;,
caption=&amp;quot;Statistics Canada NDM Table 23-10-0066, 36-10-0222, 17-10-0009\nChart by @bcshaffer&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-11-30-gasoline-demand-bc-and-the-rest-of-canada_files/figure-html/gas_summary-1.png" width="768" />&lt;/p>
&lt;p>&lt;strong>Bottom line: gasoline intensity (the amount of gasoline demand per $1000 of GDP) is falling across the board. That’s a good thing. B.C.’s gasoline intensity is falling more rapidly than the Canadian average. On a per capita basis, despite rising in the past 2 years on the back of strong GDP growth, BC is still falling relative to the Canadian average.&lt;/strong>&lt;/p></description></item><item><title>Social assistance and unemployment duration in Alberta</title><link>https://a-yamazaki1028.github.io/post/caseload-duration/</link><pubDate>Fri, 30 Nov 2018 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/post/caseload-duration/</guid><description>
&lt;p>In this post, I consider the relationship between &lt;strong>Social Assistance Caseloads&lt;/strong> and &lt;strong>Unemployment Duration&lt;/strong> in Alberta.&lt;/p>
&lt;p>Let’s start by calling the necessary libraries&lt;/p>
&lt;pre class="r">&lt;code>library(tidyverse)
library(zoo)
library(cansim) #Big thanks to Jens von Bergmann and Dmitry Shkolnik for this package!&lt;/code>&lt;/pre>
&lt;div id="first-get-caseload-data-from-open.alberta.ca" class="section level2">
&lt;h2>First, get CASELOAD data from open.alberta.ca&lt;/h2>
&lt;pre class="r">&lt;code>data.caseload &amp;lt;-read.csv(&amp;quot;https://open.alberta.ca/dataset/e1ec585f-3f52-40f2-a022-5a38ea3397e5/resource/4f97a3ae-1b3a-48e9-a96f-f65c58526e07/download/GOAIncomeSupportCSVv61.02017-05-15.csv&amp;quot;)
data.caseload &amp;lt;- data.caseload %&amp;gt;%
mutate(Date = as.Date(as.yearmon(Ref_Date,&amp;quot;%b-%y&amp;quot;))) %&amp;gt;%
filter(Geography==&amp;quot;Alberta&amp;quot;) %&amp;gt;%
dplyr::select(&amp;quot;Caseloads&amp;quot;=Value,Date,Measure)
data.caseload.total &amp;lt;- data.caseload %&amp;gt;%
filter(Measure==&amp;quot;Total Caseload&amp;quot;) %&amp;gt;%
dplyr::select(Caseloads,Date)
ggplot(data.caseload.total, aes(Date,Caseloads))+geom_line() #check data&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-11-29-caseload-duration_files/figure-html/unnamed-chunk-2-1.png" width="384" />&lt;/p>
&lt;/div>
&lt;div id="second-get-duration-data-from-statistics-canada" class="section level2">
&lt;h2>Second, get DURATION data from Statistics Canada&lt;/h2>
&lt;pre class="r">&lt;code>data.duration &amp;lt;- get_cansim(2820047) %&amp;gt;% normalize_cansim_values()
data.duration &amp;lt;- data.duration %&amp;gt;%
filter(GEO==&amp;quot;Alberta&amp;quot;,
`Duration of unemployment`==&amp;quot;Average weeks unemployed, no top-code&amp;quot;,
Sex==&amp;quot;Both sexes&amp;quot;,
`Age group`==&amp;quot;15 years and over&amp;quot;,
Date&amp;gt;=&amp;quot;2005-04-01&amp;quot;) %&amp;gt;%
dplyr::select(&amp;quot;Duration&amp;quot;=VALUE,Date)
ggplot(data.duration, aes(Date,Duration))+geom_line() #check data&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-11-29-caseload-duration_files/figure-html/unnamed-chunk-3-1.png" width="384" />&lt;/p>
&lt;/div>
&lt;div id="now-gather-into-long-format-and-do-a-quick-plot" class="section level2">
&lt;h2>Now, gather into long format and do a quick plot&lt;/h2>
&lt;pre class="r">&lt;code>plotdata &amp;lt;- merge(data.duration, data.caseload.total, by=&amp;quot;Date&amp;quot;)
plotdata &amp;lt;- gather(plotdata,key,value,2:3)
ggplot(plotdata, aes(Date,value))+
geom_line()+
facet_wrap(~key,scales=&amp;quot;free_y&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-11-29-caseload-duration_files/figure-html/unnamed-chunk-4-1.png" width="960" />&lt;/p>
&lt;/div>
&lt;div id="now-do-a-pretty-plot-with-scatter-points-and-smoothes" class="section level2">
&lt;h2>Now, do a pretty plot with scatter points and smoothes&lt;/h2>
&lt;pre class="r">&lt;code>plotdata$key[plotdata$key==&amp;quot;Caseloads&amp;quot;] &amp;lt;- &amp;quot;Caseloads (people)&amp;quot;
plotdata$key[plotdata$key==&amp;quot;Duration&amp;quot;] &amp;lt;- &amp;quot;Duration (weeks)&amp;quot;
ggplot(plotdata, aes(Date,value))+
geom_point(alpha=.5)+
geom_smooth(span=.3)+
facet_wrap(~key,scales=&amp;quot;free_y&amp;quot;)+
theme_light(12,&amp;quot;Avenir&amp;quot;)+
theme(plot.caption = element_text(size=8),
strip.text = element_text(size=12),
panel.spacing = unit(1,&amp;quot;cm&amp;quot;))+
labs(x=&amp;quot;&amp;quot;,
y=&amp;quot;&amp;quot;,
title=&amp;quot;Similar trends between caseloads and unemployment duration&amp;quot;,
caption=&amp;quot;Caseload data through Sep-18; Duration data through Oct-18
Sources: https://open.alberta.ca/dataset/income-support-caseload-alberta and CANSIM 282-0047
Chart by Blake Shaffer (@bcshaffer)&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-11-29-caseload-duration_files/figure-html/unnamed-chunk-5-1.png" width="960" />&lt;/p>
&lt;/div>
&lt;div id="we-can-also-dig-deeper-into-the-caseload-data" class="section level2">
&lt;h2>We can also dig deeper into the caseload data&lt;/h2>
&lt;p>First, let’s look at caseload recipients by family types&lt;/p>
&lt;pre class="r">&lt;code># first filter on the family type categories
data.caseload.family &amp;lt;- data.caseload %&amp;gt;%
filter(Measure %in% c(&amp;quot;Single Individuals Total&amp;quot;,&amp;quot;Lone-parent Families Total&amp;quot;,&amp;quot;Couples with Children Total&amp;quot;,&amp;quot;Couples without Children Total&amp;quot;))
# clean up the category names, not necessary
library(tm)
data.caseload.family$Measure &amp;lt;- as.character(data.caseload.family$Measure)
data.caseload.family$Measure &amp;lt;- removeWords(data.caseload.family$Measure,&amp;quot;Total&amp;quot;)
# now plot it!
ggplot(data.caseload.family, aes(Date,Caseloads))+
geom_line(size=1.5,color=&amp;quot;firebrick&amp;quot;)+
facet_wrap(~Measure,nrow=1)+
scale_y_continuous(expand=c(0,0),limits=c(0,45000))+
theme_light(12,&amp;quot;Avenir&amp;quot;)+
theme(plot.caption = element_text(size=8),
strip.text = element_text(size=12),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank())+
labs(x=&amp;quot;&amp;quot;,
y=&amp;quot;&amp;quot;,
title=&amp;quot;Alberta social assistance caseloads by recipient&amp;#39;s family type&amp;quot;,
caption=&amp;quot;Caseload data through Sep-18
Source: https://open.alberta.ca/dataset/income-support-caseload-alberta
Chart by Blake Shaffer (@bcshaffer)&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-11-29-caseload-duration_files/figure-html/unnamed-chunk-6-1.png" width="960" />&lt;/p>
&lt;p>Now let’s look at the caseload data in terms of type of worker&lt;/p>
&lt;pre class="r">&lt;code>data.caseload.worker &amp;lt;- data.caseload %&amp;gt;%
filter(Measure %in% c(&amp;quot;ETW - Working Total&amp;quot;,
&amp;quot;ETW - Not Working (Available for Work) Total&amp;quot;,
&amp;quot;ETW - Not Working (Unavailable for Work) Total&amp;quot;,
&amp;quot;BFE - Total&amp;quot;))
# clean up the category names
data.caseload.worker &amp;lt;- data.caseload.worker %&amp;gt;%
mutate(Measure=fct_recode(Measure,
&amp;quot;Working&amp;quot; = &amp;quot;ETW - Working Total&amp;quot;,
&amp;quot;Available for Work&amp;quot; = &amp;quot;ETW - Not Working (Available for Work) Total&amp;quot;,
&amp;quot;Unavailable for Work&amp;quot; = &amp;quot;ETW - Not Working (Unavailable for Work) Total&amp;quot;,
&amp;quot;Barriers to FT employment&amp;quot; = &amp;quot;BFE - Total&amp;quot;))
# now plot it!
ggplot(data.caseload.worker, aes(Date,Caseloads))+
geom_line(size=1.5,color=&amp;quot;royalblue&amp;quot;)+
facet_wrap(~Measure,nrow=1)+
scale_y_continuous(expand=c(0,0),limits=c(0,45000))+
theme_light(12,&amp;quot;Avenir&amp;quot;)+
theme(plot.caption = element_text(size=8),
strip.text = element_text(size=12),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank())+
labs(x=&amp;quot;&amp;quot;,
y=&amp;quot;&amp;quot;,
title=&amp;quot;Alberta social assistance caseloads by recipient&amp;#39;s worker type&amp;quot;,
caption=&amp;quot;Caseload data through Sep-18
Source: https://open.alberta.ca/dataset/income-support-caseload-alberta
Chart by Blake Shaffer (@bcshaffer)&amp;quot;)&lt;/code>&lt;/pre>
&lt;p>&lt;img src="https://a-yamazaki1028.github.io/%7Eayamazaki/post/2018-11-29-caseload-duration_files/figure-html/unnamed-chunk-7-1.png" width="960" />&lt;/p>
&lt;/div>
&lt;div id="bottom-line" class="section level2">
&lt;h2>Bottom line:&lt;/h2>
&lt;p>&lt;strong>The bulk of the growth in caseloads has been &lt;em>Single Individuals&lt;/em> that are &lt;em>Available for Work&lt;/em>. This also coincides with a large growth in &lt;em>Unemployment Duration&lt;/em>. This suggests workers that are seeing their unemployment benefits expire may be turning to other forms of social assistance. More details on income support recipients would help policy makers respond effectively.&lt;/strong>&lt;/p>
&lt;p>h/t to &lt;span class="citation">@ronkneebone&lt;/span> for raising attention to this important data.&lt;/p>
&lt;/div></description></item><item><title>Blogging Charts!</title><link>https://a-yamazaki1028.github.io/post/charts/</link><pubDate>Thu, 29 Nov 2018 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/post/charts/</guid><description>
&lt;p>I like to make charts.&lt;/p>
&lt;p>I often post them on Twitter (&lt;span class="citation">@bcshaffer&lt;/span>). I thought I might start posting some of them on my website as a way for me to (a) learn to use R Markdown and (b) share some of my R code that creates these charts for others who are interested in learning.&lt;/p>
&lt;p>Note: Both my R code and especially my nascent R Markdown skills are still rough. I’m sure much of it isn’t “best practice”. Far from it. It’s what I like to call ‘gets it done’ code. So learn what you can, and apologies for creating bad habits!&lt;/p>
&lt;p>&lt;em>- Blake&lt;/em>&lt;/p>
&lt;p>&lt;strong>Resources:&lt;/strong>&lt;/p>
&lt;p>I learned R primarily from Hadley Wickham and Garrett Grolemund’s book: &lt;a href="https://r4ds.had.co.nz/">R for Data Science&lt;/a>. I highly recommend it. It assumes zero previous R knowledge, even guiding you through where to download the required software, and gets you up and running in no time.&lt;/p>
&lt;p>For data visualization tips, I really like Claus Wilke’s online book: &lt;a href="https://serialmentor.com/dataviz/">Fundamentals of Data Visualization&lt;/a> (with code examples!).&lt;/p></description></item><item><title>The Effect of Climate Policy on Performance of Manufacturing Plants</title><link>https://a-yamazaki1028.github.io/publication/ctaxperformance/</link><pubDate>Sun, 01 Jul 2018 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/publication/ctaxperformance/</guid><description/></item><item><title>Jobs and Climate Policy: Evidence from British Columbia's Revenue-Neutral Carbon Tax</title><link>https://a-yamazaki1028.github.io/publication/jeem2017/</link><pubDate>Tue, 28 Mar 2017 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/publication/jeem2017/</guid><description/></item><item><title>It's not a job killing policy - The case of BC's revenue neutral carbon tax</title><link>https://a-yamazaki1028.github.io/publication/spi2016/</link><pubDate>Thu, 01 Sep 2016 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/publication/spi2016/</guid><description/></item><item><title>External Project</title><link>https://a-yamazaki1028.github.io/project/external-project/</link><pubDate>Wed, 27 Apr 2016 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/project/external-project/</guid><description/></item><item><title>Internal Project</title><link>https://a-yamazaki1028.github.io/project/internal-project/</link><pubDate>Wed, 27 Apr 2016 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/project/internal-project/</guid><description>&lt;p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis posuere tellus ac convallis placerat. Proin tincidunt magna sed ex sollicitudin condimentum. Sed ac faucibus dolor, scelerisque sollicitudin nisi. Cras purus urna, suscipit quis sapien eu, pulvinar tempor diam. Quisque risus orci, mollis id ante sit amet, gravida egestas nisl. Sed ac tempus magna. Proin in dui enim. Donec condimentum, sem id dapibus fringilla, tellus enim condimentum arcu, nec volutpat est felis vel metus. Vestibulum sit amet erat at nulla eleifend gravida.&lt;/p>
&lt;p>Nullam vel molestie justo. Curabitur vitae efficitur leo. In hac habitasse platea dictumst. Sed pulvinar mauris dui, eget varius purus congue ac. Nulla euismod, lorem vel elementum dapibus, nunc justo porta mi, sed tempus est est vel tellus. Nam et enim eleifend, laoreet sem sit amet, elementum sem. Morbi ut leo congue, maximus velit ut, finibus arcu. In et libero cursus, rutrum risus non, molestie leo. Nullam congue quam et volutpat malesuada. Sed risus tortor, pulvinar et dictum nec, sodales non mi. Phasellus lacinia commodo laoreet. Nam mollis, erat in feugiat consectetur, purus eros egestas tellus, in auctor urna odio at nibh. Mauris imperdiet nisi ac magna convallis, at rhoncus ligula cursus.&lt;/p>
&lt;p>Cras aliquam rhoncus ipsum, in hendrerit nunc mattis vitae. Duis vitae efficitur metus, ac tempus leo. Cras nec fringilla lacus. Quisque sit amet risus at ipsum pharetra commodo. Sed aliquam mauris at consequat eleifend. Praesent porta, augue sed viverra bibendum, neque ante euismod ante, in vehicula justo lorem ac eros. Suspendisse augue libero, venenatis eget tincidunt ut, malesuada at lorem. Donec vitae bibendum arcu. Aenean maximus nulla non pretium iaculis. Quisque imperdiet, nulla in pulvinar aliquet, velit quam ultrices quam, sit amet fringilla leo sem vel nunc. Mauris in lacinia lacus.&lt;/p>
&lt;p>Suspendisse a tincidunt lacus. Curabitur at urna sagittis, dictum ante sit amet, euismod magna. Sed rutrum massa id tortor commodo, vitae elementum turpis tempus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean purus turpis, venenatis a ullamcorper nec, tincidunt et massa. Integer posuere quam rutrum arcu vehicula imperdiet. Mauris ullamcorper quam vitae purus congue, quis euismod magna eleifend. Vestibulum semper vel augue eget tincidunt. Fusce eget justo sodales, dapibus odio eu, ultrices lorem. Duis condimentum lorem id eros commodo, in facilisis mauris scelerisque. Morbi sed auctor leo. Nullam volutpat a lacus quis pharetra. Nulla congue rutrum magna a ornare.&lt;/p>
&lt;p>Aliquam in turpis accumsan, malesuada nibh ut, hendrerit justo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Quisque sed erat nec justo posuere suscipit. Donec ut efficitur arcu, in malesuada neque. Nunc dignissim nisl massa, id vulputate nunc pretium nec. Quisque eget urna in risus suscipit ultricies. Pellentesque odio odio, tincidunt in eleifend sed, posuere a diam. Nam gravida nisl convallis semper elementum. Morbi vitae felis faucibus, vulputate orci placerat, aliquet nisi. Aliquam erat volutpat. Maecenas sagittis pulvinar purus, sed porta quam laoreet at.&lt;/p></description></item><item><title>An example journal article</title><link>https://a-yamazaki1028.github.io/old-not-used/publication/journal-article/</link><pubDate>Tue, 01 Sep 2015 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/old-not-used/publication/journal-article/</guid><description>&lt;div class="alert alert-note">
&lt;div>
Click the &lt;em>Cite&lt;/em> button above to demo the feature to enable visitors to import publication metadata into their reference management software.
&lt;/div>
&lt;/div>
&lt;div class="alert alert-note">
&lt;div>
Click the &lt;em>Slides&lt;/em> button above to demo Academic&amp;rsquo;s Markdown slides feature.
&lt;/div>
&lt;/div>
&lt;p>Supplementary notes can be added here, including
&lt;a href="https://sourcethemes.com/academic/docs/writing-markdown-latex/" target="_blank" rel="noopener">code and math&lt;/a>.&lt;/p></description></item><item><title>An example conference paper</title><link>https://a-yamazaki1028.github.io/old-not-used/publication/conference-paper/</link><pubDate>Mon, 01 Jul 2013 00:00:00 +0000</pubDate><guid>https://a-yamazaki1028.github.io/old-not-used/publication/conference-paper/</guid><description>&lt;div class="alert alert-note">
&lt;div>
Click the &lt;em>Cite&lt;/em> button above to demo the feature to enable visitors to import publication metadata into their reference management software.
&lt;/div>
&lt;/div>
&lt;div class="alert alert-note">
&lt;div>
Click the &lt;em>Slides&lt;/em> button above to demo Academic&amp;rsquo;s Markdown slides feature.
&lt;/div>
&lt;/div>
&lt;p>Supplementary notes can be added here, including
&lt;a href="https://sourcethemes.com/academic/docs/writing-markdown-latex/" target="_blank" rel="noopener">code and math&lt;/a>.&lt;/p></description></item></channel></rss>