{"id":134,"date":"2008-10-01T23:41:38","date_gmt":"2008-10-02T03:41:38","guid":{"rendered":"http:\/\/metcaffeination.net\/weblog\/?p=134"},"modified":"2008-10-01T23:41:38","modified_gmt":"2008-10-02T03:41:38","slug":"bailout-and-mathematica","status":"publish","type":"post","link":"https:\/\/metcaffeination.net\/weblog\/2008\/10\/01\/bailout-and-mathematica\/","title":{"rendered":"Bailout and Mathematica"},"content":{"rendered":"<p>A friend of mine (and regular commenter here) has pointed out that, even if the $700,000,000,000 bailout passes, and adds to our National Debt, we&#8217;d still have a <a href=\"http:\/\/en.wikipedia.org\/wiki\/List_of_countries_by_public_debt\">Debt-to-GDP ratio<\/a> that was less than Germany&#8217;s.<sup><a href=\"#footnote_0_134\" id=\"identifier_0_134\" class=\"footnote-link footnote-identifier-link\" title=\"He is, nevertheless, against the bailout.\">1<\/a><\/sup> Wikipedia says that the US National Debt is 60.8% of our GDP, that Germany&#8217;s is 63.1%, and that our GDP is $13.8 trillion. Well, add $700 billion to 60.8% of $13.8 trillion and the new figure is 65.8%&#8211;pretty close; there are different ways of measuring both GDP and the Debt.<\/p>\n<p>But I realized that this sort of comparison is something that <a href=\"http:\/\/www.wolfram.com\/products\/mathematica\/index.html\">Mathematica 6<\/a> is supposed to be good at.  Mathematica is an amazingly powerful system for doing mathematics on a computer. Its strength, traditionally, has been symbolic manipulation&#8211;I most often use it for the <a href=\"http:\/\/integrals.wolfram.com\/index.jsp\">Integrate<\/a> command, which can do most of the integrals that in grad school I&#8217;d look up in <a href=\"http:\/\/www.mathtable.com\/gr\/\">Gradshteyn and Ryzhik<\/a>. Version 6 has added, <a href=\"http:\/\/www.wolfram.com\/products\/mathematica\/newin6\/\">amongst other things<\/a>, a<a href=\"http:\/\/www.wolfram.com\/products\/mathematica\/newin6\/content\/LoadOnDemandCuratedData\/\"> huge library of curated data<\/a>, loaded over the Internet, that&#8217;s relatively straightforward to use.<\/p>\n<p>The command <a href=\"http:\/\/reference.wolfram.com\/mathematica\/ref\/CountryData.html\">CountryData<\/a> gives access to all sorts of country-by-country information, including &#8220;GDP&#8221; and &#8220;GovernmentDebt&#8221;. So following one of the examples in the documentation, I produced this graph, plotting the Debt-to-GDP ratio versus GDP for (nearly) all the countries for which Mathematica has data. (Note that the x-axis is a logarithmic scale.) The United States, before and after a $700 billion bailout, are shown in green and red, respectively. <\/p>\n<p>If the xhtml export actually works the way it&#8217;s supposed to, you should be able to hover your mouse cursor over each point and have a little ToolTip pop up telling you which country the data are for.<\/p>\n<table class='Output'>\n<tr style='vertical-align:middle;'>\n<td style='text-align: center;'><span><img src='http:\/\/metcaffeination.net\/weblog\/wp-content\/uploads\/2008\/10\/debtgdpxhtml_1.gif' alt='\"debtgdp.xhtml_1.gif\"' width='400' height='262' style='vertical-align:middle' usemap='#map_1'\/><\/p>\n<map name='map_1'>\n<area shape='rect' coords='374,172,378,168' title='Bailed Out United States' \/>\n<area shape='rect' coords='374,178,378,174' title='Present United States' \/>\n<area shape='rect' coords='41,91,45,87' title='Zimbabwe' \/>\n<area shape='rect' coords='109,193,113,189' title='Zambia' \/>\n<area shape='rect' coords='128,214,132,210' title='Yemen' \/>\n<area shape='rect' coords='171,197,175,193' title='Vietnam' \/>\n<area shape='rect' coords='213,219,217,215' title='Venezuela' \/>\n<area shape='rect' coords='123,216,127,212' title='Uzbekistan' \/>\n<area shape='rect' coords='130,166,134,162' title='Uruguay' \/>\n<area shape='rect' coords='374,178,378,174' title='United States' \/>\n<area shape='rect' coords='309,202,313,198' title='United Kingdom' \/>\n<area shape='rect' coords='214,233,218,229' title='United Arab Emirates' \/>\n<area shape='rect' coords='194,232,198,228' title='Ukraine' \/>\n<area shape='rect' coords='107,183,111,179' title='Uganda' \/>\n<area shape='rect' coords='242,176,246,172' title='Turkey' \/>\n<area shape='rect' coords='147,183,151,179' title='Tunisia' \/>\n<area shape='rect' coords='128,207,132,203' title='Trinidad and Tobago' \/>\n<area shape='rect' coords='218,201,222,197' title='Thailand' \/>\n<area shape='rect' coords='115,174,119,170' title='Tanzania' \/>\n<area shape='rect' coords='235,209,239,205' title='Taiwan' \/>\n<area shape='rect' coords='148,210,152,206' title='Syria' \/>\n<area shape='rect' coords='241,189,245,185' title='Switzerland' \/>\n<area shape='rect' coords='241,194,245,190' title='Sweden' \/>\n<area shape='rect' coords='152,162,156,158' title='Sudan' \/>\n<area shape='rect' coords='143,155,147,151' title='Sri Lanka' \/>\n<area shape='rect' coords='285,202,289,198' title='Spain' \/>\n<area shape='rect' coords='272,227,276,223' title='South Korea' \/>\n<area shape='rect' coords='225,208,229,204' title='South Africa' \/>\n<area shape='rect' coords='154,217,158,213' title='Slovenia' \/>\n<area shape='rect' coords='169,212,173,208' title='Slovakia' \/>\n<area shape='rect' coords='202,144,206,140' title='Singapore' \/>\n<area shape='rect' coords='7,59,11,55' title='Seychelles' \/>\n<area shape='rect' coords='153,206,157,202' title='Serbia' \/>\n<area shape='rect' coords='103,200,107,196' title='Senegal' \/>\n<area shape='rect' coords='240,204,244,200' title='Saudi Arabia' \/>\n<area shape='rect' coords='277,236,281,232' title='Russia' \/>\n<area shape='rect' coords='199,229,203,225' title='Romania' \/>\n<area shape='rect' coords='167,215,171,211' title='Qatar' \/>\n<area shape='rect' coords='216,178,220,174' title='Portugal' \/>\n<area shape='rect' coords='236,200,240,196' title='Poland' \/>\n<area shape='rect' coords='197,178,201,174' title='Philippines' \/>\n<area shape='rect' coords='187,210,191,206' title='Peru' \/>\n<area shape='rect' coords='102,213,106,209' title='Paraguay' \/>\n<area shape='rect' coords='87,205,91,201' title='Papua New Guinea' \/>\n<area shape='rect' coords='125,181,129,177' title='Panama' \/>\n<area shape='rect' coords='206,201,210,197' title='Pakistan' \/>\n<area shape='rect' coords='153,240,157,236' title='Oman' \/>\n<area shape='rect' coords='236,197,240,193' title='Norway' \/>\n<area shape='rect' coords='202,237,206,233' title='Nigeria' \/>\n<area shape='rect' coords='82,161,86,157' title='Nicaragua' \/>\n<area shape='rect' coords='194,222,198,218' title='New Zealand' \/>\n<area shape='rect' coords='262,191,266,187' title='Netherlands' \/>\n<area shape='rect' coords='88,211,92,207' title='Namibia' \/>\n<area shape='rect' coords='94,225,98,221' title='Mozambique' \/>\n<area shape='rect' coords='175,183,179,179' title='Morocco' \/>\n<area shape='rect' coords='65,168,69,164' title='Moldova' \/>\n<area shape='rect' coords='270,229,274,225' title='Mexico' \/>\n<area shape='rect' coords='89,172,93,168' title='Mauritius' \/>\n<area shape='rect' coords='206,201,210,197' title='Malaysia' \/>\n<area shape='rect' coords='49,32,53,28' title='Malawi' \/>\n<area shape='rect' coords='88,213,92,209' title='Macedonia' \/>\n<area shape='rect' coords='146,229,150,225' title='Lithuania' \/>\n<area shape='rect' coords='166,240,170,236' title='Libya' \/>\n<area shape='rect' coords='135,50,139,46' title='Lebanon' \/>\n<area shape='rect' coords='131,238,135,234' title='Latvia' \/>\n<area shape='rect' coords='192,237,196,233' title='Kuwait' \/>\n<area shape='rect' coords='138,201,142,197' title='Kenya' \/>\n<area shape='rect' coords='182,239,186,235' title='Kazakhstan' \/>\n<area shape='rect' coords='119,168,123,164' title='Jordan' \/>\n<area shape='rect' coords='333,62,337,58' title='Japan' \/>\n<area shape='rect' coords='107,104,111,100' title='Jamaica' \/>\n<area shape='rect' coords='127,179,131,175' title='Ivory Coast' \/>\n<area shape='rect' coords='300,129,304,125' title='Italy' \/>\n<area shape='rect' coords='204,142,208,138' title='Israel' \/>\n<area shape='rect' coords='220,219,224,215' title='Ireland' \/>\n<area shape='rect' coords='224,218,228,214' title='Iran' \/>\n<area shape='rect' coords='240,203,244,199' title='Indonesia' \/>\n<area shape='rect' coords='273,193,277,189' title='India' \/>\n<area shape='rect' coords='122,211,126,207' title='Iceland' \/>\n<area shape='rect' coords='196,182,200,178' title='Hungary' \/>\n<area shape='rect' coords='215,246,219,242' title='Hong Kong' \/>\n<area shape='rect' coords='103,177,107,173' title='Honduras' \/>\n<area shape='rect' coords='147,216,151,212' title='Guatemala' \/>\n<area shape='rect' coords='233,158,237,154' title='Greece' \/>\n<area shape='rect' coords='113,174,117,170' title='Ghana' \/>\n<area shape='rect' coords='317,173,321,169' title='Germany' \/>\n<area shape='rect' coords='104,215,108,211' title='Gabon' \/>\n<area shape='rect' coords='307,175,311,171' title='France' \/>\n<area shape='rect' coords='219,206,223,202' title='Finland' \/>\n<area shape='rect' coords='116,162,120,158' title='Ethiopia' \/>\n<area shape='rect' coords='123,243,127,239' title='Estonia' \/>\n<area shape='rect' coords='104,243,108,239' title='Equatorial Guinea' \/>\n<area shape='rect' coords='128,198,132,194' title='El Salvador' \/>\n<area shape='rect' coords='195,137,199,133' title='Egypt' \/>\n<area shape='rect' coords='158,210,162,206' title='Ecuador' \/>\n<area shape='rect' coords='148,200,152,196' title='Dominican Republic' \/>\n<area shape='rect' coords='229,208,233,204' title='Denmark' \/>\n<area shape='rect' coords='204,222,208,218' title='Czech Republic' \/>\n<area shape='rect' coords='128,174,132,170' title='Cyprus' \/>\n<area shape='rect' coords='159,198,163,194' title='Croatia' \/>\n<area shape='rect' coords='135,189,139,185' title='Costa Rica' \/>\n<area shape='rect' coords='201,195,205,191' title='Colombia' \/>\n<area shape='rect' coords='314,227,318,223' title='China' \/>\n<area shape='rect' coords='205,241,209,237' title='Chile' \/>\n<area shape='rect' coords='286,177,290,173' title='Canada' \/>\n<area shape='rect' coords='128,179,132,175' title='Cameroon' \/>\n<area shape='rect' coords='147,216,151,212' title='Bulgaria' \/>\n<area shape='rect' coords='280,203,284,199' title='Brazil' \/>\n<area shape='rect' coords='101,240,105,236' title='Botswana' \/>\n<area shape='rect' coords='110,221,114,217' title='Bosnia and Herzegovina' \/>\n<area shape='rect' coords='16,155,20,151' title='Bhutan' \/>\n<area shape='rect' coords='242,146,246,142' title='Belgium' \/>\n<area shape='rect' coords='177,200,181,196' title='Bangladesh' \/>\n<area shape='rect' coords='123,216,127,212' title='Bahrain' \/>\n<area shape='rect' coords='131,239,135,235' title='Azerbaijan' \/>\n<area shape='rect' coords='235,177,239,173' title='Austria' \/>\n<area shape='rect' coords='268,231,272,227' title='Australia' \/>\n<area shape='rect' coords='52,197,56,193' title='Aruba' \/>\n<area shape='rect' coords='220,177,224,173' title='Argentina' \/>\n<area shape='rect' coords='163,221,167,217' title='Angola' \/>\n<area shape='rect' coords='197,217,201,213' title='Algeria' \/>\n<area shape='rect' coords='167,215,171,211' title='Qatar' \/>\n<area shape='rect' coords='202,237,206,233' title='Nigeria' \/>\n<area shape='rect' coords='262,191,266,187' title='Netherlands' \/>\n<area shape='rect' coords='88,211,92,207' title='Namibia' \/>\n<area shape='rect' coords='65,168,69,164' title='Moldova' \/>\n<area shape='rect' coords='270,229,274,225' title='Mexico' \/>\n<area shape='rect' coords='89,172,93,168' title='Mauritius' \/>\n<area shape='rect' coords='88,213,92,209' title='Macedonia' \/>\n<area shape='rect' coords='146,229,150,225' title='Lithuania' \/>\n<area shape='rect' coords='166,240,170,236' title='Libya' \/>\n<area shape='rect' coords='192,237,196,233' title='Kuwait' \/>\n<area shape='rect' coords='220,219,224,215' title='Ireland' \/>\n<area shape='rect' coords='147,216,151,212' title='Guatemala' \/>\n<area shape='rect' coords='233,158,237,154' title='Greece' \/>\n<area shape='rect' coords='104,215,108,211' title='Gabon' \/>\n<area shape='rect' coords='148,200,152,196' title='Dominican Republic' \/>\n<area shape='rect' coords='229,208,233,204' title='Denmark' \/>\n<area shape='rect' coords='201,195,205,191' title='Colombia' \/>\n<area shape='rect' coords='147,216,151,212' title='Bulgaria' \/>\n<area shape='rect' coords='16,155,20,151' title='Bhutan' \/>\n<area shape='rect' coords='242,146,246,142' title='Belgium' \/>\n<area shape='rect' coords='220,177,224,173' title='Argentina' \/>\n<area shape='rect' coords='163,221,167,217' title='Angola' \/>\n<area shape='rect' coords='197,217,201,213' title='Algeria' \/>\n<\/map>\n<p><\/span><\/td>\n<\/tr>\n<tr style='vertical-align:middle;'>\n<td style='text-align: center;'><span><span class=\"TextInline\"><span class=\"TRInline\"><span>GDP [$US]<\/span><\/span><\/span><\/span><\/td>\n<\/tr>\n<\/table>\n<p>Mathematica has a syntax that strikes many as arcane. Since I learned about computers with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Procedural_programming\">procedural programming<\/a>, and haven&#8217;t really done any <a href=\"http:\/\/en.wikipedia.org\/wiki\/Functional_programming\">functional programming<\/a>, I too struggle to get Mathematica to do what I want it to do. But one can often do complicated things, such as the above graph, with a very compact command. To make the main graph&#8211;the red and green dots are relatively trivial additions&#8211;the command I used is:<br \/>\n<!--more--><br \/>\n<code><br \/>\ngdpplot =<br \/>\n ListLogLinearPlot[<br \/>\n  Tooltip[{CountryData[#, \"GDP\"],<br \/>\n      CountryData[#, \"GovernmentDebt\"]\/CountryData[#, \"GDP\"]},<br \/>\n     CountryData[#, \"Name\"]] & \/@ CountryData[\"Countries\"],<br \/>\n  PlotRange -> {{10^9, 2 10^13}, {0, 2}}]<br \/>\n<\/code><\/p>\n<p>There are a couple things one needs to understand for this to make sense: First is Mathematica&#8217;s syntax for <a href=\"http:\/\/reference.wolfram.com\/mathematica\/tutorial\/PureFunctions.html\">pure functions<\/a>, using all the stuff with the #s and up through the &#038;. Second, the \/@ is shorthand for the <a href=\"http:\/\/reference.wolfram.com\/mathematica\/ref\/Map.html\">Map<\/a> command, which means apply the function on the left to each element of the list on the right. Finally, the command <code>CountryData[\"Countries\"]<\/code> produces a list of all the countries for which Mathematica has data. <\/p>\n<ol class=\"footnotes\"><li id=\"footnote_0_134\" class=\"footnote\">He is, nevertheless, against the bailout. [<a href=\"#identifier_0_134\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>A friend of mine (and regular commenter here) has pointed out that, even if the $700,000,000,000 bailout passes, and adds to our National Debt, we&#8217;d still have a Debt-to-GDP ratio that was less than Germany&#8217;s.1 Wikipedia says that the US National Debt is 60.8% of our GDP, that Germany&#8217;s is 63.1%, and that our GDP [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,12,26],"tags":[],"class_list":["post-134","post","type-post","status-publish","format-standard","hentry","category-consumer-society","category-doing-the-math","category-politics"],"_links":{"self":[{"href":"https:\/\/metcaffeination.net\/weblog\/wp-json\/wp\/v2\/posts\/134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/metcaffeination.net\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/metcaffeination.net\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/metcaffeination.net\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/metcaffeination.net\/weblog\/wp-json\/wp\/v2\/comments?post=134"}],"version-history":[{"count":2,"href":"https:\/\/metcaffeination.net\/weblog\/wp-json\/wp\/v2\/posts\/134\/revisions"}],"predecessor-version":[{"id":137,"href":"https:\/\/metcaffeination.net\/weblog\/wp-json\/wp\/v2\/posts\/134\/revisions\/137"}],"wp:attachment":[{"href":"https:\/\/metcaffeination.net\/weblog\/wp-json\/wp\/v2\/media?parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/metcaffeination.net\/weblog\/wp-json\/wp\/v2\/categories?post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/metcaffeination.net\/weblog\/wp-json\/wp\/v2\/tags?post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}