<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Aurélien Goutsmedt</title>
<link>https://aurelien-goutsmedt.com/post/</link>
<atom:link href="https://aurelien-goutsmedt.com/post/index.xml" rel="self" type="application/rss+xml"/>
<description>Tutorials on bibliometrics, scraping and text analysis in R, and notes on my research.</description>
<image>
<url>https://aurelien-goutsmedt.com/assets/images/share-card.png</url>
<title>Aurélien Goutsmedt</title>
<link>https://aurelien-goutsmedt.com/post/</link>
<height>76</height>
<width>144</width>
</image>
<generator>quarto-1.10.18</generator>
<lastBuildDate>Sun, 07 Jan 2024 23:00:00 GMT</lastBuildDate>
<item>
  <title>Release of anystyleR 0.0.999 (Development version)</title>
  <dc:creator>Aurélien Goutsmedt</dc:creator>
  <link>https://aurelien-goutsmedt.com/post/release-ranystyle-development/</link>
  <description><![CDATA[ 





<p>I am thrilled to announce the inaugural development release of <a href="https://codeberg.org/agoutsmedt/anystyleR">anystyleR</a>! anystyleR (pronounce “anystyle-R”) is designed to extract, parse and clean bibliographic references from an array of sources including PDFs, text documents, and references stored in a R objects. At its core, <a href="https://codeberg.org/agoutsmedt/anystyleR">anystyleR</a> harnesses the power of the <a href="https://anystyle.io/">anystyle</a> Ruby gem, wrapping (and extending) its capabilities within an intuitive R interface.</p>
<section id="initial-setup" class="level2">
<h2 class="anchored" data-anchor-id="initial-setup">Initial Setup</h2>
<p>You can install the development version of anystyleR from Codeberg with:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># install.packages("devtools")</span></span>
<span id="cb1-2">remotes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install_git</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://codeberg.org/agoutsmedt/anystyleR"</span>)</span></code></pre></div></div>
<p>Before diving into <a href="https://codeberg.org/agoutsmedt/anystyleR">anystyleR</a>’s functionalities, ensure that <a href="https://www.ruby-lang.org/fr/downloads/">Ruby</a> and <a href="https://rubygems.org/pages/download?locale=fr">RubyGems</a> are installed on your system. If you haven’t yet ventured into the Ruby world, no worries! Installation is straigthforward, and once set up, <a href="https://codeberg.org/agoutsmedt/anystyleR">anystyleR</a> will seamlessly manage the rest.</p>
<p>To automatically install <code>anystyle</code> and <code>anystyle-cli</code> Ruby gems, simply run:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(anystyleR)</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install_anystyle</span>()</span></code></pre></div></div>
</section>
<section id="utilizing-anystyler-in-your-research-workflow" class="level2">
<h2 class="anchored" data-anchor-id="utilizing-anystyler-in-your-research-workflow">Utilizing anystyleR in your Research Workflow</h2>
<p><a href="https://codeberg.org/agoutsmedt/anystyleR">anystyleR</a> can be your go-to resource in various scenarios:</p>
<ul>
<li>Extracting references from multiple PDFs and converting them to <code>.bib</code> format.</li>
<li>Building a structured data frame from references cited across several PDFs.</li>
<li>Parsing a vector of references stored in an R object to extract detailed information.</li>
<li>Converting a bibliography in a PDF from one citation style to another in <em>word</em>.</li>
</ul>
<section id="creating-a-.bib-from-a-collection-of-pdfs" class="level3">
<h3 class="anchored" data-anchor-id="creating-a-.bib-from-a-collection-of-pdfs">Creating a <code>.bib</code> from a Collection of PDFs</h3>
<p>The <a href="https://codeberg.org/agoutsmedt/anystyleR">find_ref()</a> function leverages the power of the ‘anystyle’ Ruby gem <code>find</code> function to identify reference sections and footnotes. It will extract the references cited in a PDF. Imagine having a set of PDFs and aiming to distill the references within (here we take the PDFs stored in the package):</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(anystyleR)</span>
<span id="cb3-2"></span>
<span id="cb3-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Locating the PDF documents bundled with the package</span></span>
<span id="cb3-4">pdf_path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">system.file</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"extdata"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">package =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"anystyleR"</span>)</span>
<span id="cb3-5">pdf_files <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list.files</span>(pdf_path, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pattern =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pdf$"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">full.names =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb3-6"></span>
<span id="cb3-7">pdf_files</span></code></pre></div></div>
<pre><code>## [1] "C:/Users/goutsmedt/AppData/Local/R/win-library/4.3/anystyleR/extdata/example_doc_1.pdf"
## [2] "C:/Users/goutsmedt/AppData/Local/R/win-library/4.3/anystyleR/extdata/example_doc_2.pdf"
## [3] "C:/Users/goutsmedt/AppData/Local/R/win-library/4.3/anystyleR/extdata/example_doc_3.pdf"</code></pre>
<p>Let’s visualize the first page of references from one of these PDFs:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Leveraging pdftools to extract a page as an image</span></span>
<span id="cb5-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(pdftools)</span>
<span id="cb5-3">page_image <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> pdftools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pdf_convert</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pdf =</span> pdf_files[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>],</span>
<span id="cb5-4">                                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'png'</span>,</span>
<span id="cb5-5">                                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pages =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">22</span>) </span></code></pre></div></div>
<pre><code>## Converting page 22 to example_doc_1_22.png... done!</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">include_graphics</span>(page_image)</span></code></pre></div></div>
<p><img src="https://aurelien-goutsmedt.com/post/release-ranystyle-development/example_doc_1_22.png" width="130%"></p>
<p>Next, we extract the references, saving them in the versatile <a href="https://fr.wikipedia.org/wiki/BibTeX"><code>.bib</code> format</a>.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">find_ref</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">input =</span> pdf_files[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>],</span>
<span id="cb8-2">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getwd</span>(),</span>
<span id="cb8-3">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">output_format =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bib"</span>,</span>
<span id="cb8-4">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">overwrite =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span></code></pre></div></div>
<pre><code>## [1] "anystyle --overwrite -f bib find C:/Users/goutsmedt/AppData/Local/R/win-library/4.3/anystyleR/extdata/example_doc_1.pdf C:/Users/goutsmedt/Documents/MEGAsync/Research/R/projets/website/content/en/post/2024-01-09-release-ranystyle-development"</code></pre>
<p>To illustrate the extraction’s efficacy, let’s inspect the first lines of the generated <code>.bib</code> file:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Locating and reading the .bib file corresponding to the first PDF</span></span>
<span id="cb10-2">bib_file <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pdf$"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bib"</span>,  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">basename</span>(pdf_files[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]))</span>
<span id="cb10-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Read the first 10 lines of the .bib file</span></span>
<span id="cb10-4">bib_lines <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">readLines</span>(bib_file, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">26</span>)</span>
<span id="cb10-5"></span>
<span id="cb10-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Print the lines</span></span>
<span id="cb10-7"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(bib_lines, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span></code></pre></div></div>
<pre><code>## @article{arnold2023a,
##   author = {Arnold, M.},
##   date = {2023},
##   title = {ECB must do more to tackle inflation “Monster”, says christine lagarde’},
##   journal = {Financial Times}
## }
## @article{barro1983a,
##   author = {Barro, R.J. and Gordon, D.B.},
##   date = {1983},
##   title = {Rules, discretion and reputation in a model of monetary policy’},
##   volume = {12},
##   pages = {101–121},
##   url = {https://doi.org/10.1016/0304-3932(83)90051-X.},
##   doi = {10.1016/0304-3932(83)90051-X.},
##   journal = {Journal of Monetary Economics},
##   number = {1}
## }
## @article{b2009a,
##   author = {Béland, D.},
##   date = {2009},
##   title = {Ideas, institutions, and policy change’},
##   volume = {16},
##   pages = {701–718},
##   journal = {Journal of European Public Policy},
##   number = {5}
## }</code></pre>
</section>
<section id="transforming-pdf-references-into-a-data-frame" class="level3">
<h3 class="anchored" data-anchor-id="transforming-pdf-references-into-a-data-frame">Transforming PDF References into a Data Frame</h3>
<p><a href="https://codeberg.org/agoutsmedt/anystyleR">anystyleR</a> effortlessly bridges the gap between static PDF content and dynamic data analysis. Using the <a href="https://codeberg.org/agoutsmedt/anystyleR">find_ref_to_df()</a> function, you can convert references from PDFS directly into a data frame, specifically into a <a href="https://tibble.tidyverse.org/">tibble</a>, for enhanced usability and manipulation within the <a href="https://www.tidyverse.org/">tidyverse</a> ecosystem.</p>
<p>Let’s see how it works:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Extracting references from PDFs into a data frame</span></span>
<span id="cb12-2">extracted_refs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">find_ref_to_df</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">input =</span> pdf_files)</span></code></pre></div></div>
<pre><code>## [1] "anystyle -f json find C:/Users/goutsmedt/AppData/Local/R/win-library/4.3/anystyleR/extdata/example_doc_1.pdf "
## [1] "anystyle -f json find C:/Users/goutsmedt/AppData/Local/R/win-library/4.3/anystyleR/extdata/example_doc_2.pdf "
## [1] "anystyle -f json find C:/Users/goutsmedt/AppData/Local/R/win-library/4.3/anystyleR/extdata/example_doc_3.pdf "
## [1] "anystyle --overwrite -f ref find C:/Users/goutsmedt/AppData/Local/R/win-library/4.3/anystyleR/extdata/example_doc_1.pdf ./"
## [1] "anystyle --overwrite -f ref find C:/Users/goutsmedt/AppData/Local/R/win-library/4.3/anystyleR/extdata/example_doc_2.pdf ./"
## [1] "anystyle --overwrite -f ref find C:/Users/goutsmedt/AppData/Local/R/win-library/4.3/anystyleR/extdata/example_doc_3.pdf ./"</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(extracted_refs)</span></code></pre></div></div>
<pre><code>## # A tibble: 6 × 24
##   id_doc doc          id_ref author   title  year `container-title` volume pages
##    &lt;int&gt; &lt;chr&gt;        &lt;chr&gt;  &lt;list&gt;   &lt;chr&gt; &lt;int&gt; &lt;chr&gt;             &lt;chr&gt;  &lt;chr&gt;
## 1      1 example_doc… 1_1    &lt;tibble&gt; ECB …  2023 Financial Times   &lt;NA&gt;   &lt;NA&gt; 
## 2      1 example_doc… 1_2    &lt;tibble&gt; Rule…  1983 Journal of Monet… 12     101–…
## 3      1 example_doc… 1_3    &lt;tibble&gt; Idea…  2009 Journal of Europ… 16     701–…
## 4      1 example_doc… 1_4    &lt;tibble&gt; A st…  1999 Scottish Journal… 46     17–39
## 5      1 example_doc… 1_5    &lt;tibble&gt; Tech…  2018 International Po… 12     328–…
## 6      1 example_doc… 1_6    &lt;tibble&gt; Late…  2003 Journal of Machi… 3      &lt;NA&gt; 
## # ℹ 15 more variables: location &lt;chr&gt;, publisher &lt;chr&gt;, type &lt;chr&gt;, date &lt;chr&gt;,
## #   other_date &lt;chr&gt;, other_title &lt;chr&gt;, url &lt;chr&gt;, issue &lt;chr&gt;, doi &lt;chr&gt;,
## #   edition &lt;chr&gt;, genre &lt;chr&gt;, note &lt;chr&gt;, editor &lt;chr&gt;,
## #   `collection-title` &lt;chr&gt;, full_ref &lt;chr&gt;</code></pre>
<p>The <a href="https://codeberg.org/agoutsmedt/anystyleR">find_ref_to_df()</a> function not only parses the references but also integrates the option for further cleaning via <a href="https://codeberg.org/agoutsmedt/anystyleR">clean_ref()</a>. While automated cleaning is available, manual refinement is an option too. This dual approach ensures flexibility, allowing you to maintain control over the data quality. In any case, <a href="https://codeberg.org/agoutsmedt/anystyleR">find_ref_to_df()</a> creates a data frame with both extracted information, as well as the original full references.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Preview the original full references for manual inspection and cleaning</span></span>
<span id="cb16-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(extracted_refs<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>full_ref)</span></code></pre></div></div>
<pre><code>## [1] "Arnold, M. (2023). ECB must do more to tackle inflation “Monster”, says christine lagarde’. Financial Times"                                                                                       
## [2] "Barro, R. J., &amp; Gordon, D. B. (1983). Rules, discretion and reputation in a model of monetary policy’. Journal of Monetary Economics, 12(1), 101–121. https://doi.org/10.1016/0304-3932(83)90051-X"
## [3] "Béland, D. (2009). Ideas, institutions, and policy change’. Journal of European Public Policy, 16(5), 701–718"                                                                                     
## [4] "Berger, H., &amp; Haan, J. (1999). A state within the state? An event study on the bundesbank (1948–1973)’. Scottish Journal of Political Economy, 46(1), 17–39"                                       
## [5] "Best, J. (2018). Technocratic exceptionalism: Monetary policy and the fear of democracy’. International Political Sociology, 12(4), 328–345"                                                       
## [6] "Blei, D. M., Ng, A. Y., &amp; Jordan, M. I. (2003). Latent Dirichlet Allocation’. Journal of Machine Learning Research, 3"</code></pre>
</section>
<section id="dealing-with-string-based-references" class="level3">
<h3 class="anchored" data-anchor-id="dealing-with-string-based-references">Dealing with String-Based References</h3>
<p>Occasionally, you might already have references stored as strings in R, like this:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Sample references in string format</span></span>
<span id="cb18-2">references <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Thiemann, Matthias, Carolina Raquel Melches, and Edin Ibrocevic. 2021. “Measuring and Mitigating Systemic Risks: How the Forging of New Alliances Between Central Bank and Academic Economists Legitimize the Transnational Macroprudential Agenda.</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\"</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"> Review of international political economy 28 (6): 1433-1458"</span>,</span>
<span id="cb18-3">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Dietsch, Peter, François Claveau, and Clément Fontan. 2018. Do Central Banks Serve the People? New York: John Wiley &amp; Sons"</span>,</span>
<span id="cb18-4">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Singleton, John. 2010. Central Banking in the Twentieth Century. Cambridge: Cambridge University Press"</span>,</span>
<span id="cb18-5">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mudge, Stephanie L., and Antoine Vauchez. 2018. “Too Embedded to Fail.” Historical Social Research/Historische Sozialforschung 43(3): 248-273"</span>,</span>
<span id="cb18-6">                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Lucas, Robert E. 1972. “Expectations and the Neutrality of Money”. Journal of Economic Theory 4(2): 103-124"</span>)</span>
<span id="cb18-7"></span>
<span id="cb18-8">references</span></code></pre></div></div>
<pre><code>## [1] "Thiemann, Matthias, Carolina Raquel Melches, and Edin Ibrocevic. 2021. “Measuring and Mitigating Systemic Risks: How the Forging of New Alliances Between Central Bank and Academic Economists Legitimize the Transnational Macroprudential Agenda.\" Review of international political economy 28 (6): 1433-1458"
## [2] "Dietsch, Peter, François Claveau, and Clément Fontan. 2018. Do Central Banks Serve the People? New York: John Wiley &amp; Sons"                                                                                                                                                                                       
## [3] "Singleton, John. 2010. Central Banking in the Twentieth Century. Cambridge: Cambridge University Press"                                                                                                                                                                                                           
## [4] "Mudge, Stephanie L., and Antoine Vauchez. 2018. “Too Embedded to Fail.” Historical Social Research/Historische Sozialforschung 43(3): 248-273"                                                                                                                                                                    
## [5] "Lucas, Robert E. 1972. “Expectations and the Neutrality of Money”. Journal of Economic Theory 4(2): 103-124"</code></pre>
<p>In such case, the <code>anystyle</code> Ruby gem <code>parse</code> function, embodied in <a href="https://codeberg.org/agoutsmedt/anystyleR">anystyleR</a>’s <a href="https://codeberg.org/agoutsmedt/anystyleR">parse_ref()</a> and <a href="https://codeberg.org/agoutsmedt/anystyleR">parse_ref_to_df()</a>, becomes your go-to solution. While <a href="https://codeberg.org/agoutsmedt/anystyleR">parse_ref()</a> allows you to create a <code>.bib</code> (or other file format like <code>json</code>), <a href="https://codeberg.org/agoutsmedt/anystyleR">parse_ref_to_df()</a> transforms these references into a structured data frame:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Parsing string references into a data frame</span></span>
<span id="cb20-2">extracted_refs <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">parse_ref_to_df</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">input =</span> references)</span></code></pre></div></div>
<pre><code>## [1] "anystyle --no-overwrite -f json parse ref_to_parse.txt "</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(extracted_refs)</span></code></pre></div></div>
<pre><code>## # A tibble: 5 × 14
##   id_doc doc          id_ref author   title  year `container-title` volume pages
##    &lt;int&gt; &lt;chr&gt;        &lt;chr&gt;  &lt;list&gt;   &lt;chr&gt; &lt;int&gt; &lt;chr&gt;             &lt;chr&gt;  &lt;chr&gt;
## 1      1 ref_to_pars… 1_1    &lt;tibble&gt; Meas…  2021 Review of intern… 28     1433…
## 2      1 ref_to_pars… 1_2    &lt;tibble&gt; Do C…  2018 &lt;NA&gt;              &lt;NA&gt;   &lt;NA&gt; 
## 3      1 ref_to_pars… 1_3    &lt;tibble&gt; Cent…  2010 &lt;NA&gt;              &lt;NA&gt;   &lt;NA&gt; 
## 4      1 ref_to_pars… 1_4    &lt;tibble&gt; Too …  2018 Historical Socia… 43     248–…
## 5      1 ref_to_pars… 1_5    &lt;tibble&gt; Expe…  1972 Journal of Econo… 4      103–…
## # ℹ 5 more variables: location &lt;chr&gt;, publisher &lt;chr&gt;, type &lt;chr&gt;, date &lt;chr&gt;,
## #   issue &lt;chr&gt;</code></pre>
</section>
<section id="effortlessly-transforming-bibliographic-styles-in-word" class="level3">
<h3 class="anchored" data-anchor-id="effortlessly-transforming-bibliographic-styles-in-word">Effortlessly Transforming Bibliographic Styles in Word</h3>
<p><a href="https://codeberg.org/agoutsmedt/anystyleR">anystyleR</a>’s versatility extends beyond data manipulation and <code>.bib</code> file creation. Suppose you need to directly transfer references into a Word document, perhaps to modify the referencing style. In that case, <a href="https://codeberg.org/agoutsmedt/anystyleR">find_ref_to_word_bibliography</a> comes to your rescue.<sup>1</sup> This function is ideal for changing bibliographic style with ease:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Transforming PDF references into a Word document with a specific style</span></span>
<span id="cb24-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">find_ref_to_word_bibliography</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">input =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.path</span>(pdf_path, pdf_files[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]),</span>
<span id="cb24-3">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">csl_path =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"path/to/your_style.csl"</span>)</span></code></pre></div></div>
<p>Here’s an example of what the generated bibliography might look like:</p>
<p><img src="https://aurelien-goutsmedt.com/post/release-ranystyle-development/generated_biblio.png" width="480"></p>
</section>
</section>
<section id="explore-the-possibilities-with-anystyler" class="level2">
<h2 class="anchored" data-anchor-id="explore-the-possibilities-with-anystyler">Explore the Possibilities with anystyleR</h2>
<p>The examples above are just a glimpse into the potential of <a href="https://codeberg.org/agoutsmedt/anystyleR">anystyleR</a>. I encourage you to delve deeper into each function and explore the <a href="https://codeberg.org/agoutsmedt/anystyleR">package main vignette</a> for a comprehensive understanding of what <a href="https://codeberg.org/agoutsmedt/anystyleR">anystyleR</a> can do.</p>
<p>As <a href="https://codeberg.org/agoutsmedt/anystyleR">anystyleR</a> is still in its developmental infancy, your feedback is invaluable. Please share your experiences, report any issues, suggest improvements, or propose new features. Your input will be instrumental in refining and enhancing <a href="https://codeberg.org/agoutsmedt/anystyleR">anystyleR</a>’s capabilities.</p>
</section>
<section id="credits" class="level2">
<h2 class="anchored" data-anchor-id="credits">Credits</h2>
<p>The <em>anystyle</em> parser, a core component of <a href="https://codeberg.org/agoutsmedt/anystyleR">anystyleR</a>, has been developed by a talented team: <a href="https://github.com/a-fent">Alex Fenton</a>, <a href="https://github.com/inukshuk">Sylvester Keil</a>, <a href="https://github.com/flachware">Johannes Krtek</a> and <a href="https://github.com/namyra">Ilja Srna</a>. <em>anystyle</em> is under copyright: Copyright 2011-2018 Sylvester Keil. All rights reserved. See the <a href="https://github.com/inukshuk/anystyle-cli/blob/master/LICENSE">Licence</a> for details.</p>
<p>The <a href="https://codeberg.org/agoutsmedt/anystyleR">anystyleR</a> logo was created using DALL·E.</p>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>If you want to create a word bibliography from references stored into R, use <a href="https://codeberg.org/agoutsmedt/anystyleR">parse_ref_to_word_bibliography()</a>.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Bibliometrics</category>
  <category>R Package</category>
  <guid>https://aurelien-goutsmedt.com/post/release-ranystyle-development/</guid>
  <pubDate>Sun, 07 Jan 2024 23:00:00 GMT</pubDate>
  <media:content url="https://aurelien-goutsmedt.com/post/release-ranystyle-development/logo.png" medium="image" type="image/png" height="149" width="144"/>
</item>
<item>
  <title>Scraping Documents from the Bank of England Website</title>
  <dc:creator>Aurélien Goutsmedt</dc:creator>
  <link>https://aurelien-goutsmedt.com/post/scraping-boe/</link>
  <description><![CDATA[ 





<p>In the <a href="../../post/scraping-bis/">first tutorial</a> on web scraping, I explained how to scrape the <a href="https://www.bis.org/cbspeeches/index.htm?m=256">Bank of International Settlements database of speeches</a>. The <a href="../../post/scraping-ecb/">second tutorial</a> focused on the working papers of the <a href="https://www.ecb.europa.eu/home/html/index.en.html">European Central Bank</a> website. In this third post, I will show a method to scrape documents from the <a href="https://www.bankofengland.co.uk/">Bank of England’s</a> website.</p>
<p>In the first two posts, we had a list of documents on a webpage with different information (or “metadata”) that we wanted to scrape. For the BIS, we needed to understand the structure of the URL, to use it to change the page and scrape the metadata for all the speeches we were interested in. For the ECB, we rather needed to scroll down and click on menus to open additional details. Here, we will use a radically different approach, which involves retrieving the structure of the website, the “sitemap”, to see where we can find the metadata for the documents.<sup>1</sup></p>
<p>Unlike the first two posts, we won’t need <a href="https://docs.ropensci.org/RSelenium/">RSelenium</a> (Harrison 2022) here. We will only use <a href="https://rvest.tidyverse.org/">rvest</a> (Wickham 2022) and <a href="https://dmi3kno.github.io/polite/">polite</a> (Perepolkin 2023). Indeed, the chosen method doesn’t involve interacting with a web browser.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># pacman is a useful package to install missing packages and load them</span></span>
<span id="cb1-2"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pacman"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">installed.packages</span>()){</span>
<span id="cb1-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pacman"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dependencies =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-4">}</span>
<span id="cb1-5"></span>
<span id="cb1-6">pacman<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">p_load</span>(tidyverse,</span>
<span id="cb1-7">               rvest,</span>
<span id="cb1-8">               polite)</span></code></pre></div></div>
<section id="a-look-at-the-boe-website" class="level2">
<h2 class="anchored" data-anchor-id="a-look-at-the-boe-website">A look at the BoE Website</h2>
<p>Let’s have a look, for instance, at the speeches of the BoE at <code>https://www.bankofengland.co.uk/news/speeches</code>.</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-boe/featured.png" alt="BoE Speeches" width="736">
<p class="caption">
<span id="fig:show-op"></span>Figure 1: BoE Speeches
</p>
</div>
<p>We have a list of speeches that is relatively similar to what we had for the BIS, with a list of pages that you can change to the bottom of the webpage. However, the URL stays the same when you move to another page. I have not found any way to manipulate the URL in order to move from a page to another. But you could easily use <em>RSelenium</em> to click on the button to go to the next page.</p>
<p>Nonetheless, we can collect more information by clicking on each speech, as each speech has a dedicated webpage like this:</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-boe/example_speech.png" alt="A Speech Webpage" width="548">
<p class="caption">
<span id="fig:unnamed-chunk-1"></span>Figure 2: A Speech Webpage
</p>
</div>
<p>This means that for each speech of the BoE’s policymakers, an URL exists, and thus we should be able to find this URL from the “sitemap”.<sup>2</sup></p>
</section>
<section id="exploring-the-sitemap" class="level2">
<h2 class="anchored" data-anchor-id="exploring-the-sitemap">Exploring the Sitemap</h2>
<p>As explained in the <a href="../../post/scraping-bis/">first tutorial</a>, it is important to tell the website who we are and to check the scraping rules on that site by reading the <em>robot.txt</em>.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">root_url_BoE <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://www.bankofengland.co.uk"</span></span>
<span id="cb2-2">user_agent <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"polite R package - used for https://github.com/agoutsmedt/central_bank_database (aurelien.goutsmedt[at]uclouvain.be)"</span></span>
<span id="cb2-3">session <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bow</span>(root_url_BoE,</span>
<span id="cb2-4">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">user_agent =</span> user_agent)</span>
<span id="cb2-5"></span>
<span id="cb2-6">session<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robotstxt<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>text</span></code></pre></div></div>
<pre><code>## [robots.txt]
## --------------------------------------
## 
## User-agent: *
## Disallow: /boeapps/database/ShowChart.asp
## Disallow: /boeapps/database/_iadb-FromShowColumns.asp
## Disallow: /boeapps/iadb
## Disallow: /boeapps/titan
## Disallow: /error
## Disallow: /forms
## Disallow: /mfsd
## Disallow: /search
## Disallow: /test-folder
## Disallow: /-/media/boe/files/markets/benchmarks/sonia-statement-of-compliance-with-the-iosco-principles-for-financial-benchmarks.pdf
## 
## Sitemap: https://www.bankofengland.co.uk/_api/sitemap/getsitemap
## Host: www.bankofengland.co.uk</code></pre>
<p>The <em>robot.txt</em> also indicates the URL of the sitemap:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">sitemap <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> session<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robotstxt<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>sitemap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>value</span>
<span id="cb4-2"></span>
<span id="cb4-3">sitemap</span></code></pre></div></div>
<pre><code>## [1] "https://www.bankofengland.co.uk/_api/sitemap/getsitemap"</code></pre>
<p>This webpage gathers a (very long) list of all the existing URLs of the website. You can try to have a look at it on your browser, but it takes a very long time to load. The easiest is to read it directly here using <em>rvest</em>.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">xml_sitemap <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rvest<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_html</span>(sitemap)</span>
<span id="cb6-2"></span>
<span id="cb6-3">xml_sitemap <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_element</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xpath =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"body"</span>)</span></code></pre></div></div>
<pre><code>## {html_node}
## &lt;body&gt;
## [1] &lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"&gt;&lt;url&gt;&lt;loc&gt;htt ...</code></pre>
<p>We can see that it is the “loc” argument that interests us.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">data_frame_sitemap <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hyperlink=</span> xml_sitemap <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-2">                                   rvest<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_elements</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xpath =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".//loc"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-3">                                   rvest<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(hyperlink <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!=</span> root_url_BoE) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># we exclude the base url that we don't need anymore</span></span>
<span id="cb8-5"></span>
<span id="cb8-6">data_frame_sitemap</span></code></pre></div></div>
<pre><code>## # A tibble: 13,140 × 1
##    hyperlink                                                                    
##    &lt;chr&gt;                                                                        
##  1 https://www.bankofengland.co.uk/about                                        
##  2 https://www.bankofengland.co.uk/about/corporate-responsibility               
##  3 https://www.bankofengland.co.uk/about/corporate-responsibility/carbon-target…
##  4 https://www.bankofengland.co.uk/about/corporate-responsibility/charities-of-…
##  5 https://www.bankofengland.co.uk/about/get-involved                           
##  6 https://www.bankofengland.co.uk/about/get-involved/citizens-panels           
##  7 https://www.bankofengland.co.uk/about/get-involved/citizens-panels/cara-pete…
##  8 https://www.bankofengland.co.uk/about/get-involved/citizens-panels/emma-young
##  9 https://www.bankofengland.co.uk/about/get-involved/citizens-panels/insights-…
## 10 https://www.bankofengland.co.uk/about/get-involved/citizens-panels/nick-chen…
## # ℹ 13,130 more rows</code></pre>
<p>We now have a list of 13140 URLs. What we need to do now is to understand what these URLs are about. We can find this by looking at what follows the base URLs:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">data_frame_sitemap <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> data_frame_sitemap <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">category =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(hyperlink, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://www.bankofengland.co.uk/"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-3">                     <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/.*"</span>))</span>
<span id="cb10-4"></span>
<span id="cb10-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>(data_frame_sitemap<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>category) </span></code></pre></div></div>
<pre><code>##  [1] "about"                               "accessibility"                      
##  [3] "agents-summary"                      "alternative-liquidity-facility"     
##  [5] "annual-report"                       "archive"                            
##  [7] "article"                             "asset-purchase-facility"            
##  [9] "bank-liabilities-survey"             "bank-overground"                    
## [11] "banking-services"                    "banknotes"                          
## [13] "careers"                             "ccbs"                               
## [15] "climate-change"                      "contact"                            
## [17] "coronavirus"                         "cost-of-living"                     
## [19] "credit-conditions-review"            "credit-conditions-survey"           
## [21] "decision-maker-panel"                "education"                          
## [23] "eu-withdrawal"                       "events"                             
## [25] "explainers"                          "external-mpc-discussion-paper"      
## [27] "faq"                                 "financial-policy-summary-and-record"
## [29] "financial-stability"                 "financial-stability-in-focus"       
## [31] "financial-stability-paper"           "financial-stability-report"         
## [33] "freedom-of-information"              "gold"                               
## [35] "independent-evaluation-office"       "inflation-attitudes-survey"         
## [37] "inflation-report"                    "legal"                              
## [39] "letter"                              "markets"                            
## [41] "minutes"                             "monetary-policy"                    
## [43] "monetary-policy-report"              "monetary-policy-summary-and-minutes"
## [45] "museum"                              "news"                               
## [47] "paper"                               "payment-and-settlement"             
## [49] "prudential-regulation"               "quarterly-bulletin"                 
## [51] "record"                              "report"                             
## [53] "research"                            "rss"                                
## [55] "sitemap"                             "speech"                             
## [57] "statement"                           "statistics"                         
## [59] "sterling-monetary-framework"         "sterling-money-market-survey"       
## [61] "stress-testing"                      "subscribe-to-emails"                
## [63] "systemic-risk-survey"                "the-digital-pound"                  
## [65] "vulnerability-disclosure-policy"     "weekly-report"                      
## [67] "whistleblowing"                      "working-paper"</code></pre>
<p>We can now filter the URLs depending on what we want to scrape. For this time, let’s forget the speeches and say that we are interested in the “minutes”:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">minutes_urls <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> data_frame_sitemap <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb12-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(category <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"minutes"</span>)</span>
<span id="cb12-3"></span>
<span id="cb12-4">minutes_urls</span></code></pre></div></div>
<pre><code>## # A tibble: 669 × 2
##    hyperlink                                                            category
##    &lt;chr&gt;                                                                &lt;chr&gt;   
##  1 https://www.bankofengland.co.uk/minutes/1997/monetary-policy-commit… minutes 
##  2 https://www.bankofengland.co.uk/minutes/1997/monetary-policy-commit… minutes 
##  3 https://www.bankofengland.co.uk/minutes/1997/monetary-policy-commit… minutes 
##  4 https://www.bankofengland.co.uk/minutes/1997/monetary-policy-commit… minutes 
##  5 https://www.bankofengland.co.uk/minutes/1997/monetary-policy-commit… minutes 
##  6 https://www.bankofengland.co.uk/minutes/1997/monetary-policy-commit… minutes 
##  7 https://www.bankofengland.co.uk/minutes/1997/monetary-policy-commit… minutes 
##  8 https://www.bankofengland.co.uk/minutes/1998/monetary-policy-commit… minutes 
##  9 https://www.bankofengland.co.uk/minutes/1998/monetary-policy-commit… minutes 
## 10 https://www.bankofengland.co.uk/minutes/1998/monetary-policy-commit… minutes 
## # ℹ 659 more rows</code></pre>
</section>
<section id="scraping-minutes-metadata" class="level2">
<h2 class="anchored" data-anchor-id="scraping-minutes-metadata">Scraping Minutes Metadata</h2>
<p>Thanks to the URLs of the minutes, we have the year of the minutes. Let’s focus on the minutes of 2023.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">minutes_urls <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> minutes_urls <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb14-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dates =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(hyperlink, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;=/)</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}(?=/)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb14-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(dates <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2023</span>)</span></code></pre></div></div>
<p>Here is the first URL in our data:</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-boe/example_minute.png" alt="A Minutes Webpage" width="520">
<p class="caption">
<span id="fig:unnamed-chunk-4"></span>Figure 3: A Minutes Webpage
</p>
</div>
<p>Using <em>rvest</em>, we first extract the <code>html</code> code of the first webpage. You can see that the text of the minutes can be extracted directly from this webpage. We want to scrape the title of the document, its date, its summary, and the text content.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># first, we read the html</span></span>
<span id="cb15-2">page <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> minutes_urls <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(hyperlink) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-5">  read_html</span>
<span id="cb15-6"></span>
<span id="cb15-7"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># second, we extract the different information</span></span>
<span id="cb15-8">extracted_title <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>  page <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"h1"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>()</span>
<span id="cb15-11">extracted_date <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> page <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span>  </span>
<span id="cb15-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".published-date"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trim =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+ [A-z]+ </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+$"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dmy</span>()</span>
<span id="cb15-16"></span>
<span id="cb15-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># As the abstract and the text may gather several paragraphs, the object could be a vector of several strings. We thus save these strings as a list format (because we want one line per URL/document)</span></span>
<span id="cb15-18">abstract <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>  page <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".hero"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trim=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>()</span>
<span id="cb15-22">text <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> page <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-23">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># We extract the titles and the text together</span></span>
<span id="cb15-24">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'.page-section .content-block h2 , .page-section .content-block h3, .page-section .content-block .page-content p'</span>)  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>()</span>
<span id="cb15-27"></span>
<span id="cb15-28">metadata <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> extracted_title,</span>
<span id="cb15-29">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date =</span> extracted_date,</span>
<span id="cb15-30">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">abstract =</span> abstract,</span>
<span id="cb15-31">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> text)  </span>
<span id="cb15-32"></span>
<span id="cb15-33">metadata</span></code></pre></div></div>
<pre><code>## # A tibble: 1 × 4
##   title                                                date       abstract text 
##   &lt;chr&gt;                                                &lt;date&gt;     &lt;list&gt;   &lt;lis&gt;
## 1 Minutes of the Meeting of the Court of Directors he… 2023-06-08 &lt;chr&gt;    &lt;chr&gt;</code></pre>
<p>We can have a look at the first lines of the text extracted:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1">metadata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb17-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(text) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unlist</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-4">  .[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span>  </span>
<span id="cb17-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_c</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>()</span></code></pre></div></div>
<pre><code>## Present:
## David Roberts, Chair
## Andrew Bailey, Governor
## Ben Broadbent, Policy
## Sir Jon Cunliffe, Deputy Governor – Financial Stability
## Sir Dave Ramsden, Deputy Governor – Markets &amp; Banking
## Sam Woods, Deputy Governor – Prudential Regulation
## Sabine Chalmers
## Lord Jitesh Gadhia
## Anne Glover
## Sir Ron Kalifa
## Diana Noble
## Frances O’Grady
## Tom Shropshire 
## In attendance:
## Ben Stimson, Chief Operating Officer
## Secretary:
## Sebastian Walsh
## 1. Conflicts, Minutes and Matters Arising
## There were no conflicts declared in relation to the present agenda.
## The minutes of the meeting held on 8 February 2023 were approved.
## The Chair noted that a number of steps had been introduced to support the effectiveness of Court meetings.  
## The Chair welcomed Ruth Smith to the meeting and noted that Ruth had been appointed as interim Secretary of the Bank.  
## 2. Governor’s Update
## The Governor updated Court on recent developments in the banking system.  
## The Governor reflected that recent weeks had seen two banks with UK operations fail and parts of the financial sector come under stress. Silicon Valley Bank (SVB) and its UK subsidiary failed on 10 March due to a deposit run following significant losses in the US parent. Court observed the speed of the run on SVB. Court noted the factors underlying this, including the extent to which social media now drives bank runs.
## The PRA’s approach to the UK operations of SVB ensured a greater degree of financial resilience, particularly the subsidiarisation policy. Over the weekend that SVB UK failed, the Bank conducted a successful resolution transaction – demonstrating the effective operation of the UK’s resolution regime. SVB UK’s capital instruments were written down, and the firm was sold to HSBC. The Bank’s actions protected both depositors and public funds.
## The Governor set out that the resolution plan for Credit Suisse was well-rehearsed by the UK, US and Swiss authorities. However, the Swiss authorities had not used the resolution plan. Instead, the Swiss conducted a going-concern sale underpinned by some public support, which in turn effected a full write-down of subordinated debt instruments, while equity was only partially written down. There had been some brief fallout in AT1 markets following this action, but swift communications from the UK and EU authorities on their approach to the creditor hierarchy in resolution had stemmed this.
## Though SVB and Credit Suisse had failed for different reasons, the events had taken place in close proximity to each other. As a result of this, investors perceived that the outlook for the global banking sector was uncertain. The Governor noted that more broadly the backdrop for these events was an uncertain outlook for global economic activity. The Bank was monitoring the financial system closely, particularly the impact of recent events on financial markets, UK banks and economic conditions. The Governor noted that UK banks are well capitalised, liquid and resilient to continue supporting households and businesses.
## Providing further detail about this work, Sam Woods explained that the FPC and the PRA had been closely examining developments across the financial system as a whole.</code></pre>
<p>Now, we just need to build a loop to scrape the metadata for all the minutes. To avoid overloading the BoE website, we set a delay between navigating to the different URLs.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1">delay <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> session<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>delay</span></code></pre></div></div>
<p>We will also use the <code>TryCatch()</code> function to avoid breaking the loop in case of error (for instance when a page is not loaded correctly).</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1">errors <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>()</span>
<span id="cb20-2">metadata <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mode =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"list"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(minutes_urls))</span>
<span id="cb20-3"></span>
<span id="cb20-4">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span>(i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> minutes_urls<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>hyperlink){ </span>
<span id="cb20-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatch</span>({</span>
<span id="cb20-6">      page <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_html</span>(i)</span>
<span id="cb20-7">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Now scraping URL: "</span>, i, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>))</span>
<span id="cb20-8">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.sleep</span>(delay)</span>
<span id="cb20-9">      </span>
<span id="cb20-10">      extracted_title <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>  page <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-11">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"h1"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-12">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>()</span>
<span id="cb20-13">      extracted_date <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> page <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span>  </span>
<span id="cb20-14">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".published-date"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-15">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trim =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-16">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+ [A-z]+ </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+$"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-17">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dmy</span>()</span>
<span id="cb20-18">      abstract <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>  page <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-19">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".hero"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-20">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">trim=</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-21">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>()</span>
<span id="cb20-22">      text <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> page <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-23">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># We extract the titles and the text together</span></span>
<span id="cb20-24">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_nodes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'.page-section .content-block h2 , .page-section .content-block h3, .page-section .content-block .page-content p'</span>)  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-25">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-26">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>()</span>
<span id="cb20-27">      </span>
<span id="cb20-28">      metadata[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> extracted_title,</span>
<span id="cb20-29">                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">url =</span> i,</span>
<span id="cb20-30">                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date =</span> extracted_date,</span>
<span id="cb20-31">                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">abstract =</span> abstract,</span>
<span id="cb20-32">                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> text)   </span>
<span id="cb20-33">    }, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">error =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(e) {</span>
<span id="cb20-34">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Problem with scraping URL: "</span>, i, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>))</span>
<span id="cb20-35">    errors[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> i</span>
<span id="cb20-36">    })</span>
<span id="cb20-37">  }</span>
<span id="cb20-38"></span>
<span id="cb20-39">minutes_metadata <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(metadata)</span>
<span id="cb20-40"></span>
<span id="cb20-41">minutes_metadata</span></code></pre></div></div>
<p>When all documents have their own webpage, the <em>sitemap</em> data becomes a powerful piece of information to facilitate your scraping. Here, it can be used to easily scrape all documents published by the Bank of England. However, the structure of the page is not exactly the same within a category (the text of the minutes is not available on the webpages before 2022 but you can scrape the URL of the PDF), and between categories (e.g., look at a speech or a working paper). Consequently, a more refined code is needed. So a more sophisticated script can be found <a href="https://github.com/agoutsmedt/central_bank_database/blob/master/scraping_scripts/scraping_boe.R">here</a>.</p>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-R-rselenium" class="csl-entry">
Harrison, John. 2022. <em>RSelenium: R Bindings for ’Selenium WebDriver’</em>. <a href="https://CRAN.R-project.org/package=RSelenium" class="uri">https://CRAN.R-project.org/package=RSelenium</a>.
</div>
<div id="ref-R-polite" class="csl-entry">
Perepolkin, Dmytro. 2023. <em>Polite: Be Nice on the Web</em>. <a href="https://CRAN.R-project.org/package=polite" class="uri">https://CRAN.R-project.org/package=polite</a>.
</div>
<div id="ref-R-rvest" class="csl-entry">
Wickham, Hadley. 2022. <em>Rvest: Easily Harvest (Scrape) Web Pages</em>. <a href="https://CRAN.R-project.org/package=rvest" class="uri">https://CRAN.R-project.org/package=rvest</a>.
</div>
</div>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>This method is inspired from a script initially written by <a href="https://www.usherbrooke.ca/recherche/specialistes/details/francois.claveau">François Claveau</a> and <a href="https://www.epistemopratique.org/chaire/equipe/dion-jeremie/">Jérémie Dion</a> for a <a href="https://www.rebuildingmacroeconomics.ac.uk/academia-policy-pipeline">research project about the Bank of England</a>.↩︎</p></li>
<li id="fn2"><p>Actually, the same method could be used for scraping the speeches of the <a href="https://www.bis.org/cbspeeches/index.htm?m=256">Bank of International Settlements database</a>.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Scraping</category>
  <category>R Tutorials</category>
  <category>Central Banks</category>
  <guid>https://aurelien-goutsmedt.com/post/scraping-boe/</guid>
  <pubDate>Mon, 27 Nov 2023 23:00:00 GMT</pubDate>
  <media:content url="https://aurelien-goutsmedt.com/post/scraping-boe/featured.png" medium="image" type="image/png" height="90" width="144"/>
</item>
<item>
  <title>Scraping Working Papers from the European Central Bank Website</title>
  <dc:creator>Aurélien Goutsmedt</dc:creator>
  <link>https://aurelien-goutsmedt.com/post/scraping-ecb/</link>
  <description><![CDATA[ 





<p>After a <a href="../../post/scraping-bis/">first post</a> on scraping the <a href="https://www.bis.org/cbspeeches/index.htm?m=256">Bank of International Settlements database of speeches</a>, this post teaches how to scrape documents from the <a href="https://www.ecb.europa.eu/home/html/index.en.html">European Central Bank</a> website. More accurately, we won’t scrape the speeches of the ECB’s board members, as they are already available in a <code>.csv</code> format <a href="https://www.ecb.europa.eu/press/key/html/downloads.en.html">here</a>. Rather, we will tackle research documents via the various series of working papers published by the ECB.</p>
<p>In the previous post, we learnt the difference between static and dynamic webpages. Dynamic webpages involve interaction with your web browser: in this case, you need the <a href="https://docs.ropensci.org/RSelenium/">RSelenium</a> (Harrison 2022) package.<sup>1</sup></p>
<p>Here again, we will be confronted to dynamic webpages. However, these webpages raise novel issues. With the BIS database, the main issue was to go to the next page to scrape the metadata of the following speeches. We did it by <a href="../../post/scraping-bis/#going-on-the-bis-website-and-launching-the-bot">finding how the page number was integrated into the URL</a>. With the ECB website, the problem will be trickier for two reasons:</p>
<ul>
<li>First, all the documents are on the same page but as the page may be very long (depending on the type of documents), the page is not loaded entirely by your browser. You will thus learn to scroll down until all the documents are loaded.</li>
<li>Second, some information (like the abstract or the <a href="https://www.aeaweb.org/econlit/jelCodes.php?view=jel">JEL codes</a> of a working paper) are hidden, and you have to click on a button to display them.</li>
</ul>
<p>Before exploring that in details, let’s load the needed packages. This time, we will use <a href="https://rvest.tidyverse.org/">rvest</a> (Wickham 2022) in complement of <em>RSelenium</em> and <a href="https://dmi3kno.github.io/polite/">polite</a> (Perepolkin 2023). At the end of this post, we will test a second method with <em>rvest</em> only and not <em>RSelenium</em> to scrape working papers (but don’t spoil yourself!).</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># pacman is a useful package to install missing packages and load them</span></span>
<span id="cb1-2"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pacman"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">installed.packages</span>()){</span>
<span id="cb1-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pacman"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dependencies =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-4">}</span>
<span id="cb1-5"></span>
<span id="cb1-6">pacman<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">p_load</span>(tidyverse,</span>
<span id="cb1-7">               RSelenium,</span>
<span id="cb1-8">               rvest,</span>
<span id="cb1-9">               polite,</span>
<span id="cb1-10">               glue)</span></code></pre></div></div>
<section id="a-look-at-the-ecb-website" class="level2">
<h2 class="anchored" data-anchor-id="a-look-at-the-ecb-website">A look at the ECB Website</h2>
<p>Let’s say we want to scrape the metadata of ECB’s “occasional papers” at “https://www.ecb.europa.eu/pub/research/occasional-papers/html/index.en.html”.</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-ecb/occasional_papers.png" alt="ECB's occasional papers" width="788">
<p class="caption">
<span id="fig:show-op"></span>Figure 1: ECB’s occasional papers
</p>
</div>
<p>We can see that there is 333 occasional papers on the ECB website. Let’s try to scrape them. First, we use <em>polite</em> to “bow” in front of the ECB website. We specify who we are in the <code>user_agent</code> parameter, in order for the webmaster to contact us in case of problem. Indeed, we are trying here to follow some scraping ethical guidelines (find more developments on this issue <a href="https://towardsdatascience.com/ethics-in-web-scraping-b96b18136f01">here</a>). The <code>bow()</code> function allows us to look at permissions for scraping.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">ecb_op_path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://www.ecb.europa.eu/pub/research/occasional-papers/html/index.en.html"</span></span>
<span id="cb2-2"></span>
<span id="cb2-3">session <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bow</span>(ecb_op_path,</span>
<span id="cb2-4">               <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">user_agent =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"polite R package - used for https://github.com/agoutsmedt/central_bank_database (aurelien.goutsmedt[at]uclouvain.be)"</span>)</span>
<span id="cb2-5">session</span></code></pre></div></div>
<pre><code>## &lt;polite session&gt; https://www.ecb.europa.eu/pub/research/occasional-papers/html/index.en.html
##     User-agent: polite R package - used for https://github.com/agoutsmedt/central_bank_database (aurelien.goutsmedt[at]uclouvain.be)
##     robots.txt: 32 rules are defined for 1 bots
##    Crawl delay: 5 sec
##   The path is scrapable for this user-agent</code></pre>
<p>By looking at the <em>robots.txt</em> file, we can see more in details which paths of the website are scrapable or not. Nothing about the publications path here!</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(session<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robotstxt<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>text)</span></code></pre></div></div>
<pre><code>## User-agent: *
## Sitemap: https://www.ecb.europa.eu/sitemap.xml
## Disallow: /*_content.bg.html$
## Disallow: /*_content.cs.html$
## Disallow: /*_content.da.html$
## Disallow: /*_content.de.html$
## Disallow: /*_content.el.html$
## Disallow: /*_content.en.html$
## Disallow: /*_content.es.html$
## Disallow: /*_content.et.html$
## Disallow: /*_content.fi.html$
## Disallow: /*_content.fr.html$
## Disallow: /*_content.ga.html$
## Disallow: /*_content.hr.html$
## Disallow: /*_content.hu.html$
## Disallow: /*_content.it.html$
## Disallow: /*_content.lt.html$
## Disallow: /*_content.lv.html$
## Disallow: /*_content.mt.html$
## Disallow: /*_content.nl.html$
## Disallow: /*_content.pl.html$
## Disallow: /*_content.pt.html$
## Disallow: /*_content.ro.html$
## Disallow: /*_content.sk.html$
## Disallow: /*_content.sl.html$
## Disallow: /*_content.sv.html$
## Disallow: /ecb/10ann/shared/movies/
## Disallow: /ecb/educational/pricestab/shared/movie/
## Disallow: /ecb/educational/shared/movies/
## Disallow: /paym/coll/assets/html/dla/EA/
## Disallow: /press/tvservices/webcast/shared/video/
## Disallow: /paym/coll/assets/html/dla/EA/
## Disallow: /events/conferences/shared/movie/
## Disallow: /euro/changeover/shared/data/
## Crawl-delay: 5</code></pre>
<p>Let’s launch our bot.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">remDr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rsDriver</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">browser =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"firefox"</span>,</span>
<span id="cb6-2">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">port =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4444</span>L,</span>
<span id="cb6-3">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">chromever =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>)</span>
<span id="cb6-4">browser <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> remDr[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"client"</span>]]</span>
<span id="cb6-5">browser<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">navigate</span>(ecb_op_path)</span>
<span id="cb6-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.time</span>(session<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>delay) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># letting the page load</span></span>
<span id="cb6-7">browser<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"css"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"a.cross.linkButton.linkButtonLarge.floatRight.highlight-extra-light"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clickElement</span>() <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Refusing cookies</span></span></code></pre></div></div>
</section>
<section id="scrolling-down-and-opening-supplementary-menus" class="level2">
<h2 class="anchored" data-anchor-id="scrolling-down-and-opening-supplementary-menus">Scrolling down and opening supplementary menus</h2>
<p>We can try something quickly: we extract the list of the occasional papers number (the “No.&nbsp;XXX” information just above the title).</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">categories <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> browser<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findElements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"css selector"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".category"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_chr</span>(., <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getElementText</span>()[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]) </span>
<span id="cb7-3"></span>
<span id="cb7-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tail</span>(categories)</span></code></pre></div></div>
<pre><code>## [1] "No. 315" "No. 314" "No. 313" "No. 312" "No. 311" "No. 310"</code></pre>
<p>We got something weird here. The last paper we got in the list is No.&nbsp;310. But if we scroll all the way down to the page, we can see that the last paper should be “No.&nbsp;1”.</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-ecb/last_occasional_papers.png" alt="ECB's occasional papers" width="796">
<p class="caption">
<span id="fig:show-last-op"></span>Figure 2: ECB’s occasional papers
</p>
</div>
<p>Let’s dig a bit into the <code>html</code> code of the webpage. In Firefox, you can go to the supplementary tools and open the “web development tools”. You can see that there is something called <code>lazyload-container</code>.</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-ecb/lazyload.png" alt="Digging into ECB's website source code" width="836">
<p class="caption">
<span id="fig:lazyload"></span>Figure 3: Digging into ECB’s website source code
</p>
</div>
<p>As the number of occasional papers is quite big, for efficiency reasons, the website does not load the whole information. Consequently, if you want to scrape all the papers, you need to scroll down the page, and you need to scroll progressively to be sure that all the containers are loaded. The <code>executeScript()</code> function of <em>RSelenium</em> allows you to use some JavaScript code. Here, you don’t want to scroll horizontally, but you want to scroll vertically: you thus need to define the number of pixels by which you want to scroll down (let’s use 1600 to be sure that we will scroll down slowly). We will repeat this operation a certain number of time: as scrolling down by 1600 pixels is equivalent to scroll down by (a bit more than) five papers, we divide the number of papers by 5, to know the number of iterations of the scrolling down move.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">scroll_height <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1600</span></span>
<span id="cb9-2">scroll_iteration <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(categories[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>], <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span></span>
<span id="cb9-4"></span>
<span id="cb9-5">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span>(i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ceiling</span>(scroll_iteration)) {</span>
<span id="cb9-6">    browser<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">executeScript</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"window.scrollBy(0,{scroll_height});"</span>))</span>
<span id="cb9-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.sleep</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>)</span>
<span id="cb9-8">  }</span></code></pre></div></div>
<p>Let’s check that now all the discussion papers are available:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">categories <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> browser<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findElements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"css selector"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".category"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_chr</span>(., <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getElementText</span>()[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]) </span>
<span id="cb10-3"></span>
<span id="cb10-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(categories)</span></code></pre></div></div>
<pre><code>## [1] 333</code></pre>
<p>That’s all good. But we face a second issue: some important information are not visible yet. Indeed, by clicking on the “Details” button, you can access the abstract and the JEL codes of the paper.</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-ecb/details.png" alt="The 'details' menu" width="664">
<p class="caption">
<span id="fig:details"></span>Figure 4: The ‘details’ menu
</p>
</div>
<p>But as long as the <em>Details</em> menu is closed, the information is not accessible. So we need to find all the buttons that allow to click on the “Details” menu. But be careful, we want only the “Details” button, and not other types of button. As in the <a href="../../post/scraping-bis/">former post</a>, the <a href="https://addons.mozilla.org/fr/firefox/addon/scrapemate/">ScrapeMate</a> Firefox add-on is essential to find the right <em>CSS selector</em>.</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-ecb/scrapemate.png" alt="Using ScrapeMate Beta" width="938">
<p class="caption">
<span id="fig:scrapemate"></span>Figure 5: Using ScrapeMate Beta
</p>
</div>
<p>We can now click on all the “Details” buttons, and only the “Details” buttons:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">  buttons <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> browser<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findElements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"css selector"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".ecb-langSelector+ .accordion .header:nth-child(1) .title"</span>)</span>
<span id="cb12-2">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span>(i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(buttons)){</span>
<span id="cb12-3">    buttons[[i]]<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clickElement</span>()</span>
<span id="cb12-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.sleep</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>)</span>
<span id="cb12-5">  }</span></code></pre></div></div>
<p>Now, we have at our disposal all the information that is of interest to us. The remaining issue is that some information may be missing (or non-existent) for some papers (for instance, one paper has no author). So we extract the dates separately, and then we select the whole set of information for each paper (in the <code>papers_whole_information</code> object), and in this set, we extract in turn the title, the authors, the URL of the pdf, and the information in details.<sup>2</sup></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">papers_whole_information <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> browser<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getPageSource</span>()[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># we extract the whole info of each paper here (without the date)</span></span>
<span id="cb13-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_html</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb13-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_elements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dd"</span>)</span>
<span id="cb13-4"></span>
<span id="cb13-5">metadata <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb13-6">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">category =</span> categories,</span>
<span id="cb13-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dates =</span> browser<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findElements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"css selector"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".loaded &gt; dt"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb13-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_chr</span>(., <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getElementText</span>()[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]),</span>
<span id="cb13-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">titles =</span> papers_whole_information <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb13-10">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_elements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".category+ .title a"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb13-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>(),</span>
<span id="cb13-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">authors =</span> papers_whole_information <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb13-13">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_elements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ul"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb13-14">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text2</span>(),</span>
<span id="cb13-15">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">details =</span> papers_whole_information <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb13-16">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_elements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".ecb-langSelector+ .accordion .content-box:nth-child(2)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb13-17">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text2</span>(),</span>
<span id="cb13-18">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">url_pdf =</span> papers_whole_information <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb13-19">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_elements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".authors+ .ecb-langSelector .pdf"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb13-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"href"</span>) </span>
<span id="cb13-21">)</span>
<span id="cb13-22"></span>
<span id="cb13-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(metadata)</span></code></pre></div></div>
<pre><code>## # A tibble: 6 × 6
##   category dates             titles                      authors details url_pdf
##   &lt;chr&gt;    &lt;chr&gt;             &lt;chr&gt;                       &lt;chr&gt;   &lt;chr&gt;   &lt;chr&gt;  
## 1 No. 333  8 November 2023   Living in a world of disap… "Chiar… "Abstr… /pub/p…
## 2 No. 332  24 October 2023   The effects of high inflat… "Krzys… "Abstr… /pub/p…
## 3 No. 331  17 October 2023   The future of DAOs in fina… "Ellen… "Abstr… /pub/p…
## 4 No. 330  16 October 2023   Inflation, fiscal policy a… "Henri… "Abstr… /pub/p…
## 5 No. 329  20 September 2023 How usable are capital buf… "Georg… "Abstr… /pub/p…
## 6 No. 317  13 September 2023 Recent advances in the lit… "Rolan… "Abstr… /pub/p…</code></pre>
<p>Two points of clarification here:</p>
<ul>
<li>the <em>CSS selector</em> must be selected carefully. For instance, a paper may have several “.title a”, because it gathers some complementary documents. Paper 209 is an example. So you only want the title after the category. Hence the selector “.category+ .title a”. That’s the same logic for the “details” menu: you don’t want what is in the Annex for instance. Also, you may have several pdf links, and you just want the pdf link below the authors, which is the pdf of the paper.</li>
<li>the <code>authors</code> and <code>details</code> columns remain to be cleaned. Indeed, you can have several authors, and the <code>details</code> column gathers information about the abstract and JEL_codes, but also, in rare occasion, the “taxonomy” and the “network”. That’s why we use the <code>html_text2()</code> function of <em>rvest</em>: each type of information is separated by a linebreak (“”).</li>
</ul>
<p>Let’s clean the details. You first separate the lines and get something like that:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1">details_cleaned <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> metadata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(category, details) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">separate_longer_delim</span>(details, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span> details <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span>
<span id="cb15-5"></span>
<span id="cb15-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(details_cleaned, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>)</span></code></pre></div></div>
<pre><code>## # A tibble: 20 × 2
##    category details                                                             
##    &lt;chr&gt;    &lt;chr&gt;                                                               
##  1 No. 333  Abstract                                                            
##  2 No. 333  The loss of biodiversity and the degradation of natural ecosystems …
##  3 No. 333  JEL Code                                                            
##  4 No. 333  C55 : Mathematical and Quantitative Methods→Econometric Modeling→Mo…
##  5 No. 333  G21 : Financial Economics→Financial Institutions and Services→Banks…
##  6 No. 333  G38 : Financial Economics→Corporate Finance and Governance→Governme…
##  7 No. 333  Q5 : Agricultural and Natural Resource Economics, Environmental and…
##  8 No. 332  Abstract                                                            
##  9 No. 332  The recent spike in inflation, unprecedented in the history of the …
## 10 No. 332  JEL Code                                                            
## 11 No. 332  C3 : Mathematical and Quantitative Methods→Multiple or Simultaneous…
## 12 No. 332  E3 : Macroeconomics and Monetary Economics→Prices, Business Fluctua…
## 13 No. 332  E6 : Macroeconomics and Monetary Economics→Macroeconomic Policy, Ma…
## 14 No. 331  Abstract                                                            
## 15 No. 331  Despite the crypto-market crash in the spring of 2022 and the colla…
## 16 No. 331  JEL Code                                                            
## 17 No. 331  F38 : International Economics→International Finance→International F…
## 18 No. 331  F39 : International Economics→International Finance→Other           
## 19 No. 331  G23 : Financial Economics→Financial Institutions and Services→Non-b…
## 20 No. 331  G32 : Financial Economics→Corporate Finance and Governance→Financin…</code></pre>
<p>What you need to do is to extract the category of information (“Abstract|JEL Code|Taxonomy|Network”), and the text below represents the content of this category of information. You can then pivot the data to fill each column for the paper. Of course, most columns for taxonomy and network will be empty. As you have several JEL codes for each paper, <code>pivot_wider()</code> creates list columns for each type of information. But you can “unnest” the columns with single values (“Abstract”, “Taxonomy”, and “Network”)</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1">details_cleaned <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> details_cleaned <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(details, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^Abstract$|^JEL Code$|^Taxonomy$|^Network$"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(type, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.direction =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"down"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># we replace NA values in the type column by the information above which is non NA</span></span>
<span id="cb17-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(details, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^Abstract$|^JEL Code$|^Taxonomy$|^Network$"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># we remove the title rows</span></span>
<span id="cb17-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pivot_wider</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">names_from =</span> type, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">values_from =</span> details) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cols =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Abstract"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Taxonomy"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Network"</span>)) </span>
<span id="cb17-7"></span>
<span id="cb17-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(details_cleaned)</span></code></pre></div></div>
<pre><code>## # A tibble: 6 × 5
##   category Abstract                                  `JEL Code` Network Taxonomy
##   &lt;chr&gt;    &lt;chr&gt;                                     &lt;list&gt;     &lt;chr&gt;   &lt;chr&gt;   
## 1 No. 333  The loss of biodiversity and the degrada… &lt;chr [4]&gt;  &lt;NA&gt;    &lt;NA&gt;    
## 2 No. 332  The recent spike in inflation, unprecede… &lt;chr [3]&gt;  &lt;NA&gt;    &lt;NA&gt;    
## 3 No. 331  Despite the crypto-market crash in the s… &lt;chr [7]&gt;  &lt;NA&gt;    &lt;NA&gt;    
## 4 No. 330  This paper analyses the distributional i… &lt;chr [6]&gt;  &lt;NA&gt;    &lt;NA&gt;    
## 5 No. 329  This paper analyses banksâ€™ ability to … &lt;chr [2]&gt;  &lt;NA&gt;    &lt;NA&gt;    
## 6 No. 317  Large swings in cross-border capital flo… &lt;chr [2]&gt;  &lt;NA&gt;    &lt;NA&gt;</code></pre>
<p>Let’s “zoom” to the <code>JEL code</code> column:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(details_cleaned <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(category, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">JEL Code</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unnest</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">JEL Code</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>))</span></code></pre></div></div>
<pre><code>## # A tibble: 6 × 2
##   category `JEL Code`                                                           
##   &lt;chr&gt;    &lt;chr&gt;                                                                
## 1 No. 333  C55 : Mathematical and Quantitative Methods→Econometric Modeling→Mod…
## 2 No. 333  G21 : Financial Economics→Financial Institutions and Services→Banks,…
## 3 No. 333  G38 : Financial Economics→Corporate Finance and Governance→Governmen…
## 4 No. 333  Q5 : Agricultural and Natural Resource Economics, Environmental and …
## 5 No. 332  C3 : Mathematical and Quantitative Methods→Multiple or Simultaneous …
## 6 No. 332  E3 : Macroeconomics and Monetary Economics→Prices, Business Fluctuat…</code></pre>
<p>Finally, you just need to merge the details cleaned with the metadata:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1">metadata_cleaned <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> metadata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb21-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>details) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb21-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(details_cleaned)</span>
<span id="cb21-4"></span>
<span id="cb21-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(metadata_cleaned)</span></code></pre></div></div>
<pre><code>## # A tibble: 6 × 9
##   category dates     titles authors url_pdf Abstract `JEL Code` Network Taxonomy
##   &lt;chr&gt;    &lt;chr&gt;     &lt;chr&gt;  &lt;chr&gt;   &lt;chr&gt;   &lt;chr&gt;    &lt;list&gt;     &lt;chr&gt;   &lt;chr&gt;   
## 1 No. 333  8 Novemb… Livin… "Chiar… /pub/p… The los… &lt;chr [4]&gt;  &lt;NA&gt;    &lt;NA&gt;    
## 2 No. 332  24 Octob… The e… "Krzys… /pub/p… The rec… &lt;chr [3]&gt;  &lt;NA&gt;    &lt;NA&gt;    
## 3 No. 331  17 Octob… The f… "Ellen… /pub/p… Despite… &lt;chr [7]&gt;  &lt;NA&gt;    &lt;NA&gt;    
## 4 No. 330  16 Octob… Infla… "Henri… /pub/p… This pa… &lt;chr [6]&gt;  &lt;NA&gt;    &lt;NA&gt;    
## 5 No. 329  20 Septe… How u… "Georg… /pub/p… This pa… &lt;chr [2]&gt;  &lt;NA&gt;    &lt;NA&gt;    
## 6 No. 317  13 Septe… Recen… "Rolan… /pub/p… Large s… &lt;chr [2]&gt;  &lt;NA&gt;    &lt;NA&gt;</code></pre>
<p>And you now have a nice table of metadata for ECB occasional papers! The <a href="../../post/scraping-bis/">post on the BIS</a> explains then how to download the PDF, and how to run OCR if the text of the PDFs is not searchable. The code in this current post is also working for ECB’s “discussion papers” and “working papers”.</p>
</section>
<section id="another-method" class="level2">
<h2 class="anchored" data-anchor-id="another-method">Another Method?</h2>
<p>You can use the method above to scrape the metadata for the almost 3000 working papers of the ECB. But you can imagine that it takes a very long time to scroll down the page, and above all to open all the “Details” menu. <em>RSelenium</em> is wonderfully useful to interact with web browser, but sometimes, by digging into the source code of a webpage, you may find easier ways to extract relevant information.</p>
<p>And this is possible for the ECB research pages. We have already come across a clue to this earlier in this post. Indeed, let’s look again at the code related to the “lazyload-container”.</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-ecb/lazyload.png" alt="Digging into ECB's website code" width="836">
<p class="caption">
<span id="fig:lazyload-again"></span>Figure 6: Digging into ECB’s website code
</p>
</div>
<p>Actually it tells us that the website is loading some other pages, ending with “papers-2023.include.en.html”, “papers-2022.include.en.html”, etc., until “papers-1999.include.en.html”. Let’s try the first one: “https://www.ecb.europa.eu/pub/research/working-papers/html/papers-2023.include.en.html”</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-ecb/new_ecb_page.png" alt="A simpler ECB page" width="956">
<p class="caption">
<span id="fig:unnamed-chunk-10"></span>Figure 7: A simpler ECB page
</p>
</div>
<p>So we can scrape quite easily the occasional papers for 2023:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1">url <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://www.ecb.europa.eu/pub/research/occasional-papers/html/papers-2023.include.en.html"</span></span>
<span id="cb23-2"></span>
<span id="cb23-3">html_info <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_html</span>(url) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb23-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_elements</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xpath =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"/html/body/dd"</span>)</span>
<span id="cb23-5"></span>
<span id="cb23-6">metadata <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(</span>
<span id="cb23-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">category =</span> html_info <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb23-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_elements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".category"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb23-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>(),</span>
<span id="cb23-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dates =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_html</span>(url) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb23-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_elements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".date"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb23-12">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>(),</span>
<span id="cb23-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">titles =</span> html_info <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb23-14">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_elements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".category+ .title a"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb23-15">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text</span>(),</span>
<span id="cb23-16">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">authors =</span> html_info <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb23-17">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_elements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ul"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb23-18">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text2</span>(),</span>
<span id="cb23-19">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">details =</span> html_info <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb23-20">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_elements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".ecb-langSelector+ .accordion .content-box:nth-child(2)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb23-21">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_text2</span>(),</span>
<span id="cb23-22">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">url_pdf =</span> html_info <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb23-23">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_elements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".pdf"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb23-24">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html_attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"href"</span>) </span>
<span id="cb23-25">)</span>
<span id="cb23-26"></span>
<span id="cb23-27"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(metadata)</span></code></pre></div></div>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-R-rselenium" class="csl-entry">
Harrison, John. 2022. <em>RSelenium: R Bindings for ’Selenium WebDriver’</em>. <a href="https://CRAN.R-project.org/package=RSelenium" class="uri">https://CRAN.R-project.org/package=RSelenium</a>.
</div>
<div id="ref-R-polite" class="csl-entry">
Perepolkin, Dmytro. 2023. <em>Polite: Be Nice on the Web</em>. <a href="https://CRAN.R-project.org/package=polite" class="uri">https://CRAN.R-project.org/package=polite</a>.
</div>
<div id="ref-R-rvest" class="csl-entry">
Wickham, Hadley. 2022. <em>Rvest: Easily Harvest (Scrape) Web Pages</em>. <a href="https://CRAN.R-project.org/package=rvest" class="uri">https://CRAN.R-project.org/package=rvest</a>.
</div>
</div>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>See the end of this tutorial for some tricks to “transform” complex dynamic webpages in simpler pages and not use <em>RSelenium</em>.↩︎</p></li>
<li id="fn2"><p>If there is no author, we will have a blank string.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Scraping</category>
  <category>R Tutorials</category>
  <category>Central Banks</category>
  <guid>https://aurelien-goutsmedt.com/post/scraping-ecb/</guid>
  <pubDate>Wed, 15 Nov 2023 23:00:00 GMT</pubDate>
  <media:content url="https://aurelien-goutsmedt.com/post/scraping-ecb/featured.png" medium="image" type="image/png" height="78" width="144"/>
</item>
<item>
  <title>Scraping Central Bankers’ Speeches from the BIS Website</title>
  <dc:creator>Aurélien Goutsmedt</dc:creator>
  <link>https://aurelien-goutsmedt.com/post/scraping-bis/</link>
  <description><![CDATA[ 





<section id="scraping-data" class="level2">
<h2 class="anchored" data-anchor-id="scraping-data">Scraping data</h2>
<p>In this post, you will learn how to scrape speeches from the <a href="https://www.bis.org/cbspeeches/index.htm?m=256">Bank of International Settlements database of speeches</a>, which gathers most of central bankers’ speeches in English. We will do it programming in R. The <a href="../../post/scraping-ecb/">second tutorial</a> focuses on scraping documents from the <a href="https://www.ecb.europa.eu/home/html/index.en.html">European Central Bank</a> website and the <a href="../../post/scraping-boe/">third one</a> scrape the Bank of England’s website.</p>
<p>Before going along the scraping, let’s start by a general introduction about what web scraping is.</p>
<section id="what-is-web-scraping" class="level3">
<h3 class="anchored" data-anchor-id="what-is-web-scraping">What is web scraping?</h3>
<p>Web scraping is the process of extracting data from websites. It involves programmatically accessing a website’s content, extracting the data you want, and then saving it for further use. It involves going to a specific URL, retrieving the html content and extract the data you want from this content.</p>
<p>In general, you need to use web scraping when there is no <a href="https://en.wikipedia.org/wiki/API">API</a> (Application Programming Interface) for the website data you want to access. An API is a structured and authorized way to access data provided by a website, from a system of queries (for instance, <a href="https://www.scopus.com/">scopus</a> provides an API to <a href="../extracting-biblio-data-1/">retrieve its bibliometric data</a>).</p>
<p>Scraping data on a website implies various ethical and legal issues (for which I am not a specialist at all!). First, many websites have terms of service agreements that explicitly prohibit web scraping. Engaging in scraping without the website owner’s consent violates these terms and conditions. For instance, <a href="https://www.linkedin.com/">Linkedin</a> prohibits scraping on its website. However, the “legality” of scraping Linkedin <a href="https://www.forbes.com/sites/zacharysmith/2022/04/18/scraping-data-from-linkedin-profiles-is-legal-appeals-court-rules/">remains a complex matter</a>. Before engaging in scraping, you need to know what are the terms and conditions, and know what are the risks if you violate them.</p>
<p>A second issue has to do with overloading servers. Web scraping can put a significant load on a website’s servers, potentially leading to decreased performance or downtime. Scraping without proper rate limiting and respect for a website’s capacity can be seen as unethical and disruptive.</p>
<p>Third, if you may be allowed to scrape a website, it does not mean that you can copy and distribute the materials collected. You should be aware of copyright laws and intellectual property rights when diffusing scraped content.</p>
</section>
<section id="some-useful-resources" class="level3">
<h3 class="anchored" data-anchor-id="some-useful-resources">Some useful resources</h3>
<p>When talking about web scraping with R, three R packages stand out (but we will only use two of them here):</p>
<ul>
<li><a href="https://rvest.tidyverse.org/">rvest</a> (Wickham 2022): a package in the <a href="https://www.tidyverse.org/">tidyverse</a> spirit that helps to extract data from web pages. It works better with static web page (see below).</li>
<li><a href="https://docs.ropensci.org/RSelenium/">RSelenium</a> (Harrison 2022): this is an R binding for <a href="https://www.selenium.dev/">Selenium</a> 2.0 Remote WebDriver, which allows you to automate the use of a browser. In other words, it enables you to write a script to open a web browser and interact with a website (yes, this is where scraping starts to get fun).</li>
<li><a href="https://dmi3kno.github.io/polite/">polite</a> (Perepolkin 2023): this package allows you to look at the <a href="https://en.wikipedia.org/wiki/Robots.txt">robots.txt</a> of a website to know what are the scraping rules for this website, and to avoid hammering the site with too many requests.</li>
</ul>
<p>Depending on the website you want to scrap, using <a href="https://rvest.tidyverse.org/">rvest</a> may be sufficient (as it is the case, for instance, with <a href="https://en.wikipedia.org/wiki/Main_Page">Wikipedia</a>). For more complicated website, you may need <a href="https://docs.ropensci.org/RSelenium/">RSelenium</a>, in combination with <a href="https://rvest.tidyverse.org/">rvest</a> or alone. Indeed, it depends if the web pages you want to scrape are static or dynamic web pages. As explained by <a href="https://ivanmillanes.netlify.app/post/2020-06-30-webscraping-with-rselenium-and-rvest/">Ivan Milanes’ useful blog post</a>:</p>
<ul>
<li><a href="https://www.pcmag.com/encyclopedia/term/static-web-page">Static Web Page</a>: A Web page (HTML page) that contains the same information for all users. Although it may be periodically updated from time to time, it does not change with each user retrieval.</li>
<li><a href="https://www.pcmag.com/encyclopedia/term/dynamic-web-page">Dynamic Web Page</a>: A Web page that provides custom content for the user based on the results of a search or some other request. Also known as “dynamic HTML” or “dynamic content”, the “dynamic” term is used when referring to interactive Web pages created for each user.</li>
</ul>
<p>The web page where central bankers’ speeches are gathered is a dynamic web page and so we will use <em>RSelenium</em> to scrape the speeches.<sup>1</sup></p>
<p>To complement this tutorial, you will find two other useful tutorials for scraping using <em>rvest</em> and <em>RSelenium</em> <a href="https://www.rselenium-teaching.etiennebacher.com/#/title-slide">here</a> and <a href="https://resulumit.com/teaching/scrp_workshop">here</a>. There is also a <a href="https://r4ds.hadley.nz/webscraping">whole chapter dedicated to web scraping</a> in the recent second edition of <em>R for Data Science</em> (Wickham, Çetinkaya-Rundel, and Grolemund 2023).</p>
</section>
</section>
<section id="scraping-the-bis-speeches" class="level2">
<h2 class="anchored" data-anchor-id="scraping-the-bis-speeches">Scraping the BIS speeches</h2>
<p>If we are interested in what central bankers are saying, we may want to study their speeches. Fortunately, most of them are stored on the BIS website <a href="&quot;https://www.bis.org/cbspeeches/index.htm&quot;">there</a>.</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-bis/bis.png" alt="The BIS list of speeches" width="918">
<p class="caption">
<span id="fig:bis-website"></span>Figure 1: The BIS list of speeches
</p>
</div>
<p>What we want is</p>
<ul>
<li>to extract the metadata of these speeches: the date of the speech, the title, its description and the speaker.</li>
<li>to access to the whole text of the speech, that is stored in a pdf on the BIS website</li>
<li>to extract the text from this PDF</li>
<li>to be sure that the text is readable, which will be the case if the PDF is searchable (i.e.&nbsp;if characters are recognized).</li>
</ul>
<p>This is all these things we will learn to do in this tutorial.</p>
<section id="loading-the-packages-and-starting-your-automated-browser" class="level3">
<h3 class="anchored" data-anchor-id="loading-the-packages-and-starting-your-automated-browser">Loading the packages and starting your automated browser</h3>
<p>We first load the necessary packages. <a href="https://docs.ropensci.org/RSelenium/">RSelenium</a> (Harrison 2022) and <a href="https://dmi3kno.github.io/polite/">polite</a> are the central packages here. I like the <a href="https://here.r-lib.org/">here</a> package to manipulate paths with R but it is not essential here… <a href="https://glue.tidyverse.org/">glue</a> is used to create strings more easily, by embedding R expressions in it. <a href="https://docs.ropensci.org/pdftools/">pdftools</a> will be used to extract text from the speeches’ PDFs and <a href="https://docs.ropensci.org/tesseract/">tesseract</a> for running Optical Character Recognition (OCR) on PDFs that don’t have a good OCR.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># pacman is a useful package to install missing packages and load them</span></span>
<span id="cb1-2"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pacman"</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">installed.packages</span>()){</span>
<span id="cb1-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pacman"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dependencies =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-4">}</span>
<span id="cb1-5"></span>
<span id="cb1-6">pacman<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">p_load</span>(tidyverse,</span>
<span id="cb1-7">               RSelenium,</span>
<span id="cb1-8">               polite,</span>
<span id="cb1-9">               glue,</span>
<span id="cb1-10">               here,</span>
<span id="cb1-11">               pdftools,</span>
<span id="cb1-12">               tesseract)</span>
<span id="cb1-13"></span>
<span id="cb1-14">bis_data_path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">path.expand</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~"</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"central_bank_database"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"BIS"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Where data will go on my computer</span></span></code></pre></div></div>
</section>
<section id="going-on-the-bis-website-and-launching-the-bot" class="level3">
<h3 class="anchored" data-anchor-id="going-on-the-bis-website-and-launching-the-bot">Going on the BIS website and launching the bot</h3>
<p>We use <em>polite</em> to “bow” in front of the BIS website. It allows us to look at permissions for scraping.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">bis_website_path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://www.bis.org/"</span></span>
<span id="cb2-2"></span>
<span id="cb2-3">session <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bow</span>(bis_website_path)</span>
<span id="cb2-4">session</span></code></pre></div></div>
<pre><code>## &lt;polite session&gt; https://www.bis.org/
##     User-agent: polite R package
##     robots.txt: 15 rules are defined for 2 bots
##    Crawl delay: 5 sec
##   The path is scrapable for this user-agent</code></pre>
<p>By looking at the <em>robots.txt</em> file, we can see more in details which paths of the website are scrapable or not.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(session<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>robotstxt<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>text)</span></code></pre></div></div>
<pre><code>## #Format is:
## #       User-agent: &lt;name of spider&gt;
## #       Disallow: &lt;nothing&gt; | &lt;path&gt;
## #-------------------------------------------
## 
## User-Agent: *
## Disallow: /dcms
## Disallow: /metrics/
## Disallow: /search/
## Disallow: /staff.htm
## Disallow: /embargo/
## Disallow: /app/
## Disallow: /goto.htm
## Disallow: /login
## #Disallow: /cbhub
## Disallow: /cbhub/goto.htm
## Disallow: /doclist/
## # Committee comment letters
## Disallow: /publ/bcbs*/
## Disallow: /bcbs/ca/
## Disallow: /bcbs/commentletters/
## Disallow: /*/publ/comments/
## # Hide the Basel Framework standards, only chapters should be indexed.
## Disallow: /basel_framework/standard/
## 
## Sitemap: https://www.bis.org/sitemap.xml</code></pre>
<p>The list of speeches is at “https://www.bis.org/cbspeeches/index.htm”. This path is not among the “disallow” list, meaning that we can scrape this part of the website.</p>
<p>We want to make scraping easier, so we will display the maximum number of items per page, which is 25 here. We don’t want to scrape the whole list of speeches, so we will set a starting date: the ninth of October, 2023. By navigating towards the second page of the resulting list, you can now have an idea of what the URL looks like.</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-bis/bis_filtered.png" alt="Filtering speeches on the BIS website" width="702">
<p class="caption">
<span id="fig:bis-filtered"></span>Figure 2: Filtering speeches on the BIS website
</p>
</div>
<p>Thus, you can prepare a string with the URL to scrape, in which you can change the parameters.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">scraping_path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">expr</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"{bis_website_path}cbspeeches/index.htm?fromDate={day}%2F{month}%2F{year}&amp;cbspeeches_page={page}&amp;cbspeeches_page_length=25"</span>))</span></code></pre></div></div>
<p>Here, I could have used some simpler programming by using the <code>paste0()</code> function for instance, rather than using <code>expr()</code>. But I want to be able to change the parameters later, notably for the page number. For now, the path looks like this:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">scraping_path</span></code></pre></div></div>
<pre><code>## glue("{bis_website_path}cbspeeches/index.htm?fromDate={day}%2F{month}%2F{year}&amp;cbspeeches_page={page}&amp;cbspeeches_page_length=25")</code></pre>
<p>But then I can enter the parameters I want for the date (here, the ninth of October, 2023).</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">day <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"09"</span></span>
<span id="cb9-2">month <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"10"</span></span>
<span id="cb9-3">year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2023</span></span></code></pre></div></div>
<p>And I can evaluate the expression with these parameters, also selecting a certain page. This will be useful later in a loop to navigate from one page to the next.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">eval</span>(scraping_path, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">envir =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">page =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span></code></pre></div></div>
<pre><code>## https://www.bis.org/cbspeeches/index.htm?fromDate=09%2F10%2F2023&amp;cbspeeches_page=3&amp;cbspeeches_page_length=25</code></pre>
<p>You can check that this URL leads you to the third page of the list of speeches starting the ninth of October, 2023 (with 25 results per page).</p>
<p>Once you have the structure of the URL, it means that you can change the parameters as you want to create the list of speeches you want. Of course, you can go on the BIS website and filter by the end date or the “Institutions” or the “Country” to see what the URL would look like.</p>
<p>Now we can start the funny part. Let’s launch our automated browser with <em>RSelenium</em>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Launch Selenium to go on the website of bis</span></span>
<span id="cb12-2">driver <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rsDriver</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">browser =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"firefox"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># can also be "chrome"</span></span>
<span id="cb12-3">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">chromever =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>,</span>
<span id="cb12-4">                   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">port =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4444</span>L) </span>
<span id="cb12-5">remote_driver <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> driver[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"client"</span>]]</span></code></pre></div></div>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-bis/featured.png" alt="Automatizing your web browser" width="662">
<p class="caption">
<span id="fig:bot-picture"></span>Figure 3: Automatizing your web browser
</p>
</div>
</section>
<section id="extracting-the-data-page-by-page" class="level3">
<h3 class="anchored" data-anchor-id="extracting-the-data-page-by-page">Extracting the data page by page</h3>
<p>What we want to do is to retrieve the data about each speech (the date, the title, its description, the speaker, and also its corresponding URL) page by page. This is something that we can do with a <code>for</code> loop. But we first need to know the number of pages. You can normally see it at the bottom right of the web page.</p>
<p>There could be different way to extract this information. Here, we will use the “CSS selector”. Using the CSS selector has two advantages:</p>
<ul>
<li>It has in general a simpler content than an XPATH</li>
<li>It can be easily retrieved thanks to a Firefox add-on (which exists also for Chrome): <a href="https://addons.mozilla.org/fr/firefox/addon/scrapemate/">ScrapeMate</a></li>
</ul>
<p>Once you have set up the add-on, you can go to the URL we are working on and find the “CSS selector” for the number of pages:</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-bis/scrapmate.png" alt="Using scrapemate Firefox addon" width="624">
<p class="caption">
<span id="fig:scrape-mate"></span>Figure 4: Using scrapemate Firefox addon
</p>
</div>
<p>You can use this CSS selector to extract the text thanks to <em>RSelenium</em> and after a short cleaning, you have the total number of pages:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">remote_driver<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">navigate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">eval</span>(scraping_path, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">envir =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">page =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)))</span>
<span id="cb13-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.sleep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Just to have time to load the page</span></span>
<span id="cb13-3"></span>
<span id="cb13-4">nb_pages <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> remote_driver<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"css selector"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".pageof"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getElementText</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># We just set i for searching the total number of pages</span></span>
<span id="cb13-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pluck</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb13-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove_all</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Page 1 of "</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb13-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>()</span>
<span id="cb13-8"></span>
<span id="cb13-9">nb_pages</span></code></pre></div></div>
<pre><code>## [1] 6</code></pre>
<p>Ok. Now we can run the loop to retrieve all the data for the 6 pages. Here, we will conform to the delay set by the polite package: we will wait 5 seconds on each page, not to hammer the website with too many requests. As we need the web page to load properly to retrieve the data, it is also a way to take the time of loading the page to avoid missing data if your internet connection is too slow.</p>
<p>Here, you just have to use <em>scrapemate</em> to find the appropriate CSS selector for each information and extract the corresponding text. You can also see that by clicking on the title of the speech, you are navigating towards the dedicated web page of the corresponding speech. It means that to the title is associated a URL link, a “href” in html language. So you need to extract the “href” attribute associated to the title thanks to <em>RSelenium</em>.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1">metadata <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mode =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"list"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> nb_pages)</span>
<span id="cb15-2"></span>
<span id="cb15-3"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span>(page <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>nb_pages){</span>
<span id="cb15-4">  remote_driver<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">navigate</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">eval</span>(scraping_path))</span>
<span id="cb15-5">  nod <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nod</span>(session, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">eval</span>(scraping_path)) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># introducing to the new page</span></span>
<span id="cb15-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">Sys.sleep</span>(session<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>delay) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># using the delay time set by polite</span></span>
<span id="cb15-7"></span>
<span id="cb15-8">  metadata[[page]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">date =</span> remote_driver<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findElements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"css selector"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".item_date"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-9">                            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_chr</span>(., <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getElementText</span>()[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]),</span>
<span id="cb15-10">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">info =</span> remote_driver<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findElements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"css selector"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".item_date+ td"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-11">                            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_chr</span>(., <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getElementText</span>()[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]),</span>
<span id="cb15-12">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">url =</span> remote_driver<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findElements</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"css selector"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".dark"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-13">                            <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map_chr</span>(., <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>.<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getElementAttribute</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"href"</span>)[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]])) </span>
<span id="cb15-14">}</span>
<span id="cb15-15"></span>
<span id="cb15-16">metadata <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(metadata) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">separate</span>(info, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"title"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"description"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"speaker"</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb15-18"></span>
<span id="cb15-19"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(metadata)</span></code></pre></div></div>
<pre><code>## # A tibble: 6 × 5
##   date        title                                    description speaker url  
##   &lt;chr&gt;       &lt;chr&gt;                                    &lt;chr&gt;       &lt;chr&gt;   &lt;chr&gt;
## 1 27 Nov 2023 "Ahmet Ismaili: Welcoming remarks - Wor… "Welcoming… by Ahm… http…
## 2 27 Nov 2023 "Ahmet Ismaili: Creating values – a gat… "Introduct… by Ahm… http…
## 3 22 Nov 2023 "Christine Lagarde: Monetary policy in … "Speech by… by Chr… http…
## 4 22 Nov 2023 "Sabine Mauderer: Exposing and acting o… "Speech by… by Sab… http…
## 5 21 Nov 2023 "Jon Cunliffe: Money and payments - a \… "Speech by… by Jon… http…
## 6 21 Nov 2023 "Shaktikanta Das: Emerging India - a la… "Keynote s… by Sha… http…</code></pre>
<p>The <code>findElements()</code> function of <em>RSelenium</em> finds all the corresponding elements (here 25) and stores them in a list. The <code>map_chr()</code> allows you to get the text of each element one by one and stores the result in a vector.</p>
<p>If we want to be sure that we have retrieved the data of all the speeches, we can compare the length of our data frame, with the number of items that was indicated just above the first speech.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># We just check that we have the correct number of speeches</span></span>
<span id="cb17-2">nb_items <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> remote_driver<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">findElement</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"css selector"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".listitems"</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getElementText</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># We just set i for searching the total number of pages</span></span>
<span id="cb17-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pluck</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb17-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove_all</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"[</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">sitems]"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.integer</span>()</span>
<span id="cb17-6"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(nb_items <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(metadata)){</span>
<span id="cb17-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"You have extracted the metadata of all speeches"</span>)</span>
<span id="cb17-8">} <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span>{</span>
<span id="cb17-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"There is a problem. You have probably missed some speeches."</span>)</span>
<span id="cb17-10">}</span></code></pre></div></div>
<pre><code>## You have extracted the metadata of all speeches</code></pre>
</section>
<section id="downloading-the-pdf" class="level3">
<h3 class="anchored" data-anchor-id="downloading-the-pdf">Downloading the PDF</h3>
<p>Now we have the metadata of the speeches. But one thing we are interested in at the end is to know what the speeches are about. Most of the speeches are stored in a pdf. To retrieve these PDFs, you just need to use the URL of the speech, and replace the end of the URL “.htm” by “.pdf”. From the metadata list, we can have the whole list of the PDFs we want to download.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1">pdf_to_download <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> metadata <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb19-2">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pdf_name =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(url, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{6}[a-z]"</span>),</span>
<span id="cb19-3">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pdf_name =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_c</span>(pdf_name, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".pdf"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb19-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>(pdf_name) </span>
<span id="cb19-5"></span>
<span id="cb19-6">pdf_to_download</span></code></pre></div></div>
<pre><code>##   [1] "r231127c.pdf" "r231127d.pdf" "r231122b.pdf" "r231122a.pdf" "r231121a.pdf"
##   [6] "r231115e.pdf" "r231121i.pdf" "r231121h.pdf" "r231121g.pdf" "r231121f.pdf"
##  [11] "r231121e.pdf" "r231121d.pdf" "r231121c.pdf" "r231121b.pdf" "r231120j.pdf"
##  [16] "r231120h.pdf" "r231120i.pdf" "r231114a.pdf" "r231114b.pdf" "r231115r.pdf"
##  [21] "r231115s.pdf" "r231114c.pdf" "r231115t.pdf" "r231115u.pdf" "r231120g.pdf"
##  [26] "r231120f.pdf" "r231120e.pdf" "r231120d.pdf" "r231120c.pdf" "r231120b.pdf"
##  [31] "r231120a.pdf" "r231113s.pdf" "r231115q.pdf" "r231115o.pdf" "r231115n.pdf"
##  [36] "r231115m.pdf" "r231115j.pdf" "r231115i.pdf" "r231115f.pdf" "r231115h.pdf"
##  [41] "r231115g.pdf" "r231114d.pdf" "r231115d.pdf" "r231115p.pdf" "r231113n.pdf"
##  [46] "r231115a.pdf" "r231113m.pdf" "r231115c.pdf" "r231114e.pdf" "r231114f.pdf"
##  [51] "r231113t.pdf" "r231113o.pdf" "r231113q.pdf" "r231113x.pdf" "r231113w.pdf"
##  [56] "r231113v.pdf" "r231113u.pdf" "r231113p.pdf" "r231113r.pdf" "r231113k.pdf"
##  [61] "r231113j.pdf" "r231113i.pdf" "r231113h.pdf" "r231113g.pdf" "r231113f.pdf"
##  [66] "r231113e.pdf" "r231113d.pdf" "r231113c.pdf" "r231113b.pdf" "r231113l.pdf"
##  [71] "r231113a.pdf" "r231110a.pdf" "r231108c.pdf" "r231108b.pdf" "r231108a.pdf"
##  [76] "r231107c.pdf" "r231107b.pdf" "r231107a.pdf" "r231102a.pdf" "r231027b.pdf"
##  [81] "r231115l.pdf" "r231026l.pdf" "r231026j.pdf" "r231026q.pdf" "r231026g.pdf"
##  [86] "r231026f.pdf" "r231026e.pdf" "r231026m.pdf" "r231026d.pdf" "r231026c.pdf"
##  [91] "r231026b.pdf" "r231026a.pdf" "r231023h.pdf" "r231023g.pdf" "r231023e.pdf"
##  [96] "r231023c.pdf" "r231023b.pdf" "r231023a.pdf" "r231020f.pdf" "r231020e.pdf"
## [101] "r231020d.pdf" "r231020c.pdf" "r231020b.pdf" "r231020a.pdf" "r231019g.pdf"
## [106] "r231019e.pdf" "r231019d.pdf" "r231019c.pdf" "r231019b.pdf" "r231019a.pdf"
## [111] "r231018f.pdf" "r231018e.pdf" "r231018d.pdf" "r231018c.pdf" "r231018b.pdf"
## [116] "r231018a.pdf" "r231017e.pdf" "r231017d.pdf" "r231017c.pdf" "r231017b.pdf"
## [121] "r231012a.pdf" "r231017a.pdf" "r231011d.pdf" "r231012b.pdf" "r231011g.pdf"
## [126] "r231011f.pdf" "r231011e.pdf" "r231011a.pdf" "r231011b.pdf" "r231010h.pdf"
## [131] "r231010g.pdf" "r231010f.pdf" "r231010e.pdf" "r231010d.pdf" "r231010c.pdf"
## [136] "r231010b.pdf" "r231010a.pdf" "r231115v.pdf"</code></pre>
<p>We build a function to download these PDF using <em>polite</em>. It would avoid notably to overload the website.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1">polite_download <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(domain, url, ...){</span>
<span id="cb21-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bow</span>(domain) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb21-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nod</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(url)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb21-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rip</span>(...)  </span>
<span id="cb21-5">}</span></code></pre></div></div>
<p>There is a possibility that some PDFs are missing (that is not the case here, but it happens with the whole dataset of BIS speeches). The problem is that if a PDF is missing, you will get an error and it will stop the process of downloading PDFs So you need to use the <code>tryCatch()</code> function to take into account this error but continue the downloading process.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatch</span>(</span>
<span id="cb22-2">   {</span>
<span id="cb22-3">     <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">walk</span>(pdf_to_download, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">polite_download</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">domain =</span> bis_website_path,</span>
<span id="cb22-4">                                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">url =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"review/{.}"</span>),</span>
<span id="cb22-5">                                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">path =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(bis_data_path, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pdf"</span>),))</span>
<span id="cb22-6">   },</span>
<span id="cb22-7">   <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">error =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(e) {</span>
<span id="cb22-8">     <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No pdf exist"</span>))</span>
<span id="cb22-9">   }</span>
<span id="cb22-10">  )</span></code></pre></div></div>
<p>Here, the pdf has been stored in a specific repository on my computer, indicated by the parameter <code>path</code>.</p>
</section>
</section>
<section id="extracting-speeches-text" class="level2">
<h2 class="anchored" data-anchor-id="extracting-speeches-text">Extracting speeches text</h2>
<p>Now that we have collected the PDFs, we want to extract the text within these PDFs. We will use the package <a href="https://docs.ropensci.org/pdftools/">pdftools</a> for that. Here is a function that take the list of PDFs extracted from the metadata, extract the text, and stores it in a table with the name of the file and the corresponding page of the text (indeed, <code>pdf_text()</code> extract the text page by page). Here, we handle error in case we did not find the PDF: we don’t want the extraction of text to stop, but we want to remember that a PDF is missing.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1">extracting_text <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(file, path) {</span>
<span id="cb23-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tryCatch</span>(</span>
<span id="cb23-3">    {  </span>
<span id="cb23-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">message</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Extracting text from {file}"</span>))</span>
<span id="cb23-5">  text_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pdf_text</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(path, file)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb23-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tibble</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb23-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">page =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb23-8">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">file =</span> file) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb23-9">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> value)</span>
<span id="cb23-10">    },</span>
<span id="cb23-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">error =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(e) {</span>
<span id="cb23-12">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">print</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">glue</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"No pdf exist"</span>))</span>
<span id="cb23-13">    text_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,</span>
<span id="cb23-14">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">page =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb23-15">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">file =</span> file)</span>
<span id="cb23-16">  }</span>
<span id="cb23-17">  )</span>
<span id="cb23-18">}</span></code></pre></div></div>
<p>We can run the function for each speech we have in our dataset.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1">text_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(pdf_to_download, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extracting_text</span>(., <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(bis_data_path, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pdf"</span>))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb24-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>()</span></code></pre></div></div>
<pre><code>## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist
## No pdf exist</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(text_data)</span></code></pre></div></div>
<pre><code>## # A tibble: 6 × 3
##   text                                                                page file 
##   &lt;chr&gt;                                                              &lt;dbl&gt; &lt;chr&gt;
## 1 "Ahmet Ismaili: Welcoming remarks - World Savings Day\nWelcoming …     1 r231…
## 2 "Young people should set clear financial goals for themselves and…     2 r231…
## 3 "Ahmet Ismaili: Creating values – a gateway for the future\nIntro…     1 r231…
## 4 "Therefore, in CBK's supervisory role, the external auditor profe…     2 r231…
## 5 "3/3   BIS - Central bankers' speeches\n"                              3 r231…
## 6 "Christine Lagarde: Monetary policy in the euro area - attentive …     1 r231…</code></pre>
<section id="managing-ocr-problems" class="level3">
<h3 class="anchored" data-anchor-id="managing-ocr-problems">Managing OCR problems</h3>
<p>Sometimes, PDFs have problems of OCR. The PDFs are no searchable and so the text cannot be extracted properly (or rather, it is unreadable). It happens also with recent speeches. Therefore, we need to find the PDFs that may encounter such problems. We count the number of words in each page, and retrieve the PDFs for which the number of words is low in each page.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb28-1">pdf_without_ocr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> text_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb28-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">test_ocr =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_count</span>(text, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"[a-z]+"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Count the number of words</span></span>
<span id="cb28-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">non_ocr_document =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all</span>(test_ocr <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">250</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.by =</span> file) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb28-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(non_ocr_document <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb28-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">distinct</span>(file) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb28-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pull</span>()</span>
<span id="cb28-7"></span>
<span id="cb28-8">pdf_without_ocr</span></code></pre></div></div>
<pre><code>##  [1] "r231122a.pdf" "r231121h.pdf" "r231121g.pdf" "r231121d.pdf" "r231110a.pdf"
##  [6] "r231026f.pdf" "r231026c.pdf" "r231023h.pdf" "r231023g.pdf" "r231017d.pdf"
## [11] "r231017b.pdf" "r231011g.pdf" "r231010g.pdf" "r231010e.pdf" "r231010d.pdf"
## [16] "r231010c.pdf" "r231010b.pdf"</code></pre>
<p>Setting the threshold at 250 words is a pure rule of thumb: it allows having only true positive, but it does not prevent for having false negative (missing documents with OCR problem). It should be possible to find a better method to assess which PDF have no OCR.</p>
<p>Here is an example of a problematic PDF:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb30-1">text_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb30-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(file <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> pdf_without_ocr[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span></code></pre></div></div>
<pre><code>## # A tibble: 6 × 3
##   text                                                                page file 
##   &lt;chr&gt;                                                              &lt;dbl&gt; &lt;chr&gt;
## 1 "012345637839 \u0011 3 7839843 \u0011\u000e433\u000f\u00103783984…     1 r231…
## 2 "01ÿ34567567ÿ85996ÿ45 ÿ\u000e\u000fÿ56\u000fÿ\u000f8ÿ\u00106ÿ\u00…     2 r231…
## 3 "0123456ÿ89252 49ÿ2 8ÿ\u000e8ÿ\u000f2ÿ94\u0010\u000f8ÿ9\u0011\u00…     3 r231…
## 4 "01ÿ3456ÿ17389ÿ83ÿ 8ÿ454543ÿ348ÿ57188\u000e51 ÿ\u000f7\u000e\u001…     4 r231…
## 5 "0123ÿ56ÿ718ÿ319\n      ÿ\u000e\u000f9\u00103\u00112\u0012ÿ\u0013…     5 r231…
## 6 "0ÿ2345678934\n    \u000e\u000fÿ\u0011 ÿ\u0012\u000e\u0011\u0013\…     6 r231…</code></pre>
<p>It seems ok when you look at it, but going to the web page allows us to see that there are some problem of selection in the text and so that the OCR is not adequate.</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/scraping-bis/problem_ocr.png" alt="PDF without adequate OCR" width="438">
<p class="caption">
<span id="fig:show-ocr-problem"></span>Figure 5: PDF without adequate OCR
</p>
</div>
<p>We will now use the <a href="https://docs.ropensci.org/tesseract/">tesseract</a> package, that runs OCR. It first converts each page of the PDF into a picture (a PNG), then proceeds to OCR and extracts the text.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1">new_text_ocr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vector</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mode =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"list"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(pdf_without_ocr))</span>
<span id="cb32-2"></span>
<span id="cb32-3"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span>(i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(pdf_without_ocr)){</span>
<span id="cb32-4">  text <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> tesseract<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ocr</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(bis_data_path, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pdf"</span>, pdf_without_ocr[i]), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">engine =</span> tesseract<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tesseract</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"eng"</span>))</span>
<span id="cb32-5">  text <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tibble</span>(text) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb32-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">text =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(text, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".+(=?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>),</span>
<span id="cb32-7">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">page =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(),</span>
<span id="cb32-8">           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">file =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(pdf_without_ocr[i], <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.pdf"</span>))</span>
<span id="cb32-9">  new_text_ocr[[i]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> text</span>
<span id="cb32-10">}</span>
<span id="cb32-11"></span>
<span id="cb32-12">new_text_ocr <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(new_text_ocr)</span></code></pre></div></div>
<pre><code>## Converting page 1 to r231122a_1.png... done!
## Converting page 2 to r231122a_2.png... done!
## Converting page 3 to r231122a_3.png... done!
## Converting page 4 to r231122a_4.png... done!
## Converting page 5 to r231122a_5.png... done!
## Converting page 6 to r231122a_6.png... done!</code></pre>
<p>You can see that the text is now readable:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb34-1">new_text_ocr</span></code></pre></div></div>
<pre><code>## # A tibble: 6 × 3
##   text                                                                page file 
##   &lt;chr&gt;                                                              &lt;int&gt; &lt;chr&gt;
## 1 "Exposing and acting on risks in a fast-changing\nworld\nEIOPA An…     1 r231…
## 2 "that might be emerging, we might also be able to open up new hor…     2 r231…
## 3 "industry. Recent earnings releases by large insurers show that h…     3 r231…
## 4 "Financial System (\n\nNGFS (Central Banks and Supervisors Networ…     4 r231…
## 5 "\nNGFS (Central Banks and Supervisors Network for Greening the F…     5 r231…
## 6 "\nLadies and gentlemen,\n\nTo come back to the animal-based meta…     6 r231…</code></pre>
<p>Now you just have to integrate the now recognized text with the rest of the data. A last small step is to remove all the PNGs you have created by using <em>tesseract</em>.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb36" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb36-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># We remove all the .png we have created</span></span>
<span id="cb36-2">png_to_remove <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list.files</span>()[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_which</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list.files</span>(), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.png"</span>)]</span>
<span id="cb36-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">file.remove</span>(png_to_remove)</span></code></pre></div></div>
<p>And that’s it for the tutorial. You now have a data frame with the metadata of the speeches, and a data frame with the text, page by page for each speech.</p>
<p>If you want to scrap BIS speeches on a regular basis without scraping again what you have already collected, you may have a look at this script <a href="https://github.com/agoutsmedt/central_bank_database/blob/master/scraping_scripts/scraping_bis.R">here</a>, which is part of a <a href="https://github.com/agoutsmedt/central_bank_database/tree/master">project to collect central banks’ documents</a>. You will also find in it some function to clean BIS data.</p>
</section>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-R-rselenium" class="csl-entry">
Harrison, John. 2022. <em>RSelenium: R Bindings for ’Selenium WebDriver’</em>. <a href="https://CRAN.R-project.org/package=RSelenium" class="uri">https://CRAN.R-project.org/package=RSelenium</a>.
</div>
<div id="ref-R-polite" class="csl-entry">
Perepolkin, Dmytro. 2023. <em>Polite: Be Nice on the Web</em>. <a href="https://CRAN.R-project.org/package=polite" class="uri">https://CRAN.R-project.org/package=polite</a>.
</div>
<div id="ref-R-rvest" class="csl-entry">
Wickham, Hadley. 2022. <em>Rvest: Easily Harvest (Scrape) Web Pages</em>. <a href="https://CRAN.R-project.org/package=rvest" class="uri">https://CRAN.R-project.org/package=rvest</a>.
</div>
<div id="ref-wickham2023" class="csl-entry">
Wickham, Hadley, Mine Çetinkaya-Rundel, and Garrett Grolemund. 2023. <em>R for Data Science: Import, Tidy, Transform, Visualize, and Model Data</em>. 2nd edition. Sebastopol, CA: O’Reilly Media.
</div>
</div>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>I am not a specialist of html structures, but I was unable to extract the data using <em>rvest</em> only. I thus used <em>RSelenium</em>, and <em>RSelenium</em> only, even if most of the time you combine both packages.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Scraping</category>
  <category>R Tutorials</category>
  <category>Central Banks</category>
  <guid>https://aurelien-goutsmedt.com/post/scraping-bis/</guid>
  <pubDate>Wed, 08 Nov 2023 23:00:00 GMT</pubDate>
  <media:content url="https://aurelien-goutsmedt.com/post/scraping-bis/featured.png" medium="image" type="image/png" height="112" width="144"/>
</item>
<item>
  <title>Extracting and Cleaning Bibliometric Data with R (2)</title>
  <dc:creator>Aurélien Goutsmedt</dc:creator>
  <link>https://aurelien-goutsmedt.com/post/extracting-biblio-data-2/</link>
  <description><![CDATA[ 





<p>The last <a href="../../post/extracting-biblio-data-1/">post</a> dealt with extracting bibliometric data from Scopus and presented some steps to clean these data, notably references data, with R. We will do something similar here, but for another database: <a href="https://dimensions.ai">Dimensions</a>. Dimensions is a relatively newcomer in the world of bibliometric database, in comparison to Scopus or Web of Science. The initial advantage of Dimensions is that the <a href="https://app.dimensions.ai/discover/publication">search application</a> is open to any one (if I remember well, you just have to create an account).<sup>1</sup></p>
<section id="search-on-dimensions-website" class="level2">
<h2 class="anchored" data-anchor-id="search-on-dimensions-website">Search on Dimensions website</h2>
<p>So let’s begin with the same search than in the last post: publications using Dynamic Stochastic General Equilibrium model.<sup>2</sup> Like with Scopus, we search for “DSGE” <em>or</em> “Dynamic Stochastic General Equilibrium”. A difference here is that we can choose between search in “full data” (meaning searching also in the full-text) or in “Title and abstract” (see Figure 1). Doing the first search, we get 27 693 results on February 4, 2022. The fact that we get close to 100 results before the 1990s (when the label DSGE began to be used) means that we could have a lot of false positive. It should be explored more in-depth. But for now and for this tutorial, we will opt for a more secure search, by focusing on titles and abstracts.</p>
<div class="figure">
<img src="https://aurelien-goutsmedt.com/post/extracting-biblio-data-2/dimensions_search.png" alt="Our search on Dimensions app" width="650">
<p class="caption">
Figure 1: Our search on Dimensions app
</p>
</div>
<p>We obtain 4106 results on February 4, 2022. That is quite much than the 2633 results of our Scopus search in the last <a href="../../post/extracting-biblio-data-1/#using-scopus-website">post</a>. But I think that it can be partly explain by the fact that Dimensions integrate “preprints” and we have 1532 preprints in our results.</p>
<p>To download the result, click on “Save / Export” on the right of the search bar, and then “Export results”. Two types of export are of interest for us: “Export full record” and “Export for bibliometric mapping”. In the first case, we can export only 500 results against 2500 for the second one (see Figure 2). This is not obvious, but the second option allows you to export most metadata, including affiliations and the references cited. What do we lose in comparison to the first export? The publication type (article, preprints, etc…), acknowledgements (that can be useful; see for instance Paul-Hus et al.&nbsp;2017) and categorization of publications. That is not so much. Besides, it means that, by using the second option, you can extract more results than in Scopus (limited to 2000).</p>
<div class="figure">
<img src="https://aurelien-goutsmedt.com/post/extracting-biblio-data-2/dimensions_export.png" alt="Choosing the export format" width="514">
<p class="caption">
Figure 2: Choosing the export format
</p>
</div>
<p>Another advantage of Dimensions over Scopus is that the data exported are quite easier to clean. So let’s load the needed packages and start the cleaning.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># packages</span></span>
<span id="cb1-2">package_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb1-3">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"here"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># use for paths creation</span></span>
<span id="cb1-4">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidyverse"</span>,</span>
<span id="cb1-5">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"janitor"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># useful functions for cleaning imported data</span></span>
<span id="cb1-6">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"biblionetwork"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># creating edges</span></span>
<span id="cb1-7">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidygraph"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># for creating networks</span></span>
<span id="cb1-8">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggraph"</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># plotting networks</span></span>
<span id="cb1-9">)</span>
<span id="cb1-10"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (p <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> package_list) {</span>
<span id="cb1-11">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (p <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">installed.packages</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) {</span>
<span id="cb1-12">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(p, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dependencies =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-13">  }</span>
<span id="cb1-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(p, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">character.only =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-15">}</span>
<span id="cb1-16"></span>
<span id="cb1-17">github_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb1-18">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"agoutsmedt/networkflow"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># manipulating network</span></span>
<span id="cb1-19">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ParkerICI/vite"</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># needed for the spatialisation of the network</span></span>
<span id="cb1-20">)</span>
<span id="cb1-21"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (p <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> github_list) {</span>
<span id="cb1-22">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*/"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, p) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">installed.packages</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) {</span>
<span id="cb1-23">    devtools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install_github</span>(p)</span>
<span id="cb1-24">  }</span>
<span id="cb1-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*/"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, p), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">character.only =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-26">}</span>
<span id="cb1-27"></span>
<span id="cb1-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># paths</span></span>
<span id="cb1-29">data_path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">path.expand</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~"</span>),</span>
<span id="cb1-30">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>,</span>
<span id="cb1-31">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tuto_biblio_dsge"</span>)</span>
<span id="cb1-32">dimensions_path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(data_path, </span>
<span id="cb1-33">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dimensions"</span>)</span></code></pre></div></div>
</section>
<section id="cleaning-dimensions-data" class="level2">
<h2 class="anchored" data-anchor-id="cleaning-dimensions-data">Cleaning Dimensions data</h2>
<p>Here are the data, extracted in two steps as we have more than 2500 items:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">dimensions_data_1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(dimensions_path,</span>
<span id="cb2-2">                                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dimensions_dsge_data_2015-2022.csv"</span>),</span>
<span id="cb2-3">                           <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb2-4">dimensions_data_2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(dimensions_path,</span>
<span id="cb2-5">                                            <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dimensions_dsge_data_1996-2014.csv"</span>),</span>
<span id="cb2-6">                                       <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">skip =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb2-7"></span>
<span id="cb2-8">dimensions_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(dimensions_data_1,</span>
<span id="cb2-9">                                  dimensions_data_2) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb2-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clean_names</span>() <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cleaning column names with janitor to transform them</span></span>
<span id="cb2-11"></span>
<span id="cb2-12">dimensions_data</span></code></pre></div></div>
<pre><code>## # A tibble: 4,097 x 15
##    publication_id doi      title abstract source_title_an~ pub_year volume issue
##    &lt;chr&gt;          &lt;chr&gt;    &lt;chr&gt; &lt;chr&gt;    &lt;chr&gt;               &lt;dbl&gt; &lt;chr&gt;  &lt;chr&gt;
##  1 pub.1126055399 10.1016~ Coro~ •We pro~ Annals of Touri~     2020 83     &lt;NA&gt; 
##  2 pub.1143049966 10.1016~ The ~ This pa~ China Economic ~     2021 71     &lt;NA&gt; 
##  3 pub.1126582656 10.1073~ Conf~ We inve~ Proceedings of ~     2020 117    17   
##  4 pub.1133125128 10.3390~ To F~ The ong~ Entropy              2020 22     12   
##  5 pub.1136926910 10.1002~ Impa~ Coronav~ Managerial and ~     2021 42     7    
##  6 pub.1124254349 10.3390~ Macr~ Assessm~ Entropy              2020 22     2    
##  7 pub.1120723604 10.1016~ Carb~ In rece~ The Science of ~     2019 697    &lt;NA&gt; 
##  8 pub.1144700962 10.3390~ Immu~ The COV~ Entropy              2022 24     1    
##  9 pub.1141415103 10.1016~ Ener~ Since t~ Structural Chan~     2021 59     &lt;NA&gt; 
## 10 pub.1128536448 10.1177~ Does~ This ar~ Journal of Hosp~     2020 45     1    
## # ... with 4,087 more rows, and 7 more variables: pagination &lt;chr&gt;,
## #   authors &lt;chr&gt;, authors_affiliations_name_of_research_organization &lt;chr&gt;,
## #   authors_affiliations_country_of_research_organization &lt;chr&gt;,
## #   dimensions_url &lt;chr&gt;, times_cited &lt;dbl&gt;, cited_references &lt;chr&gt;</code></pre>
<p>We don’t need to give an ID to our documents as there is already a <code>publications_id</code> column.<sup>3</sup></p>
<section id="cleaning-duplicates" class="level3">
<h3 class="anchored" data-anchor-id="cleaning-duplicates">Cleaning duplicates</h3>
<p>One issue with Dimensions is that it integrates preprints, which can be interesting for certain types of analysis.<sup>4</sup> However, by using the “Export for bibliometric mapping” option (see the previous section), we cannot know if an item is a preprint or not. The consequence is that <em>i)</em> we can have duplicates (the same article with the preprint(s) and then the published version) but <em>ii)</em> we cannot discriminate between these duplicates as we don’t know which one is the published version. What we can do is to spot the duplicates thanks to the title and keep one of the duplicates depending on the presence of references or not.<sup>5</sup> In other words, we keep the document for which we have references, and we do not care of which one we keep if all have references.<sup>6</sup></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">duplicated_articles <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dimensions_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_count</span>(title) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">arrange</span>(title, cited_references)</span>
<span id="cb4-5"></span>
<span id="cb4-6">to_keep <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> duplicated_articles <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(title) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_head</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb4-9"></span>
<span id="cb4-10">to_remove <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> duplicated_articles <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span> publication_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> to_keep<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>publication_id)</span>
<span id="cb4-12"></span>
<span id="cb4-13">dimensions_data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dimensions_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb4-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span> publication_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> to_remove<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>publication_id)</span></code></pre></div></div>
</section>
<section id="cleaning-affiliations" class="level3">
<h3 class="anchored" data-anchor-id="cleaning-affiliations">Cleaning affiliations</h3>
<p>The goal now is to create a table which associates each document to authors’ affiliation (column <code>authors_affiliations_name_of_research_organization</code>) and the country of the affiliation (column <code>authors_affiliations_country_of_research_organization</code>). We cannot associate affiliations directly to authors as documents can have more authors than affiliations, and conversely.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">dimensions_affiliations <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dimensions_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(publication_id,</span>
<span id="cb5-3">         authors_affiliations_name_of_research_organization,</span>
<span id="cb5-4">         authors_affiliations_country_of_research_organization) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">separate_rows</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">starts_with</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"authors"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"; "</span>)</span>
<span id="cb5-6"></span>
<span id="cb5-7">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(dimensions_affiliations))</span></code></pre></div></div>
<table class="caption-top table">
<colgroup>
<col style="width: 12%">
<col style="width: 43%">
<col style="width: 43%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">publication_id</th>
<th style="text-align: left;">authors_affiliations_name_of_research_organization</th>
<th style="text-align: left;">authors_affiliations_country_of_research_organization</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">pub.1126055399</td>
<td style="text-align: left;">Temple University</td>
<td style="text-align: left;">United States</td>
</tr>
<tr class="even">
<td style="text-align: left;">pub.1126055399</td>
<td style="text-align: left;">Jiangxi University of Finance and Economics</td>
<td style="text-align: left;">China</td>
</tr>
<tr class="odd">
<td style="text-align: left;">pub.1126055399</td>
<td style="text-align: left;">University of Connecticut</td>
<td style="text-align: left;">United States</td>
</tr>
<tr class="even">
<td style="text-align: left;">pub.1143049966</td>
<td style="text-align: left;">Beijing Normal University</td>
<td style="text-align: left;">China</td>
</tr>
<tr class="odd">
<td style="text-align: left;">pub.1126582656</td>
<td style="text-align: left;">Laboratory of Theoretical Physics of Condensed Matter</td>
<td style="text-align: left;">France</td>
</tr>
<tr class="even">
<td style="text-align: left;">pub.1126582656</td>
<td style="text-align: left;">École Polytechnique</td>
<td style="text-align: left;">France</td>
</tr>
</tbody>
</table>
<p>We can now compare the country of affiliations for the dimensions document and for the Scopus affiliation cleaned in the <a href="../../post/extracting-biblio-data-1/#extracting-affiliations-and-authors">previous post</a>. We first bind together affiliations of DSGE articles from Scopus and Dimensions.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">scopus_affiliations <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_rds</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(data_path, </span>
<span id="cb6-2">                                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scopus"</span>, </span>
<span id="cb6-3">                                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data_cleaned"</span>, </span>
<span id="cb6-4">                                     <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scopus_affiliations.rds"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scopus"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>authors)</span>
<span id="cb6-7"></span>
<span id="cb6-8">dimensions_affiliations <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dimensions_affiliations <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dimensions"</span>)</span>
<span id="cb6-10"></span>
<span id="cb6-11">affiliations <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dimensions_affiliations <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"affiliations"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> authors_affiliations_name_of_research_organization,</span>
<span id="cb6-13">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"country"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> authors_affiliations_country_of_research_organization,</span>
<span id="cb6-14">         <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"citing_id"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> publication_id) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(scopus_affiliations)</span></code></pre></div></div>
<p>In Figure <span class="citation" data-cites="ref">@ref</span>(fig:country_affiliations), we can observe that the ranking is almost the same at least for the first 8 countries. Nonetheless, while we have more documents in Dimensions(3856) than in Scopus (2565), we have a relatively equivalent number of affiliations in both corpus: 5502 for Dimensions against 5461 for Scopus. Besides, we count more <code>NA</code> values (1132) than affiliations from United States (1112) in Dimensions, meaning that a lot of information is missing.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1">affiliations <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(country)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(data) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>(country) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">proportion =</span> n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sum</span>(n)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> proportion, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with_ties =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">country =</span> tidytext<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder_within</span>(country, proportion, data)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># see https://juliasilge.com/blog/reorder-within/ for more info</span></span>
<span id="cb7-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(proportion, country, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> data)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>data, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free_y"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb7-11">  tidytext<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_reordered</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Proportion of the Country in all affiliations (excluding NA)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb7-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_classic</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)</span></code></pre></div></div>
<div class="figure">
<img src="https://aurelien-goutsmedt.com/post/extracting-biblio-data-2/index.en_files/figure-html/country-affiliations-1.png" alt="Top countries for affiliations in Scopus and Dimensions" width="1152">
<p class="caption">
Figure 3: Top countries for affiliations in Scopus and Dimensions
</p>
</div>
</section>
<section id="cleaning-references" class="level3">
<h3 class="anchored" data-anchor-id="cleaning-references">Cleaning references</h3>
<p>Cleaning the references is quite easy for Dimensions:</p>
<ul>
<li>you have a clear separator between the references of each citing document: a semi-colon before a square bracket;</li>
<li>you have the same information for each references (see <code>column_names</code>) even if the information is lacking, and you have a simple separator between information: <code>|</code>.</li>
</ul>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1">references_extract <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dimensions_data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(cited_references)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"citing_id"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">=</span> publication_id) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># because the "publication_id" column is also the identifier of the reference</span></span>
<span id="cb8-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(citing_id, cited_references) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">separate_rows</span>(cited_references, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">";(?=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-6">  as_tibble</span>
<span id="cb8-7"></span>
<span id="cb8-8">column_names <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"authors"</span>,</span>
<span id="cb8-9">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"author_id"</span>,</span>
<span id="cb8-10">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"source"</span>,</span>
<span id="cb8-11">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>,</span>
<span id="cb8-12">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"volume"</span>,</span>
<span id="cb8-13">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"issue"</span>,</span>
<span id="cb8-14">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pagination"</span>,</span>
<span id="cb8-15">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"doi"</span>,</span>
<span id="cb8-16">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"publication_id"</span>,</span>
<span id="cb8-17">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"times_cited"</span>)</span>
<span id="cb8-18"></span>
<span id="cb8-19">dimensions_direct_citation <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> references_extract <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">separate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> cited_references, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">into =</span> column_names, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">|"</span>)</span>
<span id="cb8-21"></span>
<span id="cb8-22">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(dimensions_direct_citation, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span></code></pre></div></div>
<table class="caption-top table">
<colgroup>
<col style="width: 7%">
<col style="width: 14%">
<col style="width: 18%">
<col style="width: 18%">
<col style="width: 2%">
<col style="width: 3%">
<col style="width: 3%">
<col style="width: 5%">
<col style="width: 13%">
<col style="width: 7%">
<col style="width: 5%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">citing_id</th>
<th style="text-align: left;">authors</th>
<th style="text-align: left;">author_id</th>
<th style="text-align: left;">source</th>
<th style="text-align: left;">year</th>
<th style="text-align: left;">volume</th>
<th style="text-align: left;">issue</th>
<th style="text-align: left;">pagination</th>
<th style="text-align: left;">doi</th>
<th style="text-align: left;">publication_id</th>
<th style="text-align: left;">times_cited</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">pub.1126055399</td>
<td style="text-align: left;">[Yagihashi, Takeshi; Du, Juan]</td>
<td style="text-align: left;">[ur.07662443654.76; ur.013363010625.14]</td>
<td style="text-align: left;">Economic Inquiry</td>
<td style="text-align: left;">2015</td>
<td style="text-align: left;">53</td>
<td style="text-align: left;">3</td>
<td style="text-align: left;">1556-1579</td>
<td style="text-align: left;">10.1111/ecin.12204</td>
<td style="text-align: left;">pub.1003172294</td>
<td style="text-align: left;">5</td>
</tr>
<tr class="even">
<td style="text-align: left;">pub.1126055399</td>
<td style="text-align: left;">[Yan, Qi; Zhang, Hanqin Qiu]</td>
<td style="text-align: left;">[; ]</td>
<td style="text-align: left;">Asia Pacific Journal of Tourism Research</td>
<td style="text-align: left;">2012</td>
<td style="text-align: left;">17</td>
<td style="text-align: left;">5</td>
<td style="text-align: left;">534-550</td>
<td style="text-align: left;">10.1080/10941665.2011.627929</td>
<td style="text-align: left;">pub.1052463830</td>
<td style="text-align: left;">5</td>
</tr>
<tr class="odd">
<td style="text-align: left;">pub.1126055399</td>
<td style="text-align: left;">[Barro, Robert J]</td>
<td style="text-align: left;">[]</td>
<td style="text-align: left;">The Quarterly Journal of Economics</td>
<td style="text-align: left;">2006</td>
<td style="text-align: left;">121</td>
<td style="text-align: left;">3</td>
<td style="text-align: left;">823-866</td>
<td style="text-align: left;">10.1162/qjec.121.3.823</td>
<td style="text-align: left;">pub.1063352797</td>
<td style="text-align: left;">1133</td>
</tr>
<tr class="even">
<td style="text-align: left;">pub.1126055399</td>
<td style="text-align: left;">[Hall, R. E.; Jones, C. I.]</td>
<td style="text-align: left;">[; ]</td>
<td style="text-align: left;">The Quarterly Journal of Economics</td>
<td style="text-align: left;">2007</td>
<td style="text-align: left;">122</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">39-72</td>
<td style="text-align: left;">10.1162/qjec.122.1.39</td>
<td style="text-align: left;">pub.1063352822</td>
<td style="text-align: left;">450</td>
</tr>
<tr class="odd">
<td style="text-align: left;">pub.1126055399</td>
<td style="text-align: left;">[Gourio, François]</td>
<td style="text-align: left;">[]</td>
<td style="text-align: left;">American Economic Review</td>
<td style="text-align: left;">2012</td>
<td style="text-align: left;">102</td>
<td style="text-align: left;">6</td>
<td style="text-align: left;">2734-2766</td>
<td style="text-align: left;">10.1257/aer.102.6.2734</td>
<td style="text-align: left;">pub.1064525837</td>
<td style="text-align: left;">372</td>
</tr>
</tbody>
</table>
<p>Another advantage is that, as for <a href="../../post/extracting-biblio-data-1/#alternative-method-using-scopus-apis-and-rscopus">Scopus API</a> (but not for data extracted on Scopus website), references already have an identifier.<sup>7</sup> It means that you don’t have to match the citations together to find which documents are citing the same references (what we had to do <a href="../../post/extracting-biblio-data-1/#matching-references">here</a>). Thus, you can easily extract the list of the distinct references cited in your corpus, and it will make easier the building of a co-citation network later.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">dimensions_references <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dimensions_direct_citation <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">distinct</span>(publication_id, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.keep_all =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb9-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>citing_id)</span>
<span id="cb9-4"></span>
<span id="cb9-5">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tail</span>(dimensions_references, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span></code></pre></div></div>
<table class="caption-top table">
<colgroup>
<col style="width: 27%">
<col style="width: 20%">
<col style="width: 15%">
<col style="width: 2%">
<col style="width: 3%">
<col style="width: 3%">
<col style="width: 5%">
<col style="width: 9%">
<col style="width: 7%">
<col style="width: 5%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">authors</th>
<th style="text-align: left;">author_id</th>
<th style="text-align: left;">source</th>
<th style="text-align: left;">year</th>
<th style="text-align: left;">volume</th>
<th style="text-align: left;">issue</th>
<th style="text-align: left;">pagination</th>
<th style="text-align: left;">doi</th>
<th style="text-align: left;">publication_id</th>
<th style="text-align: left;">times_cited</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">[Barro, Robert J.; Grossman, Herschel I.]</td>
<td style="text-align: left;">[ur.01313542524.54; ur.015506435407.81]</td>
<td style="text-align: left;">The Review of Economic Studies</td>
<td style="text-align: left;">1974</td>
<td style="text-align: left;">41</td>
<td style="text-align: left;">1</td>
<td style="text-align: left;">87</td>
<td style="text-align: left;">10.2307/2296401</td>
<td style="text-align: left;">pub.1069867975</td>
<td style="text-align: left;">65</td>
</tr>
<tr class="even">
<td style="text-align: left;">[Benassy, Jean-Pascal]</td>
<td style="text-align: left;">[]</td>
<td style="text-align: left;">Scandinavian Journal of Economics</td>
<td style="text-align: left;">1977</td>
<td style="text-align: left;">79</td>
<td style="text-align: left;">2</td>
<td style="text-align: left;">147</td>
<td style="text-align: left;">10.2307/3439505</td>
<td style="text-align: left;">pub.1070324476</td>
<td style="text-align: left;">41</td>
</tr>
<tr class="odd">
<td style="text-align: left;">[Delli Gatti, Domenico; Gallegati, Marco; Minsky, Hyman P.]</td>
<td style="text-align: left;">[ur.011273107226.57; ; ur.015265626417.37]</td>
<td style="text-align: left;">SSRN Electronic Journal</td>
<td style="text-align: left;">1998</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">10.2139/ssrn.125848</td>
<td style="text-align: left;">pub.1102184434</td>
<td style="text-align: left;">20</td>
</tr>
<tr class="even">
<td style="text-align: left;">[Beker, Victor A.]</td>
<td style="text-align: left;">[]</td>
<td style="text-align: left;">SSRN Electronic Journal</td>
<td style="text-align: left;">2005</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">10.2139/ssrn.839307</td>
<td style="text-align: left;">pub.1102214017</td>
<td style="text-align: left;">5</td>
</tr>
<tr class="odd">
<td style="text-align: left;">[Beker, Victor A.]</td>
<td style="text-align: left;">[]</td>
<td style="text-align: left;">SSRN Electronic Journal</td>
<td style="text-align: left;">2010</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">10.2139/ssrn.1730222</td>
<td style="text-align: left;">pub.1102299065</td>
<td style="text-align: left;">7</td>
</tr>
</tbody>
</table>
<p>However, there is one problem with Dimensions ID: I suppose that Dimensions is able to match references together thanks to DOI that are often present in references data (more than in Scopus references data). The problem is that some references (in general books and chapters in books) lack many (actually almost all) information, like authors and publishing source. It means that we are not able to know what it is, if not by entering the DOI in a web browser. We will encounter this problem again when building the network.</p>
<p>As for affiliations country, we can compare the most cited references in Dimensions and in Scopus. We first extract the top 10 for Scopus and Dimensions:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">scopus_direct_citation <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_rds</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(data_path,</span>
<span id="cb10-2">                                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scopus"</span>,</span>
<span id="cb10-3">                                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data_cleaned"</span>,</span>
<span id="cb10-4">                                        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scopus_manual_direct_citation.rds"</span>))</span>
<span id="cb10-5">scopus_references <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_rds</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(data_path,</span>
<span id="cb10-6">                                   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scopus"</span>,</span>
<span id="cb10-7">                                   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data_cleaned"</span>,</span>
<span id="cb10-8">                                   <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scopus_manual_references.rds"</span>))</span>
<span id="cb10-9"></span>
<span id="cb10-10">scopus_top_ref <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> scopus_direct_citation <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_count</span>(new_id_ref) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">proportion =</span> n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(new_id_ref, proportion) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(proportion, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb10-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(scopus_references, new_id_ref, references)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(references, proportion) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scopus"</span>,</span>
<span id="cb10-19">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">references =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(references, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>)) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cleaning for plotting</span></span>
<span id="cb10-20"></span>
<span id="cb10-21">dimensions_references <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dimensions_references <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">references =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(authors, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>, year, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>, source))</span>
<span id="cb10-23"></span>
<span id="cb10-24">dimensions_top_ref <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dimensions_direct_citation <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_count</span>(publication_id) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-26">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">proportion =</span> n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(publication_id, proportion) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-28">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-29">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(proportion, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb10-30">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(dimensions_references, publication_id, references)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-31">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(references, proportion) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-32">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dimensions"</span>)</span></code></pre></div></div>
<p>We can see in Figure 4 that the 10 most cited references are the same, only the ranking is changing after the fourth position</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1">dimensions_top_ref <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb11-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(scopus_top_ref) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb11-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">references =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_wrap</span>(references, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb11-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(proportion, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fct_reorder</span>(references, proportion), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> data)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>data, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb11-7">  tidytext<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_reordered</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Proportion on all citations"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb11-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_classic</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">13</span>)</span></code></pre></div></div>
<div class="figure">
<img src="https://aurelien-goutsmedt.com/post/extracting-biblio-data-2/index.en_files/figure-html/top-ref-plot-1.png" alt="Top references of DSGE documents in Scopus and Dimensions" width="1152">
<p class="caption">
Figure 4: Top references of DSGE documents in Scopus and Dimensions
</p>
</div>
</section>
</section>
<section id="building-co-citation-network" class="level2">
<h2 class="anchored" data-anchor-id="building-co-citation-network">Building co-citation network</h2>
<p>Here, we follow what we have done for Scopus <a href="../../post/extracting-biblio-data-1/#bibliographic-co-citation-analysis">here</a>. We use the <code>biblio_cocitation</code> function of the <a href="https://agoutsmedt.github.io/biblionetwork/"><code>biblionetwork</code></a> package to build the list of edges between our nodes (i.e.&nbsp;the references). The edge between two nodes is weighted depending of the total number of times each reference has been cited in the whole Dimensions DSGE corpus (see <a href="https://agoutsmedt.github.io/biblionetwork/reference/biblio_cocitation.html">here</a> for more details).</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">citations <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dimensions_direct_citation <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb12-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_count</span>(publication_id) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb12-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(publication_id, n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb12-4">  unique</span>
<span id="cb12-5"></span>
<span id="cb12-6">references_filtered <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dimensions_references <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb12-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(citations) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb12-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb12-9"></span>
<span id="cb12-10">edges <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> biblionetwork<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">biblio_cocitation</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(dimensions_direct_citation, publication_id <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> references_filtered<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>publication_id), </span>
<span id="cb12-11">                                          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"citing_id"</span>, </span>
<span id="cb12-12">                                          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"publication_id"</span>,</span>
<span id="cb12-13">                                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight_threshold =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb12-14">edges</span></code></pre></div></div>
<pre><code>##                  from             to     weight         Source         Target
##     1: pub.1000001876 pub.1008725945 0.18814417 pub.1000001876 pub.1008725945
##     2: pub.1000001876 pub.1008947877 0.03468730 pub.1000001876 pub.1008947877
##     3: pub.1000001876 pub.1013813490 0.07749843 pub.1000001876 pub.1013813490
##     4: pub.1000001876 pub.1050095878 0.14301939 pub.1000001876 pub.1050095878
##     5: pub.1000001876 pub.1064524465 0.06073322 pub.1000001876 pub.1064524465
##    ---                                                                       
## 71877: pub.1119779752 pub.1125952654 0.40824829 pub.1119779752 pub.1125952654
## 71878: pub.1134024220 pub.1135197325 0.10846523 pub.1134024220 pub.1135197325
## 71879: pub.1134024220 pub.1135197780 0.16888013 pub.1134024220 pub.1135197780
## 71880: pub.1142606957 pub.1142611529 0.13155870 pub.1142606957 pub.1142611529
## 71881: pub.1142606957 pub.1143248862 0.10241831 pub.1142606957 pub.1143248862</code></pre>
<p>We can now create a graph using <a href="https://tidygraph.data-imaginist.com/index.html"><code>tidygraph</code></a> (Pedersen 2020) and <a href="https://github.com/agoutsmedt/networkflow"><code>networkflow</code></a>.<sup>8</sup></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">references_filtered <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> references_filtered <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb14-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">relocate</span>(publication_id, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.before =</span> authors) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># first column has to be the identifier</span></span>
<span id="cb14-3"></span>
<span id="cb14-4">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tbl_main_component</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nodes =</span> references_filtered, </span>
<span id="cb14-5">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">edges =</span> edges, </span>
<span id="cb14-6">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">directed =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb14-7">graph</span></code></pre></div></div>
<pre><code>## # A tbl_graph: 3561 nodes and 71876 edges
## #
## # An undirected simple graph with 1 component
## #
## # Node Data: 3,561 x 12 (active)
##   Id    authors author_id source year  volume issue pagination doi   times_cited
##   &lt;chr&gt; &lt;chr&gt;   &lt;chr&gt;     &lt;chr&gt;  &lt;chr&gt; &lt;chr&gt;  &lt;chr&gt; &lt;chr&gt;      &lt;chr&gt; &lt;chr&gt;      
## 1 pub.~ [Barro~ []        The Q~ 2006  121    "3"   823-866    10.1~ 1133       
## 2 pub.~ [Gouri~ []        Ameri~ 2012  102    "6"   2734-2766  10.1~ 372        
## 3 pub.~ [Isoré~ [ur.0161~ Journ~ 2017  79     ""    97-125     10.1~ 27         
## 4 pub.~ [Calvo~ [ur.0744~ Journ~ 1983  12     "3"   383-398    10.1~ 4413       
## 5 pub.~ [Chris~ [ur.0114~ Handb~ 2010  3      ""    285-367    10.1~ 126        
## 6 pub.~ [Heute~ [ur.0161~ Revie~ 2012  15     "2"   244-264    10.1~ 161        
## # ... with 3,555 more rows, and 2 more variables: references &lt;chr&gt;, n &lt;int&gt;
## #
## # Edge Data: 71,876 x 5
##    from    to weight Source         Target        
##   &lt;int&gt; &lt;int&gt;  &lt;dbl&gt; &lt;chr&gt;          &lt;chr&gt;         
## 1    33   867 0.188  pub.1000001876 pub.1008725945
## 2     4   867 0.0347 pub.1000001876 pub.1008947877
## 3    12   867 0.0775 pub.1000001876 pub.1013813490
## # ... with 71,873 more rows</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1234</span>)</span>
<span id="cb16-2">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">leiden_workflow</span>(graph) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># identifying clusters of nodes </span></span>
<span id="cb16-3"></span>
<span id="cb16-4">nb_communities <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb16-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">activate</span>(nodes) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb16-6">  as_tibble <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb16-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Com_ID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb16-8">  unique <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb16-9">  nrow</span>
<span id="cb16-10">palette <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> scico<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scico</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> nb_communities, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">palette =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hawaii"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># creating a color palette</span></span>
<span id="cb16-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>()</span>
<span id="cb16-12">  </span>
<span id="cb16-13">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">community_colors</span>(graph, palette, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">community_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Com_ID"</span>)</span>
<span id="cb16-14"></span>
<span id="cb16-15">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb16-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">activate</span>(nodes) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb16-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> n,<span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># will be used for size of nodes</span></span>
<span id="cb16-18">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">first_author =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(authors, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">[)(.+?)(?=,)"</span>),</span>
<span id="cb16-19">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(first_author, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>, year)) </span>
<span id="cb16-20"></span>
<span id="cb16-21">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">community_names</span>(graph, </span>
<span id="cb16-22">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordering_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"size"</span>, </span>
<span id="cb16-23">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">naming =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>, </span>
<span id="cb16-24">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">community_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Com_ID"</span>)</span>
<span id="cb16-25"></span>
<span id="cb16-26">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> vite<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">complete_forceatlas2</span>(graph, </span>
<span id="cb16-27">                                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">first.iter =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>)</span>
<span id="cb16-28"></span>
<span id="cb16-29"></span>
<span id="cb16-30">top_nodes  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">top_nodes</span>(graph, </span>
<span id="cb16-31">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordering_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"size"</span>, </span>
<span id="cb16-32">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">top_n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, </span>
<span id="cb16-33">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">top_n_per_com =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb16-34">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">biggest_community =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb16-35">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">community_threshold =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>)</span>
<span id="cb16-36">community_labels <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">community_labels</span>(graph, </span>
<span id="cb16-37">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">community_name_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Community_name"</span>,</span>
<span id="cb16-38">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">community_size_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Size_com"</span>,</span>
<span id="cb16-39">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">biggest_community =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb16-40">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">community_threshold =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>)</span></code></pre></div></div>
<p>A co-citation network allows us to observe what are the main influences of a field of research. At the centre of the network, we find the most cited references. On the borders of the graph, there are specific communities that influence different parts of the literature on DSGE. Here, the size of nodes depends on the number of times they are cited in our corpus.</p>
<p>If we compare to the <a href="../../post/extracting-biblio-data-1/#bibliographic-co-citation-analysis">Scopus co-citation network</a>, we find some similarities as the domination of the Smets and Wouters (2007) community.<sup>9</sup> However, the network is less dense here and displays more marginal communities. The “NA-1994” community is a good example of what I was talking about above on Dimensions identifying process. “NA-1994” (the biggest node of this community) is actually Hamilton (1994).</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">activate</span>(edges) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb17-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(weight <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>)</span>
<span id="cb17-4"></span>
<span id="cb17-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggraph</span>(graph, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"manual"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb17-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_edge_arc0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> color_edges, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> weight), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">strength =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_edge_width_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">range =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_edge_colour_identity</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_node_point</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> size, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> color), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_size_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">range =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_identity</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-12">  ggnewscale<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">new_scale</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"size"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-13">  ggrepel<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text_repel</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> top_nodes, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> Label), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontface=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">point.padding=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-14">  ggrepel<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_label_repel</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> community_labels, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> Community_name, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> color), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontface=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">point.padding=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_size_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">range =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb17-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_void</span>()</span></code></pre></div></div>
<div class="figure">
<img src="https://aurelien-goutsmedt.com/post/extracting-biblio-data-2/featured.png" alt="Bibliographic coupling network of articles using DSGE models" width="1181">
<p class="caption">
Figure 5: Bibliographic coupling network of articles using DSGE models
</p>
</div>
<p>The differences between Scopus and Dimensions co-citation network would deserve a more thorough investigation, which is outside the scope of this tutorial.<sup>10</sup> So let’s conclude just by observing what are the most cited nodes in each community. Here, we can see more clearly that community <code>02</code> with represent to a certain extent the “core” of the literature at the basis of DSGE models. Community <code>04</code> deals more with econometric problems, while community <code>05</code> tackles international issues.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1">ragg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">agg_png</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"content"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"en"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"post"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2022-02-03-extracting-biblio-data-2"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top_ref.png"</span>),</span>
<span id="cb18-2">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>, </span>
<span id="cb18-3">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">25</span>,</span>
<span id="cb18-4">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">units =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cm"</span>,</span>
<span id="cb18-5">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">res =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)</span>
<span id="cb18-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">top_nodes</span>(graph,</span>
<span id="cb18-7">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordering_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"size"</span>,</span>
<span id="cb18-8">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">top_n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>,</span>
<span id="cb18-9">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">top_n_per_com =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,</span>
<span id="cb18-10">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">biggest_community =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb18-11">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">community_threshold =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.03</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Community_name, references, n, color) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_wrap</span>(references, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>),</span>
<span id="cb18-14">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> tidytext<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder_within</span>(label, n, Community_name)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(n, label, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> color)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_identity</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Community_name, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-19">  tidytext<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_reordered</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of citations"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb18-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_classic</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span>
<span id="cb18-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">invisible</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dev.off</span>())</span></code></pre></div></div>
<div class="figure">
<img src="https://aurelien-goutsmedt.com/post/extracting-biblio-data-2/top_ref.png" alt="Most cited references per communities" width="1181">
<p class="caption">
Figure 6: Most cited references per communities
</p>
</div>
</section>
<section id="references" class="level1">
<h1>References</h1>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-hamilton1994" class="csl-entry">
Hamilton, James Douglas. 1994. <em>Time Series Analysis</em>. First. Princeton, N.J: Princeton University Press.
</div>
<div id="ref-paul-hus2017" class="csl-entry">
Paul-Hus, Adèle, Philippe Mongeon, Maxime Sainte-Marie, and Vincent Larivière. 2017. “The Sum of It All: Revealing Collaboration Patterns by Combining Authorship and Acknowledgements.” <em>Journal of Informetrics</em> 11 (1): 80–87. <a href="https://doi.org/10.1016/j.joi.2016.11.005" class="uri">https://doi.org/10.1016/j.joi.2016.11.005</a>.
</div>
<div id="ref-R-tidygraph" class="csl-entry">
Pedersen, Thomas Lin. 2020. <em>Tidygraph: A Tidy API for Graph Manipulation</em>. <a href="https://CRAN.R-project.org/package=tidygraph" class="uri">https://CRAN.R-project.org/package=tidygraph</a>.
</div>
<div id="ref-smets2007a" class="csl-entry">
Smets, Frank, and Rafael Wouters. 2007. “Shocks and Frictions in US Business Cycles: A Bayesian DSGE Approach.” <em>American Economic Review</em> 97 (3): 586–606.
</div>
</div>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>It exists also an <a href="https://docs.dimensions.ai/dsl/">API</a> for which you can ask access. It would allow you to use the <a href="https://github.com/nicholasmfraser/rdimensions">rdimensions package</a> to query data.↩︎</p></li>
<li id="fn2"><p>Keeping the same search allows us to do some comparisons with Scopus data and observe how it impacts networks and other results.↩︎</p></li>
<li id="fn3"><p>A good practice is to clean and standardise column names by using the great <a href="http://sfirke.github.io/janitor/"><code>janitor</code> package</a>. By default, <code>clean_names()</code> use <a href="https://en.wikipedia.org/wiki/Snake_case">snake case names</a>.↩︎</p></li>
<li id="fn4"><p>For instance, by studying what is eventually published and after how much time.↩︎</p></li>
<li id="fn5"><p>It remains the possibility of “hidden” duplicates if the title have changed when the document has been published.↩︎</p></li>
<li id="fn6"><p>Obviously, that is not the optimal method if what you want is to keep the published version. Here, you would need to exclude the preprints of the duplicates, for instance by removing items which display “SSRN” as their <code>source_title_anthology_title</code>. Another option, if you don’t want preprints at all is just to uncheck preprints on Dimensions search application when you are extracting your data.↩︎</p></li>
<li id="fn7"><p>Be careful: the column is also called <code>publication_id</code>, meaning that you have to change the name of the column with the identifier of citing articles.↩︎</p></li>
<li id="fn8"><p>I don’t enter in the details here as that is not the purpose of this tutorial and that the different steps are explained on <code>networkflow</code> <a href="https://github.com/agoutsmedt/networkflow">website</a>.↩︎</p></li>
<li id="fn9"><p>However, we can observe that if this community is still the biggest, it is bigger than in Scopus network and include more central references.↩︎</p></li>
<li id="fn10"><p>Part of the differences comes from differences in the initial corpus and thus is linked to the difference in Scopus and Dimensions data (notably the journals that are integrated in the databases). Another part of the differences results from our own treatment of the data: a different cleaning of references, different thresholds used to select the nodes (as we use an absolute threshold, not a relative one), different types of documents (preprints and “hidden” duplicates), etc…↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Bibliometrics</category>
  <category>Network Analysis</category>
  <category>R Tutorials</category>
  <guid>https://aurelien-goutsmedt.com/post/extracting-biblio-data-2/</guid>
  <pubDate>Wed, 02 Feb 2022 23:00:00 GMT</pubDate>
  <media:content url="https://aurelien-goutsmedt.com/post/extracting-biblio-data-2/featured.png" medium="image" type="image/png" height="120" width="144"/>
</item>
<item>
  <title>Extracting and Cleaning Bibliometric Data with R (1)</title>
  <dc:creator>Aurélien Goutsmedt</dc:creator>
  <link>https://aurelien-goutsmedt.com/post/extracting-biblio-data-1/</link>
  <description><![CDATA[ 





<p>After the <a href="../../post/roadmap-quantitative-hpe/">roadmap</a> for learning to programme in R where I listed useful tutorials and packages, I propose here to get to the heart of the matter and to learn how to extract and clean bibliometric data. This tutorial keeps in mind the issues that historians of economics can encounter, but I hope it could be also useful for other social scientists.</p>
<p>It is not easy to navigate between the different existing bibliometric database (Web of Science, Scopus, Dimensions, Jstor, Econlit, RePEc…), and to know which information they gather and how much data we can extract. I will thus bring here a series of tutorials on how to find and extract such data (if possible, by doing it via R scripts), but also on how to clean them. Indeed, depending on the database one uses, the data are in different formats, and one often has to do some cleaning (notably for the bibliographic references cited by the corpus one has extracted). In this tutorial, we will focus on <a href="https://www.scopus.com/home.uri">Scopus</a> data for which you will need an institutional access. The next <a href="../../post/extracting-biblio-data-2/">post</a> focuses on <a href="https://app.dimensions.ai/discover/publication">Dimensions</a> data and the one after will deal with <a href="https://constellate.org/">Constellate application</a> of JSTOR. Both Dimensions and Constellate are accessible without institutional access.</p>
<p>At the end of this tutorial, you will know how to get the data needed for building bibliographic networks and I will give an example of a co-citation network using the <a href="https://agoutsmedt.github.io/biblionetwork/"><code>biblionetwork</code> package</a> (Goutsmedt, Claveau, and Truc 2021). What you only need in this tutorial is a basic understanding of some functions of <a href="https://www.tidyverse.org/">Tidyverse</a> packages (Wickham 2021; Wickham et al.&nbsp;2019)—mainly <code>dplyr</code> and <code>stringr</code>—as well as a (less) basic understanding of “regex” (<a href="https://en.wikipedia.org/wiki/Regular_expression">Regular Expressions</a>).<sup>1</sup> At some points I dig into more complicated and tortuous methods when using <a href="https://dev.elsevier.com/">Elsevier/Scopus APIs</a> with <a href="https://johnmuschelli.com/rscopus/index.html"><code>rscopus</code></a> or cleaning references with the machine learning software <a href="https://anystyle.io">anystyle</a> using the command line. This will be explained in separated sections that beginners can skip.</p>
<p>Let’s first load all the packages we need and set the path to the directory where I put the data extracted from Scopus:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># packages</span></span>
<span id="cb1-2">package_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb1-3">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"here"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># use for paths creation</span></span>
<span id="cb1-4">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidyverse"</span>,</span>
<span id="cb1-5">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bib2df"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># for cleaning .bib data</span></span>
<span id="cb1-6">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"janitor"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># useful functions for cleaning imported data</span></span>
<span id="cb1-7">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"rscopus"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># using Scopus API</span></span>
<span id="cb1-8">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"biblionetwork"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># creating edges</span></span>
<span id="cb1-9">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidygraph"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># for creating networks</span></span>
<span id="cb1-10">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggraph"</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># plotting networks</span></span>
<span id="cb1-11">)</span>
<span id="cb1-12"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (p <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> package_list) {</span>
<span id="cb1-13">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (p <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">installed.packages</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) {</span>
<span id="cb1-14">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(p, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dependencies =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-15">  }</span>
<span id="cb1-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(p, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">character.only =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-17">}</span>
<span id="cb1-18"></span>
<span id="cb1-19">github_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(</span>
<span id="cb1-20">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"agoutsmedt/networkflow"</span>, <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># manipulating network</span></span>
<span id="cb1-21">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ParkerICI/vite"</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># needed for the spatialisation of the network</span></span>
<span id="cb1-22">)</span>
<span id="cb1-23"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (p <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> github_list) {</span>
<span id="cb1-24">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*/"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, p) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">installed.packages</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) {</span>
<span id="cb1-25">    devtools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install_github</span>(p)</span>
<span id="cb1-26">  }</span>
<span id="cb1-27">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*/"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>, p), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">character.only =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-28">}</span>
<span id="cb1-29"></span>
<span id="cb1-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># paths</span></span>
<span id="cb1-31">data_path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">path.expand</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"~"</span>),</span>
<span id="cb1-32">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data"</span>,</span>
<span id="cb1-33">                  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tuto_biblio_dsge"</span>)</span>
<span id="cb1-34">scopus_path <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(data_path, </span>
<span id="cb1-35">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scopus"</span>)</span></code></pre></div></div>
<section id="extracting-data-from-scopus" class="level2">
<h2 class="anchored" data-anchor-id="extracting-data-from-scopus">Extracting data from Scopus</h2>
<section id="using-scopus-website" class="level3">
<h3 class="anchored" data-anchor-id="using-scopus-website">Using Scopus website</h3>
<p>I focus here on a not so much historical subject because a very recent one: the Dynamic Stochastic General Equilibrium (DSGE) models. This type of models has emerged in the late 1990s and has become standard in academic publications as well as in policymaking institutions, notably in central banks.<sup>2</sup></p>
<p>If you don’t have one, you will need to create an account on <a href="https://www.scopus.com/home.uri">Scopus</a> using your institutional email address. Once you are on the “Documents” query page, you can search for “DSGE” or “Dynamic Stochastic General Equilibrium” in documents titles, abstracts and keywords (see Figure 1). On January 2022, I got 2633 results. You can select “All” the documents and then click on the down arrow on the righ of “CSV export” (see Figure 2). You then have to choose all the information you want to download in a <code>.csv</code>. What we need is to cross the “Include References” box as we need it for the bibliographic co-citation later (see Figure 3).<sup>3</sup></p>
<div class="figure">
<img src="https://aurelien-goutsmedt.com/post/extracting-biblio-data-1/scopus_search.png" alt="Scopus search page" width="940">
<p class="caption">
<span id="fig:scopus-search"></span>Figure 1: Scopus search page
</p>
</div>
<div class="figure">
<img src="https://aurelien-goutsmedt.com/post/extracting-biblio-data-1/scopus_search_2.png" alt="Scopus results page" width="942">
<p class="caption">
<span id="fig:scopus-search-2"></span>Figure 2: Scopus results page
</p>
</div>
<div class="figure">
<img src="https://aurelien-goutsmedt.com/post/extracting-biblio-data-1/scopus_csv_export.png" alt="Choosing the information to export in a CSV" width="948">
<p class="caption">
<span id="fig:scopus-csv-export"></span>Figure 3: Choosing the information to export in a CSV
</p>
</div>
<p>The <code>.csv</code> you have exported gathers metadata on authors, title, journal, abstract, keywords, affiliations and references on documents (mainly articles, but also conference papers, book chapters, and reviews) mentioning DSGE in their title, abstract or keywords. There are two limits at this method for extracting data:</p>
<ul>
<li>the quantity of data you can export is limited to 2000, which is not much;</li>
<li>part of the metadata are relatively raw, like affiliations and references, what involves some cleaning.</li>
</ul>
<p>I will show you how to clean these raw data in the next section. But the following sub-section explains you how to use Scopus APIs directly in R, to query more easily for different data and extract more items.</p>
</section>
<section id="alternative-method-using-scopus-apis-and-rscopus" class="level3">
<h3 class="anchored" data-anchor-id="alternative-method-using-scopus-apis-and-rscopus">Alternative method: Using Scopus APIs and <code>rscopus</code></h3>
<p>You first need to create an “API Key” on Scopus website (see more info <a href="https://johnmuschelli.com/rscopus/index.html">here</a>) associated to your account. Using the APIs allows you to extract larger set of data (see the available APIs and corresponding quotas <a href="https://dev.elsevier.com/api_key_settings.html">here</a>).</p>
<p>Let’s use <code>Rscopus</code> and set the API key:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">api_key <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"your_api_key"</span></span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set_api_key</span>(api_key)</span></code></pre></div></div>
<p>Most of the time (and it was the case for me) your institutional access is linked to an IP address and you are not able to use the APIs if you are not connected to your institution internet network. If you want to work remotely, you need to ask for a “token-based” authentification ad ask for an “Institutional Token” or “Insttoken” (see explanations <a href="https://dev.elsevier.com/tecdoc_api_authentication.html">here</a>). You just have to <a href="https://service.elsevier.com/app/contact/supporthub/researchproductsapis/">write to Elsevier</a> to explain which kind of research you are doing and ask them for an “insttoken”. That is also a good occasion, if necessary, to ask them for higher quotas.</p>
<p>Let’s set the institutional token:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">insttoken <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"your_institutional_token"</span></span>
<span id="cb3-2">insttoken <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">inst_token_header</span>(insttoken)</span></code></pre></div></div>
<p>We first run the query using “<a href="https://dev.elsevier.com/documentation/ScopusSearchAPI.wadl">Scopus Search API</a>” via <code>rscopus</code>. That is the API corresponding to the search we have done above on Scopus website. We can now extract as much as 20000 items directly per week. We get raw data with a lot of information in it (the data but also information on the query, etc.). Using <code>rscopus</code> <a href="https://johnmuschelli.com/rscopus/reference/gen_entries_to_df.html"><code>gen_entries_to_df</code> function</a>, we convert these raw data in <code>data.frames</code>.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">dsge_query <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> rscopus<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scopus_search</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TITLE-ABS-KEY(DSGE) OR TITLE-ABS-KEY(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\"</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Dynamic Stochastic General Equilibrium</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\"</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>, </span>
<span id="cb4-2">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">view =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"COMPLETE"</span>,</span>
<span id="cb4-3">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">headers =</span> insttoken)</span>
<span id="cb4-4">dsge_data_raw <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gen_entries_to_df</span>(dsge_query<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>entries)</span></code></pre></div></div>
<p>We can finally separate the different <code>data.frames</code>. We get three tables with different types of information:</p>
<ul>
<li>A table with all the articles and their metadata;</li>
<li>A table with the list of all authors of the articles;</li>
<li>A table with the list of affiliations.</li>
</ul>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1">dsge_papers <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dsge_data_raw<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>df</span>
<span id="cb5-2">dsge_affiliations <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dsge_data_raw<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>affiliation </span>
<span id="cb5-3">dsge_authors <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dsge_data_raw<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>author</span></code></pre></div></div>
<p>Now that we have the articles, we have to extract the references using scopus “<a href="https://dev.elsevier.com/documentation/AbstractRetrievalAPI.wadl">Abstract Retrieval API</a>”. We use articles internal identifier to find references. But we cannot query references with multiple identifiers, so we need to make a loop to extract references one by one. We create a <code>list</code> where we put the references for each articles (we have as many <code>data.frames</code> as articles in our list) and we bind the <code>data.frames</code> together, associating each of them to the identifier of the corresponding citing article.<sup>4</sup></p>
<p>[Modification from November 16, 2023, following a comment by Olivier:] Another issue with extracting references is that you cannot extract more than 40 references per article. If an article has more than 40 references in its bibliography, you need to make a loop in order to collect all the references.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1">citing_articles <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> dsge_papers<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dc:identifier</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># extracting the IDs of our articles on dsge</span></span>
<span id="cb6-2">citation_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>()</span>
<span id="cb6-3"></span>
<span id="cb6-4"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span>(i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(citing_articles)){</span>
<span id="cb6-5">  citations_query <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abstract_retrieval</span>(citing_articles[i],</span>
<span id="cb6-6">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">identifier =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scopus_id"</span>,</span>
<span id="cb6-7">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">view =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"REF"</span>,</span>
<span id="cb6-8">                                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">headers =</span> insttoken)</span>
<span id="cb6-9">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(citations_query<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">abstracts-retrieval-response</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)){ <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Checking if the article has some references before collecting them</span></span>
<span id="cb6-10">    </span>
<span id="cb6-11">    nb_ref <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.numeric</span>(citations_query<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">abstracts-retrieval-response</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>references<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">@total-references</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)</span>
<span id="cb6-12">    citations <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gen_entries_to_df</span>(citations_query<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">abstracts-retrieval-response</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>references<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>reference)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>df</span>
<span id="cb6-13">    </span>
<span id="cb6-14">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(nb_ref <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>){ <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># The loop to collect all the references</span></span>
<span id="cb6-15">      nb_query_left_to_do <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">floor</span>((nb_ref) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span>)</span>
<span id="cb6-16">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of requests left to do :"</span>, nb_query_left_to_do, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb6-17">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (j <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>nb_query_left_to_do){</span>
<span id="cb6-18">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Request n°"</span>, j , <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb6-19">        citations_query <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">abstract_retrieval</span>(citing_articles[i],</span>
<span id="cb6-20">                                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">identifier =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scopus_id"</span>,</span>
<span id="cb6-21">                                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">view =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"REF"</span>,</span>
<span id="cb6-22">                                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">startref =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">40</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>j<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>,</span>
<span id="cb6-23">                                              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">headers =</span> insttoken)</span>
<span id="cb6-24">        citations_sup <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gen_entries_to_df</span>(citations_query<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>content<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">abstracts-retrieval-response</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>references<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>reference)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>df</span>
<span id="cb6-25">        citations <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(citations, citations_sup)</span>
<span id="cb6-26">      }</span>
<span id="cb6-27">    }</span>
<span id="cb6-28">    </span>
<span id="cb6-29">    citations <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> citations <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-30">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tibble</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.name_repair =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"unique"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-31">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select_if</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(.)))</span>
<span id="cb6-32">    </span>
<span id="cb6-33">    citation_list[[citing_articles[i]]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> citations</span>
<span id="cb6-34">  }</span>
<span id="cb6-35">}</span>
<span id="cb6-36"></span>
<span id="cb6-37">dsge_references <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bind_rows</span>(citation_list, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.id =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"citing_art"</span>)</span></code></pre></div></div>
<p>Once you have these four <code>data.frames</code> (articles metadata, authors, affiliations and references), you can proceed to the bibliometric analysis. The only difficulty now is to navigate between the numerous columns of each <code>data.frame</code> and to understand what the different information are. To link the articles metadata <code>data.frame</code> with the reference one, you can use the scopus identifier that we have put in the reference table (in the column <code>citing_art</code>). If you want to join the articles metadata <code>data.frame</code> with the authors and affiliations ones, you have to use the <code>entry_number</code> column that exists in the three <code>data.frames</code>. This number is created by Scopus after your query, meaning that articles, affiliations and authors are not linked by a permanent identifier. Consequently, the identifiers will be regenerated and thus different if you change your query.</p>
<p>In addition to saving you the laborious task of cleaning references and affiliations, when you use the APIs, the references already have an identifier, given by Scopus. It means that if two articles cite the same reference, you will know it because this reference will have a common identifier in the citations of both the first and second article. Below, when manipulating the data extracted from Scopus website, we will need to find which citations are corresponding to the same reference ourselves.<sup>5</sup></p>
<p>If you are not to afraid by Scopus categories and language, or by querying a website through an R script, that is perhaps the quickest method to get data (and that is a method that allows you to get more data, with more complicated queries). However, in the next section, I show you how to clean the data extracted from the Scopus website above.</p>
</section>
</section>
<section id="cleaning-scopus-data" class="level2">
<h2 class="anchored" data-anchor-id="cleaning-scopus-data">Cleaning Scopus data</h2>
<p>So let’s come back to the data we have downloaded on Scopus website:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' # Cleaning scopus data from website search</span></span>
<span id="cb7-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' </span></span>
<span id="cb7-3"></span>
<span id="cb7-4">scopus_search_1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(scopus_path, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scopus_search_1998-2013.csv"</span>))</span>
<span id="cb7-5">scopus_search_2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">read_csv</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(scopus_path, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scopus_search_2014-2021.csv"</span>))</span>
<span id="cb7-6">scopus_search <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(scopus_search_1, scopus_search_2) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">citing_id =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>())) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># We create a unique ID for each doc of our corpus</span></span>
<span id="cb7-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clean_names</span>() <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># janitor function to clean column names</span></span>
<span id="cb7-9"></span>
<span id="cb7-10">scopus_search</span></code></pre></div></div>
<pre><code>## # A tibble: 2,608 × 23
##    authors      title  year source_title volume issue art_no page_start page_end
##    &lt;chr&gt;        &lt;chr&gt; &lt;dbl&gt; &lt;chr&gt;        &lt;chr&gt;  &lt;chr&gt; &lt;chr&gt;  &lt;chr&gt;      &lt;chr&gt;   
##  1 Ha J., So I. Infl…  2013 Global Econ… 42     4     &lt;NA&gt;   396        424     
##  2 Botero J., … Exog…  2013 Revista de … 16     1     &lt;NA&gt;   1          24      
##  3 Kirsanova T… Comm…  2013 Internation… 9      4     &lt;NA&gt;   99         151     
##  4 Ashimov A.A… Para…  2013 Economic De… &lt;NA&gt;   &lt;NA&gt;  &lt;NA&gt;   95         188     
##  5 Khan A., Th… Cred…  2013 Journal of … 121    6     &lt;NA&gt;   1055       1107    
##  6 Jeřábek T.,… Pred…  2013 Acta Univer… 61     7     &lt;NA&gt;   2229       2238    
##  7 Hu X., Xu B… Infl…  2013 Journal of … 5      12    &lt;NA&gt;   636        641     
##  8 Cha H.       Taki…  2013 Internation… 7      2     &lt;NA&gt;   280        296     
##  9 da Silva M.… The …  2013 North Ameri… 26     &lt;NA&gt;  &lt;NA&gt;   266        281     
## 10 Sandri D., … Fina…  2013 Journal of … 45     SUPP… &lt;NA&gt;   59         86      
## # ℹ 2,598 more rows
## # ℹ 14 more variables: page_count &lt;dbl&gt;, cited_by &lt;dbl&gt;, doi &lt;chr&gt;,
## #   affiliations &lt;chr&gt;, authors_with_affiliations &lt;chr&gt;, abstract &lt;chr&gt;,
## #   author_keywords &lt;chr&gt;, index_keywords &lt;chr&gt;, references &lt;chr&gt;,
## #   correspondence_address &lt;chr&gt;, language_of_original_document &lt;chr&gt;,
## #   document_type &lt;chr&gt;, source &lt;chr&gt;, citing_id &lt;chr&gt;</code></pre>
<p>There are several things to clean:</p>
<ul>
<li>We have several <code>authors</code> per document. For some analysis, for instance co-authorship networks, it is better to have an “author table” which associates each author to a list of papers;</li>
<li>We have several <code>affiliations</code> per article as well as several <code>authors_with_affiliations</code>. It allows us to connect authors with their affiliations, but here again we need to separate it in as many lines as authors (if I am not mistaken, it seems there is only one affiliation per author in this set of data);</li>
<li><code>references</code>;</li>
<li>Possibly to separate <code>author_keywords</code> and <code>index_keywords</code> if you want to use it.</li>
</ul>
<p>In what follows, we clean <code>scopus_search</code> in order to produce 3 additional <code>data.frames</code>:</p>
<ul>
<li>one <code>data.frame</code> which associates each article to a list of authors and their corresponding affiliation (see below);</li>
<li>one data.frame which associate each article to the list of references it cites (one article has as many lines as the number of cited references): this is a “direct citation” table (see here);</li>
<li>a list of all the references cited, which implies to find which references are the same in the direct citation table (see this sub-section)</li>
</ul>
<section id="extracting-affiliations-and-authors" class="level3">
<h3 class="anchored" data-anchor-id="extracting-affiliations-and-authors">Extracting affiliations and authors</h3>
<p>We have two columns for affiliations:</p>
<ul>
<li>one column <code>affiliations</code> with affiliations alone;</li>
<li>one column, <code>authors_with_affiliations</code> with both authors and affiliations.</li>
</ul>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1">affiliations_raw <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> scopus_search <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb9-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(citing_id, authors, affiliations, authors_with_affiliations)</span>
<span id="cb9-3"></span>
<span id="cb9-4">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(affiliations_raw, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span></code></pre></div></div>
<table class="caption-top table">
<colgroup>
<col style="width: 2%">
<col style="width: 9%">
<col style="width: 31%">
<col style="width: 56%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">citing_id</th>
<th style="text-align: left;">authors</th>
<th style="text-align: left;">affiliations</th>
<th style="text-align: left;">authors_with_affiliations</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">A1</td>
<td style="text-align: left;">Ha J., So I.</td>
<td style="text-align: left;">Department of Economics, Cornell University, Ithaca, NY, United States; Department of Economics, University of Washington, Seattle, WA, United States</td>
<td style="text-align: left;">Ha, J., Department of Economics, Cornell University, Ithaca, NY, United States; So, I., Department of Economics, University of Washington, Seattle, WA, United States</td>
</tr>
<tr class="even">
<td style="text-align: left;">A2</td>
<td style="text-align: left;">Botero J., Franco H., Hurtado Á., Mesa M.</td>
<td style="text-align: left;">Departamento de Economía, Universidad EAFIT, Medellín, Colombia; EAFIT University, Colombia</td>
<td style="text-align: left;">Botero, J., Departamento de Economía, Universidad EAFIT, Medellín, Colombia; Franco, H., Departamento de Economía, Universidad EAFIT, Medellín, Colombia; Hurtado, Á., Departamento de Economía, Universidad EAFIT, Medellín, Colombia; Mesa, M., EAFIT University, Colombia</td>
</tr>
</tbody>
</table>
<p>For a more secure cleaning, we opt for the second column, as it allows us to associate the author with his/her own affiliation as described in the column <code>authors_with_affiliations</code>. The strategy here is to separate each author from the <code>authors</code> column, then to separate the different authors and affiliations in the <code>authors_with_affiliations</code> column. Finally, we keep only the lines where the author from <code>authors_with_affiliations</code> is the same as in <code>authors</code></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1">scopus_affiliations <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> affiliations_raw <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">separate_rows</span>(authors, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">separate_rows</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">contains</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"with"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"; "</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">authors_from_affiliation =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(authors_with_affiliations, </span>
<span id="cb10-5">                                                <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^(.+?)</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.(?=,)"</span>),</span>
<span id="cb10-6">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">authors_from_affiliation =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(authors_from_affiliation, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>),</span>
<span id="cb10-7">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">affiliations =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(authors_with_affiliations, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^(.+?)</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">., "</span>),</span>
<span id="cb10-8">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">country =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(affiliations, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*, "</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Country is after the last comma</span></span>
<span id="cb10-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(authors <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> authors_from_affiliation) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb10-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(citing_id, authors, affiliations, country)</span>
<span id="cb10-11"></span>
<span id="cb10-12"></span>
<span id="cb10-13">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(scopus_affiliations))</span></code></pre></div></div>
<table class="caption-top table">
<colgroup>
<col style="width: 9%">
<col style="width: 10%">
<col style="width: 67%">
<col style="width: 12%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">citing_id</th>
<th style="text-align: left;">authors</th>
<th style="text-align: left;">affiliations</th>
<th style="text-align: left;">country</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">A1</td>
<td style="text-align: left;">Ha J.</td>
<td style="text-align: left;">Department of Economics, Cornell University, Ithaca, NY, United States</td>
<td style="text-align: left;">United States</td>
</tr>
<tr class="even">
<td style="text-align: left;">A1</td>
<td style="text-align: left;">So I.</td>
<td style="text-align: left;">Department of Economics, University of Washington, Seattle, WA, United States</td>
<td style="text-align: left;">United States</td>
</tr>
<tr class="odd">
<td style="text-align: left;">A2</td>
<td style="text-align: left;">Botero J.</td>
<td style="text-align: left;">Departamento de Economía, Universidad EAFIT, Medellín, Colombia</td>
<td style="text-align: left;">Colombia</td>
</tr>
<tr class="even">
<td style="text-align: left;">A2</td>
<td style="text-align: left;">Franco H.</td>
<td style="text-align: left;">Departamento de Economía, Universidad EAFIT, Medellín, Colombia</td>
<td style="text-align: left;">Colombia</td>
</tr>
<tr class="odd">
<td style="text-align: left;">A2</td>
<td style="text-align: left;">Hurtado Á.</td>
<td style="text-align: left;">Departamento de Economía, Universidad EAFIT, Medellín, Colombia</td>
<td style="text-align: left;">Colombia</td>
</tr>
<tr class="even">
<td style="text-align: left;">A2</td>
<td style="text-align: left;">Mesa M.</td>
<td style="text-align: left;">EAFIT University, Colombia</td>
<td style="text-align: left;">Colombia</td>
</tr>
</tbody>
</table>
</section>
<section id="clean-references" class="level3">
<h3 class="anchored" data-anchor-id="clean-references">Clean references</h3>
<p>Let’s first extract the <code>references</code> column while keeping the identifier of the citing article. We put each reference cited by an article on a separated line, using the fact that the references are separated by a semi-colon. We create an identifier for each reference.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' ## Extracting and cleaning references</span></span>
<span id="cb11-2">references_extract <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> scopus_search <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb11-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(references)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb11-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(citing_id, references) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb11-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">separate_rows</span>(references, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">sep =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"; "</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb11-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id_ref =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb11-7">  as_tibble</span>
<span id="cb11-8"></span>
<span id="cb11-9">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(references_extract))</span></code></pre></div></div>
<table class="caption-top table">
<colgroup>
<col style="width: 6%">
<col style="width: 89%">
<col style="width: 4%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">citing_id</th>
<th style="text-align: left;">references</th>
<th style="text-align: right;">id_ref</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">A1</td>
<td style="text-align: left;">Bernanke, B., Gertler, M., Gilchrist, S., Financial accelerator in a quantitative business cycle framework, NBER Working Paper No.&nbsp;W6455 (1998), NBER</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td style="text-align: left;">A1</td>
<td style="text-align: left;">Calvo, G., Staggered prices in a utility maximizing framework (1983) Journal of Monetary Economics, 12, pp.&nbsp;383-398</td>
<td style="text-align: right;">2</td>
</tr>
<tr class="odd">
<td style="text-align: left;">A1</td>
<td style="text-align: left;">Christensen, I., Dib, A., Monetary policy in an estimated DSGE model with a financial accelerator (2005) Computing in Economics and Finance, p.&nbsp;314</td>
<td style="text-align: right;">3</td>
</tr>
<tr class="even">
<td style="text-align: left;">A1</td>
<td style="text-align: left;">Dixit, A., Stiglitz, J., Monopolistic competition and optimum product diversity (1977) American Economic Review, 67 (3), pp.&nbsp;297-308</td>
<td style="text-align: right;">4</td>
</tr>
<tr class="odd">
<td style="text-align: left;">A1</td>
<td style="text-align: left;">Gerali, A., Neri, S., Sessa, L., Signoretti, F., Credit and banking in a DSGE model (2010), 42 (6), pp.&nbsp;107-141. , Working paper, Banka D’Italia, Rome</td>
<td style="text-align: right;">5</td>
</tr>
<tr class="even">
<td style="text-align: left;">A1</td>
<td style="text-align: left;">Goodfriend, M., McCallum, B., Banking and interest rates in monetary policy analysis: A quantitative exploration (2007), NBER Working Paper Series No.&nbsp;13207, NBER</td>
<td style="text-align: right;">6</td>
</tr>
</tbody>
</table>
<p>We now have one reference per line and complications begin. We need to find ways to extract the different pieces of information for each reference: authors, year, pages, volume &amp; issue information, journal, title, etc… Here are some regex that will match some of these information.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1">extract_authors <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*[:upper:][:alpha:]+( Jr(.)?)?, ([A-Z]</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.[ -]?)?([A-Z]</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.[ -]?)?([A-Z]</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.)?[A-Z]</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">."</span></span>
<span id="cb12-2">extract_year_brackets <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">()</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}(?=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">))"</span></span>
<span id="cb12-3">extract_pages <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;= (p)?p</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">. )([A-Z])?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+(-([A-Z])?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+)?"</span></span>
<span id="cb12-4">extract_volume_and_number <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;=( |^)?)</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+ </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+(-</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+)?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span></span></code></pre></div></div>
<p>We can now extract authors and year. We create a new column, <code>remaining_ref</code> which keeps the information from the <code>references</code> column but we remove the authors from it. For easier cleaning, we separate references depending on the position of the year of publication in the reference. We use the variable <code>is_article</code> to determinate where the year is and thus if the title is before the year or not.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1">cleaning_references <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> references_extract <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb13-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">authors =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(references, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(extract_authors, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?=, )"</span>)),</span>
<span id="cb13-3">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remaining_ref =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(references, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(extract_authors, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>)), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cleaning from authors</span></span>
<span id="cb13-4">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">is_article =</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">([:digit:]{4}"</span>), </span>
<span id="cb13-5">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(references, extract_year_brackets) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> as.integer)</span></code></pre></div></div>
<p>I cannot detail all the regex below but the goal is to extract as many relevant metadata as possible, first for references with the year of publication after the title (<code>is_article == TRUE</code>), which are most of the time journal articles.</p>
<blockquote class="blockquote">
<p>This code has been written in January 2022 and I will try to improve it later, notably because this use of the <code>is_article</code> variable makes the code unecessarily longer.</p>
</blockquote>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1">cleaning_articles <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cleaning_references <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb14-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(is_article <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb14-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*(?=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4})"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># pre date extraction</span></span>
<span id="cb14-4">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">journal_to_clean =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">)).*"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># post date extraction</span></span>
<span id="cb14-5">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">journal_to_clean =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(journal_to_clean, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^,"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_trim</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"both"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cleaning a bit the journal info column</span></span>
<span id="cb14-6">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pages =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(journal_to_clean, extract_pages), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># extracting pages</span></span>
<span id="cb14-7">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">volume_and_number =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(journal_to_clean, extract_volume_and_number), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># extracting standard volument and number: X (X)</span></span>
<span id="cb14-8">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">journal_to_clean =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(journal_to_clean, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (p)?p</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">. ([A-Z])?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+(-([A-Z])?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+)?"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># clean from extracted pages</span></span>
<span id="cb14-9">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">journal_to_clean =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(journal_to_clean, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"( |^)?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+ </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+(-</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+)?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># clean from extracted volume and number</span></span>
<span id="cb14-10">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">volume_and_number =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(volume_and_number), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(journal_to_clean, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;= )([A-Z])?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+(-</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+)?"</span>), volume_and_number), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># extract remaining numbers</span></span>
<span id="cb14-11">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">journal_to_clean =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(journal_to_clean, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" ([A-Z])?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+(-</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+)?"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># clean from remaining numbers</span></span>
<span id="cb14-12">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">journal =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove_all</span>(journal_to_clean, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^[:punct:]+( )?[:punct:]+( )?|(?&lt;=,( )?)[:punct:]+( )?([:punct:])?|[:punct:]( )?[:punct:]+( )?$"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># extract journal info by removing inappropriate punctuations</span></span>
<span id="cb14-13">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">first_page =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(pages, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+"</span>),</span>
<span id="cb14-14">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">volume =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(volume_and_number, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+"</span>),</span>
<span id="cb14-15">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">issue =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(volume_and_number, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">()</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+(?=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">))"</span>),</span>
<span id="cb14-16">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">publisher =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(first_page) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(volume) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(issue) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(journal, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(W|w)orking (P|p)?aper"</span>), journal, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>),</span>
<span id="cb14-17">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">book_title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(journal, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (E|e)d(s)?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.| (E|e)dite(d|urs)? "</span>), journal, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Incollection article: Title of the book here</span></span>
<span id="cb14-18">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">book_title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(book_title, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"[A-z ]+(?=,)"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># keeping only the title of the book</span></span>
<span id="cb14-19">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">publisher =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(book_title), <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, publisher), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># if we have an incollection article, that's not a book, so no publisher</span></span>
<span id="cb14-20">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">journal =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(book_title) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(publisher), <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, journal), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># removing journal as what we have is a book</span></span>
<span id="cb14-21">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">publisher =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(publisher) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(journal, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(W|w)orking (P|p)?aper"</span>), journal, publisher), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># adding working paper publisher information in publisher column</span></span>
<span id="cb14-22">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">journal =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(journal, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(W|w)orking (P|p)?aper"</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Working Paper"</span>, journal))</span>
<span id="cb14-23"></span>
<span id="cb14-24">cleaned_articles <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cleaning_articles <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb14-25">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(citing_id, id_ref, authors, year, title, journal, volume, issue, pages, first_page, book_title, publisher, references)</span></code></pre></div></div>
<p>We do the same now with the remaining references that are less numerous but that are also less easy to clean, due to the fact that the title is not clearly separated from other information (journal or publisher).</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1">cleaning_non_articles <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cleaning_references <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(is_article <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remaining_ref =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">)(,)? "</span>),</span>
<span id="cb15-4">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*(?=, ,)"</span>),</span>
<span id="cb15-5">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pages =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;= (p)?p</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">. )([A-Z])?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+(-([A-Z])?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+)?"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># extracting pages</span></span>
<span id="cb15-6">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">volume_and_number =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;=( |^)?)</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+ </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+(-</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+)?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># extracting standard volument and number: X (X)</span></span>
<span id="cb15-7">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remaining_ref =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" (p)?p</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">. ([A-Z])?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+(-([A-Z])?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+)?"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># clean from extracted pages</span></span>
<span id="cb15-8">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remaining_ref =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove_all</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*, ,"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># clean dates and already extracted titles</span></span>
<span id="cb15-9">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remaining_ref =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"( |^)?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+ </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+(-</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+)?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># clean from extracted volume and number</span></span>
<span id="cb15-10">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">volume_and_number =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(volume_and_number), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;= )([A-Z])?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+(-</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+)?"</span>), volume_and_number), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># extract remaining numbers</span></span>
<span id="cb15-11">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">remaining_ref =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" ([A-Z])?</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+(-</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+)?"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># clean from remaining numbers</span></span>
<span id="cb15-12">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">journal =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(W|w)orking (P|p)aper"</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Working Paper"</span>, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>),</span>
<span id="cb15-13">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">journal =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(M|m)anuscript"</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Manuscript"</span>, journal),</span>
<span id="cb15-14">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">journal =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_detect</span>(remaining_ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(M|m)imeo"</span>), <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Mimeo"</span>, journal),</span>
<span id="cb15-15">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">publisher =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(journal), remaining_ref, <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_trim</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"both"</span>),</span>
<span id="cb15-16">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">first_page =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(pages, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+"</span>),</span>
<span id="cb15-17">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">volume =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(volume_and_number, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+"</span>),</span>
<span id="cb15-18">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">issue =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(volume_and_number, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">()</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d+(?=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">))"</span>),</span>
<span id="cb15-19">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">book_title =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># to be symetric with "cleaned_articles"</span></span>
<span id="cb15-20"></span>
<span id="cb15-21">cleaned_non_articles <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cleaning_non_articles <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb15-22">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(citing_id, id_ref, authors, year, title, journal, volume, issue, pages, first_page, book_title, publisher, references)</span></code></pre></div></div>
<p>We merge the two <code>data.frames</code> and:</p>
<ul>
<li>we normalize and clean authors’ name to facilitate matching of references later;</li>
<li>we extract useful information like <a href="https://en.wikipedia.org/wiki/Digital_object_identifier">DOI</a> and <a href="https://en.wikipedia.org/wiki/Publisher_Item_Identifier">PII</a>.</li>
</ul>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb16-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># merging the two files.</span></span>
<span id="cb16-2">cleaned_ref <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rbind</span>(cleaned_articles, cleaned_non_articles)</span>
<span id="cb16-3"></span>
<span id="cb16-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' Now we have all the references, we can do a bit of cleaning on the authors name,</span></span>
<span id="cb16-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#' and extract useful information, like DOI, for matching later.</span></span>
<span id="cb16-6"></span>
<span id="cb16-7">cleaned_ref <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cleaned_ref <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb16-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">authors =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(authors, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" Jr</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">."</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># standardising authors name to favour matching later</span></span>
<span id="cb16-9">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">authors =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(authors, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">)(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.)?( )?"</span>),</span>
<span id="cb16-10">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">authors =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(authors, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^, "</span>),</span>
<span id="cb16-11">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">authors =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(authors), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(references, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*[:upper:]</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.(?= </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4})"</span>), authors), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># specific case</span></span>
<span id="cb16-12">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">journal =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(journal, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"[:punct:]$"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># remove unnecessary punctuations at the end</span></span>
<span id="cb16-13">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">doi =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(references, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;=DOI(:)? ).*|(?&lt;=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/doi</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.org</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/).*"</span>),</span>
<span id="cb16-14">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pii =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(doi, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"(?&lt;=PII ).*"</span>),</span>
<span id="cb16-15">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">doi =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(doi, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">",.*"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cleaning doi</span></span>
<span id="cb16-16">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pii =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_remove</span>(pii, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">",.*"</span>), <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># cleaning pii</span></span>
<span id="cb16-17">  )</span>
<span id="cb16-18"></span>
<span id="cb16-19">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(cleaned_ref, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span></code></pre></div></div>
<table class="caption-top table">
<colgroup>
<col style="width: 2%">
<col style="width: 1%">
<col style="width: 10%">
<col style="width: 1%">
<col style="width: 22%">
<col style="width: 8%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 36%">
<col style="width: 1%">
<col style="width: 1%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">citing_id</th>
<th style="text-align: right;">id_ref</th>
<th style="text-align: left;">authors</th>
<th style="text-align: right;">year</th>
<th style="text-align: left;">title</th>
<th style="text-align: left;">journal</th>
<th style="text-align: left;">volume</th>
<th style="text-align: left;">issue</th>
<th style="text-align: left;">pages</th>
<th style="text-align: left;">first_page</th>
<th style="text-align: left;">book_title</th>
<th style="text-align: left;">publisher</th>
<th style="text-align: left;">references</th>
<th style="text-align: left;">doi</th>
<th style="text-align: left;">pii</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">A1</td>
<td style="text-align: right;">1</td>
<td style="text-align: left;">Bernanke, B., Gertler, M., Gilchrist, S.</td>
<td style="text-align: right;">1998</td>
<td style="text-align: left;">Financial accelerator in a quantitative business cycle framework, NBER Working Paper No.&nbsp;W6455</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NBER</td>
<td style="text-align: left;">Bernanke, B., Gertler, M., Gilchrist, S., Financial accelerator in a quantitative business cycle framework, NBER Working Paper No.&nbsp;W6455 (1998), NBER</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
</tr>
<tr class="even">
<td style="text-align: left;">A1</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">Calvo, G.</td>
<td style="text-align: right;">1983</td>
<td style="text-align: left;">Staggered prices in a utility maximizing framework</td>
<td style="text-align: left;">Journal of Monetary Economics</td>
<td style="text-align: left;">12</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">383-398</td>
<td style="text-align: left;">383</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Calvo, G., Staggered prices in a utility maximizing framework (1983) Journal of Monetary Economics, 12, pp.&nbsp;383-398</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
</tr>
<tr class="odd">
<td style="text-align: left;">A1</td>
<td style="text-align: right;">3</td>
<td style="text-align: left;">Christensen, I., Dib, A.</td>
<td style="text-align: right;">2005</td>
<td style="text-align: left;">Monetary policy in an estimated DSGE model with a financial accelerator</td>
<td style="text-align: left;">Computing in Economics and Finance</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">314</td>
<td style="text-align: left;">314</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Christensen, I., Dib, A., Monetary policy in an estimated DSGE model with a financial accelerator (2005) Computing in Economics and Finance, p.&nbsp;314</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
</tr>
</tbody>
</table>
<blockquote class="blockquote">
<p>Practically speaking, if you are targetting a serious quantitative work, more cleaning would be needed to remove small errors. As often in this kind of automatised cleaning, 95% of cleaning can be done with few lines of code, and the rest involves many more work. I do not go further here as this is just a tutorial.</p>
</blockquote>
</section>
<section id="matching-references" class="level3">
<h3 class="anchored" data-anchor-id="matching-references">Matching references</h3>
<p>What we need to do now is to find which references are the same, to give them a unique ID. The trade-off is to match as many true positive as possible (references that are the same) while avoiding to match false positive, that is references that have some information in common, but that actually are not the same references. For instance, matching only by the authors’ names and the year of publication is too broad, as these authors can have published several articles during the same year. Here are several ways to identify a common reference that bear very few risks of matching together different references:</p>
<ul>
<li>same first author surname or authors, year, volume and page (this is the most secure ones): let’s call them <code>fayvp</code> &amp; <code>ayvp</code>;</li>
<li>same journal, volume, issue and first page: <code>jvip</code>;</li>
<li>same author, year and title: <code>ayt</code>;</li>
<li>same title, year and first page: <code>typ</code>;</li>
<li>same Doi or PII.<sup>6</sup></li>
</ul>
<p>We extract first author surname to favour matching as there are more possibilities of small differences for several authors that would prevent us to match similar references.<sup>7</sup></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1">cleaned_ref <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cleaned_ref <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb17-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">first_author =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(authors, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^[[:alpha:]+[']?[ -]?]+, ([A-Z]</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.[ -]?)?([A-Z]</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.[ -]?)?([A-Z]</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.)?[A-Z]</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.(?=(,|$))"</span>),</span>
<span id="cb17-3">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">first_author_surname =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(first_author, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*(?=,)"</span>),</span>
<span id="cb17-4">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">across</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.cols =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"authors"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"first_author"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"journal"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"title"</span>), <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toupper</span>(.))) </span></code></pre></div></div>
<p>For each type of matching, we are giving a new id to the matched references, by giving the <code>id_ref</code> of the first references matched. At the end, we compare all the new id created with all the matching methods, and we take the smaller id.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb18-1">matching_ref <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(data, id_ref, ..., col_name){</span>
<span id="cb18-2">  match <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-3">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(...) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-4">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">new_id =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>({{id_ref}})) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-5">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">drop_na</span>(...) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-6">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ungroup</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-7">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>({{id_ref}}, new_id) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-8">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename_with</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(col_name, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_new_id"</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.cols =</span> new_id)</span>
<span id="cb18-9">  </span>
<span id="cb18-10">  data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> data <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(match)</span>
<span id="cb18-12">}</span>
<span id="cb18-13"></span>
<span id="cb18-14">identifying_ref <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> cleaned_ref <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matching_ref</span>(id_ref, first_author_surname, year, title, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fayt"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matching_ref</span>(id_ref, journal, volume, issue, first_page, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"jvip"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matching_ref</span>(id_ref, authors, year, volume, first_page, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ayvp"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matching_ref</span>(id_ref, first_author_surname, year, volume, first_page, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fayvp"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb18-19">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matching_ref</span>(id_ref, title, year, first_page, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"typ"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matching_ref</span>(id_ref, pii, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pii"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb18-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matching_ref</span>(id_ref, doi, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col_name =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"doi"</span>) </span></code></pre></div></div>
<p>Now we have our direct citation table connecting the citing articles to the references. We have as many lines as the number of citations by citing articles.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1">direct_citation <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> identifying_ref <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span>  </span>
<span id="cb19-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">new_id_ref =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(., <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ends_with</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"new_id"</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>(pmin, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">na.rm =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb19-3">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">new_id_ref =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ifelse</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(new_id_ref), id_ref, new_id_ref))  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb19-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">relocate</span>(new_id_ref, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">.after =</span> citing_id) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb19-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>id_ref <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ends_with</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"new_id"</span>))</span>
<span id="cb19-6"></span>
<span id="cb19-7">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(direct_citation, new_id_ref <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>))</span></code></pre></div></div>
<table class="caption-top table">
<colgroup>
<col style="width: 3%">
<col style="width: 3%">
<col style="width: 3%">
<col style="width: 1%">
<col style="width: 14%">
<col style="width: 8%">
<col style="width: 2%">
<col style="width: 1%">
<col style="width: 2%">
<col style="width: 3%">
<col style="width: 3%">
<col style="width: 3%">
<col style="width: 34%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 3%">
<col style="width: 6%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">citing_id</th>
<th style="text-align: right;">new_id_ref</th>
<th style="text-align: left;">authors</th>
<th style="text-align: right;">year</th>
<th style="text-align: left;">title</th>
<th style="text-align: left;">journal</th>
<th style="text-align: left;">volume</th>
<th style="text-align: left;">issue</th>
<th style="text-align: left;">pages</th>
<th style="text-align: left;">first_page</th>
<th style="text-align: left;">book_title</th>
<th style="text-align: left;">publisher</th>
<th style="text-align: left;">references</th>
<th style="text-align: left;">doi</th>
<th style="text-align: left;">pii</th>
<th style="text-align: left;">first_author</th>
<th style="text-align: left;">first_author_surname</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">A1</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">CALVO, G.</td>
<td style="text-align: right;">1983</td>
<td style="text-align: left;">STAGGERED PRICES IN A UTILITY MAXIMIZING FRAMEWORK</td>
<td style="text-align: left;">JOURNAL OF MONETARY ECONOMICS</td>
<td style="text-align: left;">12</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">383-398</td>
<td style="text-align: left;">383</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Calvo, G., Staggered prices in a utility maximizing framework (1983) Journal of Monetary Economics, 12, pp.&nbsp;383-398</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">CALVO, G.</td>
<td style="text-align: left;">Calvo</td>
</tr>
<tr class="even">
<td style="text-align: left;">A3</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">CALVO, G.</td>
<td style="text-align: right;">1983</td>
<td style="text-align: left;">STAGGERED PRICES IN A UTILITY-MAXIMIZING FRAMEWORK</td>
<td style="text-align: left;">JOURNAL OF MONETARY ECONOMICS</td>
<td style="text-align: left;">12</td>
<td style="text-align: left;">3</td>
<td style="text-align: left;">383-398</td>
<td style="text-align: left;">383</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Calvo, G., Staggered Prices in a Utility-Maximizing Framework (1983) Journal of Monetary Economics, 12 (3), pp.&nbsp;383-398</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">CALVO, G.</td>
<td style="text-align: left;">Calvo</td>
</tr>
<tr class="odd">
<td style="text-align: left;">A18</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">CALVO, G.</td>
<td style="text-align: right;">1983</td>
<td style="text-align: left;">STAGGERED PRICES IN A UTILITY MAXIMIZING FRAMEWORK</td>
<td style="text-align: left;">JOURNAL OF MONETARY ECONOMICS</td>
<td style="text-align: left;">12</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">383-398</td>
<td style="text-align: left;">383</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Calvo, G., Staggered prices in a utility maximizing framework (1983) Journal of Monetary Economics, 12, pp.&nbsp;383-398</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">CALVO, G.</td>
<td style="text-align: left;">Calvo</td>
</tr>
<tr class="even">
<td style="text-align: left;">A20</td>
<td style="text-align: right;">2</td>
<td style="text-align: left;">CALVO, G.A.</td>
<td style="text-align: right;">1983</td>
<td style="text-align: left;">STAGGERED PRICES IN A UTILITY-MAXIMIZING FRAMEWORK</td>
<td style="text-align: left;">JOURNAL OF MONETARY ECONOMICS</td>
<td style="text-align: left;">12</td>
<td style="text-align: left;">3</td>
<td style="text-align: left;">383-398</td>
<td style="text-align: left;">383</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Calvo, G.A., Staggered prices in a utility-maximizing framework (1983) Journal of Monetary Economics, 12 (3), pp.&nbsp;383-398</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">CALVO, G.A.</td>
<td style="text-align: left;">Calvo</td>
</tr>
</tbody>
</table>
<p>We can extract the list of all the references cited. We have as many lines as references cited by citing articles (i.e.&nbsp;a reference cited multiple times is present only once in the table). As for matched references, we have different information (due to the fact that the references were cited differently depending on the citing articles), we take a line where information seems to be the most complete.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb20-1">important_info <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"authors"</span>,</span>
<span id="cb20-2">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span>,</span>
<span id="cb20-3">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"title"</span>,</span>
<span id="cb20-4">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"journal"</span>,</span>
<span id="cb20-5">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"volume"</span>,</span>
<span id="cb20-6">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"issue"</span>,</span>
<span id="cb20-7">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pages"</span>,</span>
<span id="cb20-8">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"book_title"</span>,</span>
<span id="cb20-9">                    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"publisher"</span>)</span>
<span id="cb20-10">references <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> direct_citation <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nb_na =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rowSums</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(., <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all_of</span>(important_info))))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(new_id_ref) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">order_by =</span> nb_na, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">with_ties =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>citing_id) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb20-15">  unique</span>
<span id="cb20-16"></span>
<span id="cb20-17">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(references, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>))</span></code></pre></div></div>
<table class="caption-top table">
<colgroup>
<col style="width: 2%">
<col style="width: 9%">
<col style="width: 1%">
<col style="width: 20%">
<col style="width: 7%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 2%">
<col style="width: 32%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 3%">
<col style="width: 4%">
<col style="width: 1%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: right;">new_id_ref</th>
<th style="text-align: left;">authors</th>
<th style="text-align: right;">year</th>
<th style="text-align: left;">title</th>
<th style="text-align: left;">journal</th>
<th style="text-align: left;">volume</th>
<th style="text-align: left;">issue</th>
<th style="text-align: left;">pages</th>
<th style="text-align: left;">first_page</th>
<th style="text-align: left;">book_title</th>
<th style="text-align: left;">publisher</th>
<th style="text-align: left;">references</th>
<th style="text-align: left;">doi</th>
<th style="text-align: left;">pii</th>
<th style="text-align: left;">first_author</th>
<th style="text-align: left;">first_author_surname</th>
<th style="text-align: right;">nb_na</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: right;">1</td>
<td style="text-align: left;">BERNANKE, B., GERTLER, M., GILCHRIST, S.</td>
<td style="text-align: right;">1998</td>
<td style="text-align: left;">FINANCIAL ACCELERATOR IN A QUANTITATIVE BUSINESS CYCLE FRAMEWORK, NBER WORKING PAPER NO. W6455</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NBER</td>
<td style="text-align: left;">Bernanke, B., Gertler, M., Gilchrist, S., Financial accelerator in a quantitative business cycle framework, NBER Working Paper No.&nbsp;W6455 (1998), NBER</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">BERNANKE, B.</td>
<td style="text-align: left;">Bernanke</td>
<td style="text-align: right;">4</td>
</tr>
<tr class="even">
<td style="text-align: right;">2</td>
<td style="text-align: left;">CALVO, G.</td>
<td style="text-align: right;">1983</td>
<td style="text-align: left;">STAGGERED PRICES IN A UTILITY-MAXIMIZING FRAMEWORK</td>
<td style="text-align: left;">JOURNAL OF MONETARY ECONOMICS</td>
<td style="text-align: left;">12</td>
<td style="text-align: left;">3</td>
<td style="text-align: left;">383-398</td>
<td style="text-align: left;">383</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Calvo, G., Staggered Prices in a Utility-Maximizing Framework (1983) Journal of Monetary Economics, 12 (3), pp.&nbsp;383-398</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">CALVO, G.</td>
<td style="text-align: left;">Calvo</td>
<td style="text-align: right;">7</td>
</tr>
<tr class="odd">
<td style="text-align: right;">3</td>
<td style="text-align: left;">CHRISTENSEN, I., DIB, A.</td>
<td style="text-align: right;">2005</td>
<td style="text-align: left;">MONETARY POLICY IN AN ESTIMATED DSGE MODEL WITH A FINANCIAL ACCELERATOR</td>
<td style="text-align: left;">COMPUTING IN ECONOMICS AND FINANCE</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">314</td>
<td style="text-align: left;">314</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Christensen, I., Dib, A., Monetary policy in an estimated DSGE model with a financial accelerator (2005) Computing in Economics and Finance, p.&nbsp;314</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">CHRISTENSEN, I.</td>
<td style="text-align: left;">Christensen</td>
<td style="text-align: right;">5</td>
</tr>
<tr class="even">
<td style="text-align: right;">4</td>
<td style="text-align: left;">DIXIT, A., STIGLITZ, J.</td>
<td style="text-align: right;">1977</td>
<td style="text-align: left;">MONOPOLISTIC COMPETITION AND OPTIMUM PRODUCT DIVERSITY</td>
<td style="text-align: left;">AMERICAN ECONOMIC REVIEW</td>
<td style="text-align: left;">67</td>
<td style="text-align: left;">3</td>
<td style="text-align: left;">297-308</td>
<td style="text-align: left;">297</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Dixit, A., Stiglitz, J., Monopolistic competition and optimum product diversity (1977) American Economic Review, 67 (3), pp.&nbsp;297-308</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">DIXIT, A.</td>
<td style="text-align: left;">Dixit</td>
<td style="text-align: right;">7</td>
</tr>
</tbody>
</table>
<p>From the initial 105313 citations, we get 52577 different references, with 10631 cited at least twice.</p>
<p>We also remove the <code>references</code> column of the initial <code>data.frame</code> as references cited are now gathered in <code>direct_citation</code>.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1">corpus <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> scopus_search <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb21-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>references)</span></code></pre></div></div>
<p>I imagine that after so many steps, you can’t wait to look at these data on DSGE models. But you will have to wait, as the following subsection presents you another method to clean (without cleaning yourself) the references. Or you can go directly to the last section that explores the cleaned data.</p>
</section>
<section id="alternative-method-anystyle" class="level3">
<h3 class="anchored" data-anchor-id="alternative-method-anystyle">Alternative method: <a href="https://anystyle.io">anystyle</a></h3>
<p><a href="https://anystyle.io">anystyle</a> is a great references parser relyng on machine learning heuristics. It has an online version where you can put the text for which you want to identify references. However, we will use the command line in order to identify more references than what the online website allows (10 000 while we have 105313 raw references).</p>
<p>Anystyle can be installed as a RubyGem. You thus need to install Ruby (<a href="https://rubyinstaller.org/downloads/">here</a> for Windows) and then install anystyle using the command line: <code>gem install anystyle</code> (see more information <a href="https://anystyle.io/">here</a>). As you need to use the command line interface, you also need to install anystyle-cli: <code>gem install anystyle-cli</code>.</p>
<blockquote class="blockquote">
<p>Some frightened reader: “What, what? wait! Command line you said?”</p>
</blockquote>
<p>Oh, yes. And that is a good occasion to refer you to these great tutorials of the great <a href="https://programminghistorian.org/en/">Programming Historian Website</a>: one for the <a href="https://programminghistorian.org/en/lessons/intro-to-bash">bash command line</a> and one for the <a href="https://programminghistorian.org/en/lessons/intro-to-powershell">Windows Powershell Command Line</a>. And it will be the occasion to use a bit <a href="https://support.rstudio.com/hc/en-us/articles/115010737148-Using-the-RStudio-Terminal-in-the-RStudio-IDE">Rstudio Terminal</a> to enter the commands.</p>
<p>Once you have installed anystyle, you need to save all the references (with one reference per line) in a <code>.txt</code>.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb22-1">ref_text <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(references_extract<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>references, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">collapse =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb22-2">name_file <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ref_in_text.txt"</span></span>
<span id="cb22-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">write_file</span>(ref_text,</span>
<span id="cb22-4">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(scopus_path,</span>
<span id="cb22-5">                name_file))</span></code></pre></div></div>
<p>To create the anystyle command, you need to name the repository where you will send the <code>.bib</code> created by anystyle from your <code>.txt</code></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1">destination_anystyle <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"anystyle_cleaned"</span></span>
<span id="cb23-2"></span>
<span id="cb23-3">directory_command <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cd "</span>, scopus_path)</span>
<span id="cb23-4">anystyle_command <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"anystyle -f bib parse "</span>,</span>
<span id="cb23-5">                           name_file,</span>
<span id="cb23-6">                           <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">" "</span>,</span>
<span id="cb23-7">                           destination_anystyle)</span></code></pre></div></div>
<p>To use anystyle, you have to use the command line of the terminal. You first have to set the path where the <code>.txt</code> is (which is here the <code>scopus_path</code>): <code>cd the_path_where_is_the_.txt</code>.</p>
<p>Then you copy and paste the anystyle command in the terminal, which here is: <code>anystyle -f bib parse ref_in_text.txt anystyle_cleaned</code>. Hopefully it will work and you wil just have to wait for the creation of the <code>.bib</code> (it took something like 10 minutes on my laptop).<sup>8</sup></p>
<blockquote class="blockquote">
<p>…waiting…</p>
</blockquote>
<p>Once we have our <code>.bib</code>, we transform it in a data frame thanks to the <a href="https://docs.ropensci.org/bib2df/"><code>bib2df</code></a> package.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb24-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">encoding =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"UTF-8"</span>)</span>
<span id="cb24-2">bib_ref <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bib2df</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(scopus_path,</span>
<span id="cb24-3">                       destination_anystyle,</span>
<span id="cb24-4">                       <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ref_in_text.bib"</span>))</span>
<span id="cb24-5">bib_ref <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> bib_ref <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb24-6">  janitor<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clean_names</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb24-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select_if</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">all</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(.))) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># removing all empty columns</span></span>
<span id="cb24-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id_ref =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb24-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(translator, citation_number, arxiv, director, source))</span>
<span id="cb24-10"></span>
<span id="cb24-11">knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span>(bib_ref))</span></code></pre></div></div>
<table class="caption-top table">
<colgroup>
<col style="width: 3%">
<col style="width: 3%">
<col style="width: 5%">
<col style="width: 12%">
<col style="width: 10%">
<col style="width: 2%">
<col style="width: 1%">
<col style="width: 3%">
<col style="width: 8%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 2%">
<col style="width: 4%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 21%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 1%">
<col style="width: 1%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">category</th>
<th style="text-align: left;">bibtexkey</th>
<th style="text-align: left;">address</th>
<th style="text-align: left;">author</th>
<th style="text-align: left;">booktitle</th>
<th style="text-align: left;">edition</th>
<th style="text-align: left;">editor</th>
<th style="text-align: left;">institution</th>
<th style="text-align: left;">journal</th>
<th style="text-align: left;">note</th>
<th style="text-align: left;">number</th>
<th style="text-align: left;">pages</th>
<th style="text-align: left;">publisher</th>
<th style="text-align: left;">school</th>
<th style="text-align: left;">series</th>
<th style="text-align: left;">title</th>
<th style="text-align: left;">type</th>
<th style="text-align: left;">volume</th>
<th style="text-align: left;">date</th>
<th style="text-align: left;">issue</th>
<th style="text-align: left;">url</th>
<th style="text-align: left;">isbn</th>
<th style="text-align: left;">doi</th>
<th style="text-align: right;">id_ref</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">ARTICLE</td>
<td style="text-align: left;">bernanke1998a</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Bernanke, B. , Gertler, M. , Gilchrist, S.</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NBER Working Paper</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">W6455</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Financial accelerator in a quantitative business cycle framework</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;"></td>
<td style="text-align: left;">1998</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">1</td>
</tr>
<tr class="even">
<td style="text-align: left;">ARTICLE</td>
<td style="text-align: left;">calvo-a</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Calvo, G.</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Journal of Monetary Economics</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">383–398</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Staggered prices in a utility maximizing framework (1983</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">12</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">2</td>
</tr>
<tr class="odd">
<td style="text-align: left;">ARTICLE</td>
<td style="text-align: left;">christensen-a</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Christensen, I., Dib, A.</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Computing in Economics and Finance</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">314</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Monetary policy in an estimated DSGE model with a financial accelerator (2005</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">3</td>
</tr>
<tr class="even">
<td style="text-align: left;">ARTICLE</td>
<td style="text-align: left;">dixit-a</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Dixit, A. , Stiglitz, J.</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">American Economic Review</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">3</td>
<td style="text-align: left;">297–308</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Monopolistic competition and optimum product diversity (1977</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">67</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">4</td>
</tr>
<tr class="odd">
<td style="text-align: left;">BOOK</td>
<td style="text-align: left;">gerali2010a</td>
<td style="text-align: left;">Banka D’Italia, Rome</td>
<td style="text-align: left;">Gerali, A. , Neri, S. , Sessa, L. , Signoretti, F.</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">107–141</td>
<td style="text-align: left;">, Working paper</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Credit and banking in a DSGE model</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">42</td>
<td style="text-align: left;">2010</td>
<td style="text-align: left;">6</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">5</td>
</tr>
<tr class="even">
<td style="text-align: left;">INCOLLECTION</td>
<td style="text-align: left;">goodfriend-a</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Goodfriend, M., McCallum, B.</td>
<td style="text-align: left;">NBER Working Paper Series No.&nbsp;13207, NBER\</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">Banking and interest rates in monetary policy analysis: A quantitative exploration (2007</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: left;">NA</td>
<td style="text-align: right;">6</td>
</tr>
</tbody>
</table>
<p>For now, there is one major limitation to this method (which is most likely linked to my lack of mastery of anystyle and ruby): the result is a list of unique references. In other words, anystyle merge together references that are similar. It means that I have to find a way to build a link between the original references <code>data.frame</code> and the <code>data.frame</code> build on the <code>.bib</code>.<sup>9</sup></p>
<p>Ideally, you can clean a bit the result. Anystyle is pretty good (and clearly better than I) for identifying the types of references, and thus to extract book title for chapter in books and editors. It is quite efficient to extract authors and titles even if I have seen many mistakes (but relatively easy to clean, as most of the time it is the year that has been put with the title). However, I also saw many mistakes for journals (incomplete name) that are not so easy to correct. If you want to clean your references data as much as possible, perhaps the best thing to do is to mix the coding cleaning approach used above with the anystyle method, and to complete missing information with one or another method.</p>
</section>
</section>
<section id="exploring-the-dsge-literature" class="level2">
<h2 class="anchored" data-anchor-id="exploring-the-dsge-literature">Exploring the DSGE literature</h2>
<p>Now we have our bibliographic data, the first thing we can look at is the most cited references in our corpus.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1">direct_citation <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb25-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_count</span>(new_id_ref) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb25-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(new_id_ref, n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb25-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb25-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb25-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(references, new_id_ref, references)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb25-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(references, n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb25-8">  knitr<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kable</span>()</span></code></pre></div></div>
<table class="caption-top table">
<colgroup>
<col style="width: 97%">
<col style="width: 2%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">references</th>
<th style="text-align: right;">n</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">Smets, F., Wouters, R., Shocks and frictions in US business cycles. a Bayesian DSGE approach (2007) American Economic Review, 97 (3), pp.&nbsp;586-606</td>
<td style="text-align: right;">780</td>
</tr>
<tr class="even">
<td style="text-align: left;">Calvo, G., Staggered Prices in a Utility-Maximizing Framework (1983) Journal of Monetary Economics, 12 (3), pp.&nbsp;383-398</td>
<td style="text-align: right;">702</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Christiano, L.J., Eichenbaum, M., Evans, C.L., Nominal rigidities and the dynamic effects of a shock to monetary policy (2005) Journal of Political Economy, 113 (1), pp.&nbsp;1-45. , http://ideas.repec.org/a/ucp/jpolec/v113y2005i1p1-45.html</td>
<td style="text-align: right;">640</td>
</tr>
<tr class="even">
<td style="text-align: left;">Smets, F., Wouters, R., An Estimated Dynamic Stochastic General Equilibrium Model of the Euro Area (2003) Journal of the European Economic Association, 1 (5), pp.&nbsp;1123-1175</td>
<td style="text-align: right;">610</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Bernanke, B., Gertler, M., Gilchrist, S., The financial accelerator in a quantitative business cycle framework (1999) NBER Working Papers Series, 1 (3), pp.&nbsp;1341-1393. , Elsevier Science B.V, (chap.&nbsp;21), Handbook of Macroeconomics</td>
<td style="text-align: right;">331</td>
</tr>
<tr class="even">
<td style="text-align: left;">An, S., Schorfheide, F., Bayesian Analysis of DSGE Models (2007) Econometric Reviews, 26 (4), pp.&nbsp;113-172</td>
<td style="text-align: right;">311</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Taylor, J., Discretion versus policy rules in practice (1993) Carnegie-Rochester Conference Series on Public Policy, 39 (0), pp.&nbsp;195-214</td>
<td style="text-align: right;">269</td>
</tr>
<tr class="even">
<td style="text-align: left;">Iacoviello, M., House prices, borrowing constraints, and monetary policy in the business cycle (2005) American Economic Review, 95 (3), pp.&nbsp;739-764</td>
<td style="text-align: right;">243</td>
</tr>
<tr class="odd">
<td style="text-align: left;">Kydland, F.E., Prescott, E.C., Time to build and aggregate fluctuations (1982) Econometrica, 50 (6), pp.&nbsp;1345-1370</td>
<td style="text-align: right;">234</td>
</tr>
<tr class="even">
<td style="text-align: left;">Schmitt-Grohe, S., Uribe, M., Closing small open economy models (2003) Journal of International Economics, 61 (1), pp.&nbsp;163-185</td>
<td style="text-align: right;">228</td>
</tr>
</tbody>
</table>
<p>As we have the affiliations, we can try to see which are the top references for economists based in different countries:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb26-1">direct_citation <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb26-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(scopus_affiliations, citing_id, country)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb26-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb26-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">group_by</span>(country) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb26-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nb_article =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb26-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(nb_article <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># we keep only countries with 5000 articles</span></span>
<span id="cb26-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_count</span>(new_id_ref) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb26-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(new_id_ref, n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb26-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">unique</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb26-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice_max</span>(n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb26-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(references, new_id_ref, references)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb26-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(references, n)  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb26-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_extract</span>(references, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">d{4}</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">)"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb26-14">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_wrap</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>),</span>
<span id="cb26-15">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> tidytext<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder_within</span>(label, n, country)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb26-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(n, label, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> country)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb26-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb26-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>country, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb26-19">  tidytext<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_reordered</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb26-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of citations"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb26-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_classic</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>)</span></code></pre></div></div>
<div class="figure">
<img src="https://aurelien-goutsmedt.com/post/extracting-biblio-data-1/index.en_files/figure-html/top-ref-country-1.png" alt="Most cited references per countries" width="1152">
<p class="caption">
<span id="fig:top-ref-country"></span>Figure 4: Most cited references per countries
</p>
</div>
<p>By using affiliations we can observe a regional preference pattern: in European countries, economists tend to cite more Smets and Wouters (2003) (the source of the European Central Bank DSGE model) than Christiano, Eichenbaum, and Evans (2005), while the opposite is true in the United States (Smets and Wouters 2007 is on US data). We can also notice that Kydland and Prescott (1982) is less popular in continental Europe.</p>
<section id="bibliographic-co-citation-analysis" class="level3">
<h3 class="anchored" data-anchor-id="bibliographic-co-citation-analysis">Bibliographic co-citation analysis</h3>
<p>To conclude this (long) tutorial, we can build a co-citation network: the references we have matched are the nodes of the network, and they are linked together depending on the number of times they are cited together (or in other words, the number of times they are together in a bibliography). We use the <code>biblio_cocitation</code> function of the <a href="https://agoutsmedt.github.io/biblionetwork/"><code>biblionetwork</code></a> package. The edge between two nodes is weighted depending of the total number of times each reference has been cited in the whole corpus (see <a href="https://agoutsmedt.github.io/biblionetwork/reference/biblio_cocitation.html">here</a> for more details).</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1">citations <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> direct_citation <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb27-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add_count</span>(new_id_ref) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb27-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(new_id_ref, n) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb27-4">  unique</span>
<span id="cb27-5"></span>
<span id="cb27-6">references_filtered <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> references <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb27-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">left_join</span>(citations) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb27-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(n <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb27-9"></span>
<span id="cb27-10">edges <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> biblionetwork<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">biblio_cocitation</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(direct_citation, new_id_ref <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> references_filtered<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>new_id_ref), </span>
<span id="cb27-11">                                          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"citing_id"</span>, </span>
<span id="cb27-12">                                          <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"new_id_ref"</span>,</span>
<span id="cb27-13">                                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight_threshold =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)</span>
<span id="cb27-14">edges</span></code></pre></div></div>
<pre><code>## Key: &lt;Source&gt;
##          from     to    weight Source Target
##        &lt;char&gt; &lt;char&gt;     &lt;num&gt;  &lt;int&gt;  &lt;int&gt;
##     1:      2      4 0.2354379      2      4
##     2:      2      5 0.1244966      2      5
##     3:      2      6 0.0518193      2      6
##     4:      2      7 0.1623352      2      7
##     5:      2     14 0.1349191      2     14
##    ---                                      
## 42657:  64761  64841 0.4045199  64761  64841
## 42658:  64841  64936 0.3481553  64841  64936
## 42659:  66416  68931 0.7453560  66416  68931
## 42660:  66416  68935 0.5039526  66416  68935
## 42661:  68931  68935 0.6761234  68931  68935</code></pre>
<p>We can then take our corpus and these edges to create a network/graph thanks to <a href="https://tidygraph.data-imaginist.com/index.html"><code>tidygraph</code></a> (Pedersen 2020) and <a href="https://github.com/agoutsmedt/networkflow"><code>networkflow</code></a>. I don’t enter in the details here as that is not the purpose of this tutorial and that the different steps are explained on <code>networkflow</code> <a href="https://github.com/agoutsmedt/networkflow">website</a>.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tbl_main_component</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nodes =</span> references_filtered, </span>
<span id="cb29-2">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">edges =</span> edges, </span>
<span id="cb29-3">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">directed =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>)</span>
<span id="cb29-4">graph</span></code></pre></div></div>
<pre><code>## # A tbl_graph: 2836 nodes and 42661 edges
## #
## # An undirected simple graph with 1 component
## #
## # A tibble: 2,836 × 18
##      Id authors      year title journal volume issue pages first_page book_title
##   &lt;int&gt; &lt;chr&gt;       &lt;int&gt; &lt;chr&gt; &lt;chr&gt;   &lt;chr&gt;  &lt;chr&gt; &lt;chr&gt; &lt;chr&gt;      &lt;chr&gt;     
## 1     2 CALVO, G.    1983 "STA… JOURNA… 12     3     383-… 383        &lt;NA&gt;      
## 2     4 DIXIT, A.,…  1977 "MON… AMERIC… 67     3     297-… 297        &lt;NA&gt;      
## 3     5 GERALI, A.…  2010 "CRE… WORKIN… 42     6     107-… 107        &lt;NA&gt;      
## 4     6 GOODFRIEND…  2007 "BAN… JOURNA… 54     5     1480… 1480       &lt;NA&gt;      
## 5     7 IACOVIELLO…  2005 "HOU… AMERIC… 95     3     739-… 739        &lt;NA&gt;      
## 6    14 ROTEMBERG,…  1982 "MON… REVIEW… 49     4     517-… 517        &lt;NA&gt;      
## # ℹ 2,830 more rows
## # ℹ 8 more variables: publisher &lt;chr&gt;, references &lt;chr&gt;, doi &lt;chr&gt;, pii &lt;chr&gt;,
## #   first_author &lt;chr&gt;, first_author_surname &lt;chr&gt;, nb_na &lt;dbl&gt;, n &lt;int&gt;
## #
## # A tibble: 42,661 × 5
##    from    to weight Source Target
##   &lt;int&gt; &lt;int&gt;  &lt;dbl&gt;  &lt;int&gt;  &lt;int&gt;
## 1     1     2 0.235       2      4
## 2     1     3 0.124       2      5
## 3     1     4 0.0518      2      6
## # ℹ 42,658 more rows</code></pre>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set.seed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1234</span>)</span>
<span id="cb31-2">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">leiden_workflow</span>(graph) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># identifying clusters of nodes </span></span>
<span id="cb31-3"></span>
<span id="cb31-4">nb_communities <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb31-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">activate</span>(nodes) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb31-6">  as_tibble <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb31-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Com_ID) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb31-8">  unique <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb31-9">  nrow</span>
<span id="cb31-10">palette <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> scico<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scico</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">n =</span> nb_communities, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">palette =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"hawaii"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># creating a color palette</span></span>
<span id="cb31-11">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sample</span>()</span>
<span id="cb31-12">  </span>
<span id="cb31-13">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">community_colors</span>(graph, palette, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">community_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Com_ID"</span>)</span>
<span id="cb31-14"></span>
<span id="cb31-15">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb31-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">activate</span>(nodes) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb31-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> n,<span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># will be used for size of nodes</span></span>
<span id="cb31-18">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(first_author_surname, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>, year)) </span>
<span id="cb31-19"></span>
<span id="cb31-20">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">community_names</span>(graph, </span>
<span id="cb31-21">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordering_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"size"</span>, </span>
<span id="cb31-22">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">naming =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"label"</span>, </span>
<span id="cb31-23">                         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">community_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Com_ID"</span>)</span>
<span id="cb31-24"></span>
<span id="cb31-25">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> vite<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">complete_forceatlas2</span>(graph, </span>
<span id="cb31-26">                                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">first.iter =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>)</span>
<span id="cb31-27"></span>
<span id="cb31-28"></span>
<span id="cb31-29">top_nodes  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">top_nodes</span>(graph, </span>
<span id="cb31-30">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordering_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"size"</span>, </span>
<span id="cb31-31">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">top_n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15</span>, </span>
<span id="cb31-32">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">top_n_per_com =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb31-33">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">biggest_community =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb31-34">                        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">community_threshold =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>)</span>
<span id="cb31-35">community_labels <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">community_labels</span>(graph, </span>
<span id="cb31-36">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">community_name_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Community_name"</span>,</span>
<span id="cb31-37">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">community_size_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Size_com"</span>,</span>
<span id="cb31-38">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">biggest_community =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb31-39">                                     <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">community_threshold =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>)</span></code></pre></div></div>
<p>A co-citation network allows us to observe what are the main influences of a field of research. At the center of the network, we find the most cited references. On the borders of the graph, there are specific communities that influence different parts of the literature on DSGE. Here, the size of nodes depends on the number of times they are cited in our corpus.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb32-1">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb32-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">activate</span>(edges) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb32-3">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(weight <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>)</span>
<span id="cb32-4"></span>
<span id="cb32-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggraph</span>(graph, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"manual"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb32-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_edge_arc0</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> color_edges, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> weight), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">strength =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_edge_width_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">range =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_edge_colour_identity</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_node_point</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> size, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> color), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_size_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">range =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_identity</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-12">  ggnewscale<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">new_scale</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"size"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-13">  ggrepel<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text_repel</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> top_nodes, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> Label), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontface=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">point.padding=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-14">  ggrepel<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_label_repel</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data =</span> community_labels, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> Community_name, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> color), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontface=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">point.padding=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_size_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">range =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb32-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_void</span>()</span></code></pre></div></div>
<div class="figure">
<img src="https://aurelien-goutsmedt.com/post/extracting-biblio-data-1/featured.png" alt="Bibliographic coupling network of articles using DSGE models" width="1181">
<p class="caption">
<span id="fig:display-network"></span>Figure 5: Bibliographic coupling network of articles using DSGE models
</p>
</div>
<p>Let’s conclude by observing what are the most cited nodes in each community. We see that community <code>04</code> deals with international issues while the <code>07</code> is linked to fiscal policy issues.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1">ragg<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">agg_png</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">here</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"content"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"en"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"post"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"2022-01-31-extracting-biblio-data-1"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"top-ref-country-1.png"</span>),</span>
<span id="cb33-2">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>, </span>
<span id="cb33-3">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">height =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span>,</span>
<span id="cb33-4">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">units =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cm"</span>,</span>
<span id="cb33-5">              <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">res =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>)</span>
<span id="cb33-6"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">top_nodes</span>(graph,</span>
<span id="cb33-7">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordering_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"size"</span>, </span>
<span id="cb33-8">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">top_n_per_com =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>,</span>
<span id="cb33-9">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">biggest_community =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb33-10">          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">community_threshold =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.04</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb33-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(Community_name, Label, title, n, color) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb33-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Label, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>, title) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb33-13">           <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">str_wrap</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">34</span>),</span>
<span id="cb33-14">         <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> tidytext<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reorder_within</span>(label, n, Community_name)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb33-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(n, label, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> color)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_col</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-17">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_identity</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-18">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">facet_wrap</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">~</span>Community_name, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scales =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"free"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-19">  tidytext<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_y_reordered</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-20">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labs</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of citations"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb33-21">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_classic</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">base_size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">11</span>)</span>
<span id="cb33-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">invisible</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dev.off</span>())</span></code></pre></div></div>
<div class="figure">
<img src="https://aurelien-goutsmedt.com/post/extracting-biblio-data-1/top-ref-country-1.png" alt="Most cited references per communities" width="1378">
<p class="caption">
<span id="fig:top-ref-community-plot"></span>Figure 6: Most cited references per communities
</p>
</div>
</section>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-christianoetal2005" class="csl-entry">
Christiano, Lawrence J., Martin Eichenbaum, and Charles L. Evans. 2005. “Nominal Rigidities and the Dynamic Effects of a Shock to Monetary Policy.” <em>Journal of Political Economy</em> 113 (1): 1–45.
</div>
<div id="ref-devroey2016d" class="csl-entry">
De Vroey, Michel. 2016. <em>A History of Macroeconomics from Keynes to Lucas and Beyond</em>. Cambridge: Cambridge University Press.
</div>
<div id="ref-R-biblionetwork" class="csl-entry">
Goutsmedt, Aurélien, François Claveau, and Alexandre Truc. 2021. <em>Biblionetwork: Create Different Types of Bibliometric Networks</em>.
</div>
<div id="ref-kydland1982" class="csl-entry">
Kydland, Finn E., and Edward C. Prescott. 1982. “Time to Build and Aggregate Fluctuations.” <em>Econometrica: Journal of the Econometric Society</em> 50 (6): 1345–70.
</div>
<div id="ref-R-tidygraph" class="csl-entry">
Pedersen, Thomas Lin. 2020. <em>Tidygraph: A Tidy API for Graph Manipulation</em>. <a href="https://CRAN.R-project.org/package=tidygraph" class="uri">https://CRAN.R-project.org/package=tidygraph</a>.
</div>
<div id="ref-sergi2020" class="csl-entry">
Sergi, Francesco. 2020. “The Standard Narrative about DSGE Models in Central Banks’ Technical Reports.” <em>The European Journal of the History of Economic Thought</em> 27 (2): 163–93.
</div>
<div id="ref-smets2003a" class="csl-entry">
Smets, Frank, and Raf Wouters. 2003. “An Estimated Dynamic Stochastic General Equilibrium Model of the Euro Area.” <em>Journal of the European Economic Association</em> 1 (5): 1123–75.
</div>
<div id="ref-smets2007a" class="csl-entry">
Smets, Frank, and Rafael Wouters. 2007. “Shocks and Frictions in US Business Cycles: A Bayesian DSGE Approach.” <em>American Economic Review</em> 97 (3): 586–606.
</div>
<div id="ref-vines2018" class="csl-entry">
Vines, David, and Samuel Wills. 2018. “The Rebuilding Macroeconomic Theory Project: An Analytical Assessment.” <em>Oxford Review of Economic Policy</em> 34 (1-2): 1–42. <a href="https://doi.org/10.1093/oxrep/grx062" class="uri">https://doi.org/10.1093/oxrep/grx062</a>.
</div>
<div id="ref-R-tidyverse" class="csl-entry">
Wickham, Hadley. 2021. <em>Tidyverse: Easily Install and Load the Tidyverse</em>. <a href="https://CRAN.R-project.org/package=tidyverse" class="uri">https://CRAN.R-project.org/package=tidyverse</a>.
</div>
<div id="ref-tidyverse2019" class="csl-entry">
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy D’Agostino McGowan, Romain François, Garrett Grolemund, et al.&nbsp;2019. “Welcome to the <span class="nocase">tidyverse</span>.” <em>Journal of Open Source Software</em> 4 (43): 1686. <a href="https://doi.org/10.21105/joss.01686" class="uri">https://doi.org/10.21105/joss.01686</a>.
</div>
</div>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Don’t worry if you don’t understand regex at the beginning, that is a good occasion to learn and to practice. You can find simpler examples <a href="https://stringr.tidyverse.org/articles/regular-expressions.html">here</a> and learn <code>stringr</code> by the same occasion.↩︎</p></li>
<li id="fn2"><p>For reflexive and historical discussions of DSGE models, see De Vroey (2016, chap.&nbsp;20), Vines and Wills (2018) and Sergi (2020).↩︎</p></li>
<li id="fn3"><p>Normally, you won’t be able to download all the data in one extraction as there is a 2000 items limit, and thus you will need to do it in two steps. The easiest is to filter by year.↩︎</p></li>
<li id="fn4"><p>We remove all <code>citations</code> <code>data.frames</code> that are empty (i.e.&nbsp;when an article cites nothing).↩︎</p></li>
<li id="fn5"><p>I will try to check that for another tutorial on bibliometric data, but I observed that I got fewer citations with the API method than with the Scopus website method. It means perhaps that if Scopus has not been able to give an identifier to a reference (perhaps because of not sufficiently clean metadata), the citation of this reference is removed from the data. Consequently, if our cleaning method is good, we could be able to keep more citations and thus to keep references that could be excluded in the APIs data extraction.↩︎</p></li>
<li id="fn6"><p>I have perhaps forget some useful combinations.↩︎</p></li>
<li id="fn7"><p>Most of the differences are due to the authors’ initials: some reference have only one when others have two initials for some authors.↩︎</p></li>
<li id="fn8"><p>In case you want to know more on the different commands of anystyle, see the <a href="https://rubydoc.info/gems/anystyle">API documentation</a>.↩︎</p></li>
<li id="fn9"><p>As I find anystyle a very interesting tool, I will try to work on that issue in the following months and find a solution. An easy way to do it would perhaps be to save one <code>.txt</code> per citing article and to run anystyle for all the <code>.txt</code>. We will have as many <code>.bib</code> as articles and we will just have to bind the resulting <code>data.frames</code>.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Bibliometrics</category>
  <category>Network Analysis</category>
  <category>R Tutorials</category>
  <guid>https://aurelien-goutsmedt.com/post/extracting-biblio-data-1/</guid>
  <pubDate>Sun, 30 Jan 2022 23:00:00 GMT</pubDate>
  <media:content url="https://aurelien-goutsmedt.com/post/extracting-biblio-data-1/featured.png" medium="image" type="image/png" height="120" width="144"/>
</item>
<item>
  <title>A Road Map for historians of economics to learn R</title>
  <dc:creator>Aurélien Goutsmedt</dc:creator>
  <link>https://aurelien-goutsmedt.com/post/roadmap-quantitative-hpe/</link>
  <description><![CDATA[ 





<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>This post will be progressively extended with new useful resources.</p>
</div>
</div>
<section id="why-learning-r" class="level2">
<h2 class="anchored" data-anchor-id="why-learning-r">Why learning R?</h2>
<p>Debates about the use of quantitative methods when studying the history of economics have flourished in the last years—see for instance the special issue in the <em>Journal of Economic Methodology</em> (Edwards, Giraud, and Schinckus 2018)—and many recent contributions have used bibliometrics, network analysis or topic-modelling.<sup>1</sup> When the temptation is growing in you to try your hand at quantitative methods (as it has been the case for me a couple of years ago), the first question is likely to be “but how can I do, and which tools should I learn to use?”</p>
<p>It exists many software (some free, others to buy) that would allow you to use bibliometrics, networks analysis or topic-modelling. Depending on what you want to do, you will have to learn each corresponding software—after being sure that the tool is appropriate to accomplish the task you have in mind. That is what I did when I wanted to use network analysis for one of my <a href="../../publications/">paper</a>: I learned how to use the very good <a href="https://gephi.org/">GEPHI</a>. However, Gephi is great when you want to manipulate networks, but at the condition that you have already built your network. And if you want to use other types of quantitative analysis on your data (for instance text analysis and topic-modelling), you will need to find another software. That is why, after this first research project integrating quantitative methods, I took another direction: I learned to program in R.<sup>2</sup></p>
<p>Obviously, learning R has a higher entry cost than learning GEPHI—2 or 3 hours should be sufficient to learn the basics of the latter. But it offers many advantages and, in the medium- and long-term, large economies of scale:</p>
<ul>
<li><p>It would allow you to manipulate more easily and more quickly your data than by using excel (either programmatically or manually). You will be able to do things you cannot do in excel. And this becomes more and more true the larger your dataset.</p></li>
<li><p>You will be able to use different quantitative methods (bibliometrics, network analysis, natural language processing, econometrics, machine learning, <em>etc.</em>) and to build visualisations just by learning one unique language (thanks to the many packages implemented in R).</p></li>
<li><p>Writing “scripts” in R allows you to re-run the same tasks without any supplementary effort each time your data are changing or you want to change a parameter of your analysis. Besides, these scripts are a resource that you will be able to re-use in other projects.</p></li>
<li><p>Outside of quantitative methods strictly speaking, learning R will enable you to do several other things:</p>
<ul>
<li>writing books, articles, reports and slides efficiently thanks to <a href="https://rmarkdown.rstudio.com/">Rmarkdown</a> (Allaire et al.&nbsp;2021);</li>
<li>publishing online your analyses and building dashboards and applications.<sup>3</sup></li>
</ul></li>
</ul>
<p>If you are convinced that programming in R could be useful for you as a historian of economics, you now need some resources to learn to code. Here is a list of useful packages and tutorials I wish I had when I started learning to program in R and which I have used extensively since then to improve my skills.</p>
</section>
<section id="first-step-the-basics" class="level2">
<h2 class="anchored" data-anchor-id="first-step-the-basics">First step: the basics</h2>
<p>The very first step is obviously to download and install R and Rstudio on your computer, and to understand the basics of R language and how to use Rstudio. The <a href="https://moderndive.netlify.app/1-getting-started.html">first chapter</a> of McConville (2021) or this <a href="https://rladiessydney.org/courses/ryouwithme/01-basicbasics-0/">lesson</a> from <a href="https://rladiessydney.org/">R-ladies Sydney</a> are good places to start from.</p>
<p>Once you are a bit familiar with what R is and the functioning of Rstudio, I think the priority is then to become familiar with the <a href="https://www.tidyverse.org/">tydiverse</a> collection of packages (Wickham 2021a; Wickham et al.&nbsp;2019). A very reliable guide here is obviously Wickham and Gromelund’s (2017) <a href="https://r4ds.had.co.nz/index.html">R for Data Science</a>. In this book, you will learn how to import data, how to transform them, how to visualise them and how to apply statistical models to them.<sup>4</sup>.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>A good way to learn actively and interactively is to try some lines of code on your own data. That is something that helped me to learn quickly (and to learn eagerly). I tried my hand at data wrangling and visualisations on the prosopographic database I was building for the collective <a href="../../projects/excavating-academia-policy/">project on the Bank of England</a> I was involved in.</p>
</div>
</div>
<p>Another useful detour when you have progressively learned the basics of R, is to understand how to organise your workflow with R and Rstudio (how to organise your files? Why and how to create an “RStudio project”?): you can find useful information in the <a href="https://stat545.com/r-basics.html">second chapter</a> of Jenny Bryan (2017). I don’t want to overload the boat too soon, but when you will have begun your first project, it could be useful to learn the basis of version control and <a href="https://git-scm.com/">git</a>. That is something that will be indispensable when you will work collectively on a project in Rstudio. Because using git is not very intuitive and because you will probably tear your hair out at first, it is better to become accustomed to use git from the beginning even (and above all?) when you are working alone. You will be confronted to simple cases and you will be less afraid to use git versioning in collective projects then. Jennyfer Bryan (2019) offers a <a href="https://happygitwithr.com/">rich documentation</a> to learn to use git and <a href="https://github.com/">github</a>—the latter being fundamental to share your code and give explanations on the projects you are working on.<sup>5</sup></p>
<p>R offers great tools for building a large variety of visualisations. The package <a href="https://ggplot2.tidyverse.org/">ggplot2</a> (Wickham et al.&nbsp;2021; Wickham 2016) is obviously the first of these tools, and you can find a dense documentation <a href="https://ggplot2-book.org/">here</a>. Kieran Healy’s (2018) book is also a good read to learn <em>ggplot2</em> while thinking about the best practices to build data visualisations. One of the advantages of the ggplot2 is that it is accompanied by many extensions (new types of visualisations, tools to customize in different ways the visualisations produced with <em>ggplot2</em>, new themes and colour palettes, animation, <em>etc</em>) listed <a href="https://exts.ggplot2.tidyverse.org/gallery/">here</a>. I acknowledge that learning this “grammar of graphics” is far from easy at the beginning, for you will have to know many functions and take into account many features when producing quantitative visualisations. The <a href="https://dreamrs.github.io/esquisse/articles/get-started.html">esquisse</a> extension (Meyer and Perrier 2021) could allow you to reduce the cost of entry and to get used to the functions of <em>ggplot2</em> gradually: it is an Rstudio add-in that allows you to build interactively your visualisations.</p>
<p>If you want to produce dynamic and interactive visualisations, the package <a href="https://plotly.com/r/">plotly</a> (Sievert et al.&nbsp;2021; Sievert 2020) offers many possibility. The advantage of <em>plotly</em> is that, for some basic features, you can convert the visualisation produced with <em>ggplot2</em> to interactive visualisations with just one line of code. But <em>plotly</em> for R also allows more complex customisation that necessitate to investigate more in-depth the different functions of the package (see a detailed documentation <a href="https://plotly-r.com/">here</a>).</p>
<p>This is it for the basics: obviously, you won’t master all the packages above in one day, and you will progressively get the hang of them in working on your own research project. However, you will likely need most of them in all the quantitative projects you will start, whether you want to do some simple statistical analysis on a prosopographic database of economists trained at the MIT, a comparison of the words used by Adam Smith and David Ricardo, or a bibliometric analysis of the publications about discrimination in economic academic journals. The following tools I will present you target more specific uses.</p>
</section>
<section id="learning-bibliometrics-and-network-analysis" class="level2">
<h2 class="anchored" data-anchor-id="learning-bibliometrics-and-network-analysis">Learning bibliometrics and network analysis</h2>
<p>Bibliometrics is useful for historians of economics to understand how the discipline has evolved, what are the major influences for specific sub-fields, how different communities have structured the discipline at different periods, <em>etc</em>.<sup>6</sup> Network analysis comes as a complement of bibliometrics to produce bibliographic coupling, co-citation, keyword or co-authorship networks.</p>
<p>A first package, <a href="https://www.bibliometrix.org/">bibliometrix</a>, offers different functions from extracting bibliometric data from different platforms (like Web of Science or Scopus), to computing statistics and building networks. I have never used it extensively, for two reasons:</p>
<ol type="1">
<li>I was working on large sets of data and <em>bibliometrix</em> appeared a bit slow for that;</li>
<li>I found the functions a bit like black boxes, and not really compatible with the <em>tidyverse</em> spirit. However, it seems very rich and I am sure it worth exploring.</li>
</ol>
<p>Once you have your data—which is far from being an easy step<sup>7</sup>—I have developed, with the help of <a href="https://sites.google.com/view/alexandre-truc/home-and-contact">Alexandre Truc</a> and <a href="https://www.epistemopratique.org/en/">François Claveau</a>, a package to make the creation of very large networks of bibliographic data easy and fast: <a href="https://agoutsmedt.github.io/biblionetwork/">biblionetwork</a> (Goutsmedt, Truc, and Claveau 2023). What you need as an input is a corpus and the references cited by this corpus, and you will be able to create easily a list of links between articles, references, authors, institutions, <em>etc.</em>, with different measures of weights for these links.</p>
<p>Once you have your edges/links, you can create a network with the help of the <a href="https://igraph.org/r/">igraph</a> package (Csardi and Nepusz 2006). <em>igraph</em> is a very rich package with many functions to calculate network statistics (like centrality measures), find clusters and arrange the nodes in space. However, manipulating networks with <em>igraph</em> is not always very intuitive. Fortunately, the <a href="https://tidygraph.data-imaginist.com/">tidygraph</a> package (Pedersen 2020) allows you to transform the networks in “tidy” data, in the <em>tidyverse</em> spirit, and to manipulate the networks accordingly. Similarly, the <a href="https://ggraph.data-imaginist.com/">ggraph</a> package (Pedersen 2021), which is an extension of <em>ggplot2</em>, allows the production of nice network visualisations.</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/roadmap-quantitative-hpe/example-graph.png" alt="Network example from the Mapping Macroeconomics project" width="1772">
<p class="caption">
<span id="fig:unnamed-chunk-1"></span>Figure 1: Network example from the Mapping Macroeconomics project
</p>
</div>
<p>Alexandre Truc and I are currently developing another package, <a href="https://github.com/agoutsmedt/networkflow">networkflow</a>, to facilitate the manipulation of networks, thanks to <em>tidygraph</em> and <em>ggraph</em>. The goal is to build some routines to mark out and accelerate the analysis of networks, from network creation, through clustering and spatialisation, to visualisation. In a close future, the package will integrate some tools for dynamic network analysis (by comparing the evolution of different networks over time).</p>
</section>
<section id="try-your-hand-at-text-mining-and-topic-modelling" class="level2">
<h2 class="anchored" data-anchor-id="try-your-hand-at-text-mining-and-topic-modelling">Try your hand at text mining and topic modelling</h2>
<p>Text mining is an essential approach to analyse large corpus and thus can bring useful information for historians of economics.</p>
<p>The first step is to transform the text of your documents in readable data in R. It first implies that the text of your documents is recognisable. To check that, you can just copy the text of a random page of your corpus and paste it on a text editor. If the text is not recognisable, or if the quality is not good, you should run <a href="https://en.wikipedia.org/wiki/Optical_character_recognition">Optical Character Recognition</a>. In my former projects, I have used a very efficient OCR via a purchased software, <a href="https://pdf.wondershare.fr/">PDF Element</a>. I found it better than the <a href="https://github.com/tesseract-ocr/tesseract">tesseract</a> OCR engine. However, I did not push the possibilities of the engine to the end. <em>tesseract</em> has been implemented in R in a <a href="https://docs.ropensci.org/tesseract/">package</a> (Ooms 2021b). If you have pdf and that the text recognition is good, you can use the <a href="https://docs.ropensci.org/pdftools/">pdftools</a> package (Ooms 2021a) to extract the text and manipulate it with R.</p>
<p>Once you have the text of your corpus ready to be imported in R, you can begin the analysis. Julia Silge and David Robinson (2020) have written a great <a href="https://www.tidytextmining.com/index.html">introductory book</a> to text mining in R. It relies on the <a href="">tidytext</a> package (Robinson and Silge 2021; Silge and Robinson 2016), which brings simple functions to do complicated things (tokenizing texts, calculating statistics like <a href="https://en.wikipedia.org/wiki/Tf%E2%80%93idf">TF-IDF</a>, <em>etc.</em>). If you want to know more about tokenization, stemming and lemmatization, stop words, or words embeddings, you can move to the next step and read the first part of <a href="https://smltar.com/">Supervised Machine Learning for Text Analysis in R</a> (Silge and Hvitfeldt 2021).</p>
<p>Once you have acquired some mastery for extracting text, cleaning and preprocessing it, and calculating standard statistics, you can be interested by more complex techniques and machine learning. Here, topic modelling can offer very rich results. It refers to the use of a model (the Latent Dirichlet Allocation being the most used) to identify <em>k</em> topics (<em>k</em> being determined by the modeller) in your corpus. The result of your topic modelling is that you will have each document of your corpus represented as a mixture of topics, and each topic represented as a mixture of words. To run topic modelling in R, you will find interesting information in Silge and Robinson’s (2020) corresponding <a href="https://www.tidytextmining.com/topicmodeling.html">chapter</a>. In this chapter, they are using the <em>topicmodels</em> package (Grün and Hornik 2021, 2011).<sup>8</sup> But I find that the <a href="https://cran.r-project.org/web/packages/stm/vignettes/stmVignette.pdf">stm</a> package (Roberts, Stewart, and Tingley 2020) is also very useful with very nice functions implemented in it. It allows you to cross your topic modelling with the meta data of your corpus.</p>
<p>Finally, to help you running topic modelling in R (but also for other text mining issues), you can check the tips and good practices discussed by Welbers, Van Atteveldt, and Benoit (2017) or Banks et al.&nbsp;(2018). More generally, R offers many resources for text mining and Natural Language Processing (NLP): you can find an overview of the different existing packages <a href="https://www.bnosac.be/index.php/blog/87-an-overview-of-the-nlp-ecosystem-in-r-nlproc-textasdata">here</a>.</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/roadmap-quantitative-hpe/NLP-R-ecosystem.png" alt="Natural Language Processing ecosystem in R" width="2116">
<p class="caption">
<span id="fig:unnamed-chunk-2"></span>Figure 2: Natural Language Processing ecosystem in R
</p>
</div>
</section>
<section id="digging-into-modelling-and-machine-learning" class="level2">
<h2 class="anchored" data-anchor-id="digging-into-modelling-and-machine-learning">Digging into modelling and machine learning</h2>
<p>I am not a specialist of modelling and machine learning at all, but I hope I will have the occasion to train myself in the next years. Indeed, there are many occasions it can be useful for historians. If you want to refresh your memory in econometrics why learning R, you can look at Schmelzer’s (2021) book that you can read <a href="https://www.econometrics-with-r.org/">online</a>. Regarding machine learning, which can have numerous applications in history of economics, notably with classification techniques, I found that Greenwell (2020) offers a nice introduction to the implementation in R of different machine learning algorithms—you can read it <a href="https://bradleyboehmke.github.io/HOML/">here</a>.</p>
<p>To help R users in their modelling job, the <a href="https://www.tidymodels.org/">tidymodels</a> collection of packages can be very useful, whether for preprocessing your data, evaluating your model or tuning your parameters. The website has also many interesting tutorials to learn the <em>tidymodels</em> approach.</p>
</section>
<section id="programming-further-functions-functions-functions-and-packages" class="level2">
<h2 class="anchored" data-anchor-id="programming-further-functions-functions-functions-and-packages">Programming further: Functions, functions, functions… and packages</h2>
<p>Once you move forward in mastering these different methods and improve your skills in R coding, an important task is to solidify your code and make it reliable for future work. The first step when writing code, is to document it: give your script a clear structure, explain why your are using this function, keep a trace of failed paths, point out what you could improve, <em>etc</em>. This could be useful for collaborators or readers of your scripts, but above all it will be useful for future you, as a messy script is the best way to lose a lot of time two or three months later when you will have to come back to your project (for instance after having received referees’ reports on your paper). You can find some useful advice <a href="https://style.tidyverse.org/index.html">here</a> about structuring your script and naming objects. As Wickham and Grolemund (2017) explain <a href="https://r4ds.had.co.nz/program-intro.html">here</a>, it is also quite useful to come back to your script and to rewrite it to make it simpler and clearer.</p>
<p>An important step in this rewriting is to transform some of your code in functions. A good general rule is that if your are copying and pasting the same part of your code more than twice, it could be useful to transform it into a function. You will find useful content about how to program functions properly in Wickham (2019), beginning by the <a href="https://r4ds.had.co.nz/functions.html">chapter on functions</a>.<sup>9</sup></p>
<p>If you have a set of functions that you are using regularly in one or several of your projects, you should consider writing a package. Even if you do not plan initially to share your code, writing a package is a good discipline for writing good code and for reproducibility. Later on, it would be useful for circulating your code and, perhaps, if you are satisfied with the result and think it could be useful to other R coders, you will want to publish it on <a href="https://cran.r-project.org/">CRAN</a>. For writing a package, Wickham and Bryan (2021) offers an essential guide that you can also find online <a href="https://r-pkgs.org/index.html">here</a>. If you want to share your package, the <a href="https://pkgdown.r-lib.org/">pkgdown</a> helps you to build easily a website documenting your package.</p>
</section>
<section id="writing-and-disseminating-your-work-with-r-mardown" class="level2">
<h2 class="anchored" data-anchor-id="writing-and-disseminating-your-work-with-r-mardown">Writing and disseminating your work with R Mardown</h2>
<p>Finally, you will probably need to circulate and publish your results. Fortunately, <a href="https://rmarkdown.rstudio.com/">R Markdown</a> is the perfect tool to do it. Outside of being able to run code within your R markdown document and thus to display the results, it offers many advantages like bibliographic management and <a href="https://www.zotero.org/">Zotero</a> integration.<sup>10</sup> It allows you to build <em>html</em>, as well as <em>pdf</em> and <em>word</em> documents. For <em>pdf</em>, it relies on <a href="https://www.latex-project.org/">LaTeX</a> and uses <a href="https://pandoc.org/">Pandoc</a> for conversion from the <a href="https://en.wikipedia.org/wiki/Markdown">markdown language</a>.<sup>11</sup> With <em>R Markdown</em>, you will be able to write (automatised) reports and <a href="https://pkgs.rstudio.com/flexdashboard/index.html">dashboards</a>, academic articles, books and thesis dissertation (Xie 2021, 2016), slides, and even build you own website (Xie, Dervieux, and Presmanes Hill 2021; Xie, Hill, and Thomas 2017) and applications (Chang et al.&nbsp;2021; Wickham 2021b).</p>
<p>To learn to use <em>R Markdown</em>, you can refer to Xie, Allaire, and Grolemund (2018) and Riederer, Xie, and Dervieux (2021) with the corresponding website <a href="https://bookdown.org/yihui/rmarkdown/">here</a> and <a href="https://bookdown.org/yihui/rmarkdown-cookbook/">here</a>.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>You can find more tutorials thanks to the very large list in the <a href="https://www.bigbookofr.com/index.html">Big Book of R</a>.</p>
</div>
</div>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-R-rmarkdown" class="csl-entry">
Allaire, JJ, Yihui Xie, Jonathan McPherson, Javier Luraschi, Kevin Ushey, Aron Atkins, Hadley Wickham, Joe Cheng, Winston Chang, and Richard Iannone. 2021. <em>Rmarkdown: Dynamic Documents for r</em>. <a href="https://CRAN.R-project.org/package=rmarkdown" class="uri">https://CRAN.R-project.org/package=rmarkdown</a>.
</div>
<div id="ref-banks2018" class="csl-entry">
Banks, George C., Haley M. Woznyj, Ryan S. Wesslen, and Roxanne L. Ross. 2018. “A Review of Best Practice Recommendations for Text Analysis in R (and a User-Friendly App).” <em>Journal of Business and Psychology</em> 33 (4): 445–59. <a href="https://doi.org/10.1007/s10869-017-9528-3" class="uri">https://doi.org/10.1007/s10869-017-9528-3</a>.
</div>
<div id="ref-bryan2017" class="csl-entry">
Bryan, Jenny. 2017. <em>STAT 545: Data Wrangling, Exploration, and Analysis with R.</em>
</div>
<div id="ref-bryan2019" class="csl-entry">
Bryan, Jennyfer. 2019. <em>Happy Git and GitHub for the <span class="nocase">useR</span></em>.
</div>
<div id="ref-R-shiny" class="csl-entry">
Chang, Winston, Joe Cheng, JJ Allaire, Carson Sievert, Barret Schloerke, Yihui Xie, Jeff Allen, Jonathan McPherson, Alan Dipert, and Barbara Borges. 2021. <em>Shiny: Web Application Framework for r</em>. <a href="https://shiny.rstudio.com/" class="uri">https://shiny.rstudio.com/</a>.
</div>
<div id="ref-claveau2016" class="csl-entry">
Claveau, François, and Yves Gingras. 2016. “Macrodynamics of Economics: A Bibliometric History.” <em>History of Political Economy</em>, January.
</div>
<div id="ref-igraph2006" class="csl-entry">
Csardi, Gabor, and Tamas Nepusz. 2006. “The Igraph Software Package for Complex Network Research.” <em>InterJournal</em> Complex Systems: 1695. <a href="https://igraph.org" class="uri">https://igraph.org</a>.
</div>
<div id="ref-R-datatable" class="csl-entry">
Dowle, Matt, and Arun Srinivasan. 2021. <em>Data.table: Extension of ‘Data.frame‘</em>. <a href="https://CRAN.R-project.org/package=data.table" class="uri">https://CRAN.R-project.org/package=data.table</a>.
</div>
<div id="ref-edwards2018" class="csl-entry">
Edwards, José, Yann Giraud, and Christophe Schinckus. 2018. “A Quantitative Turn in the Historiography of Economics?” <em>Journal of Economic Methodology</em> 25 (4): 283–90. <a href="https://doi.org/10.1080/1350178X.2018.1529133" class="uri">https://doi.org/10.1080/1350178X.2018.1529133</a>.
</div>
<div id="ref-goutsmedt_2023_7677369" class="csl-entry">
Goutsmedt, Aurélien, Alexandre Truc, and François Claveau. 2023. “<span class="nocase">biblionetwork: An R Package for Creating Different Types of Bibliometric Networks</span>.” Zenodo. <a href="https://doi.org/10.5281/zenodo.7677369" class="uri">https://doi.org/10.5281/zenodo.7677369</a>.
</div>
<div id="ref-greenwell2020" class="csl-entry">
Greenwell, Bradley Boehmke &amp; Brandon. 2020. <em>Hands-On Machine Learning with R</em>.
</div>
<div id="ref-topicmodels2011" class="csl-entry">
Grün, Bettina, and Kurt Hornik. 2011. “<span class="nocase">topicmodels</span>: An R Package for Fitting Topic Models.” <em>Journal of Statistical Software</em> 40 (13): 1–30. <a href="https://doi.org/10.18637/jss.v040.i13" class="uri">https://doi.org/10.18637/jss.v040.i13</a>.
</div>
<div id="ref-R-topicmodels" class="csl-entry">
———. 2021. <em>Topicmodels: Topic Models</em>. <a href="https://CRAN.R-project.org/package=topicmodels" class="uri">https://CRAN.R-project.org/package=topicmodels</a>.
</div>
<div id="ref-healy2018" class="csl-entry">
Healy, Kieran. 2018. <em>Data Visualization: A Practical Introduction</em>. Princeton, NJ: Princeton University Press.
</div>
<div id="ref-herfeld2019" class="csl-entry">
Herfeld, Catherine, and Malte Doehne. 2019. “The Diffusion of Scientific Innovations: A Role Typology.” <em>Studies in History and Philosophy of Science Part A</em> 77 (October): 64–80. <a href="https://doi.org/10.1016/j.shpsa.2017.12.001" class="uri">https://doi.org/10.1016/j.shpsa.2017.12.001</a>.
</div>
<div id="ref-mcconville2021" class="csl-entry">
McConville, Chester Ismay and Albert Y. Kim Foreword by Kelly S. 2021. <em>Statistical Inference via Data Science</em>.
</div>
<div id="ref-R-esquisse" class="csl-entry">
Meyer, Fanny, and Victor Perrier. 2021. <em>Esquisse: Explore and Visualize Your Data Interactively</em>.
</div>
<div id="ref-R-pdftools" class="csl-entry">
Ooms, Jeroen. 2021a. <em>Pdftools: Text Extraction, Rendering and Converting of PDF Documents</em>. <a href="https://CRAN.R-project.org/package=pdftools" class="uri">https://CRAN.R-project.org/package=pdftools</a>.
</div>
<div id="ref-R-tesseract" class="csl-entry">
———. 2021b. <em>Tesseract: Open Source OCR Engine</em>.
</div>
<div id="ref-R-tidygraph" class="csl-entry">
Pedersen, Thomas Lin. 2020. <em>Tidygraph: A Tidy API for Graph Manipulation</em>. <a href="https://CRAN.R-project.org/package=tidygraph" class="uri">https://CRAN.R-project.org/package=tidygraph</a>.
</div>
<div id="ref-R-ggraph" class="csl-entry">
———. 2021. <em>Ggraph: An Implementation of Grammar of Graphics for Graphs and Networks</em>. <a href="https://CRAN.R-project.org/package=ggraph" class="uri">https://CRAN.R-project.org/package=ggraph</a>.
</div>
<div id="ref-riederer2021" class="csl-entry">
Riederer, Emily, Yihui Xie, and Christophe Dervieux. 2021. <em>R Markdown Cookbook</em>.
</div>
<div id="ref-R-stm" class="csl-entry">
Roberts, Margaret, Brandon Stewart, and Dustin Tingley. 2020. <em>Stm: Estimation of the Structural Topic Model</em>. <a href="http://www.structuraltopicmodel.com/" class="uri">http://www.structuraltopicmodel.com/</a>.
</div>
<div id="ref-robinson2020" class="csl-entry">
Robinson, David, and Julia Silge. 2020. <em>Text Mining with R</em>.
</div>
<div id="ref-R-tidytext" class="csl-entry">
———. 2021. <em>Tidytext: Text Mining Using Dplyr, Ggplot2, and Other Tidy Tools</em>. <a href="https://github.com/juliasilge/tidytext" class="uri">https://github.com/juliasilge/tidytext</a>.
</div>
<div id="ref-schmelzer2021" class="csl-entry">
Schmelzer, Alexander Gerber, Martin Arnold. 2021. <em>Introduction to Econometrics with R</em>.
</div>
<div id="ref-plotly2020" class="csl-entry">
Sievert, Carson. 2020. <em>Interactive Web-Based Data Visualization with r, Plotly, and Shiny</em>. Chapman; Hall/CRC. <a href="https://plotly-r.com" class="uri">https://plotly-r.com</a>.
</div>
<div id="ref-R-plotly" class="csl-entry">
Sievert, Carson, Chris Parmer, Toby Hocking, Scott Chamberlain, Karthik Ram, Marianne Corvellec, and Pedro Despouy. 2021. <em>Plotly: Create Interactive Web Graphics via Plotly.js</em>. <a href="https://CRAN.R-project.org/package=plotly" class="uri">https://CRAN.R-project.org/package=plotly</a>.
</div>
<div id="ref-silge2021" class="csl-entry">
Silge, Julia, and Emil Hvitfeldt. 2021. <em>Supervised Machine Learning for Text Analysis in R</em>.
</div>
<div id="ref-tidytext2016" class="csl-entry">
Silge, Julia, and David Robinson. 2016. “Tidytext: Text Mining and Analysis Using Tidy Data Principles in r.” <em>JOSS</em> 1 (3). <a href="https://doi.org/10.21105/joss.00037" class="uri">https://doi.org/10.21105/joss.00037</a>.
</div>
<div id="ref-welbers2017a" class="csl-entry">
Welbers, Kasper, Wouter Van Atteveldt, and Kenneth Benoit. 2017. “Text Analysis in R.” <em>Communication Methods and Measures</em> 11 (4): 245–65. <a href="https://doi.org/10.1080/19312458.2017.1387238" class="uri">https://doi.org/10.1080/19312458.2017.1387238</a>.
</div>
<div id="ref-ggplot22016" class="csl-entry">
Wickham, Hadley. 2016. <em>Ggplot2: Elegant Graphics for Data Analysis</em>. Springer-Verlag New York. <a href="https://ggplot2.tidyverse.org" class="uri">https://ggplot2.tidyverse.org</a>.
</div>
<div id="ref-wickham2019" class="csl-entry">
———. 2019. <em>Advanced R, Second Edition</em>. 2nd edition. Boca Raton: Chapman and Hall/CRC.
</div>
<div id="ref-R-tidyverse" class="csl-entry">
———. 2021a. <em>Tidyverse: Easily Install and Load the Tidyverse</em>. <a href="https://CRAN.R-project.org/package=tidyverse" class="uri">https://CRAN.R-project.org/package=tidyverse</a>.
</div>
<div id="ref-wickham2021b" class="csl-entry">
———. 2021b. <em>Welcome | Mastering Shiny</em>.
</div>
<div id="ref-tidyverse2019" class="csl-entry">
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy D’Agostino McGowan, Romain François, Garrett Grolemund, et al.&nbsp;2019. “Welcome to the <span class="nocase">tidyverse</span>.” <em>Journal of Open Source Software</em> 4 (43): 1686. <a href="https://doi.org/10.21105/joss.01686" class="uri">https://doi.org/10.21105/joss.01686</a>.
</div>
<div id="ref-wickham2021a" class="csl-entry">
Wickham, Hadley, and Jennifer Bryan. 2021. <em>Welcome! | R Packages</em>.
</div>
<div id="ref-R-ggplot2" class="csl-entry">
Wickham, Hadley, Winston Chang, Lionel Henry, Thomas Lin Pedersen, Kohske Takahashi, Claus Wilke, Kara Woo, Hiroaki Yutani, and Dewey Dunnington. 2021. <em>Ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics</em>. <a href="https://CRAN.R-project.org/package=ggplot2" class="uri">https://CRAN.R-project.org/package=ggplot2</a>.
</div>
<div id="ref-wickham2017" class="csl-entry">
Wickham, Hadley, and Garrett Grolemund. 2017. <em>R for Data Science: Import, Tidy, Transform, Visualize, and Model Data</em>. 1st edition. Sebastopol, CA: O’Reilly Media.
</div>
<div id="ref-bookdown2016" class="csl-entry">
Xie, Yihui. 2016. <em>Bookdown: Authoring Books and Technical Documents with R Markdown</em>. Boca Raton, Florida: Chapman; Hall/CRC. <a href="https://bookdown.org/yihui/bookdown" class="uri">https://bookdown.org/yihui/bookdown</a>.
</div>
<div id="ref-R-bookdown" class="csl-entry">
———. 2021. <em>Bookdown: Authoring Books and Technical Documents with r Markdown</em>. <a href="https://CRAN.R-project.org/package=bookdown" class="uri">https://CRAN.R-project.org/package=bookdown</a>.
</div>
<div id="ref-rmarkdown2018" class="csl-entry">
Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. <em>R Markdown: The Definitive Guide</em>. Boca Raton, Florida: Chapman; Hall/CRC. <a href="https://bookdown.org/yihui/rmarkdown" class="uri">https://bookdown.org/yihui/rmarkdown</a>.
</div>
<div id="ref-R-blogdown" class="csl-entry">
Xie, Yihui, Christophe Dervieux, and Alison Presmanes Hill. 2021. <em>Blogdown: Create Blogs and Websites with r Markdown</em>. <a href="https://CRAN.R-project.org/package=blogdown" class="uri">https://CRAN.R-project.org/package=blogdown</a>.
</div>
<div id="ref-blogdown2017" class="csl-entry">
Xie, Yihui, Alison Presmanes Hill, and Amber Thomas. 2017. <em>Blogdown: Creating Websites with R Markdown</em>. Boca Raton, Florida: Chapman; Hall/CRC. <a href="https://bookdown.org/yihui/blogdown/" class="uri">https://bookdown.org/yihui/blogdown/</a>.
</div>
</div>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>For French-speaking readers, you can find an introduction to quantitative data and methods applied to history of economics, as well as several examples of the use of these methods <a href="../../teaching/">here</a>.↩︎</p></li>
<li id="fn2"><p>I would not argue here about whether R or Python suits better for quantitative inquiries. My choice of R is totally path-dependent: I was working at the time on a collective project where some members of the project where programming in R. It was easier for me to follow their path and ask for their help.↩︎</p></li>
<li id="fn3"><p>This website is produced notably thanks to <a href="https://pkgs.rstudio.com/blogdown/">blogdown</a> R package (Xie, Dervieux, and Presmanes Hill 2021).↩︎</p></li>
<li id="fn4"><p>Another major tool when you are dealing with very large set of data is the <a href="https://rdatatable.gitlab.io/data.table/">data.table</a> package (Dowle and Srinivasan 2021), which increases dramatically programming speed. You can find many tutorials on <em>data.table</em> features on the package website.↩︎</p></li>
<li id="fn5"><p>See for instance the <a href="https://github.com/Alex7722/macro_AA">github page</a> of one project I am working on with <a href="https://sites.google.com/view/alexandre-truc/home-and-contact">Alexandre Truc</a>.↩︎</p></li>
<li id="fn6"><p>For examples of the use of bibliometrics in history of economics, see Claveau and Gingras (2016) or Herfeld and Doehne (2019).↩︎</p></li>
<li id="fn7"><p>Collecting bibliometric data is not an easy task, as it depends on your access to different databases and to the types of information your are searching for. Besides, there is often a lot of cleaning to do on the data you have been able to download. I will try to do a blog post clarifying these issues soon.↩︎</p></li>
<li id="fn8"><p>See Julia Silge’s <a href="https://juliasilge.com/blog/">blog</a> for other examples of topic modelling in R—and for many other examples of modelling and prediction with R.↩︎</p></li>
<li id="fn9"><p>If you are programming with <em>dplyr</em>, this <a href="https://dplyr.tidyverse.org/articles/programming.html#introduction-1">vignette</a> can also be useful. Same for <em>data.table</em> <a href="https://www.r-bloggers.com/2020/01/programming-with-data-table/">here</a>.↩︎</p></li>
<li id="fn10"><p>You can read <a href="https://rstudio.github.io/visual-markdown-editing/citations.html">this</a> to see how Rstudio makes the interaction between <em>R Mardown</em> and Zotero easier.↩︎</p></li>
<li id="fn11"><p>See this <a href="https://programminghistorian.org/en/lessons/sustainable-authorship-in-plain-text-using-pandoc-and-markdown">blog post</a> for some advantages of writing in <em>markdown</em> and using <em>pandoc</em> rather than text editor like <em>Word</em>.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Bibliometrics</category>
  <category>R Package</category>
  <category>Network Analysis</category>
  <guid>https://aurelien-goutsmedt.com/post/roadmap-quantitative-hpe/</guid>
  <pubDate>Sun, 02 Jan 2022 23:00:00 GMT</pubDate>
  <media:content url="https://aurelien-goutsmedt.com/post/roadmap-quantitative-hpe/featured.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>Release of biblionetwork 0.1.0</title>
  <dc:creator>Aurélien Goutsmedt</dc:creator>
  <link>https://aurelien-goutsmedt.com/post/release-biblionetwork/</link>
  <description><![CDATA[ 





<p>I am very pleased to announce the initial release of <a href="https://agoutsmedt.github.io/biblionetwork/">biblionetwork</a> to CRAN! biblionetwork is designed to build easily and quickly large list of edges for bibliometric networks. You can identify the edges for different types of network (bibliometric coupling or co-citation, or co-authorship networks) and use different methods to calculate the weights of edges.</p>
<p>Install biblionetwork with:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"biblionetwork"</span>)</span></code></pre></div></div>
<section id="usage" class="level2">
<h2 class="anchored" data-anchor-id="usage">Usage</h2>
<p>The basic function of the package is the <code>biblio_coupling()</code> function. This function calculates the number of references that different articles share together, as well as the coupling angle value of edges in a bibliographic coupling network (Sen and Gan 1983). What you need is just a file with entities (documents, authors, universities, <em>etc.</em>) citing references.<sup>1</sup></p>
<p>This example use the <a href="https://agoutsmedt.github.io/biblionetwork/reference/index.html">data incorporated</a> in the package.<sup>2</sup></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(biblionetwork)</span>
<span id="cb2-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">biblio_coupling</span>(Ref_stagflation, </span>
<span id="cb2-3">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">source =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Citing_ItemID_Ref"</span>, </span>
<span id="cb2-4">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ref =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ItemID_Ref"</span>, </span>
<span id="cb2-5">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">normalized_weight_only =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, </span>
<span id="cb2-6">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">weight_threshold =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span></code></pre></div></div>
<pre><code>##             from         to     weight nb_shared_references     Source
##    1:     214927    2207578 0.14605935                    4     214927
##    2:     214927    5982867 0.04082483                    1     214927
##    3:     214927    8456979 0.09733285                    3     214927
##    4:     214927   10729971 0.29848100                    7     214927
##    5:     214927   16008556 0.04714045                    1     214927
##   ---                                                                 
## 2712: 1111111161 1111111172 0.03434014                    1 1111111161
## 2713: 1111111161 1111111180 0.02003610                    1 1111111161
## 2714: 1111111161 1111111183 0.04050542                    2 1111111161
## 2715: 1111111172 1111111180 0.03646625                    1 1111111172
## 2716: 1111111182 1111111183 0.27060404                    8 1111111182
##           Target
##    1:    2207578
##    2:    5982867
##    3:    8456979
##    4:   10729971
##    5:   16008556
##   ---           
## 2712: 1111111172
## 2713: 1111111180
## 2714: 1111111183
## 2715: 1111111180
## 2716: 1111111183</code></pre>
</section>
<section id="what-you-can-do-with-biblionetwork" class="level2">
<h2 class="anchored" data-anchor-id="what-you-can-do-with-biblionetwork">What you can do with biblionetwork</h2>
<p>The package incorporates different types of method for calculating edges weight, depending on the type of network your working on and the variables you want to take into account. You will find on the package website a detailed <a href="https://agoutsmedt.github.io/biblionetwork/articles/Using_biblionetwork.html">vignette</a> on these different methods and how to use the package for different networks.</p>
</section>
<section id="acknowledgements" class="level2">
<h2 class="anchored" data-anchor-id="acknowledgements">Acknowledgements</h2>
<p>The original function to find edges and calculate weights for large networks was developed by François Claveau. The different functions in this package have been developed, from Claveau’s original idea, by Alexandre Truc and Aurélien Goutsmedt. The package is maintained by Aurélien Goutsmedt.</p>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-goutsmedt2021a" class="csl-entry">
Goutsmedt, Aurélien. 2021. “From the Stagflation to the Great Inflation: Explaining the US Economy of the 1970s.” <em>Revue d’Economie Politique</em> Forthcoming. <a href="https://aurelien-goutsmedt.com/media/pdf/stagflation-great-inflation.pdf" class="uri">https://aurelien-goutsmedt.com/media/pdf/stagflation-great-inflation.pdf</a>.
</div>
<div id="ref-sen1983" class="csl-entry">
Sen, Subir K., and Shymal K. Gan. 1983. “A Mathematical Extension of the Idea of Bibliographic Coupling and Its Applications.” <em>Annals of Library Science and Documentation</em> 30 (2). <a href="http://nopr.niscair.res.in/bitstream/123456789/28008/1/ALIS%2030(2)%2078-82.pdf" class="uri">http://nopr.niscair.res.in/bitstream/123456789/28008/1/ALIS%2030(2)%2078-82.pdf</a>.
</div>
</div>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>If you want to build a coupling network with entities larger than a document (meaning entities that have published several documents, and thus can cite a reference several times), we rather recommend the use of the <a href="https://agoutsmedt.github.io/biblionetwork/reference/coupling_entity.html">coupling_entity()</a> function.↩︎</p></li>
<li id="fn2"><p>The biblionetwork package contains bibliometric data built by Goutsmedt (2021). These data gather the academic articles and books, published between 1975 and 2013, that endeavoured to explain the United States stagflation of the 1970s. They also gather all the references cited by these articles and books on stagflation. The <code>Nodes_stagflation.rda</code> file contains information about the academic articles and books on stagflation (the staflation documents), as well as about the references cited at least by two of these stagflation documents. The <code>Ref_stagflation.rda</code> is a data frame of direct citations, with the identifiers of citing documents, and the identifiers of cited documents. The <code>Authors_stagflation.rda</code> is a data frame with the list of documents explaining the US stagflation, and all the authors of these documents (<code>Nodes_stagflation.rda</code> just takes the first author for each document).↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Bibliometrics</category>
  <category>R Package</category>
  <guid>https://aurelien-goutsmedt.com/post/release-biblionetwork/</guid>
  <pubDate>Thu, 08 Apr 2021 22:00:00 GMT</pubDate>
  <media:content url="https://aurelien-goutsmedt.com/post/release-biblionetwork/logo.png" medium="image" type="image/png" height="166" width="144"/>
</item>
<item>
  <title>Exploring Stagflation Explanations with Interactive Networks</title>
  <dc:creator>Aurélien Goutsmedt</dc:creator>
  <link>https://aurelien-goutsmedt.com/post/exploring-stagflation/</link>
  <description><![CDATA[ 





<style type="text/css">
pre {
  max-height: 300px;
  overflow-y: auto;
}

pre[class] {
  max-height: 100px;
}
</style>
<section id="introduction" class="level2">
<h2 class="anchored" data-anchor-id="introduction">Introduction</h2>
<p>Bibliometric networks are an interesting tool to study the evolution of a disciplinary field or of a topic. A bibliographic coupling network, by looking at the references shared by a corpus of documents, allows us to understand the intellectual structure of a field at a certain point of time. A bibliographic co-citation network, by looking at the number of times the references cited by a corpus are cited together, reveals the main influences of a field.<sup>1</sup></p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/exploring-stagflation/citationnetworks.png" alt="Bibliographic coupling and co-citation" width="80%">
<p class="caption">
Figure 1: Bibliographic coupling and co-citation
</p>
</div>
<p>That is the two main tools I have used in my article “<a href="../../publications/">From the Stagflation to the Great Inflation: explaining the US economy of the 1970s</a>” (Goutsmedt 2021). I analysed the way economists explained the US stagflation of the 1970s (a period of high unemployment and inflation) over time. Bibliometric networks completed a qualitative reading of the relevant articles and books and helped me to underline how we went from an explanation focusing on the effects of external shocks (the end of Bretton Woods and commodity-price shocks) on growth and unemployment, in the late 1970s and early 1980s, to an explanation that focused on the Federal Reserve mistakes and the effects of monetary policy on inflation.<sup>2</sup></p>
<p>However, publishing academic articles with such tools often comes with some frustration. If bibliometric networks are helpful to prove your point and to display some of your results, they are also (and I am tempted to say “above all”) an “exploratory” tool that comes upstream of a project, well before having a clear idea of what you want to demonstrate.<sup>3</sup> You can spend some time exploring your network, studying which nodes are in which communities, studying the effects of changing some parameters (in your partitioning algorithm for instance). But at the end of the day, what you will have in your paper is this:</p>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/exploring-stagflation/graph_cocit_9713.png" alt="My co-citation network for the 1997-2013 sub-period" width="80%">
<p class="caption">
Figure 2: My co-citation network for the 1997-2013 sub-period
</p>
</div>
<p>Even if visually informative, the picture is an attempt of summarising all the information obtained by studying the network. And of course, it heavily relies on the explanations and interpretations given by its author, as it remains very hard for an external observer to understand what it is all about. Moreover, this observer is likely to experience frustration too, as she is unable to explore the network herself and depends on the visual choices made by the author.</p>
<p>The rationale behind this post is to evacuate a part of this frustration. I wanted to do several things here:</p>
<ol type="1">
<li>unveiling the database used for my article (and hoping that some people would like to use it in turn and complete/improve/expand it);</li>
<li>exposing some useful bits of R code to produce such networks. I am notably using two R packages that I am developing with <a href="https://sites.google.com/view/alexandre-truc/home-and-contact">Alexandre Truc</a>: <a href="https://agoutsmedt.github.io/biblionetwork/">biblionetwork</a> and <a href="https://github.com/agoutsmedt/networkflow">networkflow</a>. The second one heavily relies on igraph (Csardi and Nepusz 2006), tidygraph (Pedersen 2020b) and ggraph (Pedersen 2020a) great packages.</li>
<li>displaying <em>interactive</em> coupling and co-citation networks (the very reason for the long monologue above…).<sup>4</sup></li>
</ol>
<p>Before to go further, let’s charge some packages that will be useful for what follows:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1">cran_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"data.table"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"magrittr"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"igraph"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tidygraph"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggraph"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"leidenAlg"</span>,</span>
<span id="cb1-2">               <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"scico"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DT"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggiraph"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggnewscale"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ggrepel"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"htmlwidgets"</span>,</span>
<span id="cb1-3">               <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"htmltools"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"widgetframe"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigmajs"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dplyr"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"devtools"</span>)</span>
<span id="cb1-4"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span>(p <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> cran_list){</span>
<span id="cb1-5">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (p <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">installed.packages</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>){<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install.packages</span>(p,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dependencies =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)}</span>
<span id="cb1-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(p,<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">character.only=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-7">}</span>
<span id="cb1-8"></span>
<span id="cb1-9">github_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ParkerICI/vite"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"agoutsmedt/biblionetwork"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"agoutsmedt/networkflow"</span>)</span>
<span id="cb1-10"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span>(p <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> github_list){</span>
<span id="cb1-11">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*/"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,p) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">installed.packages</span>()<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>){devtools<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">install_github</span>(p)}</span>
<span id="cb1-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">gsub</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">".*/"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>,p),<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">character.only=</span><span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb1-13">}</span></code></pre></div></div>
</section>
<section id="building-a-database-of-stagflation-explanations" class="level2">
<h2 class="anchored" data-anchor-id="building-a-database-of-stagflation-explanations">Building a database of stagflation explanations</h2>
<p>The first step in my article on stagflation was to decide what could be regarded as an explanation of the US stagflation and to identify the academic articles, books and book chapters responding positively to the criteria (see Goutsmedt 2021 for the whole list of criteria). I decided to focus on documents that devoted sufficient space to deal <em>explicitly</em> with the explanation of the phenomena.</p>
<p>To identify the corresponding documents, I relied on two methods:</p>
<ul>
<li>I took as a point of departure the 2008 NBER conference on “<a href="https://www.nber.org/books-and-chapters/great-inflation-rebirth-modern-central-banking">The Great Inflation: The Rebirth of Modern Central Banking</a>”—published in 2013—and checked the bibliography of the conference articles dealing with the US economic situation to find new references about stagflation. I repeated the process with these new references and so on.</li>
<li>I searched for all the articles with the term “Stagflation” or “Great Inflation” in their title on Web of Science (WoS) and integrated to my dataset all the articles dealing with the 1970s US stagflation. I also checked the bibliography of these documents and find new ones.</li>
</ul>
<p>I ended up with 174 documents (articles in academic journals, working papers, books and book chapters). 104 were in the WoS database. I thus could extract the references cited by these articles (yes, that’s almost only academic articles that you find in WoS). The process for the 70 remaining documents was more time-consuming. I parsed the bibliography of these documents in <a href="https://anystyle.io/">anystyle</a> and cleaned the results. Then, I had to match these new references with what I got first with WoS. I eventually ended up with 572 references cited at least twice by the 174 documents on the US stagflation. 91 stagflation documents were also part of the 572 references—meaning that 83 articles and books on stagflation were either not cited or only once by other articles or books on stagflation.</p>
<p>Here is all the stagflation documents and all the references cited at least twice by these documents:<sup>5</sup> &nbsp;</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1">Nodes_stagflation <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.table</span>(Nodes_stagflation)</span>
<span id="cb2-2">data <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">datatable</span>(Nodes_stagflation[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">order</span>(Type, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">decreasing =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Author"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Title"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Journal"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Type"</span>)], </span>
<span id="cb2-3">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">rownames =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, </span>
<span id="cb2-4">                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">options =</span>  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scrollY =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"400px"</span>,</span>
<span id="cb2-5">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scrollCollapse =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb2-6">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">scrollX =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"400px"</span>,</span>
<span id="cb2-7">                                  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">paging =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>))</span>
<span id="cb2-8"></span>
<span id="cb2-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">frameWidget</span>(data)</span></code></pre></div></div>
<iframe src="index.en_files/figure-html/widgets/widget_DT.html" width="100%" height="500px">
</iframe>
<p>&nbsp; &nbsp;</p>
<p>If we look at the number of documents on stagflation per year, we see that there were two waves of interest for this topic:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">Nodes_stagflation <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-2">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(Type <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Stagflation"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb3-3">          <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">count</span>(Year) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb3-4">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggplot</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> Year, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> n, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> n)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-5">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_bar</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">stat =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-6">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_viridis</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">option =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-7">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ylab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Number of Documents on Stagflation per Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb3-8">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">xlab</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-9">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_minimal</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb3-10">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_x_discrete</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">breaks =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1975</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2013</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>))</span></code></pre></div></div>
<div class="figure" style="text-align: center">
<img src="https://aurelien-goutsmedt.com/post/exploring-stagflation/index.en_files/figure-html/doc-by-year-1.png" alt="Number of stagflation documents per year" width="672">
<p class="caption">
Figure 3: Number of stagflation documents per year
</p>
</div>
<p>I have thus decided to focus on these two waves and to study two subperiods: 1975-1986; 1997-2013.</p>
</section>
<section id="bibliometric-coupling-and-co-citation-analyses" class="level2">
<h2 class="anchored" data-anchor-id="bibliometric-coupling-and-co-citation-analyses">Bibliometric coupling and co-citation analyses</h2>
<p>For each sub-period, I build a coupling and a co-citation network. The <a href="https://agoutsmedt.github.io/biblionetwork/">biblionetwork</a> package, with the <a href="https://agoutsmedt.github.io/biblionetwork/reference/biblio_coupling.html"><code>biblio_coupling()</code></a> function, allows us to build the edges of the network, from a direct citation data frame (what each stagflation document cites), and to calculate a weight for these edges. The method for calculating the weights takes into account the size of the bibliography of each document. The <a href="https://agoutsmedt.github.io/biblionetwork/reference/biblio_cocitation.html"><code>biblio_cocitation()</code></a> function does the same for the co-citation edges and the weights measure takes into account the total number of citations of each reference.<sup>6</sup></p>
<p>The <a href="https://github.com/agoutsmedt/networkflow">networkflow</a> package offers functions wrapped around other packages, to simplify the analysis of networks and their projections. For creating and manipulating the network, I use the <a href="https://tidygraph.data-imaginist.com/">tidygraph</a> package, which wraps the functionnalities of the classic <a href="https://igraph.org/r/">igraph</a> package in a tidy format. I use the Leiden algorithm (Traag, Waltman, and van Eck 2019) to find communities—groups of nodes highly connected together—in the four networks. For structuring the network in a two-dimensional space, I use the Force Atlas 2 (FA2) layout (Jacomy et al.&nbsp;2014). FA2 is a force-based layout: basically, connected nodes are attracted together, and the layout minimises edges crossing. For community colors, I use the <a href="https://www.data-imaginist.com/2018/scico-and-the-colour-conundrum/">scico</a> package (Pedersen and Crameri 2020) which brings palettes taking into account colour blindness issues.</p>
<p>In what follows, I use a loop with conditions, to build the four networks and prepare their projection:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">graph_list <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">list</span>() <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># empty list to fill in the loop</span></span>
<span id="cb4-2"></span>
<span id="cb4-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># fixing some variables for the loop</span></span>
<span id="cb4-4">start_year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1975</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1997</span>) </span>
<span id="cb4-5">end_year <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1986</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2013</span>)</span>
<span id="cb4-6">network <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coupling"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cocitation"</span>)</span>
<span id="cb4-7">palette <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"lapaz"</span>,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"roma"</span>)</span>
<span id="cb4-8"></span>
<span id="cb4-9"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span>(i <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>){</span>
<span id="cb4-10">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span>(j <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">length</span>(network)){</span>
<span id="cb4-11">    </span>
<span id="cb4-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># direct citation data, depending on the sub-period</span></span>
<span id="cb4-13">ref <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.table</span>(Ref_stagflation) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb4-14">  .[Citing_ItemID_Ref <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.table</span>(Nodes_stagflation) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> .[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">between</span>(Year, start_year[i], end_year[i])])<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ItemID_Ref]</span>
<span id="cb4-15"></span>
<span id="cb4-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># building the list of nodes, depending on whether we are building the coupling or co-citation network </span></span>
<span id="cb4-17">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(network[j] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coupling"</span>){</span>
<span id="cb4-18">  nodes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.table</span>(Nodes_stagflation) </span>
<span id="cb4-19">    <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> .[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">between</span>(Year, start_year[i], end_year[i]) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> Type <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Stagflation"</span>]     </span>
<span id="cb4-20">    } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb4-21">  nodes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.table</span>(Nodes_stagflation) </span>
<span id="cb4-22">    <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> .[ItemID_Ref <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> ref<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ItemID_Ref]     </span>
<span id="cb4-23">    }</span>
<span id="cb4-24"></span>
<span id="cb4-25"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># calculating the number of citations of each node within the period</span></span>
<span id="cb4-26">nb_cit <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> ref[, .N, ItemID_Ref]</span>
<span id="cb4-27"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(nb_cit)[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">colnames</span>(nb_cit) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"N"</span>] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"size"</span></span>
<span id="cb4-28">nodes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">merge</span>(nodes, nb_cit, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by.x =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ItemID_Ref"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">by.y =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ItemID_Ref"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">all.x =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb4-29"></span>
<span id="cb4-30"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># setting the value of article with no citation to 0,5 to display them in the visualisation, </span></span>
<span id="cb4-31"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">#but at a smaller size than articles with one citation</span></span>
<span id="cb4-32">nodes[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.na</span>(size), size<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>]</span>
<span id="cb4-33"></span>
<span id="cb4-34"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># finding the edges and calculating their weight using the `biblionetwork` package</span></span>
<span id="cb4-35"> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(network[j] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"coupling"</span>){</span>
<span id="cb4-36">  edges <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">biblio_coupling</span>(ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Citing_ItemID_Ref"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ItemID_Ref"</span>)    </span>
<span id="cb4-37">    } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb4-38">  ref <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> ref[ItemID_Ref <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%in%</span> nodes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>ItemID_Ref]     </span>
<span id="cb4-39">  edges <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">biblio_cocitation</span>(ref, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Citing_ItemID_Ref"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ItemID_Ref"</span>)</span>
<span id="cb4-40">    }</span>
<span id="cb4-41"></span>
<span id="cb4-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># creating the graph with `networkflow` package</span></span>
<span id="cb4-43">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">tbl_main_component</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">edges =</span> edges, </span>
<span id="cb4-44">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nodes =</span> nodes, </span>
<span id="cb4-45">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">directed =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, </span>
<span id="cb4-46">                            <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">node_key =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ItemID_Ref"</span>)</span>
<span id="cb4-47"></span>
<span id="cb4-48"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># finding communities </span></span>
<span id="cb4-49">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">leiden_workflow</span>(graph, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">niter =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>)</span>
<span id="cb4-50"></span>
<span id="cb4-51"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># giving colors</span></span>
<span id="cb4-52"></span>
<span id="cb4-53">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">community_colors</span>(graph, </span>
<span id="cb4-54">                          <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">palette =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scico</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">begin =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">palette =</span> palette[j])))</span>
<span id="cb4-55"></span>
<span id="cb4-56"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># calculating coordinates using the package `vite` and its Force Atlas 2 implementation</span></span>
<span id="cb4-57">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> vite<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">complete_forceatlas2</span>(graph, </span>
<span id="cb4-58">                                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">first.iter =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5000</span>, </span>
<span id="cb4-59">                                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">overlap.method =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"repel"</span>, </span>
<span id="cb4-60">                                    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">overlap.iter =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>)</span>
<span id="cb4-61"></span>
<span id="cb4-62">graph_list[[<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(i),<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-"</span>,<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(network[j]))]] <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph</span>
<span id="cb4-63">}</span>
<span id="cb4-64">}</span></code></pre></div></div>
<p>In my article, I use the <a href="https://ggraph.data-imaginist.com/">ggraph</a> package to project the networks. Here, I resort to the <a href="http://sigmajs.john-coene.com/index.html">sigmajs</a> package (Coene 2020) for building interactive graphs. It relies on the <a href="http://sigmajs.org/">Sigma javascript library</a>, which is also used for the software <a href="https://gephi.org/">GEPHI</a>.</p>
<section id="the-1975-1986-period" class="level3">
<h3 class="anchored" data-anchor-id="the-1975-1986-period">The 1975-1986 period</h3>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Isolating the nodes and giving the proper names to the columns,</span></span>
<span id="cb5-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># to project with sigmajs</span></span>
<span id="cb5-3">nodes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph_list[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">activate</span>(nodes) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tibble</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> Id) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Author_date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>,Title,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>,Journal)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(id,Year,Author,label,Title,Journal,size,color,x,y) </span>
<span id="cb5-9"></span>
<span id="cb5-10">edges <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph_list[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">activate</span>(edges) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tibble</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">source =</span> Source, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">target =</span> Target, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> weight, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> color_edges) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb5-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(id,source,target,color,size) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.table</span>() </span>
<span id="cb5-17"></span>
<span id="cb5-18"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># every identifier in character format for projection</span></span>
<span id="cb5-19">nodes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(nodes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id)</span>
<span id="cb5-20">edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>source <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>source)</span>
<span id="cb5-21">edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>target <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>target)</span>
<span id="cb5-22">edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id)</span>
<span id="cb5-23"></span>
<span id="cb5-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># projecting the interactive graph</span></span>
<span id="cb5-25">x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sigmajs</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># initialise</span></span>
<span id="cb5-26">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_nodes</span>(nodes, id, label, size, color, x, y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add nodes</span></span>
<span id="cb5-27">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_edges</span>(edges, id, source, target, size, color) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add edges</span></span>
<span id="cb5-28">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_settings</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drawLabels =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drawEdgeLabels =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, </span>
<span id="cb5-29">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">defaultEdgeType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"curve"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minNodeSize =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxNodeSize =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, </span>
<span id="cb5-30">                <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minEdgeSize =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxEdgeSize =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>,</span>
<span id="cb5-31">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">borderSize =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labelHoverBGColor =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"node"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">singleHover =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb5-32">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hideEdgesOnMove =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">zoomMin =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">zoomMax =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb5-33">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_neighbors</span>()</span>
<span id="cb5-34"></span>
<span id="cb5-35"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">frameWidget</span>(x)</span></code></pre></div></div>
<iframe src="index.en_files/figure-html/widgets/widget_sigma_1.html" width="100%" height="500px">
</iframe>
<p>&nbsp;</p>
<p>A more detailed analysis could be find in my <a href="../../publications/">article</a>, but the major results to highlight are:</p>
<ul>
<li>The centre of the graph is occupied by Robert Gordon’s papers (Gordon 1975a, 1975b, 1977), as well as Phelps (1978), which are highly cited (the size of a node corresponds to its number of citation within the sub-period). Sachs (1979) and Perry (1978) are also highly cited nodes, in communities close to the central dense part of the graph. Several of these articles have been published in the <em>Brookings Papers on Economic Activity</em> and gave an important role to supply-shocks (notably commodity price shocks) and inflation inertia.</li>
<li>The community North-East—the one with Milton Friedman’s Nobel Prize article (Friedman 1977)—echoes the “schools of thought” debates of the 1970s, with the opposition between Keynesians and Monetarists. That is clearly a peripheral community.</li>
</ul>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Isolating the nodes and giving the proper names to the columns,</span></span>
<span id="cb6-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># to project with sigmajs</span></span>
<span id="cb6-3">nodes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph_list[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">activate</span>(nodes) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tibble</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> Id) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Author_date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>,Title,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>,Journal)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(id,Year,Author,label,Title,Journal,size,color,x,y) </span>
<span id="cb6-9"></span>
<span id="cb6-10">edges <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph_list[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">activate</span>(edges) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tibble</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">source =</span> Source, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">target =</span> Target, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> weight, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> color_edges) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb6-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(id,source,target,color,size) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.table</span>() </span>
<span id="cb6-17"></span>
<span id="cb6-18">nodes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(nodes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id)</span>
<span id="cb6-19">edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>source <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>source)</span>
<span id="cb6-20">edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>target <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>target)</span>
<span id="cb6-21">edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id)</span>
<span id="cb6-22"></span>
<span id="cb6-23"></span>
<span id="cb6-24">x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sigmajs</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># initialise</span></span>
<span id="cb6-25">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_nodes</span>(nodes, id, label, size, color, x, y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add nodes</span></span>
<span id="cb6-26">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_settings</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drawLabels =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drawEdgeLabels =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, </span>
<span id="cb6-27">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">defaultEdgeType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"curve"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minNodeSize =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxNodeSize =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>, </span>
<span id="cb6-28">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minEdgeSize =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxEdgeSize =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb6-29">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">borderSize =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labelHoverBGColor =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"node"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">singleHover =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb6-30">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hideEdgesOnMove =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">zoomMin =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">zoomMax =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb6-31">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_edges</span>(edges, id, source, target, size, color) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add edges</span></span>
<span id="cb6-32">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_neighbors</span>()</span>
<span id="cb6-33"></span>
<span id="cb6-34"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">frameWidget</span>(x)</span></code></pre></div></div>
<iframe src="index.en_files/figure-html/widgets/widget_sigma_2.html" width="100%" height="500px">
</iframe>
<p>&nbsp; &nbsp;</p>
<p>For the co-citation network, we can observe that:</p>
<ul>
<li>The most central (and highly cited nodes) are the same than in the coupling network. Major references for the stagflation documents are stagflation documents themselves, and we can see that the articles valuing supply-shocks and inflation inertia explanations are central.</li>
<li>Friedman’s work, notably its famous 1967 AEA presidential lecture (Friedman 1968), and rational expectations contributions (Lucas 1973; Barro 1976) are South-East of the graph, in a relatively marginal communities. In other words, many articles that are currently considered as central in the history of macroeconomics, were not important for explaining stagflation in the late 1970s and early 1980s.</li>
</ul>
</section>
<section id="the-1997-2013-period" class="level3">
<h3 class="anchored" data-anchor-id="the-1997-2013-period">The 1997-2013 period</h3>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Isolating the nodes and giving the proper names to the columns,</span></span>
<span id="cb7-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># to project with sigmajs</span></span>
<span id="cb7-3">nodes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph_list[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">activate</span>(nodes) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tibble</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> Id) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Author_date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>,Title,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>,Journal)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(id,Year,Author,label,Title,Journal,size,color,x,y) </span>
<span id="cb7-9"></span>
<span id="cb7-10">edges <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph_list[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">activate</span>(edges) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tibble</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">source =</span> Source, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">target =</span> Target, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> weight, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> color_edges) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb7-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(id,source,target,color,size) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.table</span>() </span>
<span id="cb7-17">nodes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(nodes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id)</span>
<span id="cb7-18">edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>source <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>source)</span>
<span id="cb7-19">edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>target <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>target)</span>
<span id="cb7-20">edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id)</span>
<span id="cb7-21"></span>
<span id="cb7-22"></span>
<span id="cb7-23">x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sigmajs</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># initialise</span></span>
<span id="cb7-24">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_nodes</span>(nodes, id, label, size, color, x, y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add nodes</span></span>
<span id="cb7-25">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_settings</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drawLabels =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drawEdgeLabels =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, </span>
<span id="cb7-26">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">defaultEdgeType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"curve"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minNodeSize =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxNodeSize =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, </span>
<span id="cb7-27">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minEdgeSize =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxEdgeSize =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.8</span>,</span>
<span id="cb7-28">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">borderSize =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labelHoverBGColor =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"node"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">singleHover =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb7-29">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hideEdgesOnMove =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">zoomMin =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">zoomMax =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb7-30">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_edges</span>(edges, id, source, target, size, color) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add edges</span></span>
<span id="cb7-31">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_neighbors</span>()</span>
<span id="cb7-32"></span>
<span id="cb7-33"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">frameWidget</span>(x)</span></code></pre></div></div>
<iframe src="index.en_files/figure-html/widgets/widget_sigma_3.html" width="100%" height="500px">
</iframe>
<p>&nbsp; &nbsp;</p>
<p>In the second sub-period, we can see that:</p>
<ul>
<li>there is a marginal group North of the graph. That is the documents dealing with the oil shocks of the 1970s. The most cited reference of the group, Clarida, Galí, and Gertler (2000), but also, for instance, Barsky and Kilian (2002), rejected the supply-shock explanation of the 1970s.</li>
<li>The documents in the two other communities did not really address supply-shocks and focused on monetary policy and debated what are the main reasons for explaning the FED’s inability to stop inflation.</li>
</ul>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Isolating the nodes and giving the proper names to the columns,</span></span>
<span id="cb8-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># to project with sigmajs</span></span>
<span id="cb8-3">nodes <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph_list[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-4">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">activate</span>(nodes) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-5">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tibble</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> Id) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Author_date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>,Title,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">", "</span>,Journal)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(id,Year,Author,label,Title,Journal,size,color,x,y) </span>
<span id="cb8-9"></span>
<span id="cb8-10">edges <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> graph_list[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>]] <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">activate</span>(edges) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as_tibble</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rename</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">source =</span> Source, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">target =</span> Target, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> weight, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> color_edges) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span></span>
<span id="cb8-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mutate</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>()) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">select</span>(id,source,target,color,size) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-16">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.data.table</span>() </span>
<span id="cb8-17"></span>
<span id="cb8-18">nodes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(nodes<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id)</span>
<span id="cb8-19">edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>source <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>source)</span>
<span id="cb8-20">edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>target <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>target)</span>
<span id="cb8-21">edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.character</span>(edges<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id)</span>
<span id="cb8-22"></span>
<span id="cb8-23"></span>
<span id="cb8-24">x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sigmajs</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># initialise</span></span>
<span id="cb8-25">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_nodes</span>(nodes, id, label, size, color, x, y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add nodes</span></span>
<span id="cb8-26">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_settings</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drawLabels =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">drawEdgeLabels =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>, </span>
<span id="cb8-27">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">defaultEdgeType =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"curve"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minNodeSize =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxNodeSize =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">18</span>, </span>
<span id="cb8-28">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">minEdgeSize =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">maxEdgeSize =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>,</span>
<span id="cb8-29">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">borderSize =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labelHoverBGColor =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"node"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">singleHover =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>,</span>
<span id="cb8-30">                 <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">hideEdgesOnMove =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">zoomMin =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">zoomMax =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> </span>
<span id="cb8-31">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_edges</span>(edges, id, source, target, size, color) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%&gt;%</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># add edges</span></span>
<span id="cb8-32">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sg_neighbors</span>()</span>
<span id="cb8-33"></span>
<span id="cb8-34"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">frameWidget</span>(x)</span></code></pre></div></div>
<iframe src="index.en_files/figure-html/widgets/widget_sigma_4.html" width="100%" height="500px">
</iframe>
<p>&nbsp; &nbsp;</p>
<p>When we look at co-citation, we see that:</p>
<ul>
<li>Clarida, Galí, and Gertler (2000), DeLong (1997), Orphanides (2003) and Sargent (1999) are the most cited references and are central in the graph, meaning that they are cited by many articles in each community.</li>
<li>References on oil-shocks, like Hamilton (1983) empirical study about the effects of oil shocks on output and inflation, are situated North of the graph and relatively peripheral.</li>
<li>Friedman (1968), Lucas (1976), Kydland and Prescott (1977) and Barro and Gordon (1983), which were not influential in the 1970s-1980s for explaining stagflation—whereas they are considered as path-breaking articles in the history of macroeconomics—became highly cited references by different communities.</li>
</ul>
<p>These four graphs reveal a similar story: the methodological battles of the 1970s made marginal apparitions in the contributions explaining the US stagflation in the 1970s and early 1980s. Supply-shocks and inflation inertia were seen as the major mechanisms underlying the stagflation and the minority which proposed alternative explanations was forced to deal also with the supply-shocks explanation. After 1997, stagflation explanations largely differed from the 1970s and 1980s, and focused on the role played by the monetary policy of the Fed, questioning the role of distorting political pressure, bad economic ideas, bad policies and inappropriate institutional settings. The path-breaking contributions that stimulated methodological debates in macroeconomics in the 1970s, and which were mostly ignored in the stagflation literature at the time, were now central references.<sup>7</sup></p>
</section>
</section>
<section id="another-package-for-building-interactive-networks" class="level2">
<h2 class="anchored" data-anchor-id="another-package-for-building-interactive-networks">Another package for building interactive networks</h2>
<p>By way of conclusion, I would like to write some words on the building of interactive networks. The sigmajs package is great as it allows R users to resort to Sigma Javascript library, which is a really great tool for network visualisations. With very few manipulations, you can build an interactive graph with interesting features (displaying labels and seeing connected nodes when clicking on one node). However, it offers only limited possibilities, in comparisons to ggraph for instance, to change the visual features of your graph (for instance, putting a border line around each node, having a long label on several lines or changing edges and nodes opacity).</p>
<p>Consequently, I have also tried the <a href="https://davidgohel.github.io/ggiraph/">ggiraph</a> package (Gohel and Skintzos 2020), which relies on <a href="https://ggplot2.tidyverse.org/">ggplot2</a>. It allows me to do something similar to the ggraph visualisations of my article. It is more flexible, notably for the label. But the zoom function appears less fluid, and above all I was unable to reproduce sigmajs feature when clicking on the nodes.<sup>8</sup></p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Extracting the labl of most cited nodes (networkflow function)</span></span>
<span id="cb9-2">top_nodes  <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">top_nodes</span>(graph_list[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]], <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">top_n =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">top_n_per_com =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ordering_column =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"size"</span>)</span>
<span id="cb9-3"></span>
<span id="cb9-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># building the graph like in ggraph, but using geom_point_interactive()</span></span>
<span id="cb9-5">graph <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ggraph</span>(graph_list[[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]], <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"manual"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb9-6">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_edge_arc</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color =</span> color_edges, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width =</span> weight), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">strength =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-7">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_edge_width_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">range =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-8">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_edge_colour_identity</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-9">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_point_interactive</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y =</span> y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">tooltip =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">paste0</span>(Author_date,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Title: "</span>,Title,<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">Journal: "</span>,Journal), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data_id =</span> Com_ID, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> size, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> color), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pch =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">21</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-10">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_size_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">range =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">13</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-11">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_fill_identity</span>() <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-12">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">new_scale</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"size"</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-13">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">geom_text</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">data=</span>top_nodes, <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aes</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x=</span>x, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y=</span>y, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label =</span> Author_date), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fontface=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"bold"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">alpha =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">show.legend =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">FALSE</span>) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-14">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scale_size_continuous</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">range =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span></span>
<span id="cb9-15">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">theme_void</span>()</span>
<span id="cb9-16"></span>
<span id="cb9-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># transforming the graph in an interactive graph with ggiraph</span></span>
<span id="cb9-18">x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">girafe</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ggobj =</span> graph)</span>
<span id="cb9-19"></span>
<span id="cb9-20">x <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">girafe_options</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x =</span> x,</span>
<span id="cb9-21">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">opts_tooltip</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">opacity =</span> .<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">use_fill =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>),</span>
<span id="cb9-22">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">opts_zoom</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>),</span>
<span id="cb9-23">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sizingPolicy</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">defaultWidth =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"100%"</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">defaultHeight =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"250px"</span>),</span>
<span id="cb9-24">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">opts_hover_inv</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">css =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"opacity:0.1;"</span>),</span>
<span id="cb9-25">                    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">opts_hover</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">css =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"opacity:1;r:5pt;"</span>))</span>
<span id="cb9-26"></span>
<span id="cb9-27"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">frameWidget</span>(x)</span></code></pre></div></div>
<iframe src="index.en_files/figure-html/widgets/widget_ggiraph.html" width="100%" height="500px">
</iframe>
<p>&nbsp;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<p>&nbsp;</p>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-barro1976" class="csl-entry">
Barro, Robert J. 1976. “Rational Expectations and the Role of Monetary Policy.” <em>Journal of Monetary Economics</em> 2 (1): 1–32.
</div>
<div id="ref-barro1983a" class="csl-entry">
Barro, Robert J., and David B. Gordon. 1983. “A Positive Theory of Monetary Policy in a Natural Rate Model.” <em>Journal of Political Economy</em> 91 (4): 589–610.
</div>
<div id="ref-barsky2002" class="csl-entry">
Barsky, Robert B., and Lutz Kilian. 2002. “Do We Really Know That Oil Caused the Great Stagflation? A Monetary Alternative.” In <em>NBER Macroeconomics Annual 2001, Volume 16</em>, 137–98. MIT Press.
</div>
<div id="ref-boullier2016" class="csl-entry">
Boullier, Dominique, Maxime Crépel, and Mathieu Jacomy. 2016. “Zoomer n’est pas explorer.” <em>Reseaux</em> n° 195 (1): 131–61. <a href="https://www.cairn.info/revue-reseaux-2016-1-page-131.htm" class="uri">https://www.cairn.info/revue-reseaux-2016-1-page-131.htm</a>.
</div>
<div id="ref-claridaetal2000" class="csl-entry">
Clarida, Richard, Jordi Galí, and Mark Gertler. 2000. “Monetary Policy Rules and Macroeconomic Stability: Evidence and Some Theory.” <em>The Quarterly Journal of Economics</em> 115 (1): 147–80.
</div>
<div id="ref-claveau2016" class="csl-entry">
Claveau, François, and Yves Gingras. 2016. “Macrodynamics of Economics: A Bibliometric History.” <em>History of Political Economy</em> 48 (4): 551–92. <a href="https://read.dukeupress.edu/hope/article-abstract/48/4/551/12684/Macrodynamics-of-Economics-A-Bibliometric-History" class="uri">https://read.dukeupress.edu/hope/article-abstract/48/4/551/12684/Macrodynamics-of-Economics-A-Bibliometric-History</a>.
</div>
<div id="ref-coene2020" class="csl-entry">
Coene, John. 2020. <em>Sigmajs: Interface to ’Sigma.js’ Graph Visualization Library</em>. <a href="https://CRAN.R-project.org/package=sigmajs" class="uri">https://CRAN.R-project.org/package=sigmajs</a>.
</div>
<div id="ref-gabor2006" class="csl-entry">
Csardi, Gabor, and Tamas Nepusz. 2006. “The Igraph Software Package for Complex Network Research.” <em>InterJournal</em> Complex Systems: 1695. <a href="https://igraph.org" class="uri">https://igraph.org</a>.
</div>
<div id="ref-delong1997" class="csl-entry">
DeLong, J Bradford. 1997. “America’s Peacetime Inflation: The 1970s.” In <em>Reducing Inflation. Motivation and Strategy</em>, 247–80. Chicago: University of Chicago Press.
</div>
<div id="ref-friedman1968" class="csl-entry">
Friedman, Milton. 1968. “The Role of Monetary Policy.” <em>American Economic Review</em> 58 (1): 1–17.
</div>
<div id="ref-friedman1977" class="csl-entry">
———. 1977. “Nobel Lecture: Inflation and Unemployment.” <em>Journal of Political Economy</em> 85 (3): 451–72.
</div>
<div id="ref-gingras2016" class="csl-entry">
Gingras, Yves. 2016. <em>Bibliometrics and Research Evaluation: Uses and Abuses</em>. The MIT Press. <a href="https://direct.mit.edu/books/book/4081/bibliometrics-and-research-evaluationuses-and" class="uri">https://direct.mit.edu/books/book/4081/bibliometrics-and-research-evaluationuses-and</a>.
</div>
<div id="ref-gohel2020" class="csl-entry">
Gohel, David, and Panagiotis Skintzos. 2020. <em>Ggiraph: Make ’Ggplot2’ Graphics Interactive</em>. <a href="https://CRAN.R-project.org/package=ggiraph" class="uri">https://CRAN.R-project.org/package=ggiraph</a>.
</div>
<div id="ref-gordon1975b" class="csl-entry">
Gordon, Robert J. 1975a. “Alternative Responses of Policy to External Supply Shocks.” <em>Brookings Papers on Economic Activity</em> 1975 (1): 183–206.
</div>
<div id="ref-gordon1975c" class="csl-entry">
———. 1975b. “The Impact of Aggregate Demand on Prices.” <em>Brookings Papers on Economic Activity</em> 1975 (3): 613–70.
</div>
<div id="ref-gordon1977b" class="csl-entry">
———. 1977. “Can the Inflation of the 1970s Be Explained?” <em>Brookings Papers on Economic Activity</em> 1977 (1): 253–79.
</div>
<div id="ref-goutsmedt2021a" class="csl-entry">
Goutsmedt, Aurélien. 2021. “From the Stagflation to the Great Inflation: Explaining the US Economy of the 1970s.” <em>Revue d’Economie Politique</em> Forthcoming. <a href="https://aurelien-goutsmedt.com/media/pdf/stagflation-great-inflation.pdf" class="uri">https://aurelien-goutsmedt.com/media/pdf/stagflation-great-inflation.pdf</a>.
</div>
<div id="ref-hamilton1983" class="csl-entry">
Hamilton, James D. 1983. “Oil and the Macroeconomy Since World War II.” <em>Journal of Political Economy</em> 91 (2): 228–48.
</div>
<div id="ref-jacomy2014" class="csl-entry">
Jacomy, Mathieu, Tommaso Venturini, Sebastien Heymann, and Mathieu Bastian. 2014. “ForceAtlas2, a Continuous Graph Layout Algorithm for Handy Network Visualization Designed for the Gephi Software.” <em>PloS One</em> 9 (6): e98679.
</div>
<div id="ref-kydlandprescott1977" class="csl-entry">
Kydland, Finn E., and Edward C. Prescott. 1977. “Rules Rather Than Discretion: The Inconsistency of Optimal Plans.” <em>Journal of Political Economy</em> 85 (3): 473–92.
</div>
<div id="ref-lucas1973" class="csl-entry">
Lucas, Robert E. 1973. “Some International Evidence on Output-Inflation Tradeoffs.” <em>American Economic Review</em> 63 (3): 326–34.
</div>
<div id="ref-lucas1976" class="csl-entry">
———. 1976. “Econometric Policy Evaluation: A Critique.” <em>Carnegie-Rochester Conference Series on Public Policy</em> 1: 19–46.
</div>
<div id="ref-orphanides2003" class="csl-entry">
Orphanides, Athanasios. 2003. “The Quest for Prosperity Without Inflation.” <em>Journal of Monetary Economics</em> 50 (3): 633–63.
</div>
<div id="ref-pedersen2020b" class="csl-entry">
Pedersen, Thomas Lin. 2020a. <em>Ggraph: An Implementation of Grammar of Graphics for Graphs and Networks</em>. <a href="https://CRAN.R-project.org/package=ggraph" class="uri">https://CRAN.R-project.org/package=ggraph</a>.
</div>
<div id="ref-pedersen2020a" class="csl-entry">
———. 2020b. <em>Tidygraph: A Tidy API for Graph Manipulation</em>. <a href="https://CRAN.R-project.org/package=tidygraph" class="uri">https://CRAN.R-project.org/package=tidygraph</a>.
</div>
<div id="ref-pedersen2020c" class="csl-entry">
Pedersen, Thomas Lin, and Fabio Crameri. 2020. <em>Scico: Colour Palettes Based on the Scientific Colour-Maps</em>. <a href="https://CRAN.R-project.org/package=scico" class="uri">https://CRAN.R-project.org/package=scico</a>.
</div>
<div id="ref-perry1978" class="csl-entry">
Perry, George L. 1978. “Slowing the Wage-Price Spiral: The Macroeconomic View.” <em>Brookings Papers on Economic Activity</em> 1978 (2): 259–99.
</div>
<div id="ref-phelps1978" class="csl-entry">
Phelps, Edmund S. 1978. “Commodity-Supply Shock and Full-Employment Monetary Policy.” <em>Journal of Money, Credit and Banking</em> 10 (2): 206–21.
</div>
<div id="ref-sachs1979" class="csl-entry">
Sachs, Jeffrey D. 1979. “Wages, Profits, and Macroeconomic Adjustment: A Comparative Study.” <em>Brookings Papers on Economic Activity</em> 1979 (2): 269–332.
</div>
<div id="ref-sargent1999" class="csl-entry">
Sargent, Thomas J. 1999. <em>The Conquest of American Inflation</em>. Princeton: Princeton University Press.
</div>
<div id="ref-traag2019" class="csl-entry">
Traag, Vincent A, Ludo Waltman, and Nees Jan van Eck. 2019. “From Louvain to Leiden: Guaranteeing Well-Connected Communities.” <em>Scientific Reports</em> 9 (1): 1–12.
</div>
<div id="ref-weingart2015" class="csl-entry">
Weingart, Scott B. 2015. “Finding the History and Philosophy of Science.” <em>Erkenntnis</em> 80 (1): 201–13. <a href="https://doi.org/10.1007/s10670-014-9621-1" class="uri">https://doi.org/10.1007/s10670-014-9621-1</a>.
</div>
</div>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>For introduction and application of bibliographic coupling and co-citation methods, see Gingras (2016), Claveau and Gingras (2016), and Weingart (2015).↩︎</p></li>
<li id="fn2"><p>The issue of how we explain the US stagflation regularly reappears. See for instance Paul Krugman’s <a href="https://paulkrugman.substack.com/p/stagflation-revisited">blog post</a>.↩︎</p></li>
<li id="fn3"><p>It should be clear however that bibliometric networks are never a proof in themselves. They are always subject to a lot of interpretations and what we see has always to be taken with great care (for an nice illustration, in French, see Boullier, Crépel, and Jacomy 2016).↩︎</p></li>
<li id="fn4"><p>What follows it not an attempt to reproduce exactly the results of my paper. With developing the <a href="https://github.com/agoutsmedt/networkflow">networkflow</a> package, part of my script have changed, as well as the algorithm implementation I use for Force Atlas 2 and Leiden. Besides, I could not keep the same seed, and thus the partition and spacialisation results could be slightly different. However, I am confident that it is not going against the interpretation of my results I had in the article.↩︎</p></li>
<li id="fn5"><p>As it involved a lot of hand cleaning, it is likely that some mistakes remain. It does not impact the analysis, but the metadata are not perfectly clean.↩︎</p></li>
<li id="fn6"><p>The basic idea is that if two highly cited documents are cited once together, their link has to be weaker than if these two document were rarely cited.↩︎</p></li>
<li id="fn7"><p>In my article, I supported the analyses above by studying further the networks—for instance, by studying the share of links between communities—and by quantitative textual analysis.↩︎</p></li>
<li id="fn8"><p>I did not find any way to highlight the nodes connected to a certain node. For those who have some inspiration, the question is <a href="https://stackoverflow.com/questions/66396940/hover-effect-on-neighbour-nodes-in-network">here</a>.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Bibliometrics</category>
  <category>History of Macroeconomics</category>
  <guid>https://aurelien-goutsmedt.com/post/exploring-stagflation/</guid>
  <pubDate>Thu, 25 Feb 2021 23:00:00 GMT</pubDate>
  <media:content url="https://aurelien-goutsmedt.com/post/exploring-stagflation/featured.png" medium="image" type="image/png" height="97" width="144"/>
</item>
</channel>
</rss>
