<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/build-your-own-offshore-company/"></div></div><div><a data-url="http://www.r-bloggers.com/build-your-own-offshore-company/" data-counturl="http://www.r-bloggers.com/build-your-own-offshore-company/" data-count="horizontal" data-text="Build your own offshore company" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://opiateforthemass.es/articles/BYOOC/"> Opiate for the masses</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<h2>Hackathons are not alike</h2>
<p><span>R</span>ecently, a number of this blog’s authors were at a <a target="_blank" href="https://www.eventbrite.com/e/mission-economy-der-hackathon-von-handelsblatt-wirtschaftswoche-und-3m-tickets-24346149990">data hackathon</a>, the strangest one we’ve been to so far. It was more of a startup pitch gathering, complete with pitch training and whatnot. I was repeatedly asked by other participants “so, how do you want to monetise your idea?”. My answer was simple: I don’t. I already have a job.</p>
<p>The topic of the hackathon was sufficiently vague (“ideas on economy, media, news, content, social media, digitilisation, knowledge management, content creation and distribution, and media transformation”), so we decided we wanted to take a look at the recently published <a target="_blank" href="https://panamapapers.icij.org/">Panama Papers data</a>.</p>
<p>Since the entire setup for the project is in R – the data preparation, the analysis, the dashboard, and even the presentation – I think it might be of interest to other people of the R community, hence this blogpost. For those impatient, here’s the direct link to the shiny app, and you can ignore my rambings: <a target="_blank" href="https://safferli.shinyapps.io/hackathon_shiny/">https://safferli.shinyapps.io/hackathon_shiny/</a>. I will only post the most intersting code snippets, the full code (for all preparatory data hacking, the shiny dashboard, and the presentation) is available <a target="_blank" href="https://github.com/safferli/mission_economy_hackathon2016">on github</a>, as always.</p>
<h2>Panama Papers</h2>
<p>For those that have been living under a rock in April, the Panama Papers are a leak of data from Mossack Fonseca, a law firm in Panama specialising in setting up offshore companies. It is so far the largest leak (source: <a target="_blank" href="http://www.economist.com/news/international/21696497-huge-trove-documents-has-revealed-secrets-offshore-business-presaging-tougher">The Economist</a>) in history with 2.6TB of (original) data, and 11.5 million documents. It contains references to 29 billionaires (as ranked in Forbes), and 12 current or former country leaders.</p>
<p>The data on the <em>network</em> of firms and persons has recently been <a target="_blank" href="https://offshoreleaks.icij.org/">made available</a>, and contains roughly 320 thousand companies. The hard work of cleaning the raw data and putting it into a useful format (.csv and a graph database format (neo4j) are provided) was done by newspaper companies and journalists world-wide.</p>
<h2>Random Name Generator</h2>
<p>My initial impulse to take a look at the data more closely came when a friend of mine and I realised that a lot of the company names in the Panama Papers actually kind of funny – and that it is extremely clear that nothing reputable can be expected from these companies. For instance, there is a “Moonlight Import/Export”, and a “You’ll See Ltd.”.</p>
<p>So, we agreed that we’d build a random name generator for offshore companies, using the most popular company names from the Panama papers. To make things more “web-two-zero-y”, we would build one of these “modern Facebook viral thingies”, where you can generate the name from your birth date – e.g. your day of birth will always point to a fixed name part. We built a nice infographic for this, which is also available <a target="_blank" href="https://github.com/safferli/mission_economy_hackathon2016/blob/master/offshore-company-name-generator.jpg">on github to download</a>.</p>
<p><img alt="Offshore Company Name Generator" src="http://i1.wp.com/opiateforthemass.es/images/safferli/offshore-company-name-generator.jpg?w=456" data-recalc-dims="1"></p>
<p>How do we get to the names? Quite easily. We first grab the names from provided data, use the excellent <code>tidyr::separate</code> to split the names into their parts (e.g. “My Company” becoming “My” and “Company”), remove a couple of common stopwords and then pick the 31 most prevalent company name parts.</p>
<figure>
<pre><code data-lang="r"><span># read company data provided by the Panama Papers
</span><span>Entities</span><span> </span><span>&lt;-</span><span> </span><span>read_csv</span><span>(</span><span>paste0</span><span>(</span><span>csv_folder</span><span>,</span><span> </span><span>&quot;Entities.csv&quot;</span><span>))</span><span>
</span><span>Entities</span><span> </span><span>%&lt;>%</span><span>
</span><span># get lower-case names
</span><span> </span><span>mutate</span><span>(</span><span>n</span><span> </span><span>=</span><span> </span><span>name</span><span> </span><span>%>%</span><span> </span><span>tolower</span><span>)</span><span> </span><span>%>%</span><span>
</span><span># get last &quot;word&quot; of name for corporation form (e.g. &quot;ltd.&quot;)
</span><span> </span><span>mutate</span><span>(</span><span>form</span><span> </span><span>=</span><span> </span><span>gsub</span><span>(</span><span>&quot;.* &quot;</span><span>,</span><span> </span><span>&quot;&quot;</span><span>,</span><span> </span><span>n</span><span>))</span><span>
</span><span># split the names into one column per &quot;word&quot;
</span><span>Entities</span><span> </span><span>%&lt;>%</span><span> </span><span>separate</span><span>(</span><span>n</span><span>,</span><span> </span><span>paste0</span><span>(</span><span>&quot;n&quot;</span><span>,</span><span> </span><span>1</span><span>:</span><span>20</span><span>),</span><span> </span><span>fill</span><span> </span><span>=</span><span> </span><span>&quot;right&quot;</span><span>)</span><span>
</span><span># stopwords -- we don't want these in our companies
</span><span>stop</span><span> </span><span>&lt;-</span><span> </span><span>c</span><span>(</span><span>letters</span><span>,</span><span> </span><span>&quot;the&quot;</span><span>,</span><span> </span><span>&quot;com&quot;</span><span>,</span><span> </span><span>&quot;and&quot;</span><span>,</span><span> </span><span>&quot;of&quot;</span><span>,</span><span> </span><span>&quot;int&quot;</span><span>,</span><span> </span><span>&quot;pty&quot;</span><span>,</span><span> </span><span>&quot;samoa&quot;</span><span>,</span><span> </span><span>&quot;sdn&quot;</span><span>,</span><span> </span><span>&quot;europe&quot;</span><span>,</span><span> </span><span>&quot;ptc&quot;</span><span>,</span><span> </span><span>&quot;&quot;</span><span>)</span><span>
</span><span># first &quot;word&quot; of the company name
</span><span>n</span><span> </span><span>&lt;-</span><span> </span><span>&quot;n1&quot;</span><span>
</span><span>filter_criteria</span><span> </span><span>&lt;-</span><span> </span><span>lazyeval</span><span>::</span><span>interp</span><span>(</span><span>~</span><span> </span><span>!</span><span> </span><span>col</span><span> </span><span>%in%</span><span> </span><span>stop</span><span> </span><span>&amp;</span><span> </span><span>!</span><span> </span><span>col</span><span> </span><span>%in%</span><span> </span><span>Entities</span><span>$</span><span>form</span><span>,</span><span> </span><span>col</span><span> </span><span>=</span><span> </span><span>as.name</span><span>(</span><span>n</span><span>))</span><span>
</span><span>first</span><span> </span><span>&lt;-</span><span> </span><span>Entities</span><span> </span><span>%>%</span><span> </span><span>group_by_</span><span>(</span><span>.dots</span><span> </span><span>=</span><span> </span><span>n</span><span>)</span><span> </span><span>%>%</span><span> </span><span>summarize</span><span>(</span><span>n</span><span> </span><span>=</span><span> </span><span>n</span><span>())</span><span> </span><span>%>%</span><span> </span><span>filter_</span><span>(</span><span>filter_criteria</span><span>)</span><span> </span><span>%>%</span><span> </span><span>arrange</span><span>(</span><span>-</span><span>n</span><span>)</span><span> </span><span>%>%</span><span> </span><span>.</span><span>[[</span><span>n</span><span>]]</span><span> </span><span>%>%</span><span> </span><span>head</span><span>(</span><span>31</span><span>)</span><span>
</span><span># birthdates: 31 days in a month, get top 31
</span><span>paste</span><span>(</span><span>1</span><span>:</span><span>31</span><span>,</span><span> </span><span>&quot;=&quot;</span><span>,</span><span> </span><span>first</span><span>,</span><span> </span><span>&quot;\n&quot;</span><span>)</span><span> </span><span>%>%</span><span> </span><span>cat</span></code></pre>
</figure>
<p>This we do for the first three parts of the company name, and voilà, the company name generator is done!</p>
<h2>Shiny dashboard</h2>
<p>The next logical step was to build an app for this.</p>
<ol>
<li>randomly generate a name, until you’re satisfied with the result</li>
<li>pick an intermediary – the person who will help you set up the offshore company
<ul>
<li>we’ll let you pick a country you want to start with, and then show the top five intermediaries, ranked by who opened up the most offshore companies</li>
<li>for convenience, we add a google maps link to the intermediary’s address, so you can fire up your GPS easily</li>
<li>check out <a target="_blank" href="https://github.com/safferli/mission_economy_hackathon2016/blob/master/intermediaries_from_country.R">intermediaries_from_country.R</a> on github</li>
</ul>
</li>
<li>pick a jurisdiction for the offshore company by showing pictures of the available beaches
<ul>
<li>beach pictures were taken from the first result of a google image search of <code>&quot;$countryname+beach&quot;</code>, with some fine tuning by hand (the US beach had girls in bikinis, which we did not think were appropriate for such a serious business proposal).</li>
<li>check out <a target="_blank" href="https://github.com/safferli/mission_economy_hackathon2016/blob/master/jurisdiction_images.R">jurisdiction_images.R</a> on github</li>
</ul>
</li>
</ol>
<p>All output is parsed into a <code>fluidRow()</code> UI element, step by step adding a new “row” to the dashboard.</p>
<p>The Shiny app is available on <a target="_blank" href="https://safferli.shinyapps.io/hackathon_shiny/">shinyapps.io</a>, on the free plan, so it will be a bit slow: <a target="_blank" href="https://safferli.shinyapps.io/hackathon_shiny/">https://safferli.shinyapps.io/hackathon_shiny/</a>. Head on over and build your own offshore company!</p>
<h2>Conclusion</h2>
<p>Ironically, we won the “Best Pitch” award for our project, even though we didn’t really <em>pitch</em> anything, and I also did not participate in the pitch training. If you speak German and are not put off by a shaky handcam recording, you can check out my presentation <a target="_blank" href="https://www.facebook.com/handelsblatt/videos/10153740851923233">here</a>. My talk starts at 1hr15min, roughly.</p>
<p>Writing this article, I just found out that there is a Panama Papers <a target="_blank" href="https://github.com/dgrtwo/rpanama">R package on github</a>. So there you go, you can also get the data the easy way!</p>
<p>Code and data for this analysis is available on <a target="_blank" href="https://github.com/safferli/mission_economy_hackathon2016">github</a>, as always.</p>
<p><a target="_blank" href="http://opiateforthemass.es/articles/BYOOC/">Build your own offshore company</a> was originally published by Kirill Pomogajko at <a target="_blank" href="http://opiateforthemass.es/articles/BYOOC/">Opiate for the masses</a> on July 06, 2016.</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/build-your-own-offshore-company/"></div></div><div><a data-url="http://www.r-bloggers.com/build-your-own-offshore-company/" data-counturl="http://www.r-bloggers.com/build-your-own-offshore-company/" data-count="vertical" data-text="Build your own offshore company" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://opiateforthemass.es/articles/BYOOC/"> Opiate for the masses</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/Djnx-v4Va18"></a></div>