Skip to content

Instantly share code, notes, and snippets.

@Abechtel
Created April 27, 2015 00:46
Show Gist options
  • Save Abechtel/8f44293f1cc6a95f54da to your computer and use it in GitHub Desktop.
Save Abechtel/8f44293f1cc6a95f54da to your computer and use it in GitHub Desktop.
Loans to Individuals vs Net Interest Income - Exercise 5
Year individualloans netinterestincome fake InvestmentSecurities TotalRealEstateLoan TotalLoanstoindividuals CommercialandIndustrial TotalEquityCapital TotalAssets TotalLoansandLeases NetInterestIncome NonInterestIncome
1966 2.82 9.54 3 9092998 2912002 2821732 6765725 2249042 30116623 15975056 9535486 5726220
1967 3.02 8.79 4 10291687 3253500 3018414 7406229 2498514 33198543 17086231 8791761 4829332
1968 3.38 7.19 7 11385097 3684955 3376657 8055859 2679025 36722511 19016745 7189465 4293934
1969 3.57 7.03 6 10351283 4072371 3573193 8624460 2892054 37253439 20021759 7030927 4584319
1970 3.83 7.30 5 11686033 4266187 3830640 9082287 3123053 41295980 20956146 7299256 4620765
1971 4.39 7.52 2 13853795 4730600 4387277 9316722 3384330 45842776 23116269 7523445 3955219
1972 4.89 9.09 8 15204420 5502793 4893538 11295190 3760957 54065281 28836238 9085204 4502502
1973 5.60 9.33 6 15627322 6458908 5603639 14798423 4080549 63111206 35666577 9330237 4317514
1974 5.98 8.30 8 16267138 7164015 5981928 17961383 4448876 70859405 40916860 8300895 3862536
1975 6.46 12.74 3 20262687 7677361 6462606 16867226 4894178 73708407 40081848 12735252 8417175
1976 7.15 13.69 4 22303469 9218604 7148616 16408284 5630681 78647460 41605478 13686591 8191240
1977 8.43 12.15 7 22927072 11339256 8434130 17755024 6114969 87224761 47099825 12146584 6317720
1978 9.73 9.20 6 23030831 14016870 9727272 26955465 6702790 117184652 64398747 9198749 4552070
1979 10.35 8.62 5 23509904 16207609 10345934 32448522 7351894 132790311 73131365 8621753 4224903
1980 9.73 8.07 2 25214804 17171191 9728060 36132538 7952211 141156629 78939938 8073569 4010053
1981 9.89 7.83 8 25602988 18331406 9890931 43048968 8529033 156570987 89440944 7825168 3342531
1982 10.63 7.44 6 26584521 18980029 10633899 45433899 9060869 158088476 93211777 7436636 3002437
1983 11.96 7.18 8 30158100 19692600 11963900 43938800 9609400 163946000 93363000 7181088 3116899
1984 12.94 6.67 3 28201820 19547067 12943186 41890092 10099305 159010226 94421508 6666336 2702850
1985 13.82 6.75 4 31069441 19694256 13817904 39187114 10830079 163380526 92049628 6753911 3514784
1986 14.31 6.55 7 34602469 21481931 14311661 41645038 11511053 173066328 96982925 6551099 2825571
1987 12.79 6.02 6 35695697 25395584 12786237 42151948 10438475 178873951 102172706 6023946 2627754
1988 12.89 5.73 5 35501076 29720622 12890966 40827780 11645040 184690501 104363972 5730780 2372109
1989 13.28 5.73 2 37549717 34275747 13276693 41206557 12460909 192366813 107724635 5734539 2311743
1990 13.82 5.48 8 39082803 38517734 13823378 41593087 13373088 196886184 110792895 5475833 2299073
1991 13.35 5.27 6 44907934 40942818 13348665 38845398 14229882 199139893 106973154 5265618 2065143
1992 13.17 5.12 8 47980691 42414388 13174078 35150254 15603921 200874999 104818218 5122186 1909167
1993 14.95 5.08 3 51877876 44656325 14947088 35293866 17574268 211980180 108744046 5080254 1561938
1994 16.40 4.58 4 52183511 48241165 16400607 38298600 18466225 224764460 118160796 4575783 1625001
1995 18.17 4.36 7 51940441 51713051 18165175 43308699 20198232 238710753 128594617 4361167 1473327
1996 17.27 4.03 6 53051693 56628828 17266577 50041210 21648629 247068657 141289349 4031099 1341594
1997 15.85 3.61 5 60903548 67762945 15849193 49188879 22071377 265401070 148760837 3607813 1204873
1998 16.44 3.37 2 69427498 68626746 16441184 57342237 23410588 297307328 163834862 3365677 1000499
1999 15.36 3.11 8 68607934 77874761 15356738 67731056 24494554 328726971 199221612 3110936 821005
2000 14.36 2.85 6 74171541 89547312 14362788 75242164 25693269 355509976 213021353 2846421 687612
2001 23.45 2.48 8 101576094 107888565 23449066 73822174 32987341 435928432 244850110 2481568 592515
2002 27.15 2.31 3 115315860 119448379 27154171 77176595 40294666 486431766 281659134 2312195 560480
2003 18.88 1.96 4 137662151 118523727 18880704 71182893 41360943 538581942 299304238 1958351 584076
2004 11.26 1.85 7 73250671 114104669 11259550 43794521 26571757 300818918 181028543 1853488 461681
2005 11.35 1.51 6 78761919 129504337 11345021 48182621 28858308 334961714 202979369 1514413 402173
2006 10.88 1.29 5 82254503 125260773 10879637 48049578 30634976 338792776 199450786 1287475 333657
2007 10.43 1.21 2 61796051 135579523 10427906 49259955 40425670 351043919 209942300 1205869 317985
2008 10.48 1.25 8 60224749 124313325 10480550 34385615 26466663 332563066 182263447 1253691 305548
2009 10.96 1.04 6 60219407 111997506 10959729 31334332 25870139 297158069 164430028 1042341 232231
2010 10.09 0.91 8 60090507 102304956 10085263 29579226 27462429 294850707 153549448 913765 200862
2011 11.13 0.80 5 79750665 121953888 11126258 38429977 38575955 370186176 190057947 799534 177452
2012 11.95 0.72 7 85564250 115378523 11945558 43107232 40010524 370031574 191943093 722399 164162
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Chicago Fed Loans to Individuals (in billions)</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>
<style type="text/css">
body {
background-color: white;
font-family: Helvetica;
}
svg {
background-color: white;
}
circle:hover {
fill: lightblue;
}
.axis path,
.axis line {
fill:none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
</style>
</head>
<body>
<h1>Relationship of Loans to Individuals and Net Interest Income (in billions)</h1>
<p> This scatterplot shows the relationship between the Chicago Fed's Loans to Individuals and its Net Interest Income for a given year between 1966 and 2012; Source: <a href="http://fdic.gov">FDIC</a>
<p>Loans to Individuals are plotted on the X axis; Net Interest Income is plotted on the Y axis</p>
<script type="text/javascript">
var w = 800;
var h = 400;
var padding = [ 20, 50, 30, 50 ];
var xScale = d3.scale.linear()
.range([ padding[3], w - padding[3]]);
var yScale = d3.scale.linear()
.range([ padding[0], h - padding[2] ]);
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.ticks (10)
.tickFormat(function(d) {
return "$" + d
});
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left")
.ticks(15)
.tickFormat(function(d) {
return "$" + d
});
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
d3.csv("ChicagoFDIC.csv", function(data) {
data.sort(function(a, b) {
return d3.descending(+a.individualloans, +b.individualloans);
});
xScale.domain([ 0, d3.max(data, function(d) {
return +d.individualloans;
}) ]);
yScale.domain([
d3.max(data, function(d) {
return +d.netinterestincome;
}), 0 ]);
var circles = svg.selectAll("circle")
.data(data)
.enter()
.append("circle");
circles.attr("cx", -100)
.attr("cy", function(d) {
return yScale(d.netinterestincome);
})
.attr("r", 4)
.attr("fill", "darkblue")
.append("title")
.text(function(d) {
return "In " + d.Year + ", the Chicago Fed held $" + d.individualloans + " billion in Loans to Individuals";
});
circles.sort(function(a, b) {
return d3.ascending(+a.individualloans, +b.netinterestincome);
})
.transition()
.delay(function(d, i) {
return i * 50;
})
.duration(2000)
.attr("cx", function(d) {
return xScale(d.individualloans);
})
.attr("r",4);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + (h - padding[2]) + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + (padding[3] - 5) + ",0)")
.call(yAxis);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment