

{"id":4622,"date":"2016-08-08T18:22:35","date_gmt":"2016-08-08T23:22:35","guid":{"rendered":"https:\/\/rud.is\/b\/?p=4622"},"modified":"2018-03-07T16:40:37","modified_gmt":"2018-03-07T21:40:37","slug":"counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion","status":"publish","type":"post","link":"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/","title":{"rendered":"Counting [U.S.] Expatriation with R (a.k.a. a Decade of Desertion)"},"content":{"rendered":"<div style=\"text-align:left; font-size:11pt; font-style:italic; margin-left:22pt; margin-right:22pt; border-left:4px solid #b2b2b2; border-right:4px solid #b2b2b2; padding-left:5.5pt; padding-right:5.5pt\">\n<b>2016-08-13 UPDATE:<\/b> Fortune <a href=\"http:\/\/fortune.com\/2016\/08\/11\/us-citizens-renounce\/\">has a story on this<\/a> and it does seem to be tax-related vs ideology. @thosjleeper suggested something similar as well about a week ago.\n<\/div>\n<p>If you&#8217;re even remotely following the super insane U.S. 2016 POTUS <strike>circus<\/strike> election you&#8217;ve no doubt seen a resurgence of _&#8221;if X gets elected, I&#8217;m moving to Y&#8221;_ claims by folks who are &#8220;anti&#8221; one candidate or another. The [Washington Examiner](http:\/\/www.washingtonexaminer.com\/americans-renouncing-citizenship-near-record-highs\/article\/2598074) did a story on last quarter&#8217;s U.S. expatriation numbers. I didn&#8217;t realize we had a department in charge of tracking and posting that data, but we do thanks to inane bureaucratic compliance laws.<\/p>\n<p>I should have put _&#8221;posting that data&#8221;_ in quotes as it&#8217;s collected quarterly and posted ~2 months later in non-uniform HTML and PDF form across individual posts in a unique\/custom Federal Register publishing system. How&#8217;s that hope and change in &#8220;open government data&#8221; working out for y&#8217;all?<\/p>\n<p>The data is organized enough that we can take a look at the history of expatriation with some help from R. Along the way we&#8217;ll:<\/p>\n<p>&#8211; see how to make parameterized web requests a bit cleaner with `httr`<br \/>\n&#8211; get even _more_ practice using the `purrr` package<br \/>\n&#8211; perhaps learn a new &#8220;trick&#8221; when using the `stringi` package<br \/>\n&#8211; show how we can &#8220;make do&#8221; living in a non-XPath 2 world (it&#8217;s actually pretty much at XPath 3 now, too #sigh) <\/p>\n<p>A manual hunt on that system will eventually reveal a search URL that you can use in a `read.csv()` (to grab a list of URLs with the data, not the data itself #ugh). Those URLs are _gnarly_ (you&#8217;ll see what I mean if you do the hunt) but we can take advantage of the standardized URL query parameter that are used in the egregiously long URLs in a far more readable fashion if we use `httr::GET()` directly, especially since `httr::content()` will auto-convert the resultant CSV to a `tibble` for us since the site sets the response MIME type appropriately.<\/p>\n<p>Unfortunately, when using the `6039G` search parameter (the expatriate tracking form ID) we do need to filter out non-quarterly report documents since the bureaucrats must have their ancillary TPS reports.<\/p>\n<pre id=\"expat-get-csv\"><code class=\"language-r\">library(dplyr)\r\nlibrary(httr)\r\nlibrary(rvest)\r\nlibrary(purrr)\r\nlibrary(lubridate)\r\nlibrary(ggplot2) # devtools::install_github(&quot;hadley\/ggplot2&quot;)\r\nlibrary(hrbrmisc) # devtools::install_github(&quot;hrbrmstr\/hrbrmisc&quot;)\r\nlibrary(ggalt)\r\nlibrary(grid)\r\nlibrary(scales)\r\nlibrary(magrittr)\r\nlibrary(stringi)\r\n\r\nGET(&quot;https:\/\/www.federalregister.gov\/articles\/search.csv&quot;,\r\n    query=list(`conditions[agency_ids][]`=254,\r\n               `conditions[publication_date][gte]`=&quot;01\/01\/2006&quot;,\r\n               `conditions[publication_date][lte]`=&quot;7\/29\/2016&quot;,\r\n               `conditions[term]`=&quot;6039G&quot;,\r\n               `conditions[type][]`=&quot;NOTICE&quot;)) %&gt;%\r\n  content(&quot;parsed&quot;) %&gt;%\r\n  filter(grepl(&quot;^Quarterly&quot;, title)) -&gt; register\r\n\r\nglimpse(register)\r\n## Observations: 44\r\n## Variables: 9\r\n## $ citation         &lt;chr&gt; &quot;81 FR 50058&quot;, &quot;81 FR 27198&quot;, &quot;81 FR 65...\r\n## $ document_number  &lt;chr&gt; &quot;2016-18029&quot;, &quot;2016-10578&quot;, &quot;2016-02312...\r\n## $ title            &lt;chr&gt; &quot;Quarterly Publication of Individuals, ...\r\n## $ publication_date &lt;chr&gt; &quot;07\/29\/2016&quot;, &quot;05\/05\/2016&quot;, &quot;02\/08\/2016...\r\n## $ type             &lt;chr&gt; &quot;Notice&quot;, &quot;Notice&quot;, &quot;Notice&quot;, &quot;Notice&quot;,...\r\n## $ agency_names     &lt;chr&gt; &quot;Treasury Department; Internal Revenue ...\r\n## $ html_url         &lt;chr&gt; &quot;https:\/\/www.federalregister.gov\/articl...\r\n## $ page_length      &lt;int&gt; 9, 17, 16, 20, 8, 20, 16, 12, 9, 15, 8,...\r\n## $ qtr              &lt;date&gt; 2016-06-30, 2016-03-31, 2015-12-31, 20...<\/code><\/pre>\n<p>Now, we grab the content at each of the `html_url`s and save them off to be kind to bandwidth and\/or folks with slow connections (so you don&#8217;t have to re-grab the HTML):<\/p>\n<pre id=\"expat-get-html\"><code class=\"language-r\">docs &lt;- map(register$html_url, read_html)\r\nsaveRDS(docs, file=&quot;deserters.rds&quot;)<\/code><\/pre>\n<p>That generates a list of parsed HTML documents.<\/p>\n<p>The reporting dates aren&#8217;t 100% consistent (i.e. not always &#8220;n&#8221; weeks from the collection date), but the data collection dates _embedded textually in the report_ are (mostly&hellip;some vary in the use of upper\/lower case). So, we use the fact that these are boring legal documents that use the same language for various phrases and extract the &#8220;quarter ending&#8221; dates so we know what year\/quarter the data is relevant for:<\/p>\n<pre id=\"expat-year-qtr\"><code class=\"language-r\">register %&lt;&gt;%\r\n  mutate(qtr=map_chr(docs, ~stri_match_all_regex(html_text(.), &quot;quarter ending ([[:alnum:], ]+)\\\\.&quot;,\r\n                                                     opts_regex=stri_opts_regex(case_insensitive=TRUE))[[1]][,2]),\r\n         qtr=mdy(qtr))<\/code><\/pre>\n<p>I don&#8217;t often use that particular `magrittr` pipe, but it &#8220;feels right&#8221; in this case and is handy in a pinch.<\/p>\n<p>If you visit some of the URLs directly, you&#8217;ll see that there are tables and\/or lists of names of the expats. However, there are woefully inconsistent naming &#038; formatting conventions for these lists of names *and* (as I noted earlier) there&#8217;s no XPath 2 support in R. Therefore, we have to make a slightly more verbose XPath query to target the necessary table for scraping since we need to account for vastly different column name structures for the tables we are targeting.<\/p>\n<p>NOTE: Older HTML pages may not have HTML tables at all and some only reference PDFs, so don&#8217;t rely on this code working beyond these particular dates (at least consistently).<\/p>\n<p>We&#8217;ll also tidy up the data into a neat `tibble` for plotting.<\/p>\n<pre id=\"expat-tabs\"><code class=\"language-r\">map(docs, ~html_nodes(., xpath=&quot;.\/\/table[contains(., &#039;First name&#039;) or\r\n                                         contains(., &#039;FIRST NAME&#039;) or\r\n                                         contains(., &#039;FNAME&#039;)]&quot;)) %&gt;%\r\n  map(~html_table(.)[[1]]) -&gt; tabs\r\n\r\ndata_frame(date=register$qtr, count=map_int(tabs, nrow)) %&gt;%\r\n  filter(format(as.Date(date), &quot;%Y&quot;) &gt;= 2006) -&gt; left<\/code><\/pre>\n<p>With the data wrangling work out of the way, we can tally up the throngs of folks desperate for greener pastures. First, by quarter:<\/p>\n<pre id=\"expat-plot-01\"><code class=\"language-r\">gg &lt;- ggplot(left, aes(date, count))\r\ngg &lt;- gg + geom_lollipop()\r\ngg &lt;- gg + geom_label(data=data.frame(),\r\n                      aes(x=min(left$date), y=1500, label=&quot;# individuals&quot;),\r\n                      family=&quot;Arial Narrow&quot;, fontface=&quot;italic&quot;, size=3, label.size=0, hjust=0)\r\ngg &lt;- gg + scale_x_date(expand=c(0,14), limits=range(left$date))\r\ngg &lt;- gg + scale_y_continuous(expand=c(0,0), label=comma, limits=c(0,1520))\r\ngg &lt;- gg + labs(x=NULL, y=NULL,\r\n                title=&quot;A Decade of Desertion&quot;,\r\n                subtitle=&quot;Quarterly counts of U.S. individuals who have chosen to expatriate (2006-2016)&quot;,\r\n                caption=&quot;Source: https:\/\/www.federalregister.gov\/&quot;)\r\ngg &lt;- gg + theme_hrbrmstr_an(grid=&quot;Y&quot;)\r\ngg<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4623\" data-permalink=\"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/rstudio-12\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio.png?fit=1312%2C726&amp;ssl=1\" data-orig-size=\"1312,726\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"RStudio\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio.png?fit=510%2C282&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio.png?resize=510%2C282&#038;ssl=1\" alt=\"RStudio\" width=\"510\" height=\"282\" class=\"aligncenter size-full wp-image-4623\" \/><\/a><\/p>\n<p>and, then annually:<\/p>\n<pre id=\"expat-plot-02\"><code class=\"language-r\">left %&gt;%\r\n  mutate(year=format(date, &quot;%Y&quot;)) %&gt;%\r\n  count(year, wt=count) %&gt;%\r\n  ggplot(aes(year, n)) -&gt; gg\r\n\r\ngg &lt;- gg + geom_bar(stat=&quot;identity&quot;, width=0.6)\r\ngg &lt;- gg + geom_label(data=data.frame(), aes(x=0, y=5000, label=&quot;# individuals&quot;),\r\n                      family=&quot;Arial Narrow&quot;, fontface=&quot;italic&quot;, size=3, label.size=0, hjust=0)\r\ngg &lt;- gg + scale_y_continuous(expand=c(0,0), label=comma, limits=c(0,5100))\r\ngg &lt;- gg + labs(x=NULL, y=NULL,\r\n                title=&quot;A Decade of Desertion&quot;,\r\n                subtitle=&quot;Annual counts of U.S. individuals who have chosen to expatriate (2006-2016)&quot;,\r\n                caption=&quot;Source: https:\/\/www.federalregister.gov\/&quot;)\r\ngg &lt;- gg + theme_hrbrmstr_an(grid=&quot;Y&quot;)\r\ngg<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio-1.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4624\" data-permalink=\"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/rstudio-13\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio-1.png?fit=1310%2C730&amp;ssl=1\" data-orig-size=\"1310,730\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"RStudio\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio-1.png?fit=510%2C284&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio-1.png?resize=510%2C284&#038;ssl=1\" alt=\"RStudio\" width=\"510\" height=\"284\" class=\"aligncenter size-full wp-image-4624\" \/><\/a><\/p>\n<p>The exodus isn&#8217;t _massive_ but it&#8217;s actually more than I expected. It&#8217;d be interesting to track various US tax code laws, enactment of other compliance regulations and general news events to see if there are underlying reasons for the overall annual increases but also the dips in some quarters (which could just be data collection hiccups by the Feds&hellip;after all, this is government work). If you want to do all the math for correcting survey errors, it&#8217;d also be interesting to normalize this by population and track all the data back to 1996 (when HIPPA mandated the creation &#038; publication of this quarterly list) and then see if you can predict where we&#8217;ll be at the end of this year (though I suspect political events are a motivator for at least a decent fraction of some of the quarters).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2016-08-13 UPDATE: Fortune has a story on this and it does seem to be tax-related vs ideology. @thosjleeper suggested something similar as well about a week ago. If you&#8217;re even remotely following the super insane U.S. 2016 POTUS circus election you&#8217;ve no doubt seen a resurgence of _&#8221;if X gets elected, I&#8217;m moving to Y&#8221;_ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4624,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[91],"tags":[810],"class_list":["post-4622","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-post"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Counting [U.S.] Expatriation with R (a.k.a. a Decade of Desertion) - rud.is<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Counting [U.S.] Expatriation with R (a.k.a. a Decade of Desertion) - rud.is\" \/>\n<meta property=\"og:description\" content=\"2016-08-13 UPDATE: Fortune has a story on this and it does seem to be tax-related vs ideology. @thosjleeper suggested something similar as well about a week ago. If you&#8217;re even remotely following the super insane U.S. 2016 POTUS circus election you&#8217;ve no doubt seen a resurgence of _&#8221;if X gets elected, I&#8217;m moving to Y&#8221;_ [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/\" \/>\n<meta property=\"og:site_name\" content=\"rud.is\" \/>\n<meta property=\"article:published_time\" content=\"2016-08-08T23:22:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-03-07T21:40:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio-1.png?fit=1310%2C730&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1310\" \/>\n\t<meta property=\"og:image:height\" content=\"730\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"hrbrmstr\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"hrbrmstr\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/08\\\/08\\\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/08\\\/08\\\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\\\/\"},\"author\":{\"name\":\"hrbrmstr\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"headline\":\"Counting [U.S.] Expatriation with R (a.k.a. a Decade of Desertion)\",\"datePublished\":\"2016-08-08T23:22:35+00:00\",\"dateModified\":\"2018-03-07T21:40:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/08\\\/08\\\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\\\/\"},\"wordCount\":859,\"commentCount\":6,\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"image\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/08\\\/08\\\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2016\\\/08\\\/RStudio-1.png?fit=1310%2C730&ssl=1\",\"keywords\":[\"post\"],\"articleSection\":[\"R\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/08\\\/08\\\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/08\\\/08\\\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\\\/\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/08\\\/08\\\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\\\/\",\"name\":\"Counting [U.S.] Expatriation with R (a.k.a. a Decade of Desertion) - rud.is\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/08\\\/08\\\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/08\\\/08\\\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2016\\\/08\\\/RStudio-1.png?fit=1310%2C730&ssl=1\",\"datePublished\":\"2016-08-08T23:22:35+00:00\",\"dateModified\":\"2018-03-07T21:40:37+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/08\\\/08\\\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/08\\\/08\\\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/08\\\/08\\\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2016\\\/08\\\/RStudio-1.png?fit=1310%2C730&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2016\\\/08\\\/RStudio-1.png?fit=1310%2C730&ssl=1\",\"width\":1310,\"height\":730},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2016\\\/08\\\/08\\\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/rud.is\\\/b\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Counting [U.S.] Expatriation with R (a.k.a. a Decade of Desertion)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/\",\"name\":\"rud.is\",\"description\":\"&quot;In God we trust. All others must bring data&quot;\",\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/rud.is\\\/b\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\",\"name\":\"hrbrmstr\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"width\":460,\"height\":460,\"caption\":\"hrbrmstr\"},\"logo\":{\"@id\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\"},\"description\":\"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7\",\"sameAs\":[\"http:\\\/\\\/rud.is\"],\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/author\\\/hrbrmstr\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Counting [U.S.] Expatriation with R (a.k.a. a Decade of Desertion) - rud.is","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/","og_locale":"en_US","og_type":"article","og_title":"Counting [U.S.] Expatriation with R (a.k.a. a Decade of Desertion) - rud.is","og_description":"2016-08-13 UPDATE: Fortune has a story on this and it does seem to be tax-related vs ideology. @thosjleeper suggested something similar as well about a week ago. If you&#8217;re even remotely following the super insane U.S. 2016 POTUS circus election you&#8217;ve no doubt seen a resurgence of _&#8221;if X gets elected, I&#8217;m moving to Y&#8221;_ [&hellip;]","og_url":"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/","og_site_name":"rud.is","article_published_time":"2016-08-08T23:22:35+00:00","article_modified_time":"2018-03-07T21:40:37+00:00","og_image":[{"width":1310,"height":730,"url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio-1.png?fit=1310%2C730&ssl=1","type":"image\/png"}],"author":"hrbrmstr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"hrbrmstr","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/#article","isPartOf":{"@id":"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/"},"author":{"name":"hrbrmstr","@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"headline":"Counting [U.S.] Expatriation with R (a.k.a. a Decade of Desertion)","datePublished":"2016-08-08T23:22:35+00:00","dateModified":"2018-03-07T21:40:37+00:00","mainEntityOfPage":{"@id":"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/"},"wordCount":859,"commentCount":6,"publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"image":{"@id":"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio-1.png?fit=1310%2C730&ssl=1","keywords":["post"],"articleSection":["R"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/","url":"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/","name":"Counting [U.S.] Expatriation with R (a.k.a. a Decade of Desertion) - rud.is","isPartOf":{"@id":"https:\/\/rud.is\/b\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/#primaryimage"},"image":{"@id":"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio-1.png?fit=1310%2C730&ssl=1","datePublished":"2016-08-08T23:22:35+00:00","dateModified":"2018-03-07T21:40:37+00:00","breadcrumb":{"@id":"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/#primaryimage","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio-1.png?fit=1310%2C730&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio-1.png?fit=1310%2C730&ssl=1","width":1310,"height":730},{"@type":"BreadcrumbList","@id":"https:\/\/rud.is\/b\/2016\/08\/08\/counting-u-s-expatriation-with-r-a-k-a-a-decade-of-desertion\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rud.is\/b\/"},{"@type":"ListItem","position":2,"name":"Counting [U.S.] Expatriation with R (a.k.a. a Decade of Desertion)"}]},{"@type":"WebSite","@id":"https:\/\/rud.is\/b\/#website","url":"https:\/\/rud.is\/b\/","name":"rud.is","description":"&quot;In God we trust. All others must bring data&quot;","publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/rud.is\/b\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886","name":"hrbrmstr","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","width":460,"height":460,"caption":"hrbrmstr"},"logo":{"@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1"},"description":"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7","sameAs":["http:\/\/rud.is"],"url":"https:\/\/rud.is\/b\/author\/hrbrmstr\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/08\/RStudio-1.png?fit=1310%2C730&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p23idr-1cy","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":5801,"url":"https:\/\/rud.is\/b\/2017\/04\/13\/come-fly-with-me-well-not-really-comparing-involuntary-disembarking-rates-across-u-s-airlines-in-r\/","url_meta":{"origin":4622,"position":0},"title":"Come Fly With Me (well, not really) \u2014 Comparing Involuntary Disembarking Rates Across U.S. Airlines in R","author":"hrbrmstr","date":"2017-04-13","format":false,"excerpt":"By now, word of the forcible deplanement of a medical professional by United has reached even the remotest of outposts in the #rstats universe. Since the news brought this practice to global attention, I found some aggregate U.S. Gov data made a quick, annual, aggregate look at this soon after\u2026","rel":"","context":"In &quot;data wrangling&quot;","block_context":{"text":"data wrangling","link":"https:\/\/rud.is\/b\/category\/data-wrangling\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3413,"url":"https:\/\/rud.is\/b\/2015\/05\/15\/u-s-drought-monitoring-with-hexbin-state-maps-in-r\/","url_meta":{"origin":4622,"position":1},"title":"U.S. Drought Monitoring With Hexbin State Maps in R","author":"hrbrmstr","date":"2015-05-15","format":false,"excerpt":"On the news, today, of the early stages of drought hitting the U.S. northeast states I decided to springboard off of yesterday's post and show a more practical use of hexbin state maps than the built-in (and still purpose unknown to me) \"bees\" data. The U.S. Drought Monitor site supplies\u2026","rel":"","context":"In &quot;cartography&quot;","block_context":{"text":"cartography","link":"https:\/\/rud.is\/b\/category\/cartography\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4826,"url":"https:\/\/rud.is\/b\/2017\/01\/04\/the-most-important-commodity-in-2017-is-data\/","url_meta":{"origin":4622,"position":2},"title":"The Most Important Commodity in 2017 is Data","author":"hrbrmstr","date":"2017-01-04","format":false,"excerpt":"Despite being in cybersecurity nigh forever (a career that quickly turns one into a determined skeptic if you're doing your job correctly) I have often trusted various (not to be named) news sources, reports and data sources to provide honest and as-unbiased-as-possible information. The debacle in the U.S. in late\u2026","rel":"","context":"In &quot;Data Analysis&quot;","block_context":{"text":"Data Analysis","link":"https:\/\/rud.is\/b\/category\/data-analysis-2\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/01\/BN-RL751_NACM98_9U_20170103102059.jpg?fit=700%2C683&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/01\/BN-RL751_NACM98_9U_20170103102059.jpg?fit=700%2C683&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/01\/BN-RL751_NACM98_9U_20170103102059.jpg?fit=700%2C683&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2017\/01\/BN-RL751_NACM98_9U_20170103102059.jpg?fit=700%2C683&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":4474,"url":"https:\/\/rud.is\/b\/2016\/06\/28\/making-time-rivers-in-r\/","url_meta":{"origin":4622,"position":3},"title":"Making &#8220;Time Rivers&#8221; in R","author":"hrbrmstr","date":"2016-06-28","format":false,"excerpt":"Once again, @albertocairo notices an interesting chart and spurs pondering in the visualization community with [his post](http:\/\/www.thefunctionalart.com\/2016\/06\/defying-conventions-in-visualization.html) covering an unusual \"vertical time series\" chart produced for the print version of the NYTimes: I'm actually less concerned about the vertical time series chart component here since I agree with TAVE* Cairo\u2026","rel":"","context":"In &quot;Charts &amp; Graphs&quot;","block_context":{"text":"Charts &amp; Graphs","link":"https:\/\/rud.is\/b\/category\/charts-graphs\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/06\/Cursor_and_RStudio-1.png?fit=1200%2C1181&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/06\/Cursor_and_RStudio-1.png?fit=1200%2C1181&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/06\/Cursor_and_RStudio-1.png?fit=1200%2C1181&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/06\/Cursor_and_RStudio-1.png?fit=1200%2C1181&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/06\/Cursor_and_RStudio-1.png?fit=1200%2C1181&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":4217,"url":"https:\/\/rud.is\/b\/2016\/03\/29\/easier-composite-u-s-choropleths-with-albersusa\/","url_meta":{"origin":4622,"position":4},"title":"Easier Composite U.S. Choropleths with albersusa","author":"hrbrmstr","date":"2016-03-29","format":false,"excerpt":"Folks who've been tracking this blog on R-bloggers probably remember [this post](https:\/\/rud.is\/b\/2014\/11\/16\/moving-the-earth-well-alaska-hawaii-with-r\/) where I showed how to create a composite U.S. map with an Albers projection (which is commonly referred to as AlbersUSA these days thanks to D3). I'm not sure why I didn't think of this earlier, but you\u2026","rel":"","context":"In &quot;cartography&quot;","block_context":{"text":"cartography","link":"https:\/\/rud.is\/b\/category\/cartography\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1622,"url":"https:\/\/rud.is\/b\/2012\/10\/05\/diy-zeroaccess-geoip-visualizations-back-to-the-basics\/","url_meta":{"origin":4622,"position":5},"title":"DIY ZeroAccess GeoIP Visualizations :: Back To The Basics","author":"hrbrmstr","date":"2012-10-05","format":false,"excerpt":"While shiny visualizations are all well-and-good, sometimes plain ol' charts & graphs can give you the data you're looking for. If we take the one-liner filter from the previous example and use it to just output CSV-formatted summary data: cat ZeroAccessGeoIPs.csv | cut -f1,1 -d\\,| sort | uniq -c |\u2026","rel":"","context":"In &quot;Charts &amp; Graphs&quot;","block_context":{"text":"Charts &amp; Graphs","link":"https:\/\/rud.is\/b\/category\/charts-graphs\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/4622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/comments?post=4622"}],"version-history":[{"count":0,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/4622\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media\/4624"}],"wp:attachment":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media?parent=4622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/categories?post=4622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/tags?post=4622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}