Introduction to Python for Econometrics, Statistics and Data Analysis Kevin Sheppard 2024 Scribd Download
Introduction to Python for Econometrics, Statistics and Data Analysis Kevin Sheppard 2024 Scribd Download
com
https://ebookmass.com/product/introduction-to-python-for-
econometrics-statistics-and-data-analysis-kevin-sheppard/
OR CLICK HERE
DOWLOAD NOW
https://ebookmass.com/product/introduction-to-python-for-econometrics-
statistics-and-data-analysis-5th-edition-kevin-sheppard/
ebookmass.com
https://ebookmass.com/product/introduction-to-statistics-and-data-
analysis-6th-edition-roxy-peck/
ebookmass.com
https://ebookmass.com/product/statistics-and-data-analysis-for-
nursing-research-2nd-edition-2nd-edition/
ebookmass.com
https://ebookmass.com/product/the-virtues-in-psychiatric-practice-
john-r-peteet/
ebookmass.com
Sustainable Resource Management: Modern Approaches and
Contexts 1st Edition Chaudhery Mustansar Hussain
https://ebookmass.com/product/sustainable-resource-management-modern-
approaches-and-contexts-1st-edition-chaudhery-mustansar-hussain/
ebookmass.com
https://ebookmass.com/product/excel-vba-programming-for-dummies-6th-
edition-dick-kusleika/
ebookmass.com
https://ebookmass.com/product/study-guide-for-foundations-and-adult-
health-nursing-8th-edition/
ebookmass.com
https://ebookmass.com/product/lippincott-illustrated-reviews-
biochemistry-lippincott-illustrated-reviews-series-7th-edition-ebook-
pdf/
ebookmass.com
https://ebookmass.com/product/philosophy-of-life-german-
lebensphilosophie-1870-1920-prof-frederick-c-beiser/
ebookmass.com
Peace through Self-Determination. Success and Failure of
Territorial Autonomy Felix Schulte
https://ebookmass.com/product/peace-through-self-determination-
success-and-failure-of-territorial-autonomy-felix-schulte/
ebookmass.com
Introduction to Python for
Econometrics, Statistics and Data Analysis
3rd Edition, 1st Revision
Kevin Sheppard
University of Oxford
• Verified that all code and examples work correctly against 2019 versions of modules. The notable
packages and their versions are:
• Python 2.7 support has been officially dropped, although most examples continue to work with 2.7.
Do not Python 2.7 in 2019 for numerical code.
• Fixed direct download of FRED data due to API changes, thanks to Jesper Termansen.
• Thanks for Bill Tubbs for a detailed read and multiple typo reports.
• Tested all code on Pyton 3.6. Code has been tested against the current set of modules installed by
conda as of February 2018. The notable packages and their versions are:
– NumPy: 1.13
– Pandas: 0.22
ii
Notes to the 3rd Edition
This edition includes the following changes from the second edition (August 2014):
• Python 3.5 is the default version of Python instead of 2.7. Python 3.5 (or newer) is well supported by
the Python packages required to analyze data and perform statistical analysis, and bring some new
useful features, such as a new operator for matrix multiplication (@).
• Removed distinction between integers and longs in built-in data types chapter. This distinction is
only relevant for Python 2.7.
• dot has been removed from most examples and replaced with @ to produce more readable code.
• Split Cython and Numba into separate chapters to highlight the improved capabilities of Numba.
• Verified all code working on current versions of core libraries using Python 3.5.
• pandas
• New chapter introducing statsmodels, a package that facilitates statistical analysis of data. statsmod-
els includes regression analysis, Generalized Linear Models (GLM) and time-series analysis using
ARIMA models.
iv
Changes since the Second Edition
• Added diagnostic tools and a simple method to use external code in the Cython section.
• Added examples of joblib and IPython’s cluster to the chapter on running code in parallel.
• New chapter introducing object-oriented programming as a method to provide structure and orga-
nization to related code.
• Added seaborn to the recommended package list, and have included it be default in the graphics
chapter.
• Based on experience teaching Python to economics students, the recommended installation has
been simplified by removing the suggestion to use virtual environment. The discussion of virtual
environments as been moved to the appendix.
• Changed the Anaconda install to use both create and install, which shows how to install additional
packages.
This edition includes the following changes from the first edition (March 2012):
• The preferred installation method is now Continuum Analytics’ Anaconda. Anaconda is a complete
scientific stack and is available for all major platforms.
• New chapter on pandas. pandas provides a simple but powerful tool to manage data and perform
preliminary analysis. It also greatly simplifies importing and exporting data.
• Numba provides just-in-time compilation for numeric Python code which often produces large per-
formance gains when pure NumPy solutions are not available (e.g. looping code).
• Numerous typos
1 Introduction 1
1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Important Components of the Python Scientific Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 Using Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.A Additional Installation Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5 Basic Math 57
5.1 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.2 Broadcasting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.3 Addition (+) and Subtraction (-) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.4 Multiplication (*) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.5 Matrix Multiplication (@) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.6 Array and Matrix Division (/) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.7 Exponentiation (**) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.8 Parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.9 Transpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.10 Operator Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.11 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
7 Special Arrays 77
7.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
15 Graphics 141
15.1 seaborn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
15.2 2D Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
15.3 Advanced 2D Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
15.4 3D Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
15.5 General Plotting Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
15.6 Exporting Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
15.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
xii CONTENTS
16 pandas 161
16.1 Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
16.2 Statistical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
16.3 Time-series Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
16.4 Importing and Exporting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
16.5 Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
16.6 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
When this fruit is first ripe it requires, from its excessive acidity,
nearly its weight of sugar to render it palatable; but after hanging
some time upon the trees it becomes much mellowed in flavour, and
may be sufficiently sweetened with a smaller proportion. According
to the state of the fruit then, take for each pound (leaving it in
bunches) from twelve to sixteen ounces of sugar, and boil it with
three-quarters of a pint of water until it forms a syrup. Throw in the
bunches of fruit, and simmer them for five or six minutes. If their
weight of sugar be used, they will become in that time perfectly
transparent. As all vessels of tin affect the colour of the barberries,
they should be boiled in a copper stewpan, or in a German
enamelled one, which would be far better.
Barberries, 1 lb.; sugar, 12 to 16 oz.; water, 3/4 pint; fruit simmered
in syrup, 5 to 6 minutes.
BLACK CAPS PAR EXCELLENCE.
Extract the juice from some fresh red currants by simmering them
very gently for a few minutes over a slow fire: strain it through a
folded muslin, and to one pound of it add a pound and a half of
nonsuches or of freshly gathered codlings, pared, and rather deeply
cored, that the fibrous part of the apple may be avoided. Boil these
quite slowly until the mixture is perfectly smooth, then, to evaporate
part of the moisture, let the boiling be quickened. In from twenty-five
to thirty minutes draw the pan from the fire, and throw in gradually a
pound and a quarter of sugar in fine powder: mix it well with the fruit,
and when it is dissolved continue the boiling rapidly for twenty
minutes longer, keeping the mixture constantly stirred; put it into a
mould, and store it, when cold, for winter use, or serve it for rice-
crust, or for the second course: in the latter case decorate it with
spikes of blanched almonds, or pistachio-nuts, and heap solid
whipped cream round it, or pour a custard into the dish. For rice-
crust it may be garnished with dice of the palest apple-jelly.
Juice of red currants, 1 lb.; nonsuches, or codlings (pared and
cored), 1-1/2 lb.: 25 to 30 minutes. Sugar, 1-1/2 lb.: 20 minutes.
Obs.—A portion of raspberries, if still in season, may be mixed
with the currants for this gâteau, should the flavour be liked.
For other and excellent varieties of gâteaux of fruit, see Newton
solid, and damson solid, Chapter XXIV. Ripe peaches and
nonsuches will likewise do well for it. Codlings answer perfectly for
the preceding receipt, and the preparation is of fine colour and very
pleasant flavour: it ought to cut in clear firm slices. Other varieties of
fruit can be mingled in the same manner.
JELLIES.
To four calf’s feet well cleaned and divided, pour a gallon of water
and let them stew until it is reduced to rather less than two quarts; or
if, after the flesh has quite fallen from the bones, the liquor on being
strained off should exceed that quantity, reduce it by rapid boiling in
a clean uncovered pan over a very clear fire. When it is perfectly firm
and cold, take it clear of fat and sediment, and add to it a bottle of
sherry, which should be of good quality (for poor, thin wines are not
well adapted to the purpose), three-quarters of a pound of sugar
broken small, the juice of five large or of six moderate-sized lemons,
and the whites, with the shells finely crushed, of seven eggs, or of
more should they be very small. The rinds of three lemons, pared
exceedingly thin, may be thrown into the jelly a few minutes before it
is taken from the fire; or they may be put into the jelly-bag previously
to its being poured through, when they will impart to it a slight and
delicate flavour, without deepening its colour much. If it is to be
moulded, something more than half an ounce of isinglass should be
dropped lightly in where the liquid becomes visible through the head
of scum, when the mixture begins to boil; for if not sufficiently firm, it
will break when it is dished. It may be roughed, or served in glasses
without this addition; and in a liquid state will be found an admirable
ingredient for Oxford, or other punch.
Calf’s feet, 4; water, 1 gallon: to be reduced more than half.
Sherry, 1 bottle; sugar, 3/4 lb. (more to taste); juice of 5 large
lemons, or of six moderate-sized; whites and shells of 7 eggs, or
more if small; rinds of lemons, 3 (for moulding, nearly 3/4 oz. of
isinglass): 15 to 20 minutes.
Obs.—An excellent and wholesome jelly for young people may be
made with good orange or raisin wine, instead of sherry; to either of
these the juice of three or four oranges, with a small portion of the
rind, may be added instead of part of the lemons.
MODERN VARIETIES OF CALF’S FEET JELLY.
(Author’s Receipt.)
To a pint and a half of firm calf’s feet stock, put a pint of strained
China-orange juice mixed with that of one or two lemons; add to
these six ounces of sugar, broken small, the very thin rinds of three
oranges and one lemon, and the whites of six eggs with half the
shells crushed small. Stir these gently over a clear fire until the head
of scum begins to form, but not at all afterwards. Simmer the jelly for
ten minutes from the first full boil; take it from the fire, let it stand a
little, then pour it through a jelly-bag until perfectly clear. This is an
original, and entirely new receipt, which we can recommend to the
reader, the jelly being very pale, beautifully transparent, and delicate
in flavour: it would, we think, be peculiarly acceptable to such
invalids as are forbidden to take wine in any form.
The proportions both of sugar and of lemon-juice must be
somewhat varied according to the season in which the oranges are
used.
Strong calf’s feet stock, 1-1/2 pint; strained orange-juice, mixed
with a small portion of lemon-juice, 1 pint; sugar, 6 oz.; rinds of
oranges, 3; of lemon, 1: 10 minutes.
Obs.—A small pinch of isinglass thrown into the jelly when it
begins to boil will much assist to clear it. When the flavour of Seville
oranges is liked, two or three can be used with the sweet ones.
ORANGE ISINGLASS JELLY.
The oranges for these should be large. First, mark the handle of
the basket evenly across the stalk end of the fruit with the back of a
small knife, or with a silver one, and let it be quite half an inch wide;
then trace a line across from one end of the handle to the other
exactly in the middle of the orange, and when the other side is
marked in the same way, cut just through the rind with the point of a
penknife, being careful not to pierce the fruit itself; next, with a tea or
dessertspoon, take of the quartered rind on either side of the handle;
pass a penknife under the handle itself; work the point of a spoon
gently between the orange and the basket, until they are separated
in every part; then take the fruit between the thumb and fingers, and
press it carefully out through one of the spaces on either side of the
handle.
Baskets thus made may be filled with any of the jellies of which the
receipts are given here: but they should be nearly cold before they
are poured in; and they ought also to be very clear. Some of the
baskets may be filled with ratifias, and dished alternately with those
which contain the jelly.
LEMON CALF’S FEET JELLY.
Infuse in a pint of water for five minutes the rind of half a Seville
orange, pared extremely thin; add an ounce of isinglass; and when
this is dissolved throw in four ounces of good sugar in lumps; stir
well, and simmer the whole for a few minutes, then mix with it four
large wineglassesful of Constantia, and strain the jelly through a fine
cloth of close texture; let it settle and cool, then pour it gently from
any sediment there may be, into a mould which has been laid for an
hour or two into water. We had this jelly made in the first instance for
an invalid who was forbidden to take acids, and it proved so
agreeable in flavour that we can recommend it for the table. The
isinglass, with an additional quarter of an ounce, might be clarified,
and the sugar and orange-rind boiled with it afterwards.
Water, 1 pint; rind, 1/2 Seville orange: 5 minutes. Isinglass, 1 oz.;
sugar, 4 oz.: 5 to 7 minutes. Constantia, 4 large wineglassesful.
RHUBARB ISINGLASS JELLY.
A great variety of equally elegant and excellent jellies for the table
may be made with clarified isinglass, clear syrup, and the juice of
almost any kind of fresh fruit; but as the process of making them is
nearly the same for all, we shall limit our receipts to one or two,
which will serve to direct the makers for the rest. Boil together
quickly for fifteen minutes one pint of water and three-quarters of a
pound of very good sugar; measure a quart of ripe richly-flavoured
strawberries without their stalks; the scarlet answer best, from the
colour which they give: on these pour the boiling syrup, and let them
stand all night. The next day clarify two ounces and a half of
isinglass in a pint of water, as directed at the beginning of this
chapter; drain the syrup from the strawberries very closely, add to it
two or three tablespoonsful of red currant juice, and the clear juice of
one large or two small lemons; and when the isinglass is nearly cold
mix the whole, and put it into moulds. The French, who excel in
these fruit-jellies, always mix the separate ingredients when they are
almost cold; and they also place them over ice for an hour or so after
they are moulded, which is a great advantage, as they then require
less isinglass, and are in consequence much more delicate. When
the fruit abounds, instead of throwing it into the syrup, bruise lightly
from three to four pints, throw two tablespoonsful of sugar over it,
and let the juice flow from it for an hour or two; then pour a little
water over, and use the juice without boiling, which will give a jelly of
finer flavour than the other.
Water, 1 pint; sugar, 3/4 lb.: 15 minutes. Strawberries, 1 quart;
isinglass, 2-1/2 oz.; water, 1 pint (white of egg, 1 to 2 teaspoonsful);
juice, 1 large or 2 small lemons.
FANCY JELLIES.
Description of
Belgrave Mould.
Figure No. 1,
represents the
mould in its
entireness. No. 2,
shows the interior
of it (inverted). A is
a thin metal plate
which when turned
downwards forms
the bottom of the
No. 1. mould, and which No. 2.
is perforated in six
places to permit
the fluted columns B to pass through it. There is also a larger
aperture in the middle to admit the centre cylinder. The plate is fixed,
and the whole is held in its place by the part which folds over the
larger scallop D at either end. There is also a cover which fits to the
mould, and which is pressed on it before it is dipped into water, to
prevent its getting into the cylinders.
Transparent jelly is shown to much
advantage, and is particularly brilliant in
appearance, when moulded in shapes
resembling that of the engraving here,
which are now very commonly used for the
purpose.
The centre spaces can be filled, after the
jelly is dished, with very light whipped
cream, coloured and flavoured so as to eat
agreeably with it, and to please the eye as well: this may be
tastefully garnished with preserved, or with fresh fruit; but one of
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookmass.com