Package AER': R Topics Documented
Package AER': R Topics Documented
Package AER': R Topics Documented
February 3, 2024
Version 1.2-12
Date 2024-02-02
Title Applied Econometrics with R
Description Functions, data sets, examples, demos, and vignettes for the book
Christian Kleiber and Achim Zeileis (2008),
Applied Econometrics with R, Springer-Verlag, New York.
ISBN 978-0-387-77316-2. <doi:10.1007/978-0-387-77318-6>
(See the vignette ``AER'' for a package overview.)
LazyLoad yes
Depends R (>= 3.0.0), car (>= 2.0-19), lmtest, sandwich (>= 2.4-0),
survival (>= 2.37-5), zoo
Suggests boot, dynlm, effects, fGarch, forecast, foreign, ineq,
KernSmooth, lattice, longmemo, MASS, mlogit, nlme, nnet, np,
plm, pscl, quantreg, rgl, ROCR, rugarch, sampleSelection,
scatterplot3d, strucchange, systemfit (>= 1.1-20), truncreg,
tseries, urca, vars
Imports stats, Formula (>= 0.2-0)
License GPL-2 | GPL-3
NeedsCompilation no
Author Christian Kleiber [aut] (<https://orcid.org/0000-0002-6781-4733>),
Achim Zeileis [aut, cre] (<https://orcid.org/0000-0003-0918-3766>)
Maintainer Achim Zeileis <Achim.Zeileis@R-project.org>
Repository CRAN
Date/Publication 2024-02-03 14:10:02 UTC
R topics documented:
Affairs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
ArgentinaCPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Baltagi2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
BankWages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1
2 R topics documented:
BenderlyZwick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
BondYield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
CameronTrivedi1998 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
CartelStability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
CASchools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
ChinaIncome . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
CigarettesB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
CigarettesSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
CollegeDistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
ConsumerGood . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
CPS1985 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
CPS1988 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
CPSSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
CreditCard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
dispersiontest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
DJFranses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
DJIA8012 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
DoctorVisits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
DutchAdvert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
DutchSales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Electricity1955 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Electricity1970 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
EquationCitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Equipment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
EuroEnergy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Fatalities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Fertility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Franses1998 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
FrozenJuice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
GermanUnemployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
GoldSilver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Greene2003 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
GrowthDJ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
GrowthSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Grunfeld . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
GSOEP9402 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
GSS7402 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Guns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
HealthInsurance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
HMDA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
HousePrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
ivreg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
ivreg.fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Journals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
KleinI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Longley . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
ManufactCosts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
MarkDollar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
R topics documented: 3
MarkPound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
MASchools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Medicaid1986 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Mortgage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
MotorCycles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
MotorCycles2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
MSCISwitzerland . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Municipalities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
MurderRates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
NaturalGas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
NMES1988 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
NYSESW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
OECDGas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
OECDGrowth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
OlympicTV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
OrangeCounty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Parade2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
PepperPrice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
PhDPublications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
ProgramEffectiveness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
PSID1976 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
PSID1982 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
PSID7682 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
RecreationDemand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
ResumeNames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
ShipAccidents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
SIC33 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
SmokeBan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
SportsCards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
STAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
StockWatson2007 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
StrikeDuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
summary.ivreg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
SwissLabor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
TeachingRatings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
TechChange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
tobit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
TradeCredit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
TravelMode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
UKInflation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
UKNonDurables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
USAirlines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
USConsump1950 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
USConsump1979 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
USConsump1993 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
USCrudes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
USGasB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
USGasG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
4 Affairs
USInvest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
USMacroB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
USMacroG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
USMacroSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
USMacroSWM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
USMacroSWQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
USMoney . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
USProdIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
USSeatBelts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
USStocksSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
WeakInstrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
WinkelmannBoes2009 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Index 203
Description
Infidelity data, known as Fair’s Affairs. Cross-section data from a survey conducted by Psychology
Today in 1969.
Usage
data("Affairs")
Format
A data frame containing 601 observations on 9 variables.
affairs numeric. How often engaged in extramarital sexual intercourse during the past year? 0 =
none, 1 = once, 2 = twice, 3 = 3 times, 7 = 4–10 times, 12 = monthly, 12 = weekly, 12 = daily.
gender factor indicating gender.
age numeric variable coding age in years: 17.5 = under 20, 22 = 20–24, 27 = 25–29, 32 = 30–34,
37 = 35–39, 42 = 40–44, 47 = 45–49, 52 = 50–54, 57 = 55 or over.
yearsmarried numeric variable coding number of years married: 0.125 = 3 months or less, 0.417
= 4–6 months, 0.75 = 6 months–1 year, 1.5 = 1–2 years, 4 = 3–5 years, 7 = 6–8 years, 10 =
9–11 years, 15 = 12 or more years.
children factor. Are there children in the marriage?
religiousness numeric variable coding religiousness: 1 = anti, 2 = not at all, 3 = slightly, 4 =
somewhat, 5 = very.
education numeric variable coding level of education: 9 = grade school, 12 = high school graduate,
14 = some college, 16 = college graduate, 17 = some graduate work, 18 = master’s degree, 20
= Ph.D., M.D., or other advanced degree.
occupation numeric variable coding occupation according to Hollingshead classification (reverse
numbering).
Affairs 5
rating numeric variable coding self rating of marriage: 1 = very unhappy, 2 = somewhat unhappy,
3 = average, 4 = happier than average, 5 = very happy.
Source
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
Fair, R.C. (1978). A Theory of Extramarital Affairs. Journal of Political Economy, 86, 45–61.
See Also
Greene2003
Examples
data("Affairs")
## Greene (2003)
## Tab. 22.3 and 22.4
fm_ols <- lm(affairs ~ age + yearsmarried + religiousness + occupation + rating,
data = Affairs)
fm_probit <- glm(I(affairs > 0) ~ age + yearsmarried + religiousness + occupation + rating,
data = Affairs, family = binomial(link = "probit"))
library("MASS")
fm_nb <- glm.nb(affairs ~ age + yearsmarried + religiousness + occupation + rating,
data = Affairs)
## Tab. 22.6
library("pscl")
fm_zip <- zeroinfl(affairs ~ age + yearsmarried + religiousness + occupation + rating | age +
yearsmarried + religiousness + occupation + rating, data = Affairs)
6 ArgentinaCPI
Description
Time series of consumer price index (CPI) in Argentina (index with 1969(4) = 1).
Usage
data("ArgentinaCPI")
Format
A quarterly univariate time series from 1970(1) to 1989(4).
Source
Online complements to Franses (1998).
References
De Ruyter van Steveninck, M.A. (1996). The Impact of Capital Imports; Argentina 1970–1989.
Amsterdam: Thesis Publishers.
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
See Also
Franses1998
Examples
data("ArgentinaCPI")
plot(ArgentinaCPI)
plot(log(ArgentinaCPI))
library("dynlm")
## estimation sample 1970.3-1988.4 means
acpi <- window(ArgentinaCPI, start = c(1970,1), end = c(1988,4))
## alternatively
ar(diff(log(acpi)), order.max = 1, method = "ols")
Baltagi2002 7
Description
This manual page collects a list of examples from the book. Some solutions might not be exact and
the list is certainly not complete. If you have suggestions for improvement (preferably in the form
of code), please contact the package maintainer.
References
Baltagi, B.H. (2002). Econometrics, 3rd ed., Berlin: Springer-Verlag.
See Also
BenderlyZwick, CigarettesB, EuroEnergy, Grunfeld, Mortgage, NaturalGas, OECDGas, OrangeCounty,
PSID1982, TradeCredit, USConsump1993, USCrudes, USGasB, USMacroB
Examples
################################
## Cigarette consumption data ##
################################
## data
data("CigarettesB", package = "AER")
## Table 3.3
cig_lm <- lm(packs ~ price, data = CigarettesB)
summary(cig_lm)
## Figure 3.9
plot(residuals(cig_lm) ~ price, data = CigarettesB)
abline(h = 0, lty = 2)
## Figure 3.10
cig_pred <- with(CigarettesB,
data.frame(price = seq(from = min(price), to = max(price), length = 30)))
cig_pred <- cbind(cig_pred, predict(cig_lm, newdata = cig_pred, interval = "confidence"))
plot(packs ~ price, data = CigarettesB)
lines(fit ~ price, data = cig_pred)
lines(lwr ~ price, data = cig_pred, lty = 2)
lines(upr ~ price, data = cig_pred, lty = 2)
#####################################
## US consumption data (1950-1993) ##
#####################################
## data
data("USConsump1993", package = "AER")
plot(USConsump1993, plot.type = "single", col = 1:2)
## Chapter 8
library("strucchange")
## Recursive residuals
rr <- recresid(fm)
rr
## Recursive CUSUM test
rcus <- efp(expenditure ~ income, data = USConsump1993)
plot(rcus)
Baltagi2002 9
sctest(rcus)
## Harvey-Collier test
harvtest(fm)
## NOTE" Mistake in Baltagi (2002) who computes
## the t-statistic incorrectly as 0.0733 via
mean(rr)/sd(rr)/sqrt(length(rr))
## whereas it should be (as in harvtest)
mean(rr)/sd(rr) * sqrt(length(rr))
## Rainbow test
raintest(fm, center = 23)
## Chapter 11
## Table 11.1 Instrumental-variables regression
usc <- as.data.frame(USConsump1993)
usc$investment <- usc$income - usc$expenditure
fm_ols <- lm(expenditure ~ income, data = usc)
fm_iv <- ivreg(expenditure ~ income | investment, data = usc)
## Hausman test
cf_diff <- coef(fm_iv) - coef(fm_ols)
vc_diff <- vcov(fm_iv) - vcov(fm_ols)
x2_diff <- as.vector(t(cf_diff) %*% solve(vc_diff) %*% cf_diff)
pchisq(x2_diff, df = 2, lower.tail = FALSE)
## Chapter 14
## ACF and PACF for expenditures and first differences
exps <- USConsump1993[, "expenditure"]
(acf(exps))
(pacf(exps))
(acf(diff(exps)))
(pacf(diff(exps)))
################################
## Grunfeld's investment data ##
################################
## Ex. 10.9
library("systemfit")
gr_ols <- systemfit(invest ~ value + capital, method = "OLS", data = pgr)
gr_sur <- systemfit(invest ~ value + capital, method = "SUR", data = pgr)
#########################################
## Panel study on income dynamics 1982 ##
#########################################
## data
data("PSID1982", package = "AER")
## Table 4.1
earn_lm <- lm(log(wage) ~ . + I(experience^2), data = PSID1982)
summary(earn_lm)
## Table 13.1
union_lpm <- lm(I(as.numeric(union) - 1) ~ . - wage, data = PSID1982)
union_probit <- glm(union ~ . - wage, data = PSID1982, family = binomial(link = "probit"))
union_logit <- glm(union ~ . - wage, data = PSID1982, family = binomial)
## probit OK, logit and LPM rather different.
Description
Wages of employees of a US bank.
Usage
data("BankWages")
Format
A data frame containing 474 observations on 4 variables.
job Ordered factor indicating job category, with levels "custodial", "admin" and "manage".
education Education in years.
gender Factor indicating gender.
minority Factor. Is the employee member of a minority?
Source
Online complements to Heij, de Boer, Franses, Kloek, and van Dijk (2004).
https://global.oup.com/booksites/content/0199268010/datasets/ch6/xr614bwa.asc
BenderlyZwick 11
References
Heij, C., de Boer, P.M.C., Franses, P.H., Kloek, T. and van Dijk, H.K. (2004). Econometric Methods
with Applications in Business and Economics. Oxford: Oxford University Press.
Examples
data("BankWages")
BenderlyZwick Benderly and Zwick Data: Inflation, Growth and Stock Returns
Description
Time series data, 1952–1982.
Usage
data("BenderlyZwick")
Format
An annual multiple time series from 1952 to 1982 with 5 variables.
returns real annual returns on stocks, measured using the Ibbotson-Sinquefeld data base.
growth annual growth rate of output, measured by real GNP (from the given year to the next year).
12 BenderlyZwick
inflation inflation rate, measured as growth of price rate (from December of the previous year to
December of the present year).
growth2 annual growth rate of real GNP as given by Baltagi.
inflation2 inflation rate as given by Baltagi
Source
The first three columns of the data are from Table 1 in Benderly and Zwick (1985). The remaining
columns are taken from the online complements of Baltagi (2002). The first column is identical
in both sources, the other two variables differ in their numeric values and additionally the growth
series seems to be lagged differently. Baltagi (2002) states Lott and Ray (1992) as the source for
his version of the data set.
References
See Also
Baltagi2002
Examples
data("BenderlyZwick")
plot(BenderlyZwick)
Description
Monthly averages of the yield on a Moody’s Aaa rated corporate bond (in percent/year).
Usage
data("BondYield")
Format
A monthly univariate time series from 1990(1) to 1994(12).
Source
Online complements to Greene (2003), Table F20.1.
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003
Examples
data("BondYield")
plot(BondYield)
Description
This manual page collects a list of examples from the book. Some solutions might not be exact and
the list is certainly not complete. If you have suggestions for improvement (preferably in the form
of code), please contact the package maintainer.
References
Cameron, A.C. and Trivedi, P.K. (1998). Regression Analysis of Count Data. Cambridge: Cam-
bridge University Press.
14 CameronTrivedi1998
See Also
DoctorVisits, NMES1988, RecreationDemand
Examples
library("MASS")
library("pscl")
###########################################
## Australian health service utilization ##
###########################################
## data
data("DoctorVisits", package = "AER")
## Poisson regression
dv_pois <- glm(visits ~ . + I(age^2), data = DoctorVisits, family = poisson)
dv_qpois <- glm(visits ~ . + I(age^2), data = DoctorVisits, family = quasipoisson)
## Table 3.3
round(cbind(
Coef = coef(dv_pois),
MLH = sqrt(diag(vcov(dv_pois))),
MLOP = sqrt(diag(vcovOPG(dv_pois))),
NB1 = sqrt(diag(vcov(dv_qpois))),
RS = sqrt(diag(sandwich(dv_pois)))
), digits = 3)
## Table 3.4
## NM2-ML
dv_nb <- glm.nb(visits ~ . + I(age^2), data = DoctorVisits)
summary(dv_nb)
## NB1-GLM = quasipoisson
summary(dv_qpois)
##########################################
## Demand for medical care in NMES 1988 ##
##########################################
## dependent variable
CameronTrivedi1998 15
## Table 6.1
table(cut(nmes$visits, c(0:13, 100)-0.5, labels = 0:13))
## NegBin regression
nmes_nb <- glm.nb(visits ~ ., data = nmes)
## NegBin hurdle
nmes_h <- hurdle(visits ~ ., data = nmes, dist = "negbin")
## Table 6.8
coeftest(nmes_h, vcov = sandwich)
logLik(nmes_h)
1/nmes_h$theta
###################################################
## Recreational boating trips to Lake Somerville ##
###################################################
## data
data("RecreationDemand", package = "AER")
## Poisson model:
## Cameron and Trivedi (1998), Table 6.11
## Ozuna and Gomez (1995), Table 2, col. 3
fm_pois <- glm(trips ~ ., data = RecreationDemand, family = poisson)
summary(fm_pois)
logLik(fm_pois)
coeftest(fm_pois, vcov = sandwich)
## Negbin model:
## Cameron and Trivedi (1998), Table 6.11
## Ozuna and Gomez (1995), Table 2, col. 5
library("MASS")
fm_nb <- glm.nb(trips ~ ., data = RecreationDemand)
coeftest(fm_nb, vcov = vcovOPG)
logLik(fm_nb)
## ZIP model:
## Cameron and Trivedi (1998), Table 6.11
fm_zip <- zeroinfl(trips ~ . | quality + income, data = RecreationDemand)
summary(fm_zip)
logLik(fm_zip)
16 CameronTrivedi1998
## Hurdle models
## Cameron and Trivedi (1998), Table 6.13
## poisson-poisson
sval <- list(count = c(2.15, 0.044, .467, -.097, .601, .002, -.036, .024),
zero = c(-1.88, 0.815, .403, .01, 2.95, 0.006, -.052, .046))
fm_hp0 <- hurdle(trips ~ ., data = RecreationDemand, dist = "poisson",
zero = "poisson", start = sval, maxit = 0)
fm_hp1 <- hurdle(trips ~ ., data = RecreationDemand, dist = "poisson",
zero = "poisson", start = sval)
fm_hp2 <- hurdle(trips ~ ., data = RecreationDemand, dist = "poisson",
zero = "poisson")
sapply(list(fm_hp0, fm_hp1, fm_hp2), logLik)
## negbin-negbin
fm_hnb <- hurdle(trips ~ ., data = RecreationDemand, dist = "negbin", zero = "negbin")
summary(fm_hnb)
logLik(fm_hnb)
sval <- list(count = c(0.841, 0.172, .622, -.057, .576, .057, -.078, .012),
zero = c(-3.046, 4.638, -.025, .026, 16.203, 0.030, -.156, .117),
theta = c(count = 1/1.7, zero = 1/5.609))
fm_hnb2 <- try(hurdle(trips ~ ., data = RecreationDemand,
dist = "negbin", zero = "negbin", start = sval))
if(!inherits(fm_hnb2, "try-error")) {
summary(fm_hnb2)
logLik(fm_hnb2)
}
## geo-negbin
sval98 <- list(count = c(0.841, 0.172, .622, -.057, .576, .057, -.078, .012),
zero = c(-2.88, 1.44, .4, .03, 9.43, 0.01, -.08, .071),
theta = c(count = 1/1.7))
sval96 <- list(count = c(0.841, 0.172, .622, -.057, .576, .057, -.078, .012),
zero = c(-2.882, 1.437, .406, .026, 11.936, 0.008, -.081, .071),
theta = c(count = 1/1.7))
## logit-negbin
fm_hgnb2 <- hurdle(trips ~ ., data = RecreationDemand, dist = "negbin")
summary(fm_hgnb2)
logLik(fm_hgnb2)
CartelStability CartelStability
Description
Weekly observations on prices and other factors from 1880–1886, for a total of 326 weeks.
Usage
data("CartelStability")
Format
A data frame containing 328 observations on 5 variables.
Source
Online complements to Stock and Watson (2007).
References
Porter, R. H. (1983). A Study of Cartel Stability: The Joint Executive Committee, 1880–1886. The
Bell Journal of Economics, 14, 301–314.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("CartelStability")
summary(CartelStability)
18 CASchools
Description
The dataset contains data on test performance, school characteristics and student demographic back-
grounds for school districts in California.
Usage
data("CASchools")
Format
A data frame containing 420 observations on 14 variables.
district character. District code.
school character. School name.
county factor indicating county.
grades factor indicating grade span of district.
students Total enrollment.
teachers Number of teachers.
calworks Percent qualifying for CalWorks (income assistance).
lunch Percent qualifying for reduced-price lunch.
computer Number of computers.
expenditure Expenditure per student.
income District average income (in USD 1,000).
english Percent of English learners.
read Average reading score.
math Average math score.
Details
The data used here are from all 420 K-6 and K-8 districts in California with data available for 1998
and 1999. Test scores are on the Stanford 9 standardized test administered to 5th grade students.
School characteristics (averaged across the district) include enrollment, number of teachers (mea-
sured as “full-time equivalents”, number of computers per classroom, and expenditures per student.
Demographic variables for the students are averaged across the district. The demographic variables
include the percentage of students in the public assistance program CalWorks (formerly AFDC),
the percentage of students that qualify for a reduced price lunch, and the percentage of students that
are English learners (that is, students for whom English is a second language).
Source
Online complements to Stock and Watson (2007).
ChinaIncome 19
References
Stock, J. H. and Watson, M. W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007, MASchools
Examples
## data and transformations
data("CASchools")
CASchools$stratio <- with(CASchools, students/teachers)
CASchools$score <- with(CASchools, (math + read)/2)
## p. 159
fm2 <- lm(score ~ I(stratio < 20), data = CASchools)
## p. 199
fm3 <- lm(score ~ stratio + english, data = CASchools)
## p. 224
fm4 <- lm(score ~ stratio + expenditure + english, data = CASchools)
Description
Time series of real national income in China per section (index with 1952 = 100).
Usage
data("ChinaIncome")
20 CigarettesB
Format
An annual multiple time series from 1952 to 1988 with 5 variables.
agriculture Real national income in agriculture sector.
industry Real national income in industry sector.
construction Real national income in construction sector.
transport Real national income in transport sector.
commerce Real national income in commerce sector.
Source
Online complements to Franses (1998).
References
Chow, G.C. (1993). Capital Formation and Economic Growth in China. Quarterly Journal of
Economics, 103, 809–842.
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
See Also
Franses1998
Examples
data("ChinaIncome")
plot(ChinaIncome)
Description
Cross-section data on cigarette consumption for 46 US States, for the year 1992.
Usage
data("CigarettesB")
Format
A data frame containing 46 observations on 3 variables.
packs Logarithm of cigarette consumption (in packs) per person of smoking age (> 16 years).
price Logarithm of real price of cigarette in each state.
income Logarithm of real disposable income (per capita) in each state.
CigarettesB 21
Source
The data are from Baltagi (2002).
References
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
Baltagi, B.H. and Levin, D. (1992). Cigarette Taxation: Raising Revenues and Reducing Consump-
tion. Structural Change and Economic Dynamics, 3, 321–335.
See Also
Baltagi2002, CigarettesSW
Examples
data("CigarettesB")
## Baltagi (2002)
## Table 3.3
cig_lm <- lm(packs ~ price, data = CigarettesB)
summary(cig_lm)
Description
Panel data on cigarette consumption for the 48 continental US States from 1985–1995.
Usage
data("CigarettesSW")
Format
A data frame containing 48 observations on 7 variables for 2 periods.
Source
Online complements to Stock and Watson (2007).
References
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007, CigarettesB
CollegeDistance 23
Examples
## Stock and Watson (2007)
## data and transformations
data("CigarettesSW")
CigarettesSW <- transform(CigarettesSW,
rprice = price/cpi,
rincome = income/population/cpi,
rtax = tax/cpi,
rtdiff = (taxs - tax)/cpi
)
c1985 <- subset(CigarettesSW, year == "1985")
c1995 <- subset(CigarettesSW, year == "1995")
## Equations 12.9--12.11
fm_s1 <- lm(log(rprice) ~ rtdiff, data = c1995)
coeftest(fm_s1, vcov = hc1)
fm_s2 <- lm(log(packs) ~ fitted(fm_s1), data = c1995)
fm_ivreg <- ivreg(log(packs) ~ log(rprice) | rtdiff, data = c1995)
coeftest(fm_ivreg, vcov = hc1)
## Equation 12.15
fm_ivreg2 <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + rtdiff, data = c1995)
coeftest(fm_ivreg2, vcov = hc1)
## Equation 12.16
fm_ivreg3 <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + rtdiff + rtax,
data = c1995)
coeftest(fm_ivreg3, vcov = hc1)
Description
Cross-section data from the High School and Beyond survey conducted by the Department of Edu-
cation in 1980, with a follow-up in 1986. The survey included students from approximately 1,100
high schools.
Usage
data("CollegeDistance")
24 CollegeDistance
Format
A data frame containing 4,739 observations on 14 variables.
Details
Rouse (1995) computed years of education by assigning 12 years to all members of the senior
class. Each additional year of secondary education counted as a one year. Students with vocational
degrees were assigned 13 years, AA degrees were assigned 14 years, BA degrees were assigned 16
years, those with some graduate education were assigned 17 years, and those with a graduate degree
were assigned 18 years.
Stock and Watson (2007) provide separate data files for the students from Western states and the
remaining students. CollegeDistance includes both data sets, subsets are easily obtained (see also
examples).
Source
Online complements to Stock and Watson (2007).
References
Rouse, C.E. (1995). Democratization or Diversion? The Effect of Community Colleges on Educa-
tional Attainment. Journal of Business & Economic Statistics, 12, 217–224.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
ConsumerGood 25
Examples
## exclude students from Western states
data("CollegeDistance")
cd <- subset(CollegeDistance, region != "west")
summary(cd)
Description
Time series of distribution, market share and price of a fast-moving consumer good.
Usage
data("ConsumerGood")
Format
A weekly multiple time series from 1989(11) to 1991(9) with 3 variables.
distribution Distribution.
share Market share.
price Price.
Source
Online complements to Franses (1998).
References
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
See Also
Franses1998
Examples
data("ConsumerGood")
plot(ConsumerGood)
26 CPS1985
Description
Cross-section data originating from the May 1985 Current Population Survey by the US Census
Bureau (random sample drawn for Berndt 1991).
Usage
data("CPS1985")
Format
A data frame containing 534 observations on 11 variables.
Source
StatLib.
http://lib.stat.cmu.edu/datasets/CPS_85_Wages
References
Berndt, E.R. (1991). The Practice of Econometrics. New York: Addison-Wesley.
See Also
CPS1988, CPSSW
CPS1988 27
Examples
data("CPS1985")
## Berndt (1991)
## Exercise 2, p. 196
cps_2b <- lm(log(wage) ~ union + education, data = CPS1985)
cps_2c <- lm(log(wage) ~ -1 + union + education, data = CPS1985)
## Exercise 3, p. 198/199
cps_3a <- lm(log(wage) ~ education + experience + I(experience^2),
data = CPS1985)
cps_3b <- lm(log(wage) ~ gender + education + experience + I(experience^2),
data = CPS1985)
cps_3c <- lm(log(wage) ~ gender + married + education + experience + I(experience^2),
data = CPS1985)
cps_3e <- lm(log(wage) ~ gender*married + education + experience + I(experience^2),
data = CPS1985)
## Exercise 4, p. 199/200
cps_4a <- lm(log(wage) ~ gender + union + ethnicity + education + experience + I(experience^2),
data = CPS1985)
cps_4c <- lm(log(wage) ~ gender + union + ethnicity + education * experience + I(experience^2),
data = CPS1985)
## Exercise 6, p. 203
cps_6a <- lm(log(wage) ~ gender + union + ethnicity + education + experience + I(experience^2),
data = CPS1985)
cps_6a_noeth <- lm(log(wage) ~ gender + union + education + experience + I(experience^2),
data = CPS1985)
anova(cps_6a_noeth, cps_6a)
## Exercise 8, p. 208
cps_8a <- lm(log(wage) ~ gender + union + ethnicity + education + experience + I(experience^2),
data = CPS1985)
summary(cps_8a)
coeftest(cps_8a, vcov = vcovHC(cps_8a, type = "HC0"))
Description
Cross-section data originating from the March 1988 Current Population Survey by the US Census
Bureau.
Usage
data("CPS1988")
28 CPS1988
Format
A data frame containing 28,155 observations on 7 variables.
wage Wage (in dollars per week).
education Number of years of education.
experience Number of years of potential work experience.
ethnicity Factor with levels "cauc" and "afam" (African-American).
smsa Factor. Does the individual reside in a Standard Metropolitan Statistical Area (SMSA)?
region Factor with levels "northeast", "midwest", "south", "west".
parttime Factor. Does the individual work part-time?
Details
A sample of men aged 18 to 70 with positive annual income greater than USD 50 in 1992, who
are not self-employed nor working without pay. Wages are deflated by the deflator of Personal
Consumption Expenditure for 1992.
A problem with CPS data is that it does not provide actual work experience. It is therefore custom-
ary to compute experience as age - education - 6 (as was done by Bierens and Ginther, 2001), this
may be considered potential experience. As a result, some respondents have negative experience.
Source
Personal web page of Herman J. Bierens.
References
Bierens, H.J., and Ginther, D. (2001). Integrated Conditional Moment Testing of Quantile Regres-
sion Models. Empirical Economics, 26, 307–324.
Buchinsky, M. (1998). Recent Advances in Quantile Regression Models: A Practical Guide for
Empirical Research. Journal of Human Resources, 33, 88–126.
See Also
CPS1985, CPSSW
Examples
## OLS and LAD fits (for LAD see Bierens and Ginter, Tables 1-3.A.)
mincer_ols <- lm(mincer, data = CPS1988)
quart_ols <- lm(quart, data = CPS1988)
buchinsky_ols <- lm(buchinsky, data = CPS1988)
Description
Stock and Watson (2007) provide several subsets created from March Current Population Surveys
(CPS) with data on the relationship of earnings and education over several year.
Usage
data("CPSSW9204")
data("CPSSW9298")
data("CPSSW04")
data("CPSSW3")
data("CPSSW8")
data("CPSSWEducation")
Format
CPSSW9298: A data frame containing 13,501 observations on 5 variables. CPSSW9204: A data
frame containing 15,588 observations on 5 variables. CPSSW04: A data frame containing 7,986
observations on 4 variables. CPSSW3: A data frame containing 20,999 observations on 3 variables.
CPSSW8: A data frame containing 61,395 observations on 5 variables. CPSSWEducation: A data
frame containing 2,950 observations on 4 variables.
Details
Each month the Bureau of Labor Statistics in the US Department of Labor conducts the Current
Population Survey (CPS), which provides data on labor force characteristics of the population,
including the level of employment, unemployment, and earnings. Approximately 65,000 randomly
selected US households are surveyed each month. The sample is chosen by randomly selecting
addresses from a database. Details can be found in the Handbook of Labor Statistics and is described
on the Bureau of Labor Statistics website (https://www.bls.gov/).
The survey conducted each March is more detailed than in other months and asks questions about
earnings during the previous year. The data sets contain data for 2004 (from the March 2005 survey),
and some also for earlier years (up to 1992).
If education is given, it is for full-time workers, defined as workers employed more than 35 hours
per week for at least 48 weeks in the previous year. Data are provided for workers whose highest
educational achievement is a high school diploma and a bachelor’s degree.
Earnings for years earlier than 2004 were adjusted for inflation by putting them in 2004 USD using
the Consumer Price Index (CPI). From 1992 to 2004, the price of the CPI market basket rose by
34.6%. To make earnings in 1992 and 2004 comparable, 1992 earnings are inflated by the amount
of overall CPI price inflation, by multiplying 1992 earnings by 1.346 to put them into 2004 dollars.
CPSSW9204 provides the distribution of earnings in the US in 1992 and 2004 for college-educated
full-time workers aged 25–34. CPSSW04 is a subset of CPSSW9204 and provides the distribution of
earnings in the US in 2004 for college-educated full-time workers aged 25–34. CPSSWEducation
is similar (but not a true subset) and contains the distribution of earnings in the US in 2004 for
college-educated full-time workers aged 29–30. CPSSW8 contains a larger sample with workers
aged 21–64, additionally providing information about the region of residence. CPSSW9298 is sim-
ilar to CPSSW9204 providing data from 1992 and 1998 (with the 1992 subsets not being exactly
identical). CPSSW3 provides trends (from 1992 to 2004) in hourly earnings in the US of working
college graduates aged 25–34 (in 2004 USD).
Source
Online complements to Stock and Watson (2007).
References
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007, CPS1985, CPS1988
Examples
data("CPSSW3")
with(CPSSW3, interaction.plot(year, gender, earnings))
Description
Cross-section data on the credit history for a sample of applicants for a type of credit card.
Usage
data("CreditCard")
Format
A data frame containing 1,319 observations on 12 variables.
card Factor. Was the application for a credit card accepted?
reports Number of major derogatory reports.
age Age in years plus twelfths of a year.
income Yearly income (in USD 10,000).
share Ratio of monthly credit card expenditure to yearly income.
expenditure Average monthly credit card expenditure.
owner Factor. Does the individual own their home?
selfemp Factor. Is the individual self-employed?
dependents Number of dependents.
months Months living at current address.
majorcards Number of major credit cards held.
active Number of active credit accounts.
Details
According to Greene (2003, p. 952) dependents equals 1 + number of dependents, our calcula-
tions suggest that it equals number of dependents.
Greene (2003) provides this data set twice in Table F21.4 and F9.1, respectively. Table F9.1 has just
the observations, rounded to two digits. Here, we give the F21.4 version, see the examples for the
F9.1 version. Note that age has some suspiciously low values (below one year) for some applicants.
One of these differs between the F9.1 and F21.4 version.
Source
Online complements to Greene (2003). Table F21.4.
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
32 CreditCard
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003
Examples
data("CreditCard")
## Greene (2003)
## extract data set F9.1
ccard <- CreditCard[1:100,]
ccard$income <- round(ccard$income, digits = 2)
ccard$expenditure <- round(ccard$expenditure, digits = 2)
ccard$age <- round(ccard$age + .01)
## suspicious:
CreditCard$age[CreditCard$age < 1]
## the first of these is also in TableF9.1 with 36 instead of 0.5:
ccard$age[79] <- 36
## Example 11.1
ccard <- ccard[order(ccard$income),]
ccard0 <- subset(ccard, expenditure > 0)
cc_ols <- lm(expenditure ~ age + owner + income + I(income^2), data = ccard0)
## Figure 11.1
plot(residuals(cc_ols) ~ income, data = ccard0, pch = 19)
## Table 11.1
mean(ccard$age)
prop.table(table(ccard$owner))
mean(ccard$income)
summary(cc_ols)
sqrt(diag(vcovHC(cc_ols, type = "HC0")))
sqrt(diag(vcovHC(cc_ols, type = "HC2")))
sqrt(diag(vcovHC(cc_ols, type = "HC1")))
Description
Tests the null hypothesis of equidispersion in Poisson GLMs against the alternative of overdisper-
sion and/or underdispersion.
Usage
dispersiontest(object, trafo = NULL, alternative = c("greater", "two.sided", "less"))
Arguments
object a fitted Poisson GLM of class "glm" as fitted by glm with family poisson.
trafo a specification of the alternative (see also details), can be numeric or a (positive)
function or NULL (the default).
alternative a character string specifying the alternative hypothesis: "greater" corresponds
to overdispersion, "less" to underdispersion and "two.sided" to either one.
Details
The standard Poisson GLM models the (conditional) mean E[y] = µ which is assumed to be equal
to the variance VAR[y] = µ. dispersiontest assesses the hypothesis that this assumption holds
(equidispersion) against the alternative that the variance is of the form:
VAR[y] = µ + α · trafo(µ).
VAR[y] = (1 + α) · µ = dispersion · µ.
By default, for trafo = NULL, the latter dispersion formulation is used in dispersiontest. Other-
wise, if trafo is specified, the test is formulated in terms of the parameter α. The transformation
trafo can either be specified as a function or an integer corresponding to the function function(x)
x^trafo, such that trafo = 1 and trafo = 2 yield the linear and quadratic formulations respec-
tively.
Value
An object of class "htest".
34 DJFranses
References
Cameron, A.C. and Trivedi, P.K. (1990). Regression-based Tests for Overdispersion in the Poisson
Model. Journal of Econometrics, 46, 347–364.
Cameron, A.C. and Trivedi, P.K. (1998). Regression Analysis of Count Data. Cambridge: Cam-
bridge University Press.
Cameron, A.C. and Trivedi, P.K. (2005). Microeconometrics: Methods and Applications. Cam-
bridge: Cambridge University Press.
See Also
glm, poisson, glm.nb
Examples
data("RecreationDemand")
rd <- glm(trips ~ ., data = RecreationDemand, family = poisson)
## further examples
data("DoctorVisits")
dv <- glm(visits ~ . + I(age^2), data = DoctorVisits, family = poisson)
dispersiontest(dv)
data("NMES1988")
nmes <- glm(visits ~ health + age + gender + married + income + insurance,
data = NMES1988, family = poisson)
dispersiontest(nmes)
Description
Dow Jones index time series computed at the end of the week where week is assumed to run from
Thursday to Wednesday.
Usage
data("DJFranses")
DJIA8012 35
Format
A weekly univariate time series from 1980(1) to 1994(42).
Source
Online complements to Franses (1998).
References
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
See Also
Franses1998
Examples
data("DJFranses")
plot(DJFranses)
Description
Time series of the Dow Jones Industrial Average (DJIA) index.
Usage
data("DJIA8012")
Format
A daily univariate time series from 1980-01-01 to 2012-12-31 (of class "zoo" with "Date" index).
Source
Online complements to Franses, van Dijk and Opschoor (2014).
https://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-e
time-series-models-business-and-economic-forecasting-2nd-edition
References
Franses, P.H., van Dijk, D. and Opschoor, A. (2014). Time Series Models for Business and Eco-
nomic Forecasting, 2nd ed. Cambridge, UK: Cambridge University Press.
36 DoctorVisits
Examples
data("DJIA8012")
plot(DJIA8012)
Description
Cross-section data originating from the 1977–1978 Australian Health Survey.
Usage
data("DoctorVisits")
Format
A data frame containing 5,190 observations on 12 variables.
freerepat Factor. Does the individual have free government health insurance due to old age, dis-
ability or veteran status?
nchronic Factor. Is there a chronic condition not limiting activity?
lchronic Factor. Is there a chronic condition limiting activity?
Source
References
Cameron, A.C. and Trivedi, P.K. (1986). Econometric Models Based on Count Data: Comparisons
and Applications of Some Estimators and Tests. Journal of Applied Econometrics, 1, 29–53.
Cameron, A.C. and Trivedi, P.K. (1998). Regression Analysis of Count Data. Cambridge: Cam-
bridge University Press.
Mullahy, J. (1997). Heterogeneity, Excess Zeros, and the Structure of Count Data Models. Journal
of Applied Econometrics, 12, 337–350.
See Also
CameronTrivedi1998
Examples
Description
Time series of television and radio advertising expenditures (in real terms) in The Netherlands.
Usage
data("DutchAdvert")
Format
A four-weekly multiple time series from 1978(1) to 1994(13) with 2 variables.
Source
Originally available as an online supplement to Franses (1998). Now available via online comple-
ments to Franses, van Dijk and Opschoor (2014).
https://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-e
time-series-models-business-and-economic-forecasting-2nd-edition
References
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
Franses, P.H., van Dijk, D. and Opschoor, A. (2014). Time Series Models for Business and Eco-
nomic Forecasting, 2nd ed. Cambridge, UK: Cambridge University Press.
See Also
Franses1998
Examples
data("DutchAdvert")
plot(DutchAdvert)
Description
Time series of retail sales index in The Netherlands.
Usage
data("DutchSales")
Format
A monthly univariate time series from 1960(5) to 1995(9).
Source
Online complements to Franses (1998).
References
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
See Also
Franses1998
Examples
data("DutchSales")
plot(DutchSales)
Description
Cost function data for 145 (+14) US electricity producers in 1955.
Usage
data("Electricity1955")
Format
A data frame containing 159 observations on 8 variables.
Details
The data contains several extra observations that are aggregates of commonly owned firms. Only
the first 145 observations should be used for analysis.
Source
Online complements to Greene (2003). Table F14.2.
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
Electricity1970 41
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
Nerlove, M. (1963) “Returns to Scale in Electricity Supply.” In C. Christ (ed.), Measurement in
Economics: Studies in Mathematical Economics and Econometrics in Memory of Yehuda Grunfeld.
Stanford University Press, 1963.
See Also
Greene2003, Electricity1970
Examples
data("Electricity1955")
Electricity <- Electricity1955[1:145,]
## Greene (2003)
## Example 7.3
## Cobb-Douglas cost function
fm_all <- lm(log(cost/fuel) ~ log(output) + log(labor/fuel) + log(capital/fuel),
data = Electricity)
summary(fm_all)
## Table 7.4
## log quadratic cost function
fm_all2 <- lm(log(cost/fuel) ~ log(output) + I(log(output)^2) + log(labor/fuel) + log(capital/fuel),
data = Electricity)
summary(fm_all2)
Description
Usage
data("Electricity1970")
42 Electricity1970
Format
Details
The data are from Christensen and Greene (1976) and pertain to the year 1970. However, the file
contains some extra observations, the holding companies. Only the first 123 observations are needed
to replicate Christensen and Greene (1976).
Source
References
Christensen, L. and Greene, W.H. (1976). Economies of Scale in U.S. Electric Power Generation.
Journal of Political Economy, 84, 655–676.
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003, Electricity1955
Examples
data("Electricity1970")
Description
Analysis of citations of evolutionary biology papers published in 1998 in the top three journals (as
judged by their 5-year impact factors in the Thomson Reuters Journal Citation Reports 2010).
Usage
data("EquationCitations")
Format
A data frame containing 649 observations on 13 variables.
journal Factor. Journal in which the paper was published (The American Naturalist, Evolution,
Proceedings of the Royal Society of London B: Biological Sciences).
authors Character. Names of authors.
volume Volume in which the paper was published.
startpage Starting page of publication.
pages Number of pages.
equations Number of equations in total.
mainequations Number of equations in main text.
appequations Number of equations in appendix.
cites Number of citations in total.
selfcites Number of citations by the authors themselves.
othercites Number of citations by other authors.
theocites Number of citations by theoretical papers.
nontheocites Number of citations by nontheoretical papers.
Details
Fawcett and Higginson (2012) investigate the relationship between the number of citations evolu-
tionary biology papers receive, depending on the number of equations per page in the cited paper.
Overall it can be shown that papers with many mathematical equations significantly lower the num-
ber of citations they receive, in particular from nontheoretical papers.
Source
Online supplements to Fawcett and Higginson (2012).
https://www.pnas.org/doi/suppl/10.1073/pnas.1205259109/suppl_file/sd01.xlsx
44 EquationCitations
References
Fawcett, T.W. and Higginson, A.D. (2012). Heavy Use of Equations Impedes Communication
among Biologists. PNAS – Proceedings of the National Academy of Sciences of the United States
of America, 109, 11735–11739. doi:10.1073/pnas.1205259109
See Also
PhDPublications
Examples
#################
## Replication ##
#################
## Table 1
m1a <- glm.nb(othercites ~ I(equations/pages) * pages + journal,
data = EquationCitations)
m1b <- update(m1a, nontheocites ~ .)
m1c <- update(m1a, theocites ~ .)
nbtable(m1a)
nbtable(m1b)
nbtable(m1c)
## Table 2
m2a <- glm.nb(
othercites ~ (I(mainequations/pages) + I(appequations/pages)) * pages + journal,
data = EquationCitations)
m2b <- update(m2a, nontheocites ~ .)
m2c <- update(m2a, theocites ~ .)
nbtable(m2a)
nbtable(m2b)
nbtable(m2c)
###############
## Extension ##
###############
Equipment 45
Description
Usage
data("Equipment")
Format
Source
Journal of Applied Econometrics Data Archive.
http://qed.econ.queensu.ca/jae/1998-v13.2/zellner-ryu/
Online complements to Greene (2003), Table F9.2.
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
Zellner, A. and Revankar, N. (1969). Generalized Production Functions. Review of Economic
Studies, 36, 241–250.
Zellner, A. and Ryu, H. (1998). Alternative Functional Forms for Production, Cost and Returns to
Scale Functions. Journal of Applied Econometrics, 13, 101–127.
See Also
Greene2003
Examples
## Greene (2003), Example 17.5
data("Equipment")
## Cobb-Douglas
fm_cd <- lm(log(valueadded/firms) ~ log(capital/firms) + log(labor/firms), data = Equipment)
## optimization
opt <- optim(par0, nlogL, hessian = TRUE)
## Table 17.2
opt$par
sqrt(diag(solve(opt$hessian)))[1:4]
-opt$value
## re-fit ML model
fm_ml <- GCobbDouglas(opt$par[4])
deviance(fm_ml)
sqrt(diag(vcov(fm_ml)))
Description
Cross-section data on energy consumption for 20 European countries, for the year 1980.
Usage
data("EuroEnergy")
Format
A data frame containing 20 observations on 2 variables.
gdp Real gross domestic product for the year 1980 (in million 1975 US dollars).
energy Aggregate energy consumption (in million kilograms coal equivalence).
Source
The data are from Baltagi (2002).
48 Fatalities
References
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
See Also
Baltagi2002
Examples
data("EuroEnergy")
energy_lm <- lm(log(energy) ~ log(gdp), data = EuroEnergy)
influence.measures(energy_lm)
Description
US traffic fatalities panel data for the “lower 48” US states (i.e., excluding Alaska and Hawaii),
annually for 1982 through 1988.
Usage
data("Fatalities")
Format
A data frame containing 336 observations on 34 variables.
Details
Traffic fatalities are from the US Department of Transportation Fatal Accident Reporting System.
The beer tax is the tax on a case of beer, which is an available measure of state alcohol taxes more
generally. The drinking age variable is a factor indicating whether the legal drinking age is 18, 19,
or 20. The two binary punishment variables describe the state’s minimum sentencing requirements
for an initial drunk driving conviction.
Total vehicle miles traveled annually by state was obtained from the Department of Transportation.
Personal income was obtained from the US Bureau of Economic Analysis, and the unemployment
rate was obtained from the US Bureau of Labor Statistics.
Source
Online complements to Stock and Watson (2007).
References
Ruhm, C. J. (1996). Alcohol Policies and Highway Vehicle Fatalities. Journal of Health Economics,
15, 435–454.
Stock, J. H. and Watson, M. W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
50 Fatalities
See Also
StockWatson2007
Examples
Description
Cross-section data from the 1980 US Census on married women aged 21–35 with two or more
children.
Usage
data("Fertility")
data("Fertility2")
52 Fertility
Format
A data frame containing 254,654 (and 30,000, respectively) observations on 8 variables.
Details
Fertility2 is a random subset of Fertility with 30,000 observations.
There are conflicts in the ethnicity coding (see also examples). Hence, it was not possible to create
a single factor and the original three indicator variables have been retained.
Not all variables from Angrist and Evans (1998) have been included.
Source
Online complements to Stock and Watson (2007).
References
Angrist, J.D., and Evans, W.N. (1998). Children and Their Parents’ Labor Supply: Evidence from
Exogenous Variation in Family Size American Economic Review, 88, 450–477.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("Fertility2")
fm2 <- lm(mkids ~ gender1 + gender2 + samegender + age + afam + hispanic + other, data = Fertility2)
summary(fm2)
fm3 <- lm(mkids ~ gender1 + twoboys + twogirls + age + afam + hispanic + other, data = Fertility2)
summary(fm3)
Description
This manual page collects a list of examples from the book. Some solutions might not be exact and
the list is certainly not complete. If you have suggestions for improvement (preferably in the form
of code), please contact the package maintainer.
References
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
See Also
ArgentinaCPI, ChinaIncome, ConsumerGood, DJFranses, DutchAdvert, DutchSales, GermanUnemployment,
MotorCycles, OlympicTV, PepperPrice, UKNonDurables, USProdIndex
Examples
###########################
## Convenience functions ##
###########################
#######################################
## Index of US industrial production ##
#######################################
###########################################
## Consumption of non-durables in the UK ##
###########################################
##############################
## Dutch retail sales index ##
##############################
###########################################
## TV and radio advertising expenditures ##
###########################################
Description
Monthly data on the price of frozen orange juice concentrate and temperature in the orange-growing
region of Florida.
Usage
data("FrozenJuice")
Format
A monthly multiple time series from 1950(1) to 2000(12) with 3 variables.
price Average producer price for frozen orange juice.
ppi Producer price index for finished goods. Used to deflate the overall producer price index for
finished goods to eliminate the effects of overall price inflation.
fdd Number of freezing degree days at the Orlando, Florida, airport. Calculated as the sum of
the number of degrees Fahrenheit that the minimum temperature falls below freezing (32
degrees Fahrenheit = about 0 degrees Celsius) in a given day over all days in the month: fdd
= sum(max(0, 32 - minimum daily temperature)), e.g. for February fdd is the number of
freezing degree days from January 11 to February 10.
Details
The orange juice price data are the frozen orange juice component of processed foods and feeds
group of the Producer Price Index (PPI), collected by the US Bureau of Labor Statistics (BLS series
wpu02420301). The orange juice price series was divided by the overall PPI for finished goods
to adjust for general price inflation. The freezing degree days series was constructed from daily
minimum temperatures recorded at Orlando area airports, obtained from the National Oceanic and
Atmospheric Administration (NOAA) of the US Department of Commerce.
Source
Online complements to Stock and Watson (2007).
References
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
## load data
data("FrozenJuice")
library("dynlm")
fm_dyn <- dynlm(d(100 * log(price/ppi)) ~ fdd, data = FrozenJuice)
coeftest(fm_dyn, vcov = vcovHC(fm_dyn, type = "HC1"))
Description
Time series of unemployment rate (in percent) in Germany.
Usage
data("GermanUnemployment")
Format
A quarterly multiple time series from 1962(1) to 1991(4) with 2 variables.
unadjusted Raw unemployment rate,
adjusted Seasonally adjusted rate.
Source
Online complements to Franses (1998).
GoldSilver 57
References
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
See Also
Franses1998
Examples
data("GermanUnemployment")
plot(GermanUnemployment, plot.type = "single", col = 1:2)
Description
Usage
data("GoldSilver")
Format
A daily multiple time series from 1977-12-30 to 2012-12-31 (of class "zoo" with "Date" index).
Source
References
Franses, P.H., van Dijk, D. and Opschoor, A. (2014). Time Series Models for Business and Eco-
nomic Forecasting, 2nd ed. Cambridge, UK: Cambridge University Press.
58 GoldSilver
Examples
library("forecast")
arfima(as.vector(absgret), max.p = 0, max.q = 1)
VARselect(lgs8612m, 5)
gs2 <- VAR(lgs8612m, 2)
summary(gs2)
summary(gs2)$covres
## p.266
ls <- lgs8612[, "silver"]
lg <- lgs8612[, "gold"]
library("tseries")
adf.test(resid(gsreg), k = 0)
adf.test(resid(sgreg), k = 0)
Description
This manual page collects a list of examples from the book. Some solutions might not be exact and
the list is certainly not complete. If you have suggestions for improvement (preferably in the form
of code), please contact the package maintainer.
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
URL https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm.
See Also
Affairs, BondYield, CreditCard, Electricity1955, Electricity1970, Equipment, Grunfeld,
KleinI, Longley, ManufactCosts, MarkPound, Municipalities, ProgramEffectiveness, PSID1976,
SIC33, ShipAccidents, StrikeDuration, TechChange, TravelMode, UKInflation, USConsump1950,
USConsump1979, USGasG, USAirlines, USInvest, USMacroG, USMoney
Examples
#####################################
## US consumption data (1970-1979) ##
#####################################
60 Greene2003
## Example 1.1
data("USConsump1979", package = "AER")
plot(expenditure ~ income, data = as.data.frame(USConsump1979), pch = 19)
fm <- lm(expenditure ~ income, data = as.data.frame(USConsump1979))
summary(fm)
abline(fm)
#####################################
## US consumption data (1940-1950) ##
#####################################
## data
data("USConsump1950", package = "AER")
usc <- as.data.frame(USConsump1950)
usc$war <- factor(usc$war, labels = c("no", "yes"))
## Example 2.1
plot(expenditure ~ income, data = usc, type = "n", xlim = c(225, 375), ylim = c(225, 350))
with(usc, text(income, expenditure, time(USConsump1950)))
## single model
fm <- lm(expenditure ~ income, data = usc)
summary(fm)
## compare
anova(fm, fm2)
## visualize
abline(fm, lty = 3)
abline(coef(fm2)[1:2])
abline(sum(coef(fm2)[c(1, 3)]), coef(fm2)[2], lty = 2)
## Example 3.2
summary(fm)$r.squared
summary(lm(expenditure ~ income, data = usc, subset = war == "no"))$r.squared
summary(fm2)$r.squared
########################
## US investment data ##
########################
## p. 22-24
coef(lm(invest ~ trend + gnp, data = us))
coef(lm(invest ~ gnp, data = us))
## Table 3.4
fm <- lm(invest ~ trend + gnp + interest + inflation, data = us)
fm1 <- lm(invest ~ 1, data = us)
anova(fm1, fm)
## Example 4.1
set.seed(123)
w <- rnorm(10000)
x <- rnorm(10000)
eps <- 0.5 * w
y <- 0.5 + 0.5 * x + eps
b <- rep(0, 500)
for(i in 1:500) {
ix <- sample(1:10000, 100)
b[i] <- lm.fit(cbind(1, x[ix]), y[ix])$coef[2]
}
hist(b, breaks = 20, col = "lightgray")
###############################
## Longley's regression data ##
###############################
## Example 4.6
fm1 <- dynlm(employment ~ time(employment) + price + gnp + armedforces,
data = Longley)
fm2 <- update(fm1, end = 1961)
cbind(coef(fm2), coef(fm1))
## Figure 4.3
plot(rstandard(fm2), type = "b", ylim = c(-3, 3))
abline(h = c(-2, 2), lty = 2)
62 Greene2003
#########################################
## US gasoline market data (1960-1995) ##
#########################################
## data
data("USGasG", package = "AER")
## Greene (2003)
## Example 2.3
fm <- lm(log(gas/population) ~ log(price) + log(income) + log(newcar) + log(usedcar),
data = as.data.frame(USGasG))
summary(fm)
## Example 4.4
## estimates and standard errors (note different offset for intercept)
coef(fm)
sqrt(diag(vcov(fm)))
## confidence interval
confint(fm, parm = "log(income)")
## test linear hypothesis
linearHypothesis(fm, "log(income) = 1")
## Figure 7.5
plot(price ~ gas, data = as.data.frame(USGasG), pch = 19,
col = (time(USGasG) > 1973) + 1)
legend("topleft", legend = c("after 1973", "up to 1973"), pch = 19, col = 2:1, bty = "n")
## Example 7.6
## re-used in Example 8.3
## linear time trend
ltrend <- 1:nrow(USGasG)
## shock factor
shock <- factor(time(USGasG) > 1973, levels = c(FALSE, TRUE), labels = c("before", "after"))
## 1960-1995
fm1 <- lm(log(gas/population) ~ log(income) + log(price) + log(newcar) + log(usedcar) + ltrend,
data = as.data.frame(USGasG))
summary(fm1)
## pooled
fm2 <- lm(
log(gas/population) ~ shock + log(income) + log(price) + log(newcar) + log(usedcar) + ltrend,
data = as.data.frame(USGasG))
summary(fm2)
## segmented
fm3 <- lm(
log(gas/population) ~ shock/(log(income) + log(price) + log(newcar) + log(usedcar) + ltrend),
data = as.data.frame(USGasG))
summary(fm3)
## Chow test
anova(fm3, fm1)
library("strucchange")
sctest(log(gas/population) ~ log(income) + log(price) + log(newcar) + log(usedcar) + ltrend,
Greene2003 63
## Example 12.2
library("dynlm")
resplot <- function(obj, bound = TRUE) {
res <- residuals(obj)
sigma <- summary(obj)$sigma
plot(res, ylab = "Residuals", xlab = "Year")
grid()
abline(h = 0)
if(bound) abline(h = c(-2, 2) * sigma, col = "red")
lines(res)
}
resplot(dynlm(log(gas/population) ~ log(price), data = USGasG))
resplot(dynlm(log(gas/population) ~ log(price) + log(income), data = USGasG))
resplot(dynlm(log(gas/population) ~ log(price) + log(income) + log(newcar) + log(usedcar) +
log(transport) + log(nondurable) + log(durable) +log(service) + ltrend, data = USGasG))
## different shock variable than in 7.6
shock <- factor(time(USGasG) > 1974, levels = c(FALSE, TRUE), labels = c("before", "after"))
resplot(dynlm(log(gas/population) ~ shock/(log(price) + log(income) + log(newcar) + log(usedcar) +
log(transport) + log(nondurable) + log(durable) + log(service) + ltrend), data = USGasG))
## NOTE: something seems to be wrong with the sigma estimates in the `full' models
## ML
g <- as.data.frame(USGasG)
y <- log(g$gas/g$population)
X <- as.matrix(cbind(log(g$price), log(g$income), log(g$newcar), log(g$usedcar)))
arima(y, order = c(1, 0, 0), xreg = X)
#######################################
## US macroeconomic data (1950-2000) ##
#######################################
## data and trend
data("USMacroG", package = "AER")
ltrend <- 0:(nrow(USMacroG) - 1)
## Example 5.3
## OLS and IV regression
64 Greene2003
library("dynlm")
fm_ols <- dynlm(consumption ~ gdp, data = USMacroG)
fm_iv <- dynlm(consumption ~ gdp | L(consumption) + L(gdp), data = USMacroG)
## Hausman statistic
library("MASS")
b_diff <- coef(fm_iv) - coef(fm_ols)
v_diff <- summary(fm_iv)$cov.unscaled - summary(fm_ols)$cov.unscaled
(t(b_diff) %*% ginv(v_diff) %*% b_diff) / summary(fm_ols)$sigma^2
## Wu statistic
auxreg <- dynlm(gdp ~ L(consumption) + L(gdp), data = USMacroG)
coeftest(dynlm(consumption ~ gdp + fitted(auxreg), data = USMacroG))[3,3]
## agrees with Greene (but not with errata)
## Example 6.1
## Table 6.1
fm6.1 <- dynlm(log(invest) ~ tbill + inflation + log(gdp) + ltrend, data = USMacroG)
fm6.3 <- dynlm(log(invest) ~ I(tbill - inflation) + log(gdp) + ltrend, data = USMacroG)
summary(fm6.1)
summary(fm6.3)
deviance(fm6.1)
deviance(fm6.3)
vcov(fm6.1)[2,3]
## F test
linearHypothesis(fm6.1, "tbill + inflation = 0")
## alternatively
anova(fm6.1, fm6.3)
## t statistic
sqrt(anova(fm6.1, fm6.3)[2,5])
## Example 6.3
## Distributed lag model:
## log(Ct) = b0 + b1 * log(Yt) + b2 * log(C(t-1)) + u
us <- log(USMacroG[, c(2, 5)])
fm_distlag <- dynlm(log(consumption) ~ log(dpi) + L(log(consumption)),
data = USMacroG)
summary(fm_distlag)
## Example 6.4
## predict investiment in 2001(1)
predict(fm6.1, interval = "prediction",
newdata = data.frame(tbill = 4.48, inflation = 5.262, gdp = 9316.8, ltrend = 204))
## Example 7.7
## no GMM available in "strucchange"
## using OLS instead yields
Greene2003 65
## Example 8.2
## Ct = b0 + b1*Yt + b2*Y(t-1) + v
fm1 <- dynlm(consumption ~ dpi + L(dpi), data = USMacroG)
## Ct = a0 + a1*Yt + a2*C(t-1) + u
fm2 <- dynlm(consumption ~ dpi + L(consumption), data = USMacroG)
## Table 9.1
fm_ols <- lm(consumption ~ dpi, data = as.data.frame(USMacroG))
fm_nls <- nls(consumption ~ alpha + beta * dpi^gamma,
start = list(alpha = coef(fm_ols)[1], beta = coef(fm_ols)[2], gamma = 1),
control = nls.control(maxiter = 100), data = as.data.frame(USMacroG))
summary(fm_ols)
summary(fm_nls)
deviance(fm_ols)
deviance(fm_nls)
vcov(fm_nls)
## Example 9.7
## F test
fm_nls2 <- nls(consumption ~ alpha + beta * dpi,
start = list(alpha = coef(fm_ols)[1], beta = coef(fm_ols)[2]),
control = nls.control(maxiter = 100), data = as.data.frame(USMacroG))
anova(fm_nls, fm_nls2)
## Wald test
linearHypothesis(fm_nls, "gamma = 1")
## Example 12.1
fm_m1 <- dynlm(log(m1) ~ log(gdp) + log(cpi), data = USMacroG)
summary(fm_m1)
## Figure 12.1
par(las = 1)
plot(0, 0, type = "n", axes = FALSE,
xlim = c(1950, 2002), ylim = c(-0.3, 0.225),
xaxs = "i", yaxs = "i",
xlab = "Quarter", ylab = "", main = "Least Squares Residuals")
box()
axis(1, at = c(1950, 1963, 1976, 1989, 2002))
axis(2, seq(-0.3, 0.225, by = 0.075))
grid(4, 7, col = grey(0.6))
abline(0, 0)
lines(residuals(fm_m1), lwd = 2)
## Example 12.3
fm_pc <- dynlm(d(inflation) ~ unemp, data = USMacroG)
summary(fm_pc)
## Figure 12.3
plot(residuals(fm_pc))
## natural unemployment rate
coef(fm_pc)[1]/coef(fm_pc)[2]
## autocorrelation
res <- residuals(fm_pc)
summary(dynlm(res ~ L(res)))
## Example 12.4
coeftest(fm_m1)
coeftest(fm_m1, vcov = NeweyWest(fm_m1, lag = 5))
summary(fm_m1)$r.squared
dwtest(fm_m1)
as.vector(acf(residuals(fm_m1), plot = FALSE)$acf)[2]
## matches Tab. 12.1 errata and Greene 6e, apart from Newey-West SE
#################################################
## Cost function of electricity producers 1870 ##
#################################################
####################################################
## SIC 33: Production for primary metals industry ##
####################################################
## data
Greene2003 67
## Example 6.2
## Translog model
fm_tl <- lm(
output ~ labor + capital + I(0.5 * labor^2) + I(0.5 * capital^2) + I(labor * capital),
data = log(SIC33))
## Cobb-Douglas model
fm_cb <- lm(output ~ labor + capital, data = log(SIC33))
###############################
## Cost data for US airlines ##
###############################
## data
data("USAirlines", package = "AER")
## Example 7.2
fm_full <- lm(log(cost) ~ log(output) + I(log(output)^2) + log(price) + load + year + firm,
data = USAirlines)
fm_time <- lm(log(cost) ~ log(output) + I(log(output)^2) + log(price) + load + year,
data = USAirlines)
fm_firm <- lm(log(cost) ~ log(output) + I(log(output)^2) + log(price) + load + firm,
data = USAirlines)
fm_no <- lm(log(cost) ~ log(output) + I(log(output)^2) + log(price) + load, data = USAirlines)
## Table 7.2
anova(fm_full, fm_time)
anova(fm_full, fm_firm)
anova(fm_full, fm_no)
68 Greene2003
summary(fm_no)
summary(fm_gm)
summary(fm_firm)
fixef(fm_firm)
summary(fm_time)
fixef(fm_time)
summary(fm_ft)
fixef(fm_ft, effect = "individual")
fixef(fm_ft, effect = "time")
## Table 13.2
fm_rfirm <- plm(log(cost) ~ log(output) + log(price) + load, data = usair, model = "random")
fm_rft <- plm(log(cost) ~ log(output) + log(price) + load, data = usair, model = "random",
effect = "twoways")
summary(fm_rfirm)
summary(fm_rft)
#################################################
## Cost function of electricity producers 1955 ##
#################################################
## Nerlove data
data("Electricity1955", package = "AER")
Electricity <- Electricity1955[1:145,]
## Example 7.3
## Cobb-Douglas cost function
Greene2003 69
## Figure 7.4
plot(residuals(fm_all) ~ log(output), data = Electricity)
## scaling seems to be different in Greene (2003) with logQ > 10?
## grouped functions
Electricity$group <- with(Electricity, cut(log(output), quantile(log(output), 0:5/5),
include.lowest = TRUE, labels = 1:5))
fm_group <- lm(
log(cost/fuel) ~ group/(log(output) + log(labor/fuel) + log(capital/fuel)) - 1,
data = Electricity)
## Table 7.4
## log quadratic cost function
fm_all2 <- lm(
log(cost/fuel) ~ log(output) + I(log(output)^2) + log(labor/fuel) + log(capital/fuel),
data = Electricity)
summary(fm_all2)
##########################
## Technological change ##
##########################
## Exercise 7.1
data("TechChange", package = "AER")
fm1 <- lm(I(output/technology) ~ log(clr), data = TechChange)
fm2 <- lm(I(output/technology) ~ I(1/clr), data = TechChange)
fm3 <- lm(log(output/technology) ~ log(clr), data = TechChange)
fm4 <- lm(log(output/technology) ~ I(1/clr), data = TechChange)
##################################
## Expenditure and default data ##
##################################
## Example 11.1
ccard <- ccard[order(ccard$income),]
ccard0 <- subset(ccard, expenditure > 0)
cc_ols <- lm(expenditure ~ age + owner + income + I(income^2), data = ccard0)
## Figure 11.1
plot(residuals(cc_ols) ~ income, data = ccard0, pch = 19)
## Table 11.1
mean(ccard$age)
prop.table(table(ccard$owner))
mean(ccard$income)
summary(cc_ols)
sqrt(diag(vcovHC(cc_ols, type = "HC0")))
sqrt(diag(vcovHC(cc_ols, type = "HC2")))
sqrt(diag(vcovHC(cc_ols, type = "HC1")))
data = ccard0)
alphai <- coef(lm(log(residuals(cc_fgls3)^2) ~ log(income), data = ccard0))[2]
}
alpha ## 1.7623 for Greene
cc_fgls3 <- lm(expenditure ~ age + owner + income + I(income^2), weights = 1/income^alpha,
data = ccard0)
## Table 11.2
cc_fit <- list(cc_ols, cc_wls1, cc_wls2, cc_fgls2, cc_fgls1, cc_fgls3, cc_fgls4)
t(sapply(cc_fit, coef))
t(sapply(cc_fit, function(obj) sqrt(diag(vcov(obj)))))
###################################
## DEM/GBP exchange rate returns ##
###################################
################################
## Grunfeld's investment data ##
################################
## Tab. 13.4
fm_pool <- lm(invest ~ value + capital, data = ggr)
summary(fm_pool)
logLik(fm_pool)
## White correction
sqrt(diag(vcovHC(fm_pool, type = "HC0")))
## heteroskedastic FGLS
auxreg1 <- lm(residuals(fm_pool)^2 ~ firm - 1, data = ggr)
fm_pfgls <- lm(invest ~ value + capital, data = ggr, weights = 1/fitted(auxreg1))
summary(fm_pfgls)
## Tab. 13.5
auxreg2 <- lm(residuals(fm_pfgls)^2 ~ firm - 1, data = ggr)
auxreg3 <- lm(residuals(fm_pmlh)^2 ~ firm - 1, data = ggr)
rbind(
"OLS" = coef(auxreg1),
"Het. FGLS" = coef(auxreg2),
"Het. ML" = coef(auxreg3))
## Tab. 14.1
library("systemfit")
fm_sur <- systemfit(invest ~ value + capital, data = pggr, method = "SUR",
methodResidCov = "noDfCor")
fm_psur <- systemfit(invest ~ value + capital, data = pggr, method = "SUR", pooled = TRUE,
methodResidCov = "noDfCor", residCovWeighted = TRUE)
## Tab 14.2
fm_ols <- systemfit(invest ~ value + capital, data = pggr, method = "OLS")
fm_pols <- systemfit(invest ~ value + capital, data = pggr, method = "OLS", pooled = TRUE)
## or "by hand"
fm_gm <- lm(invest ~ value + capital, data = ggr, subset = firm == "General Motors")
mean(residuals(fm_gm)^2) ## Greene uses MLE
## etc.
fm_pool <- lm(invest ~ value + capital, data = ggr)
## End(Not run)
## Fig. 14.2
plot(unlist(residuals(fm_sur)[, c(3, 1, 2, 5, 4)]),
type = "l", ylab = "SUR residuals", ylim = c(-400, 400), xaxs = "i", yaxs = "i")
abline(v = c(20,40,60,80), h = 0, lty = 2)
###################
## Klein model I ##
###################
## data
data("KleinI", package = "AER")
74 Greene2003
library("systemfit")
system <- list(
consumption = consumption ~ cprofits + Lcprofits + I(pwage + gwage),
invest = invest ~ cprofits + Lcprofits + capital,
pwage = pwage ~ gnp + Lgnp + trend)
############################################
## Transportation equipment manufacturing ##
############################################
## data
data("Equipment", package = "AER")
## Example 17.5
## Cobb-Douglas
fm_cd <- lm(log(valueadded/firms) ~ log(capital/firms) + log(labor/firms),
data = Equipment)
## optimization
opt <- optim(par0, nlogL, hessian = TRUE)
## Table 17.2
opt$par
sqrt(diag(solve(opt$hessian)))[1:4]
-opt$value
## re-fit ML model
fm_ml <- GCobbDouglas(opt$par[4])
deviance(fm_ml)
sqrt(diag(vcov(fm_ml)))
############################
## Municipal expenditures ##
############################
76 Greene2003
## Table 18.2
data("Municipalities", package = "AER")
summary(Municipalities)
###########################
## Program effectiveness ##
###########################
####################################
## Labor force participation data ##
####################################
## Example 4.5
summary(gr_lm)
## or equivalently
gr_lm1 <- lm(log(hours * wage) ~ 1, data = PSID1976, subset = participation == "yes")
anova(gr_lm1, gr_lm)
## Table 21.3
summary(gr_probit1)
####################
## Ship accidents ##
####################
## subset data
data("ShipAccidents", package = "AER")
sa <- subset(ShipAccidents, service > 0)
## Table 21.20
sa_full <- glm(incidents ~ type + construction + operation, family = poisson,
data = sa, offset = log(service))
summary(sa_full)
## model comparison
anova(sa_full, sa_notype, test = "Chisq")
anova(sa_full, sa_noperiod, test = "Chisq")
######################################
## Fair's extramarital affairs data ##
######################################
## data
78 GrowthDJ
library("MASS")
fm_nb <- glm.nb(affairs ~ age + yearsmarried + religiousness + occupation + rating,
data = Affairs)
## Tab. 22.6
library("pscl")
fm_zip <- zeroinfl(affairs ~ age + yearsmarried + religiousness + occupation + rating | age +
yearsmarried + religiousness + occupation + rating, data = Affairs)
######################
## Strike durations ##
######################
## Table 22.10
fit_exp <- fitdistr(StrikeDuration$duration, "exponential")
fit_wei <- fitdistr(StrikeDuration$duration, "weibull")
fit_wei$estimate[2]^(-1)
fit_lnorm <- fitdistr(StrikeDuration$duration, "lognormal")
1/fit_lnorm$estimate[2]
exp(-fit_lnorm$estimate[1])
## Weibull and lognormal distribution have
## different parameterizations, see Greene p. 794
## Example 22.10
library("survival")
fm_wei <- survreg(Surv(duration) ~ uoutput, dist = "weibull", data = StrikeDuration)
summary(fm_wei)
Description
Growth regression data as provided by Durlauf & Johnson (1995).
Usage
data("GrowthDJ")
Format
A data frame containing 121 observations on 10 variables.
Details
The data are derived from the Penn World Table 4.0 and are given in Mankiw, Romer and Weil
(1992), except literacy60 that is from the World Bank’s World Development Report.
Source
Journal of Applied Econometrics Data Archive.
http://qed.econ.queensu.ca/jae/1995-v10.4/durlauf-johnson/
References
Durlauf, S.N., and Johnson, P.A. (1995). Multiple Regimes and Cross-Country Growth Behavior.
Journal of Applied Econometrics, 10, 365–384.
Koenker, R., and Zeileis, A. (2009). On Reproducible Econometric Research. Journal of Applied
Econometrics, 24(5), 833–847.
Mankiw, N.G, Romer, D., and Weil, D.N. (1992). A Contribution to the Empirics of Economic
Growth. Quarterly Journal of Economics, 107, 407–437.
Masanjala, W.H., and Papageorgiou, C. (2004). The Solow Model with CES Technology: Nonlin-
earities and Parameter Heterogeneity. Journal of Applied Econometrics, 19, 171–201.
80 GrowthSW
See Also
OECDGrowth, GrowthSW
Examples
## data for non-oil-producing countries
data("GrowthDJ")
dj <- subset(GrowthDJ, oil == "no")
## Different scalings have been used by different authors,
## different types of standard errors, etc.,
## see Koenker & Zeileis (2009) for an overview
dj_sub2 <- lm(dj_model, data = dj, subset = gdp60 >= 1800 & literacy60 >= 50)
coeftest(dj_sub2, vcov = sandwich)
Description
Data on average growth rates over 1960–1995 for 65 countries, along with variables that are poten-
tially related to growth.
Usage
data("GrowthSW")
Format
A data frame containing 65 observations on 6 variables.
growth average annual percentage growth of real GDP from 1960 to 1995.
rgdp60 value of GDP per capita in 1960, converted to 1960 US dollars.
tradeshare average share of trade in the economy from 1960 to 1995, measured as the sum of
exports (X) plus imports (M), divided by GDP; that is, the average value of (X + M)/GDP
from 1960 to 1995.
education average number of years of schooling of adult residents in that country in 1960.
Grunfeld 81
revolutions average annual number of revolutions, insurrections (successful or not) and coup d’etats
in that country from 1960 to 1995.
assassinations average annual number of political assassinations in that country from 1960 to 1995
(in per million population).
Source
Online complements to Stock and Watson (2007).
References
Beck, T., Levine, R., and Loayza, N. (2000). Finance and the Sources of Growth. Journal of
Financial Economics, 58, 261–300.
Stock, J. H. and Watson, M. W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007, GrowthDJ, OECDGrowth
Examples
data("GrowthSW")
summary(GrowthSW)
Description
Panel data on 11 large US manufacturing firms over 20 years, for the years 1935–1954.
Usage
data("Grunfeld")
Format
A data frame containing 20 annual observations on 3 variables for 11 firms.
invest Gross investment, defined as additions to plant and equipment plus maintenance and repairs
in millions of dollars deflated by the implicit price deflator of producers’ durable equipment
(base 1947).
value Market value of the firm, defined as the price of common shares at December 31 (or, for
WH, IBM and CH, the average price of December 31 and January 31 of the following year)
times the number of common shares outstanding plus price of preferred shares at December
31 (or average price of December 31 and January 31 of the following year) times number of
preferred shares plus total book value of debt at December 31 in millions of dollars deflated
by the implicit GNP price deflator (base 1947).
82 Grunfeld
capital Stock of plant and equipment, defined as the accumulated sum of net additions to plant
and equipment deflated by the implicit price deflator for producers’ durable equipment (base
1947) minus depreciation allowance deflated by depreciation expense deflator (10 years mov-
ing average of wholesale price index of metals and metal products, base 1947).
firm factor with 11 levels: "General Motors", "US Steel", "General Electric", "Chrysler",
"Atlantic Refining", "IBM", "Union Oil", "Westinghouse", "Goodyear", "Diamond Match",
"American Steel".
year Year.
Details
This is a popular data set for teaching purposes. Unfortunately, there exist several different versions
(see Kleiber and Zeileis, 2010, for a detailed discussion). In particular, the version provided by
Greene (2003) has a couple of errors for "US Steel" (firm 2): investment in 1940 is 261.6 (instead
of the correct 361.6), investment in 1952 is 645.2 (instead of the correct 645.5), capital in 1946 is
132.6 (instead of the correct 232.6).
Here, we provide the original data from Grunfeld (1958). The data for the first 10 firms are identical
to those of Baltagi (2002) or Baltagi (2005), now also used by Greene (2008).
Source
The data are taken from Grunfeld (1958, Appendix, Tables 2–9 and 11–13).
References
Baltagi, B.H. (2002). Econometrics, 3rd ed., Berlin: Springer-Verlag.
Baltagi, B.H. (2005). Econometric Analysis of Panel Data, 3rd ed. Chichester, UK: John Wiley.
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
Greene, W.H. (2008). Econometric Analysis, 6th edition. Upper Saddle River, NJ: Prentice Hall.
Grunfeld, Y. (1958). The Determinants of Corporate Investment. Unpublished Ph.D. Dissertation,
University of Chicago.
Kleiber, C., and Zeileis, A. (2010). “The Grunfeld Data at 50.” German Economic Review, 11(4),
404–417. doi:10.1111/j.14680475.2010.00513.x
See Also
Baltagi2002, Greene2003
Examples
## Greene (2003)
## subset of data with mistakes
ggr <- subset(Grunfeld, firm %in% c("General Motors", "US Steel",
"General Electric", "Chrysler", "Westinghouse"))
ggr[c(26, 38), 1] <- c(261.6, 645.2)
Grunfeld 83
## equivalently
library("plm")
pggr <- pdata.frame(ggr, c("firm", "year"))
library("systemfit")
fm_ols <- systemfit(invest ~ value + capital, data = pggr, method = "OLS")
fm_pols <- systemfit(invest ~ value + capital, data = pggr, method = "OLS",
pooled = TRUE)
## Tab. 14.1
fm_sur <- systemfit(invest ~ value + capital, data = pggr, method = "SUR",
methodResidCov = "noDfCor")
fm_psur <- systemfit(invest ~ value + capital, data = pggr, method = "SUR", pooled = TRUE,
methodResidCov = "noDfCor", residCovWeighted = TRUE)
## Further examples:
## help("Greene2003")
## Panel models
library("plm")
pg <- pdata.frame(subset(Grunfeld, firm != "American Steel"), c("firm", "year"))
## Hausman test
phtest(fm_fe, fm_reswar)
## Further examples:
## help("Baltagi2002")
## help("Greene2003")
Description
Cross-section data for 675 14-year old children born between 1980 and 1988. The sample is taken
from the German Socio-Economic Panel (GSOEP) for the years 1994 to 2002 to investigate the
determinants of secondary school choice.
Usage
data("GSOEP9402")
Format
A data frame containing 675 observations on 12 variables.
Details
This sample from the German Socio-Economic Panel (GSOEP) for the years between 1994 and
2002 has been selected by Winkelmann and Boes (2009) to investigate the determinants of sec-
ondary school choice.
In the German schooling system, students are separated relatively early into different school types,
depending on their ability as perceived by the teachers after four years of primary school. Af-
ter that, around the age of ten, students are placed into one of three types of secondary school:
"Hauptschule" (lower secondary school), "Realschule" (middle secondary school), or "Gymnasium"
(upper secondary school). Only a degree from the latter type of school (called Abitur) provides di-
rect access to universities.
A frequent criticism of this system is that the tracking takes place too early, and that it cements
inequalities in education across generations. Although the secondary school choice is based on the
teachers’ recommendations, it is typically also influenced by the parents; both indirectly through
their own educational level and directly through influence on the teachers.
Source
Online complements to Winkelmann and Boes (2009).
References
Winkelmann, R., and Boes, S. (2009). Analysis of Microdata, 2nd ed. Berlin and Heidelberg:
Springer-Verlag.
See Also
WinkelmannBoes2009
Examples
## data
data("GSOEP9402", package = "AER")
## visualization
plot(school ~ meducation, data = gsoep, breaks = c(7, 9, 10.5, 11.5, 12.5, 15, 18))
## alternatively
86 GSS7402
library("mlogit")
gsoep_mnl2 <- mlogit(
school ~ 0 | meducation + memployment + log(income) + log(size) + parity + year2,
data = gsoep, shape = "wide", reflevel = "Hauptschule")
coeftest(gsoep_mnl2)[1:12,]
## Table 5.2
library("effects")
gsoep_eff <- effect("meducation", gsoep_mnl,
xlevels = list(meducation = sort(unique(gsoep$meducation))))
gsoep_eff$prob
plot(gsoep_eff, confint = FALSE)
## omit year
gsoep_mnl1 <- multinom(
school ~ meducation + memployment + log(income) + log(size) + parity,
data = gsoep)
lrtest(gsoep_mnl, gsoep_mnl1)
## Chapter 6
## Table 6.1
library("MASS")
gsoep_pop <- polr(
school ~ meducation + I(memployment != "none") + log(income) + log(size) + parity + year2,
data = gsoep, method = "probit", Hess = TRUE)
gsoep_pol <- polr(
school ~ meducation + I(memployment != "none") + log(income) + log(size) + parity + year2,
data = gsoep, Hess = TRUE)
## effects
eff_pol1 <- allEffects(gsoep_pol1)
plot(eff_pol1, ask = FALSE, confint = FALSE)
Description
Cross-section data for 9120 women taken from every fourth year of the US General Social Survey
between 1974 and 2002 to investigate the determinants of fertility.
GSS7402 87
Usage
data("GSS7402")
Format
A data frame containing 9120 observations on 10 variables.
kids Number of children. This is coded as a numerical variable but note that the value 8 actually
encompasses 8 or more children.
age Age of respondent.
education Highest year of school completed.
year GSS year for respondent.
siblings Number of brothers and sisters.
agefirstbirth Woman’s age at birth of first child.
ethnicity factor indicating ethnicity. Is the individual Caucasian ("cauc") or not ("other")?
city16 factor. Did the respondent live in a city (with population > 50,000) at age 16?
lowincome16 factor. Was the income below average at age 16?
immigrant factor. Was the respondent (or both parents) born abroad?
Details
This subset of the US General Social Survey (GSS) for every fourth year between 1974 and 2002
has been selected by Winkelmann and Boes (2009) to investigate the determinants of fertility. To
do so they typically restrict their empirical analysis to the women for which the completed fertility
is (assumed to be) known, employing the common cutoff of 40 years. Both, the average number of
children borne to a woman and the probability of being childless, are of interest.
Source
Online complements to Winkelmann and Boes (2009).
References
Winkelmann, R., and Boes, S. (2009). Analysis of Microdata, 2nd ed. Berlin and Heidelberg:
Springer-Verlag.
See Also
WinkelmannBoes2009
Examples
## Chapter 1
## exploratory statistics
gss_kids <- prop.table(table(gss40$kids))
names(gss_kids)[9] <- "8+"
library("lattice")
trellis.par.set(theme = canonical.theme(color = FALSE))
print(xyplot(gss_zoo[,3:1], type = "b", xlab = "Year"))
Description
Guns is a balanced panel of data on 50 US states, plus the District of Columbia (for a total of 51
states), by year for 1977–1999.
Usage
data("Guns")
Format
A data frame containing 1,173 observations on 13 variables.
state factor indicating state.
year factor indicating year.
violent violent crime rate (incidents per 100,000 members of the population).
murder murder rate (incidents per 100,000).
robbery robbery rate (incidents per 100,000).
prisoners incarceration rate in the state in the previous year (sentenced prisoners per 100,000 res-
idents; value for the previous year).
afam percent of state population that is African-American, ages 10 to 64.
cauc percent of state population that is Caucasian, ages 10 to 64.
male percent of state population that is male, ages 10 to 29.
population state population, in millions of people.
income real per capita personal income in the state (US dollars).
density population per square mile of land area, divided by 1,000.
law factor. Does the state have a shall carry law in effect in that year?
Details
Each observation is a given state in a given year. There are a total of 51 states times 23 years =
1,173 observations.
Source
Online complements to Stock and Watson (2007).
References
Ayres, I., and Donohue, J.J. (2003). Shooting Down the ‘More Guns Less Crime’ Hypothesis.
Stanford Law Review, 55, 1193–1312.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
90 HealthInsurance
See Also
StockWatson2007
Examples
## data
data("Guns")
## visualization
library("lattice")
xyplot(log(violent) ~ as.numeric(as.character(year)) | state, data = Guns, type = "l")
Description
Cross-section data originating from the Medical Expenditure Panel Survey survey conducted in
1996.
Usage
data("HealthInsurance")
Format
A data frame containing 8,802 observations on 11 variables.
Details
This is a subset of the data used in Perry and Rosen (2004).
Source
Online complements to Stock and Watson (2007).
References
Perry, C. and Rosen, H.S. (2004). “The Self-Employed are Less Likely than Wage-Earners to Have
Health Insurance. So What?” in Holtz-Eakin, D. and Rosen, H.S. (eds.), Entrepeneurship and
Public Policy, MIT Press.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("HealthInsurance")
summary(HealthInsurance)
prop.table(xtabs(~ selfemp + insurance, data = HealthInsurance), 1)
Description
Cross-section data on the Home Mortgage Disclosure Act (HMDA).
Usage
data("HMDA")
92 HMDA
Format
A data frame containing 2,380 observations on 14 variables.
deny Factor. Was the mortgage denied?
pirat Payments to income ratio.
hirat Housing expense to income ratio.
lvrat Loan to value ratio.
chist Factor. Credit history: consumer payments.
mhist Factor. Credit history: mortgage payments.
phist Factor. Public bad credit record?
unemp 1989 Massachusetts unemployment rate in applicant’s industry.
selfemp Factor. Is the individual self-employed?
insurance Factor. Was the individual denied mortgage insurance?
condomin Factor. Is the unit a condominium?
afam Factor. Is the individual African-American?
single Factor. Is the individual single?
hschool Factor. Does the individual have a high-school diploma?
Details
Only includes variables used by Stock and Watson (2007), some of which had to be generated from
the raw data.
Source
Online complements to Stock and Watson (2007).
References
Munnell, A. H., Tootell, G. M. B., Browne, L. E. and McEneaney, J. (1996). Mortgage Lending in
Boston: Interpreting HMDA Data. American Economic Review, 86, 25–53.
Stock, J. H. and Watson, M. W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("HMDA")
Description
Sales prices of houses sold in the city of Windsor, Canada, during July, August and September,
1987.
Usage
data("HousePrices")
Format
A data frame containing 546 observations on 12 variables.
price Sale price of a house.
lotsize Lot size of a property in square feet.
bedrooms Number of bedrooms.
bathrooms Number of full bathrooms.
stories Number of stories excluding basement.
driveway Factor. Does the house have a driveway?
recreation Factor. Does the house have a recreational room?
fullbase Factor. Does the house have a full finished basement?
gasheat Factor. Does the house use gas for hot water heating?
aircon Factor. Is there central air conditioning?
garage Number of garage places.
prefer Factor. Is the house located in the preferred neighborhood of the city?
Source
Journal of Applied Econometrics Data Archive.
http://qed.econ.queensu.ca/jae/1996-v11.6/anglin-gencay/
References
Anglin, P., and Gencay, R. (1996). Semiparametric Estimation of a Hedonic Price Function. Journal
of Applied Econometrics, 11, 633–648.
Verbeek, M. (2004). A Guide to Modern Econometrics, 2nd ed. Chichester, UK: John Wiley.
94 ivreg
Examples
data("HousePrices")
Description
Fit instrumental-variable regression by two-stage least squares. This is equivalent to direct instrumental-
variables estimation when the number of instruments is equal to the number of predictors.
Usage
ivreg(formula, instruments, data, subset, na.action, weights, offset,
contrasts = NULL, model = TRUE, y = TRUE, x = FALSE, ...)
Arguments
formula, instruments
formula specification(s) of the regression relationship and the instruments. Ei-
ther instruments is missing and formula has three parts as in y ~ x1 + x2 |
z1 + z2 + z3 (recommended) or formula is y ~ x1 + x2 and instruments is a
one-sided formula ~ z1 + z2 + z3 (only for backward compatibility).
data an optional data frame containing the variables in the model. By default the
variables are taken from the environment of the formula.
ivreg 95
Details
ivreg is the high-level interface to the work-horse function ivreg.fit, a set of standard methods
(including print, summary, vcov, anova, hatvalues, predict, terms, model.matrix, bread,
estfun) is available and described on summary.ivreg.
Regressors and instruments for ivreg are most easily specified in a formula with two parts on the
right-hand side, e.g., y ~ x1 + x2 | z1 + z2 + z3, where x1 and x2 are the regressors and z1, z2,
and z3 are the instruments. Note that exogenous regressors have to be included as instruments for
themselves. For example, if there is one exogenous regressor ex and one endogenous regressor en
with instrument in, the appropriate formula would be y ~ ex + en | ex + in. Equivalently, this can
be specified as y ~ ex + en | . - en + in, i.e., by providing an update formula with a . in the second
part of the formula. The latter is typically more convenient, if there is a large number of exogenous
regressors.
Value
ivreg returns an object of class "ivreg", with the following components:
terms a list with elements "regressors" and "instruments" containing the terms
objects for the respective components.
levels levels of the categorical regressors.
contrasts the contrasts used for categorical regressors.
model the full model frame (if model = TRUE).
y the response vector (if y = TRUE).
x a list with elements "regressors", "instruments", "projected", containing
the model matrices from the respective components (if x = TRUE). "projected"
is the matrix of regressors projected on the image of the instruments.
References
Greene, W. H. (1993) Econometric Analysis, 2nd ed., Macmillan.
See Also
ivreg.fit, lm, lm.fit
Examples
## data
data("CigarettesSW", package = "AER")
CigarettesSW <- transform(CigarettesSW,
rprice = price/cpi,
rincome = income/population/cpi,
tdiff = (taxs - tax)/cpi
)
## model
fm <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + I(tax/cpi),
data = CigarettesSW, subset = year == "1995")
summary(fm)
summary(fm, vcov = sandwich, df = Inf, diagnostics = TRUE)
## ANOVA
fm2 <- ivreg(log(packs) ~ log(rprice) | tdiff, data = CigarettesSW, subset = year == "1995")
anova(fm, fm2)
Description
Fit instrumental-variable regression by two-stage least squares. This is equivalent to direct instrumental-
variables estimation when the number of instruments is equal to the number of predictors.
ivreg.fit 97
Usage
ivreg.fit(x, y, z, weights, offset, ...)
Arguments
x regressor matrix.
y vector with dependent variable.
z instruments matrix.
weights an optional vector of weights to be used in the fitting process.
offset an optional offset that can be used to specify an a priori known component to be
included during fitting.
... further arguments passed to lm.fit or lm.wfit, respectively.
Details
ivreg is the high-level interface to the work-horse function ivreg.fit, a set of standard methods
(including summary, vcov, anova, hatvalues, predict, terms, model.matrix, bread, estfun) is
available and described on summary.ivreg.
ivreg.fit is a convenience interface to lm.fit (or lm.wfit) for first projecting x onto the image
of z and the running a regression of y onto the projected x.
Value
ivreg.fit returns an unclassed list with the following components:
See Also
ivreg, lm.fit
98 Journals
Examples
## data
data("CigarettesSW")
CigarettesSW <- transform(CigarettesSW,
rprice = price/cpi,
rincome = income/population/cpi,
tdiff = (taxs - tax)/cpi
)
## high-level interface
fm <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + I(tax/cpi),
data = CigarettesSW, subset = year == "1995")
## low-level interface
y <- fm$y
x <- model.matrix(fm, component = "regressors")
z <- model.matrix(fm, component = "instruments")
ivreg.fit(x, y, z)$coefficients
Description
Subscriptions to economics journals at US libraries, for the year 2000.
Usage
data("Journals")
Format
A data frame containing 180 observations on 10 variables.
Details
Data on 180 economic journals, collected in particular for analyzing journal pricing. See also
https://econ.ucsb.edu/~tedb/Journals/jpricing.html for general information on this topic
as well as a more up-to-date version of the data set. This version is taken from Stock and Watson
(2007).
The data as obtained from the online complements for Stock and Watson (2007) contained two
journals with title “World Development”. One of these (observation 80) seemed to be an error and
was changed to “The World Economy”.
Source
Online complements to Stock and Watson (2007).
References
Bergstrom, T. (2001). Free Labor for Costly Journals? Journal of Economic Perspectives, 15,
183–198.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
Description
Klein’s Model I for the US economy.
Usage
data("KleinI")
Format
An annual multiple time series from 1920 to 1941 with 9 variables.
consumption Consumption.
cprofits Corporate profits.
pwage Private wage bill.
invest Investment.
capital Previous year’s capital stock.
gnp Gross national product.
gwage Government wage bill.
gexpenditure Government spending.
taxes Taxes.
Source
Online complements to Greene (2003). Table F15.1.
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
Longley 101
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
Klein, L. (1950). Economic Fluctuations in the United States, 1921–1941. New York: John Wiley.
Maddala, G.S. (1977). Econometrics. New York: McGraw-Hill.
See Also
Greene2003
Examples
Description
US macroeconomic time series, 1947–1962.
Usage
data("Longley")
Format
An annual multiple time series from 1947 to 1962 with 4 variables.
Details
An extended version of this data set, formatted as a "data.frame" is available as longley in base
R.
Source
Online complements to Greene (2003). Table F4.2.
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
Longley, J.W. (1967). An Appraisal of Least-Squares Programs from the Point of View of the User.
Journal of the American Statistical Association, 62, 819–841.
See Also
longley, Greene2003
Examples
data("Longley")
library("dynlm")
Description
US time series data on prices and cost shares in manufacturing, 1947–1971.
Usage
data("ManufactCosts")
MarkDollar 103
Format
An annual multiple time series from 1947 to 1971 with 9 variables.
Source
Online complements to Greene (2003).
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
References
Berndt, E. and Wood, D. (1975). Technology, Prices, and the Derived Demand for Energy. Review
of Economics and Statistics, 57, 376–384.
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003
Examples
data("ManufactCosts")
plot(ManufactCosts)
Description
A time series of intra-day percentage returns of Deutsche mark/US dollar (DEM/USD) exchange
rates, consisting of two observations per day from 1992-10-01 through 1993-09-29.
Usage
data("MarkDollar")
104 MarkPound
Format
A univariate time series of 518 returns (exact dates unknown) for the DEM/USD exchange rate.
Source
Journal of Business & Economic Statistics Data Archive.
http://www.amstat.org/publications/jbes/upload/index.cfm?fuseaction=ViewArticles&pub=JBES&issue=96-2
References
Bollerslev, T., and Ghysels, E. (1996). Periodic Autoregressive Conditional Heteroskedasticity.
Journal of Business & Economic Statistics, 14, 139–151.
See Also
MarkPound
Examples
library("tseries")
data("MarkDollar")
## GARCH(1,1)
fm <- garch(MarkDollar, grad = "numerical")
summary(fm)
logLik(fm)
Description
A daily time series of percentage returns of Deutsche mark/British pound (DEM/GBP) exchange
rates from 1984-01-03 through 1991-12-31.
Usage
data("MarkPound")
Format
A univariate time series of 1974 returns (exact dates unknown) for the DEM/GBP exchange rate.
Details
Greene (2003, Table F11.1) rounded the series to six digits while eight digits are given in Bollerslev
and Ghysels (1996). Here, we provide the original data. Using round a series can be produced
that is virtually identical to that of Greene (2003) (except for eight observations where a slightly
different rounding arithmetic was used).
MASchools 105
Source
Journal of Business & Economic Statistics Data Archive.
http://www.amstat.org/publications/jbes/upload/index.cfm?fuseaction=ViewArticles&pub=JBES&issue=96-2
References
Bollerslev, T., and Ghysels, E. (1996). Periodic Autoregressive Conditional Heteroskedasticity.
Journal of Business & Economic Statistics, 14, 139–151.
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003, MarkDollar
Examples
Description
The dataset contains data on test performance, school characteristics and student demographic back-
grounds for school districts in Massachusetts.
106 MASchools
Usage
data("MASchools")
Format
A data frame containing 220 observations on 16 variables.
Details
The Massachusetts data are district-wide averages for public elementary school districts in 1998.
The test score is taken from the Massachusetts Comprehensive Assessment System (MCAS) test,
administered to all fourth graders in Massachusetts public schools in the spring of 1998. The test is
sponsored by the Massachusetts Department of Education and is mandatory for all public schools.
The data analyzed here are the overall total score, which is the sum of the scores on the English,
Math, and Science portions of the test. Data on the student-teacher ratio, the percent of students re-
ceiving a subsidized lunch and on the percent of students still learning english are averages for each
elementary school district for the 1997–1998 school year and were obtained from the Massachusetts
department of education. Data on average district income are from the 1990 US Census.
Source
Online complements to Stock and Watson (2007).
References
Stock, J. H. and Watson, M. W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
Medicaid1986 107
See Also
StockWatson2007, CASchools
Examples
## Massachusetts
data("MASchools")
## More examples, notably the entire Table 9.2, can be found in:
## help("StockWatson2007")
Description
Cross-section data originating from the 1986 Medicaid Consumer Survey. The data comprise two
groups of Medicaid eligibles at two sites in California (Santa Barbara and Ventura counties): a
group enrolled in a managed care demonstration program and a fee-for-service comparison group
of non-enrollees.
Usage
data("Medicaid1986")
Format
A data frame containing 996 observations on 14 variables.
visits Number of doctor visits.
exposure Length of observation period for ambulatory care (days).
children Total number of children in the household.
108 Medicaid1986
Source
Journal of Applied Econometrics Data Archive.
http://qed.econ.queensu.ca/jae/1997-v12.3/gurmu/
References
Gurmu, S. (1997). Semi-Parametric Estimation of Hurdle Regression Models with an Application
to Medicaid Utilization. Journal of Applied Econometrics, 12, 225–242.
Examples
## scale regressors
Medicaid1986$age2 <- Medicaid1986$age^2 / 100
Medicaid1986$school <- Medicaid1986$school / 10
Medicaid1986$income <- Medicaid1986$income / 10
## subsets
afdc <- subset(Medicaid1986, program == "afdc")[, c(1, 3:4, 15, 5:9, 11:13)]
ssi <- subset(Medicaid1986, program == "ssi")[, c(1, 3:4, 15, 5:13)]
## Gurmu (1997):
## Table VI., Poisson and negbin models
afdc_pois <- glm(visits ~ ., data = afdc, family = poisson)
summary(afdc_pois)
coeftest(afdc_pois, vcov = sandwich)
Mortgage 109
Description
Cross-section data about fixed versus adjustable mortgages for 78 households.
Usage
data("Mortgage")
Format
A data frame containing 78 observations on 16 variables.
rate Factor with levels "fixed" and "adjustable".
age Age of the borrower.
school Years of schooling for the borrower.
networth Net worth of the borrower.
interest Fixed interest rate.
points Ratio of points paid on adjustable to fixed rate mortgages.
maturities Ratio of maturities on adjustable to fixed rate mortgages.
years Years at the present address.
married Factor. Is the borrower married?
110 MotorCycles
Source
The data is from Baltagi (2002).
References
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
Dhillon, U.S., Shilling, J.D. and Sirmans, C.F. (1987). Choosing Between Fixed and Adjustable
Rate Mortgages. Journal of Money, Credit and Banking, 19, 260–267.
See Also
Baltagi2002
Examples
data("Mortgage")
plot(rate ~ interest, data = Mortgage, breaks = fivenum(Mortgage$interest))
plot(rate ~ margin, data = Mortgage, breaks = fivenum(Mortgage$margin))
plot(rate ~ coborrower, data = Mortgage)
Description
Time series of stock of motor cycles (two wheels) in The Netherlands (in thousands).
Usage
data("MotorCycles")
Format
An annual univariate time series from 1946 to 1993.
MotorCycles2 111
Details
An updated version is available under the name MotorCycles2. However, the values for the years
1992 and 1993 differ there.
Source
Online complements to Franses (1998).
References
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
See Also
Franses1998, MotorCycles2
Examples
data("MotorCycles")
plot(MotorCycles)
Description
Time series of stock of motor cycles (two wheels) in The Netherlands (in thousands).
Usage
data("MotorCycles2")
Format
An annual univariate time series from 1946 to 2012.
Details
This is an update of the series that was available with Franses (1998). However, the values for the
years 1992 and 1993 differ.
Source
Online complements to Franses, van Dijk and Opschoor (2014).
https://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-e
time-series-models-business-and-economic-forecasting-2nd-edition
112 MSCISwitzerland
References
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
Franses, P.H., van Dijk, D. and Opschoor, A. (2014). Time Series Models for Business and Eco-
nomic Forecasting, 2nd ed. Cambridge, UK: Cambridge University Press.
See Also
Franses1998, MotorCycles
Examples
data("MotorCycles2")
plot(MotorCycles2)
Description
Usage
data("MSCISwitzerland")
Format
A daily univariate time series from 1994-12-30 to 2012-12-31 (of class "zoo" with "Date" index).
Source
References
Ding, Z., Granger, C. W. J. and Engle, R. F. (1993). A Long Memory Property of Stock Market
Returns and a New Model. Journal of Empirical Finance, 1(1), 83–106.
Franses, P.H., van Dijk, D. and Opschoor, A. (2014). Time Series Models for Business and Eco-
nomic Forecasting, 2nd ed. Cambridge, UK: Cambridge University Press.
MSCISwitzerland 113
Examples
## Figure 7.7
plot(acf(dlmsci9501^2, lag.max = 200, na.action = na.exclude),
ylim = c(-0.1, 0.3), type = "l")
## standard errors using first derivatives (as apparently used by Franses et al.)
library("tseries")
msci9501_g11 <- garch(zooreg(dlmsci9501), trace = FALSE)
summary(msci9501_g11)
round(msci9501_g11a@fit$coef, 3)
round(msci9501_g11a@fit$se.coef, 3)
## GJR form using reparameterization as given by Ding et al. (1993, pp. 100-101)
coef(msci9501_tg11)["alpha1"] * (1 - coef(msci9501_tg11)["gamma1"])^2 ## alpha*
4 * coef(msci9501_tg11)["alpha1"] * coef(msci9501_tg11)["gamma1"] ## gamma*
library("rugarch")
spec_g11 <- ugarchspec(variance.model = list(model = "sGARCH"),
mean.model = list(armaOrder = c(0,0), include.mean = FALSE))
msci9501_g11b <- ugarchfit(spec_g11, data = dlmsci9501)
msci9501_g11b
114 Municipalities
round(coef(msci9501_gjrg11), 3)
Description
Panel data set for 265 Swedish municipalities covering 9 years (1979-1987).
Usage
data("Municipalities")
Format
A data frame containing 2,385 observations on 5 variables.
Details
Total expenditures contains both capital and current expenditures.
Expenditures, revenues, and grants are expressed in million SEK. The series are deflated and in per
capita form. The implicit deflator is a municipality-specific price index obtained by dividing total
local consumption expenditures at current prices by total local consumption expenditures at fixed
(1985) prices.
The data are gathered by Statistics Sweden and obtained from Financial Accounts for the Munici-
palities (Kommunernas Finanser).
Source
Journal of Applied Econometrics Data Archive.
http://qed.econ.queensu.ca/jae/2000-v15.4/dahlberg-johansson/
MurderRates 115
References
Dahlberg, M., and Johansson, E. (2000). An Examination of the Dynamic Behavior of Local Gov-
ernments Using GMM Bootstrapping Methods. Journal of Applied Econometrics, 15, 401–416.
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003
Examples
## Greene (2003), Table 18.2
data("Municipalities")
summary(Municipalities)
Description
Cross-section data on states in 1950.
Usage
data("MurderRates")
Format
A data frame containing 44 observations on 8 variables.
Source
Maddala (2001), Table 8.4, p. 330
116 NaturalGas
References
Maddala, G.S. (2001). Introduction to Econometrics, 3rd ed. New York: John Wiley.
McManus, W.S. (1985). Estimates of the Deterrent Effect of Capital Punishment: The Importance
of the Researcher’s Prior Beliefs. Journal of Political Economy, 93, 417–425.
Stokes, H. (2004). On the Advantage of Using Two or More Econometric Software Systems to
Solve the Same Problem. Journal of Economic and Social Measurement, 29, 307–320.
Examples
data("MurderRates")
Description
Panel data originating from 6 US states over the period 1967–1989.
Usage
data("NaturalGas")
NMES1988 117
Format
A data frame containing 138 observations on 10 variables.
state factor. State abbreviation.
statecode factor. State Code.
year factor coding year.
consumption Consumption of natural gas by the residential sector.
price Price of natural gas
eprice Price of electricity.
oprice Price of distillate fuel oil.
lprice Price of liquefied petroleum gas.
heating Heating degree days.
income Real per-capita personal income.
Source
The data are from Baltagi (2002).
References
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
See Also
Baltagi2002
Examples
data("NaturalGas")
summary(NaturalGas)
Description
Cross-section data originating from the US National Medical Expenditure Survey (NMES) con-
ducted in 1987 and 1988. The NMES is based upon a representative, national probability sample
of the civilian non-institutionalized population and individuals admitted to long-term care facilities
during 1987. The data are a subsample of individuals ages 66 and over all of whom are covered by
Medicare (a public insurance program providing substantial protection against health-care costs).
Usage
data("NMES1988")
118 NMES1988
Format
A data frame containing 4,406 observations on 19 variables.
Source
Journal of Applied Econometrics Data Archive for Deb and Trivedi (1997).
http://qed.econ.queensu.ca/jae/1997-v12.3/deb-trivedi/
References
Cameron, A.C. and Trivedi, P.K. (1998). Regression Analysis of Count Data. Cambridge: Cam-
bridge University Press.
Deb, P., and Trivedi, P.K. (1997). Demand for Medical Care by the Elderly: A Finite Mixture
Approach. Journal of Applied Econometrics, 12, 313–336.
Zeileis, A., Kleiber, C., and Jackman, S. (2008). Regression Models for Count Data in R. Journal
of Statistical Software, 27(8). doi:10.18637/jss.v027.i08.
See Also
CameronTrivedi1998
NMES1988 119
Examples
## packages
library("MASS")
library("pscl")
## dependent variable
hist(nmes$visits, breaks = 0:(max(nmes$visits)+1) - 0.5)
plot(table(nmes$visits))
## bivariate visualization
par(mfrow = c(3, 2))
plot(clog(visits) ~ health, data = nmes, varwidth = TRUE)
plot(clog(visits) ~ cfac(chronic), data = nmes)
plot(clog(visits) ~ insurance, data = nmes, varwidth = TRUE)
plot(clog(visits) ~ gender, data = nmes, varwidth = TRUE)
plot(cfac(visits, c(0:2, 4, 6, 10, 100)) ~ school, data = nmes, breaks = 9)
par(mfrow = c(1, 1))
## Poisson regression
nmes_pois <- glm(visits ~ ., data = nmes, family = poisson)
summary(nmes_pois)
## quasipoisson model
nmes_qpois <- glm(visits ~ ., data = nmes, family = quasipoisson)
## NegBin regression
nmes_nb <- glm.nb(visits ~ ., data = nmes)
## hurdle regression
nmes_hurdle <- hurdle(visits ~ . | chronic + insurance + school + gender,
120 NYSESW
Description
A daily time series from 1990 to 2005 of the New York Stock Exchange composite index.
Usage
data("NYSESW")
Format
A daily univariate time series from 1990-01-02 to 2005-11-11 (of class "zoo" with "Date" index).
Source
Online complements to Stock and Watson (2007).
OECDGas 121
References
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
## returns
data("NYSESW")
ret <- 100 * diff(log(NYSESW))
plot(ret)
Description
Panel data on gasoline consumption in 18 OECD countries over 19 years, 1960–1978.
Usage
data("OECDGas")
Format
A data frame containing 342 observations on 6 variables.
Source
The data is from Baltagi (2002).
122 OECDGrowth
References
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
Baltagi, B.H. and Griffin, J.M. (1983). Gasoline Demand in the OECD: An Application of Pooling
and Testing Procedures. European Economic Review, 22, 117–137.
See Also
Baltagi2002
Examples
data("OECDGas")
library("lattice")
xyplot(exp(cars) ~ year | country, data = OECDGas, type = "l")
xyplot(exp(gas) ~ year | country, data = OECDGas, type = "l")
Description
Cross-section data on OECD countries, used for growth regressions.
Usage
data("OECDGrowth")
Format
A data frame with 22 observations on the following 6 variables.
gdp85 real GDP in 1985 (per person of working age, i.e., age 15 to 65), in 1985 international
prices.
gdp60 real GDP in 1960 (per person of working age, i.e., age 15 to 65), in 1985 international
prices.
invest average of annual ratios of real domestic investment to real GDP (1960–1985).
school percentage of the working-age population that is in secondary school.
randd average of annual ratios of gross domestic expenditure on research and development to
nominal GDP (of available observations during 1960–1985).
popgrowth annual population growth 1960–1985, computed as log(pop85/pop60)/25.
Source
Appendix 1 Nonneman and Vanhoudt (1996), except for one bad misprint: The value of school for
Norway is given as 0.01, the correct value is 0.1 (see Mankiw, Romer and Weil, 1992). OECDGrowth
contains the corrected data.
OECDGrowth 123
References
Mankiw, N.G., Romer, D., and Weil, D.N. (1992). A Contribution to the Empirics of Economic
Growth. Quarterly Journal of Economics, 107, 407–437.
Nonneman, W., and Vanhoudt, P. (1996). A Further Augmentation of the Solow Model and the
Empirics of Economic Growth. Quarterly Journal of Economics, 111, 943–953.
Zaman, A., Rousseeuw, P.J., and Orhan, M. (2001). Econometric Applications of High-Breakdown
Robust Regression Techniques. Economics Letters, 71, 1–8.
See Also
GrowthDJ, GrowthSW
Examples
data("OECDGrowth")
## large residuals
nok1 <- abs(residuals(so_lts))/so_lts$scale[2] > 2.5
residuals(so_lts)[nok1]/so_lts$scale[2]
## high leverage
X <- model.matrix(so_ols)[,-1]
cv <- cov.rob(X, nsamp = "exact")
mh <- sqrt(mahalanobis(X, cv$center, cv$cov))
nok2 <- mh > 2.5
mh[nok2]
124 OlympicTV
## bad leverage
nok <- which(nok1 & nok2)
nok
Description
Television rights for Olympic Games for US networks (in millions USD).
Usage
data("OlympicTV")
Format
A data frame with 10 observations and 2 variables.
Source
Online complements to Franses (1998).
References
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
See Also
Franses1998
Examples
data("OlympicTV")
plot(OlympicTV$rights)
OrangeCounty 125
Description
Quarterly time series data on employment in Orange county, 1965–1983.
Usage
data("OrangeCounty")
Format
A quarterly multiple time series from 1965 to 1983 with 2 variables.
employment Quarterly employment in Orange county.
gnp Quarterly real GNP.
Source
The data is from Baltagi (2002).
References
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
See Also
Baltagi2002
Examples
data("OrangeCounty")
plot(OrangeCounty)
Description
US earnings data, as provided in an annual survey of Parade (here from 2005), the Sunday news-
paper magazine supplementing the Sunday (or Weekend) edition of many daily newspapers in the
USA.
Usage
data("Parade2005")
126 Parade2005
Format
A data frame containing 130 observations on 5 variables.
Details
In addition to the four variables provided by Parade (earnings, age, gender, and state), a fifth vari-
able was introduced, the “celebrity factor” (here actors, athletes, TV personalities, politicians, and
CEOs are considered celebrities). The data are quite far from a simple random sample, there being
substantial oversampling of celebrities.
Source
Parade (2005). What People Earn. Issue March 13, 2005.
Examples
## data
data("Parade2005")
attach(Parade2005)
summary(Parade2005)
## bivariate visualizations
plot(density(log(earnings), bw = "SJ"), type = "l", main = "log(earnings)")
rug(log(earnings))
plot(log(earnings) ~ gender, main = "log(earnings)")
library("ineq")
plot(Lc(noncel$earnings), main = "log(earnings)")
lines(Lc(cel$earnings), lty = 2)
lines(Lc(earnings), lty = 3)
Gini(noncel$earnings)
Gini(cel$earnings)
Gini(earnings)
## detach data
detach(Parade2005)
PepperPrice 127
Description
Time series of average monthly European spot prices for black and white pepper (fair average
quality) in US dollars per ton.
Usage
data("PepperPrice")
Format
A monthly multiple time series from 1973(10) to 1996(4) with 2 variables.
Source
Originally available as an online supplement to Franses (1998). Now available via online comple-
ments to Franses, van Dijk and Opschoor (2014).
https://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-e
time-series-models-business-and-economic-forecasting-2nd-edition
References
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
Franses, P.H., van Dijk, D. and Opschoor, A. (2014). Time Series Models for Business and Eco-
nomic Forecasting, 2nd ed. Cambridge, UK: Cambridge University Press.
Examples
## data
data("PepperPrice", package = "AER")
plot(PepperPrice, plot.type = "single", col = 1:2)
## package
library("tseries")
library("urca")
## stationarity tests
kpss.test(log(PepperPrice[, "white"]))
## cointegration
po.test(log(PepperPrice))
pepper_jo <- ca.jo(log(PepperPrice), ecdet = "const", type = "trace")
summary(pepper_jo)
pepper_jo2 <- ca.jo(log(PepperPrice), ecdet = "const", type = "eigen")
summary(pepper_jo2)
Description
Cross-section data on the scientific productivity of PhD students in biochemistry.
Usage
data("PhDPublications")
Format
A data frame containing 915 observations on 6 variables.
Source
Online complements to Long (1997).
References
Long, J.S. (1990). Regression Models for Categorical and Limited Dependent Variables. Thousand
Oaks: Sage Publications.
Long, J.S. (1997). The Origin of Sex Differences in Science. Social Forces, 68, 1297–1315.
ProgramEffectiveness 129
Examples
Description
Data used to study the effectiveness of a program.
Usage
data("ProgramEffectiveness")
Format
A data frame containing 32 cross-section observations on 4 variables.
Details
The data are taken form Spencer and Mazzeo (1980) who examined whether a new method of
teaching economics significantly influenced performance in later economics courses.
Source
Online complements to Greene (2003).
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
Spector, L. and Mazzeo, M. (1980). Probit Analysis and Economic Education. Journal of Economic
Education, 11, 37–44.
See Also
Greene2003
Examples
data("ProgramEffectiveness")
Description
Cross-section data originating from the 1976 Panel Study of Income Dynamics (PSID), based on
data for the previous year, 1975.
Usage
data("PSID1976")
Format
A data frame containing 753 observations on 21 variables.
participation Factor. Did the individual participate in the labor force in 1975? (This is essentially
wage > 0 or hours > 0.)
hours Wife’s hours of work in 1975.
PSID1976 131
Details
Source
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
McCullough, B.D. (2004). Some Details of Nonlinear Estimation. In: Altman, M., Gill, J., and
McDonald, M.P.: Numerical Issues in Statistical Computing for the Social Scientist. Hoboken, NJ:
John Wiley, Ch. 8, 199–218.
Mroz, T.A. (1987). The Sensitivity of an Empirical Model of Married Women’s Hours of Work to
Economic and Statistical Assumptions. Econometrica, 55, 765–799.
Winkelmann, R., and Boes, S. (2009). Analysis of Microdata, 2nd ed. Berlin and Heidelberg:
Springer-Verlag.
Wooldridge, J.M. (2002). Econometric Analysis of Cross-Section and Panel Data. Cambridge, MA:
MIT Press.
See Also
Greene2003, WinkelmannBoes2009
Examples
###################
## Greene (2003) ##
###################
## Example 4.5
summary(gr_lm)
## or equivalently
gr_lm1 <- lm(log(hours * wage) ~ 1, data = PSID1976, subset = participation == "yes")
anova(gr_lm1, gr_lm)
#######################
## Wooldridge (2002) ##
#######################
## convenience functions
pseudoR2 <- function(obj) 1 - as.vector(logLik(obj)/logLik(update(obj, . ~ 1)))
misclass <- function(obj) 1 - sum(diag(prop.table(table(
model.response(model.frame(obj)), round(fitted(obj))))))
coeftest(wl_logit)
logLik(wl_logit)
misclass(wl_logit)
pseudoR2(wl_logit)
coeftest(wl_probit)
logLik(wl_probit)
misclass(wl_probit)
pseudoR2(wl_probit)
#######################
## McCullough (2004) ##
#######################
## p. 203
mc_probit <- glm(participation ~ nwincome + education + experience + I(experience^2) +
age + youngkids + oldkids, family = binomial(link = "probit"), data = PSID1976)
mc_tobit <- tobit(hours ~ nwincome + education + experience + I(experience^2) + age +
youngkids + oldkids, data = PSID1976)
coeftest(mc_probit)
coeftest(mc_tobit)
coeftest(mc_tobit, vcov = vcovOPG)
Description
Cross-section data originating from the Panel Study on Income Dynamics, 1982.
Usage
data("PSID1982")
Format
A data frame containing 595 observations on 12 variables.
experience Years of full-time work experience.
weeks Weeks worked.
occupation factor. Is the individual a white-collar ("white") or blue-collar ("blue") worker?
industry factor. Does the individual work in a manufacturing industry?
south factor. Does the individual reside in the South?
smsa factor. Does the individual reside in a SMSA (standard metropolitan statistical area)?
married factor. Is the individual married?
gender factor indicating gender.
union factor. Is the individual’s wage set by a union contract?
education Years of education.
ethnicity factor indicating ethnicity. Is the individual African-American ("afam") or not ("other")?
wage Wage.
PSID7682 135
Details
PSID1982 is the cross-section for the year 1982 taken from a larger panel data set PSID7682 for the
years 1976–1982, originating from Cornwell and Rupert (1988). Baltagi (2002) just uses the 1982
cross-section; hence PSID1982 is available as a standalone data set because it was included in AER
prior to the availability of the full PSID7682 panel version.
Source
The data is from Baltagi (2002).
References
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
Cornwell, C., and Rupert, P. (1988). Efficient Estimation with Panel Data: An Empirical Compari-
son of Instrumental Variables Estimators. Journal of Applied Econometrics, 3, 149–155.
See Also
PSID7682, Baltagi2002
Examples
data("PSID1982")
plot(density(PSID1982$wage, bw = "SJ"))
Description
Panel data on earnings of 595 individuals for the years 1976–1982, originating from the Panel Study
of Income Dynamics.
Usage
data("PSID7682")
136 PSID7682
Format
A data frame containing 7 annual observations on 12 variables for 595 individuals.
Details
The data were originally analyzed by Cornwell and Rupert (1988) and employed for assessing
various instrumental-variable estimators for panel models (including the Hausman-Taylor model).
Baltagi and Khanti-Akom (1990) reanalyzed the data, made corrections to the data and also suggest
modeling with a different set of instruments.
PSID7682 is the version of the data as provided by Baltagi (2005), or Greene (2008).
Baltagi (2002) just uses the cross-section for the year 1982, i.e., subset(PSID7682, year == "1982").
This is also available as a standalone data set PSID1982 because it was included in AER prior to
the availability of the full PSID7682 panel version.
Source
Online complements to Baltagi (2005).
http://www.wiley.com/legacy/wileychi/baltagi3e/data_sets.html
Also provided in the online complements to Greene (2008), Table F9.1.
https://pages.stern.nyu.edu/~wgreene/Text/Edition6/tablelist6.htm
References
Baltagi, B.H., and Khanti-Akom, S. (1990). On Efficient Estimation with Panel Data: An Empirical
Comparison of Instrumental Variables Estimators. Journal of Applied Econometrics, 5, 401–406.
Baltagi, B.H. (2001). Econometric Analysis of Panel Data, 2nd ed. Chichester, UK: John Wiley.
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
RecreationDemand 137
Baltagi, B.H. (2005). Econometric Analysis of Panel Data, 3rd ed. Chichester, UK: John Wiley.
Cornwell, C., and Rupert, P. (1988). Efficient Estimation with Panel Data: An Empirical Compari-
son of Instrumental Variables Estimators. Journal of Applied Econometrics, 3, 149–155.
Greene, W.H. (2008). Econometric Analysis, 6th ed. Upper Saddle River, NJ: Prentice Hall.
See Also
PSID1982, Baltagi2002
Examples
data("PSID7682")
library("plm")
psid <- pdata.frame(PSID7682, c("id", "year"))
Description
Cross-section data on the number of recreational boating trips to Lake Somerville, Texas, in 1980,
based on a survey administered to 2,000 registered leisure boat owners in 23 counties in eastern
Texas.
138 RecreationDemand
Usage
data("RecreationDemand")
Format
A data frame containing 659 observations on 8 variables.
Details
According to the original source (Seller, Stoll and Chavas, 1985, p. 168), the quality rating is on a
scale from 1 to 5 and gives 0 for those who had not visited the lake. This explains the remarkably
low mean for this variable, but also suggests that its treatment in various more recent publications
is far from ideal. For consistency with other sources we handle the variable as a numerical variable,
including the zeros.
Source
Journal of Business & Economic Statistics Data Archive.
http://www.amstat.org/publications/jbes/upload/index.cfm?fuseaction=ViewArticles&pub=JBES&issue=96-4
References
Cameron, A.C. and Trivedi, P.K. (1998). Regression Analysis of Count Data. Cambridge: Cam-
bridge University Press.
Gurmu, S. and Trivedi, P.K. (1996). Excess Zeros in Count Models for Recreational Trips. Journal
of Business & Economic Statistics, 14, 469–477.
Ozuna, T. and Gomez, I.A. (1995). Specification and Testing of Count Data Recreation Demand
Functions. Empirical Economics, 20, 543–550.
Seller, C., Stoll, J.R. and Chavas, J.-P. (1985). Validation of Empirical Measures of Welfare Change:
A Comparison of Nonmarket Techniques. Land Economics, 61, 156–175.
See Also
CameronTrivedi1998
ResumeNames 139
Examples
data("RecreationDemand")
## Poisson model:
## Cameron and Trivedi (1998), Table 6.11
## Ozuna and Gomez (1995), Table 2, col. 3
fm_pois <- glm(trips ~ ., data = RecreationDemand, family = poisson)
summary(fm_pois)
logLik(fm_pois)
coeftest(fm_pois, vcov = sandwich)
## Negbin model:
## Cameron and Trivedi (1998), Table 6.11
## Ozuna and Gomez (1995), Table 2, col. 5
library("MASS")
fm_nb <- glm.nb(trips ~ ., data = RecreationDemand)
coeftest(fm_nb, vcov = vcovOPG)
## ZIP model:
## Cameron and Trivedi (1998), Table 6.11
library("pscl")
fm_zip <- zeroinfl(trips ~ . | quality + income, data = RecreationDemand)
summary(fm_zip)
## Hurdle models
## Cameron and Trivedi (1998), Table 6.13
## poisson-poisson
fm_hp <- hurdle(trips ~ ., data = RecreationDemand, dist = "poisson", zero = "poisson")
## negbin-negbin
fm_hnb <- hurdle(trips ~ ., data = RecreationDemand, dist = "negbin", zero = "negbin")
## binom-negbin == geo-negbin
fm_hgnb <- hurdle(trips ~ ., data = RecreationDemand, dist = "negbin")
ResumeNames Are Emily and Greg More Employable Than Lakisha and Jamal?
Description
Cross-section data about resume, call-back and employer information for 4,870 fictitious resumes.
Usage
data("ResumeNames")
140 ResumeNames
Format
A data frame containing 4,870 observations on 27 variables.
name factor indicating applicant’s first name.
gender factor indicating gender.
ethnicity factor indicating ethnicity (i.e., Caucasian-sounding vs. African-American sounding first
name).
quality factor indicating quality of resume.
call factor. Was the applicant called back?
city factor indicating city: Boston or Chicago.
jobs number of jobs listed on resume.
experience number of years of work experience on the resume.
honors factor. Did the resume mention some honors?
volunteer factor. Did the resume mention some volunteering experience?
military factor. Does the applicant have military experience?
holes factor. Does the resume have some employment holes?
school factor. Does the resume mention some work experience while at school?
email factor. Was the e-mail address on the applicant’s resume?
computer factor. Does the resume mention some computer skills?
special factor. Does the resume mention some special skills?
college factor. Does the applicant have a college degree or more?
minimum factor indicating minimum experience requirement of the employer.
equal factor. Is the employer EOE (equal opportunity employment)?
wanted factor indicating type of position wanted by employer.
requirements factor. Does the ad mention some requirement for the job?
reqexp factor. Does the ad mention some experience requirement?
reqcomm factor. Does the ad mention some communication skills requirement?
reqeduc factor. Does the ad mention some educational requirement?
reqcomp factor. Does the ad mention some computer skills requirement?
reqorg factor. Does the ad mention some organizational skills requirement?
industry factor indicating type of employer industry.
Details
Cross-section data about resume, call-back and employer information for 4,870 fictitious resumes
sent in response to employment advertisements in Chicago and Boston in 2001, in a randomized
controlled experiment conducted by Bertrand and Mullainathan (2004). The resumes contained
information concerning the ethnicity of the applicant. Because ethnicity is not typically included
on a resume, resumes were differentiated on the basis of so-called “Caucasian sounding names”
(such as Emily Walsh or Gregory Baker) and “African American sounding names” (such as Lakisha
Washington or Jamal Jones). A large collection of fictitious resumes were created and the pre-
supposed ethnicity (based on the sound of the name) was randomly assigned to each resume. These
resumes were sent to prospective employers to see which resumes generated a phone call from the
prospective employer.
ShipAccidents 141
Source
Online complements to Stock and Watson (2007).
References
Bertrand, M. and Mullainathan, S. (2004). Are Emily and Greg More Employable Than Lakisha
and Jamal? A Field Experiment on Labor Market Discrimination. American Economic Review, 94,
991–1013.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("ResumeNames")
summary(ResumeNames)
prop.table(xtabs(~ ethnicity + call, data = ResumeNames), 1)
Description
Data on ship accidents.
Usage
data("ShipAccidents")
Format
A data frame containing 40 observations on 5 ship types in 4 vintages and 2 service periods.
type factor with levels "A" to "E" for the different ship types,
construction factor with levels "1960-64", "1965-69", "1970-74", "1975-79" for the periods of
construction,
operation factor with levels "1960-74", "1975-79" for the periods of operation,
service aggregate months of service,
incidents number of damage incidents.
142 ShipAccidents
Details
The data are from McCullagh and Nelder (1989, p. 205, Table 6.2) and were also used by Greene
(2003, Ch. 21), see below.
There are five ships (observations 7, 15, 23, 31, 39) with an operation period before the construction
period, hence the variables service and incidents are necessarily 0. An additional observation
(34) has entries representing accidentally empty cells (see McCullagh and Nelder, 1989, p. 205).
It is a bit unclear what exactly the above means. In any case, the models are fit only to those
observations with service > 0.
Source
Online complements to Greene (2003).
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
McCullagh, P. and Nelder, J.A. (1989). Generalized Linear Models, 2nd edition. London: Chapman
& Hall.
See Also
Greene2003
Examples
data("ShipAccidents")
sa <- subset(ShipAccidents, service > 0)
## model comparison
anova(sa_full, sa_notype, test = "Chisq")
anova(sa_full, sa_noperiod, test = "Chisq")
Description
Statewide production data for primary metals industry (SIC 33).
Usage
data("SIC33")
Format
A data frame containing 27 observations on 3 variables.
output Value added.
labor Labor input.
capital Capital stock.
Source
Online complements to Greene (2003). Table F6.1.
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003
Examples
vcov(fm_tl)
vcov(fm_cb)
## 3D Visualization
library("scatterplot3d")
s3d <- scatterplot3d(log(SIC33)[,c(2, 3, 1)], pch = 16)
s3d$plane3d(fm_cb, lty.box = "solid", col = 4)
## Interactive 3D Visualization
if(require("rgl")) {
x <- log(SIC33)[,2]
y <- log(SIC33)[,3]
z <- log(SIC33)[,1]
plot3d(x, y, z, type = "s", col = "gray", radius = 0.1)
x <- seq(4.5, 7.5, by = 0.5)
y <- seq(5.5, 10, by = 0.5)
z <- outer(x, y, function(x, y) predict(fm_cb, data.frame(labor = x, capital = y)))
surface3d(x, y, z, color = "blue", alpha = 0.5, shininess = 128)
}
Description
Estimation of the effect of workplace smoking bans on smoking of indoor workers.
Usage
data("SmokeBan")
Format
A data frame containing 10,000 observations on 7 variables.
smoker factor. Is the individual a current smoker?
ban factor. Is there a work area smoking ban?
age age in years.
education factor indicating highest education level attained: high school (hs) drop out, high school
graduate, some college, college graduate, master’s degree (or higher).
afam factor. Is the individual African-American?
hispanic factor. Is the individual Hispanic?
gender factor indicating gender.
SportsCards 145
Details
SmokeBank is a cross-sectional data set with observations on 10,000 indoor workers, which is a
subset of a 18,090-observation data set collected as part of the National Health Interview Survey
in 1991 and then again (with different respondents) in 1993. The data set contains information on
whether individuals were, or were not, subject to a workplace smoking ban, whether or not the
individuals smoked and other individual characteristics.
Source
References
Evans, W. N., Farrelly, M.C., and Montgomery, E. (1999). Do Workplace Smoking Bans Reduce
Smoking? American Economic Review, 89, 728–747.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("SmokeBan")
Description
Trading sports cards: Does ownership increase the value of goods to consumers?
Usage
data("SportsCards")
146 SportsCards
Format
A data frame containing 148 observations on 9 variables.
good factor. Was the individual given good A or B (see below)?
dealer factor. Was the individual a dealer?
permonth number of trades per month reported by the individual.
years number of years that the individual has been trading.
income factor indicating income group (in 1000 USD).
gender factor indicating gender.
education factor indicating highest level of education (8th grade or less, high school, 2-year col-
lege, other post-high school, 4-year college or graduate school).
age age in years.
trade factor. Did the individual trade the good he was given for the other good?
Details
SportsCards contains data from 148 randomly selected traders who attended a trading card show
in Orlando, Florida, in 1998. Traders were randomly given one of two sports collectables, say good
A or good B, that had approximately equal market value. Those receiving good A were then given
the option of trading good A for good B with the experimenter; those receiving good B were given
the option of trading good B for good A with the experimenter. Good A was a ticket stub from the
game that Cal Ripken Jr. set the record for consecutive games played, and Good B was a souvenir
from the game that Nolan Ryan won his 300th game.
Source
Online complements to Stock and Watson (2007).
References
List, J.A. (2003). Does Market Experience Eliminate Market Anomalies? Quarterly Journal of
Economcis, 118, 41–71.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("SportsCards")
summary(SportsCards)
plot(trade ~ permonth, data = SportsCards, breaks = c(0, 5, 10, 20, 30, 70))
plot(trade ~ years, data = SportsCards, breaks = c(0, 5, 10, 20, 60))
STAR 147
Description
The Project STAR public access data set, assessing the effect of reducing class size on test scores
in the early grades.
Usage
data("STAR")
Format
A data frame containing 11,598 observations on 47 variables.
gender factor indicating student’s gender.
ethnicity factor indicating student’s ethnicity with levels "cauc" (Caucasian), "afam" (African-
American), "asian" (Asian), "hispanic" (Hispanic), "amindian" (American-Indian) or "other".
birth student’s birth quarter (of class yearqtr).
stark factor indicating the STAR class type in kindergarten: regular, small, or regular-with-aide.
NA indicates that no STAR class was attended.
star1 factor indicating the STAR class type in 1st grade: regular, small, or regular-with-aide. NA
indicates that no STAR class was attended.
star2 factor indicating the STAR class type in 2nd grade: regular, small, or regular-with-aide. NA
indicates that no STAR class was attended.
star3 factor indicating the STAR class type in 3rd grade: regular, small, or regular-with-aide. NA
indicates that no STAR class was attended.
readk total reading scaled score in kindergarten.
read1 total reading scaled score in 1st grade.
read2 total reading scaled score in 2nd grade.
read3 total reading scaled score in 3rd grade.
mathk total math scaled score in kindergarten.
math1 total math scaled score in 1st grade.
math2 total math scaled score in 2nd grade.
math3 total math scaled score in 3rd grade.
lunchk factor indicating whether the student qualified for free lunch in kindergarten.
lunch1 factor indicating whether the student qualified for free lunch in 1st grade.
lunch2 factor indicating whether the student qualified for free lunch in 2nd grade.
lunch3 factor indicating whether the student qualified for free lunch in 3rd grade.
schoolk factor indicating school type in kindergarten: "inner-city", "suburban", "rural" or
"urban".
148 STAR
school1 factor indicating school type in 1st grade: "inner-city", "suburban", "rural" or "urban".
school2 factor indicating school type in 2nd grade: "inner-city", "suburban", "rural" or
"urban".
school3 factor indicating school type in 3rd grade: "inner-city", "suburban", "rural" or "urban".
degreek factor indicating highest degree of kindergarten teacher: "bachelor", "master", "specialist",
or "master+".
degree1 factor indicating highest degree of 1st grade teacher: "bachelor", "master", "specialist",
or "phd".
degree2 factor indicating highest degree of 2nd grade teacher: "bachelor", "master", "specialist",
or "phd".
degree3 factor indicating highest degree of 3rd grade teacher: "bachelor", "master", "specialist",
or "phd".
ladderk factor indicating teacher’s career ladder level in kindergarten: "level1", "level2", "level3",
"apprentice", "probation" or "pending".
ladder1 factor indicating teacher’s career ladder level in 1st grade: "level1", "level2", "level3",
"apprentice", "probation" or "noladder".
ladder2 factor indicating teacher’s career ladder level in 2nd grade: "level1", "level2", "level3",
"apprentice", "probation" or "noladder".
ladder3 factor indicating teacher’s career ladder level in 3rd grade: "level1", "level2", "level3",
"apprentice", "probation" or "noladder".
experiencek years of teacher’s total teaching experience in kindergarten.
experience1 years of teacher’s total teaching experience in 1st grade.
experience2 years of teacher’s total teaching experience in 2nd grade.
experience3 years of teacher’s total teaching experience in 3rd grade.
tethnicityk factor indicating teacher’s ethnicity in kindergarten with levels "cauc" (Caucasian) or
"afam" (African-American).
tethnicity1 factor indicating teacher’s ethnicity in 1st grade with levels "cauc" (Caucasian) or
"afam" (African-American).
tethnicity2 factor indicating teacher’s ethnicity in 2nd grade with levels "cauc" (Caucasian) or
"afam" (African-American).
tethnicity3 factor indicating teacher’s ethnicity in 3rd grade with levels "cauc" (Caucasian), "afam"
(African-American), or "asian" (Asian).
systemk factor indicating school system ID in kindergarten.
system1 factor indicating school system ID in 1st grade.
system2 factor indicating school system ID in 2nd grade.
system3 factor indicating school system ID in 3rd grade.
schoolidk factor indicating school ID in kindergarten.
schoolid1 factor indicating school ID in 1st grade.
schoolid2 factor indicating school ID in 2nd grade.
schoolid3 factor indicating school ID in 3rd grade.
STAR 149
Details
Project STAR (Student/Teacher Achievement Ratio) was a four-year longitudinal class-size study
funded by the Tennessee General Assembly and conducted in the late 1980s by the State Department
of Education. Over 7,000 students in 79 schools were randomly assigned into one of three inter-
ventions: small class (13 to 17 students per teacher), regular class (22 to 25 students per teacher),
and regular-with-aide class (22 to 25 students with a full-time teacher’s aide). Classroom teachers
were also randomly assigned to the classes they would teach. The interventions were initiated as
the students entered school in kindergarten and continued through third grade.
The Project STAR public access data set contains data on test scores, treatment groups, and student
and teacher characteristics for the four years of the experiment, from academic year 1985–1986 to
academic year 1988–1989. The test score data analyzed in this chapter are the sum of the scores on
the math and reading portion of the Stanford Achievement Test.
Stock and Watson (2007) obtained the data set from the Project STAR Web site.
The data is provided in wide format. Reshaping it into long format is illustrated below. Note that
the levels of the degree, ladder and tethnicity variables differ slightly between kindergarten
and higher grades.
Source
Online complements to Stock and Watson (2007).
References
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("STAR")
## fit a single model nested in grade (equivalent to fmk, fm1, fm2, fmk)
fm <- lm(I(read + math) ~ 0 + grade/star, data = star)
coeftest(fm, vcov = sandwich)
## visualization
library("lattice")
bwplot(I(read + math) ~ star | grade, data = star)
Description
This manual page collects a list of examples from the book. Some solutions might not be exact and
the list is certainly not complete. If you have suggestions for improvement (preferably in the form
of code), please contact the package maintainer.
References
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
CartelStability, CASchools, CigarettesSW, CollegeDistance, CPSSW04, CPSSW3, CPSSW8,
CPSSW9298, CPSSW9204, CPSSWEducation, Fatalities, Fertility, Fertility2, FrozenJuice,
GrowthSW, Guns, HealthInsurance, HMDA, Journals, MASchools, NYSESW, ResumeNames, SmokeBan,
SportsCards, STAR, TeachingRatings, USMacroSW, USMacroSWM, USMacroSWQ, USSeatBelts, USStocksSW,
WeakInstrument
Examples
###############################
## Current Population Survey ##
StockWatson2007 151
###############################
## p. 165
data("CPSSWEducation", package = "AER")
plot(earnings ~ education, data = CPSSWEducation)
fm <- lm(earnings ~ education, data = CPSSWEducation)
coeftest(fm, vcov = sandwich)
abline(fm)
############################
## California test scores ##
############################
## p. 152
fm1 <- lm(score ~ stratio, data = CASchools)
coeftest(fm1, vcov = sandwich)
## p. 159
fm2 <- lm(score ~ I(stratio < 20), data = CASchools)
## p. 199
fm3 <- lm(score ~ stratio + english, data = CASchools)
## p. 224
fm4 <- lm(score ~ stratio + expenditure + english, data = CASchools)
#####################################
## Economics journal Subscriptions ##
#####################################
###############################
## Massachusetts test scores ##
###############################
##################################
## Home mortgage disclosure act ##
##################################
## data
data("HMDA", package = "AER")
fm4 <- glm(deny ~ pirat + afam, family = binomial(link = "probit"), data = HMDA)
fm5 <- glm(deny ~ pirat + afam, family = binomial(link = "logit"), data = HMDA)
#########################################################
## Shooting down the "More Guns Less Crime" hypothesis ##
#########################################################
## data
data("Guns", package = "AER")
###########################
## US traffic fatalities ##
###########################
######################################
## Cigarette consumption panel data ##
######################################
## Equations 12.9--12.11
fm_s1 <- lm(log(rprice) ~ rtdiff, data = c1995)
coeftest(fm_s1, vcov = hc1)
fm_s2 <- lm(log(packs) ~ fitted(fm_s1), data = c1995)
fm_ivreg <- ivreg(log(packs) ~ log(rprice) | rtdiff, data = c1995)
coeftest(fm_ivreg, vcov = hc1)
## Equation 12.15
fm_ivreg2 <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + rtdiff, data = c1995)
coeftest(fm_ivreg2, vcov = hc1)
## Equation 12.16
fm_ivreg3 <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + rtdiff + rtax,
data = c1995)
coeftest(fm_ivreg3, vcov = hc1)
#####################################################
## Project STAR: Student-teacher achievement ratio ##
#####################################################
## data
data("STAR", package = "AER")
## p. 488
fmk <- lm(I(readk + mathk) ~ stark, data = STAR)
fm1 <- lm(I(read1 + math1) ~ star1, data = STAR)
fm2 <- lm(I(read2 + math2) ~ star2, data = STAR)
fm3 <- lm(I(read3 + math3) ~ star3, data = STAR)
coeftest(fm3, vcov = sandwich)
## p. 489
fmke <- lm(I(readk + mathk) ~ stark + experiencek, data = STAR)
coeftest(fmke, vcov = sandwich)
## equivalently:
## - reshape data from wide into long format
## - fit a single model nested in grade
## (a) variables and their levels
nam <- c("star", "read", "math", "lunch", "school", "degree", "ladder",
"experience", "tethnicity", "system", "schoolid")
lev <- c("k", "1", "2", "3")
## (b) reshaping
star <- reshape(STAR, idvar = "id", ids = row.names(STAR),
times = lev, timevar = "grade", direction = "long",
varying = lapply(nam, function(x) paste(x, lev, sep = "")))
## (c) improve variable names and type
names(star)[5:15] <- nam
StockWatson2007 159
#################################################
## Quarterly US macroeconomic data (1957-2005) ##
#################################################
## data
data("USMacroSW", package = "AER")
library("dynlm")
usm <- ts.intersect(USMacroSW, 4 * 100 * diff(log(USMacroSW[, "cpi"])))
colnames(usm) <- c(colnames(USMacroSW), "infl")
##########################################
## Monthly US stock returns (1931-2002) ##
##########################################
##################################
StockWatson2007 161
## load data
data("FrozenJuice")
#############################################
## New York Stock Exchange composite index ##
#############################################
## returns
data("NYSESW", package = "AER")
ret <- 100 * diff(log(NYSESW))
plot(ret)
## fit GARCH(1,1)
library("tseries")
fm <- garch(coredata(ret))
162 StrikeDuration
Description
Usage
data("StrikeDuration")
Format
Details
The original data provided by Kennan (1985) are on a monthly basis, for the period 1968(1) through
1976(12). Greene (2003) only provides the June data for each year. Also, the duration for observa-
tion 36 is given as 3 by Greene while Kennan has 2. Here we use Greene’s version.
uoutput is the residual from a regression of the logarithm of industrial production in manufacturing
on time, time squared, and monthly dummy variables.
Source
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
Kennan, J. (1985). The Duration of Contract Strikes in US Manufacturing. Journal of Economet-
rics, 28, 5–28.
See Also
Greene2003
summary.ivreg 163
Examples
data("StrikeDuration")
library("MASS")
Description
Methods to standard generics for instrumental-variable regressions fitted by ivreg.
Usage
## S3 method for class 'ivreg'
summary(object, vcov. = NULL, df = NULL, diagnostics = FALSE, ...)
## S3 method for class 'ivreg'
anova(object, object2, test = "F", vcov = NULL, ...)
Arguments
object, object2, x
an object of class "ivreg" as fitted by ivreg.
vcov., vcov a specification of the covariance matrix of the estimated coefficients. This can
be specified as a matrix or as a function yielding a matrix when applied to the
fitted model. If it is a function it is also employed in the two diagnostic F tests
(if diagnostics = TRUE in the summary() method).
164 summary.ivreg
Details
ivreg is the high-level interface to the work-horse function ivreg.fit, a set of standard methods
(including summary, vcov, anova, hatvalues, predict, terms, model.matrix, update, bread,
estfun) is available.
See Also
ivreg, lm.fit
Examples
## data
data("CigarettesSW")
CigarettesSW <- transform(CigarettesSW,
rprice = price/cpi,
rincome = income/population/cpi,
tdiff = (taxs - tax)/cpi
)
## model
fm <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + I(tax/cpi),
data = CigarettesSW, subset = year == "1995")
summary(fm)
summary(fm, vcov = sandwich, df = Inf, diagnostics = TRUE)
## ANOVA
fm2 <- ivreg(log(packs) ~ log(rprice) | tdiff, data = CigarettesSW, subset = year == "1995")
anova(fm, fm2, vcov = sandwich, test = "Chisq")
SwissLabor 165
Description
Cross-section data originating from the health survey SOMIPOPS for Switzerland in 1981.
Usage
data("SwissLabor")
Format
A data frame containing 872 observations on 7 variables.
participation Factor. Did the individual participate in the labor force?
income Logarithm of nonlabor income.
age Age in decades (years divided by 10).
education Years of formal education.
youngkids Number of young children (under 7 years of age).
oldkids Number of older children (over 7 years of age).
foreign Factor. Is the individual a foreigner (i.e., not Swiss)?
Source
Journal of Applied Econometrics Data Archive.
http://qed.econ.queensu.ca/jae/1996-v11.3/gerfin/
References
Gerfin, M. (1996). Parametric and Semi-Parametric Estimation of the Binary Response Model of
Labour Market Participation. Journal of Applied Econometrics, 11, 321–339.
Examples
data("SwissLabor")
### alternatively
fm_logit <- glm(participation ~ . + I(age^2), data = SwissLabor,
family = binomial)
summary(fm_logit)
166 TeachingRatings
Description
Data on course evaluations, course characteristics, and professor characteristics for 463 courses for
the academic years 2000–2002 at the University of Texas at Austin.
Usage
data("TeachingRatings")
Format
Details
A sample of student instructional ratings for a group of university teachers along with beauty rating
(average from six independent judges) and a number of other characteristics.
Source
The data were provided by Prof. Hamermesh. The first 8 variables are also available in the online
complements to Stock and Watson (2007) at
TechChange 167
References
Hamermesh, D.S., and Parker, A. (2005). Beauty in the Classroom: Instructors’ Pulchritude and
Putative Pedagogical Productivity. Economics of Education Review, 24, 369–376.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("TeachingRatings", package = "AER")
Description
US time series data, 1909–1949.
Usage
data("TechChange")
Format
An annual multiple time series from 1909 to 1949 with 3 variables.
output Output.
clr Capital/labor ratio.
technology Index of technology.
168 tobit
Source
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
Solow, R. (1957). Technical Change and the Aggregate Production Function. Review of Economics
and Statistics, 39, 312–320.
See Also
Greene2003
Examples
data("TechChange")
## Greene (2003)
## Exercise 7.1
fm1 <- lm(I(output/technology) ~ log(clr), data = TechChange)
fm2 <- lm(I(output/technology) ~ I(1/clr), data = TechChange)
fm3 <- lm(log(output/technology) ~ log(clr), data = TechChange)
fm4 <- lm(log(output/technology) ~ I(1/clr), data = TechChange)
library("strucchange")
sctest(I(output/technology) ~ log(clr), data = TechChange, type = "Chow", point = c(1942, 1))
Description
Usage
Arguments
formula a symbolic description of a regression model of type y ~ x1 + x2 + ....
left left limit for the censored dependent variable y. If set to -Inf, y is assumed not
to be left-censored.
right right limit for the censored dependent variable y. If set to Inf, the default, y is
assumed not to be right-censored.
dist assumed distribution for the dependent variable y. This is passed to survreg,
see the respective man page for more details.
subset a specification of the rows to be used.
data a data frame containing the variables in the model.
... further arguments passed to survreg.
Details
The function tobit is a convenience interface to survreg (for survival regression, including cen-
sored regression) setting different defaults and providing a more convenient interface for specifica-
tion of the censoring information.
The default is the classical tobit model (Tobin 1958, Greene 2003) assuming a normal distribution
for the dependent variable with left-censoring at 0.
Technically, the formula of type y ~ x1 + x2 + ... passed to tobit is simply transformed into a
formula suitable for survreg: This means the dependent variable is first censored and then wrapped
into a Surv object containing the censoring information which is subsequently passed to survreg,
e.g., Surv(ifelse(y <= 0, 0, y), y > 0, type = "left") ~ x1 + x2 + ... for the default settings.
Value
An object of class "tobit" inheriting from class "survreg".
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
Tobin, J. (1958). Estimation of Relationships for Limited Dependent Variables. Econometrica, 26,
24–36.
Examples
data("Affairs")
summary(fm.tobit)
summary(fm.tobit2)
170 TradeCredit
Description
Macroeconomic time series data from 1946 to 1966 on trade credit and the money market.
Usage
data("TradeCredit")
Format
An annual multiple time series from 1946 to 1966 on 7 variables.
Source
The data are from Baltagi (2002).
References
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
Laffer, A.B. (1970). Trade Credit and the Money Market. Journal of Political Economy, 78, 239–
267.
See Also
Baltagi2002
Examples
data("TradeCredit")
plot(TradeCredit)
TravelMode 171
Description
Data on travel mode choice for travel between Sydney and Melbourne, Australia.
Usage
data("TravelMode")
Format
Source
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003
172 UKInflation
Examples
Description
Time series of observed and expected price changes in British manufacturing.
Usage
data("UKInflation")
Format
A quarterly multiple time series from 1972(1) to 1985(2) with 2 variables.
Source
Online complements to Greene (2003), Table F8.1.
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
Pesaran, M.H., and Hall, A.D. (1988). Tests of Non-nested Linear Regression Models Subject To
Linear Restrictions. Economics Letters, 27, 341–348.
UKNonDurables 173
See Also
Greene2003
Examples
data("UKInflation")
plot(UKInflation)
Description
Time series of consumption of non-durables in the UK (in 1985 prices).
Usage
data("UKNonDurables")
Format
A quarterly univariate time series from 1955(1) to 1988(4).
Source
Online complements to Franses (1998).
References
Osborn, D.R. (1988). A Survey of Seasonality in UK Macroeconomic Variables. International
Journal of Forecasting, 6, 327–336.
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
See Also
Franses1998
Examples
data("UKNonDurables")
plot(UKNonDurables)
Description
Cost data for six US airlines in 1970–1984.
Usage
data("USAirlines")
Format
A data frame containing 90 observations on 6 variables.
Source
Online complements to Greene (2003). Table F7.1.
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
USConsump1950 175
See Also
Greene2003
Examples
data("USAirlines")
## Table 7.2
anova(fm_full, fm_time)
anova(fm_full, fm_firm)
anova(fm_full, fm_no)
Description
Time series data on US income and consumption expenditure, 1940–1950.
Usage
data("USConsump1950")
176 USConsump1950
Format
An annual multiple time series from 1940 to 1950 with 3 variables.
income Disposable income.
expenditure Consumption expenditure.
war Indicator variable: Was the year a year of war?
Source
Online complements to Greene (2003). Table F2.1.
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003, USConsump1979, USConsump1993
Examples
## Greene (2003)
## data
data("USConsump1950")
usc <- as.data.frame(USConsump1950)
usc$war <- factor(usc$war, labels = c("no", "yes"))
## Example 2.1
plot(expenditure ~ income, data = usc, type = "n", xlim = c(225, 375), ylim = c(225, 350))
with(usc, text(income, expenditure, time(USConsump1950)))
## single model
fm <- lm(expenditure ~ income, data = usc)
summary(fm)
## compare
anova(fm, fm2)
## visualize
abline(fm, lty = 3)
abline(coef(fm2)[1:2])
abline(sum(coef(fm2)[c(1, 3)]), coef(fm2)[2], lty = 2)
## Example 3.2
summary(fm)$r.squared
summary(lm(expenditure ~ income, data = usc, subset = war == "no"))$r.squared
USConsump1979 177
summary(fm2)$r.squared
Description
Time series data on US income and consumption expenditure, 1970–1979.
Usage
data("USConsump1979")
Format
An annual multiple time series from 1970 to 1979 with 2 variables.
Source
Online complements to Greene (2003). Table F1.1.
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003, USConsump1950, USConsump1993
Examples
data("USConsump1979")
plot(USConsump1979)
Description
Time series data on US income and consumption expenditure, 1950–1993.
Usage
data("USConsump1993")
Format
An annual multiple time series from 1950 to 1993 with 2 variables.
Source
The data is from Baltagi (2002).
References
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
See Also
Baltagi2002, USConsump1950, USConsump1979
Examples
## Chapter 8
library("strucchange")
USCrudes 179
## Recursive residuals
rr <- recresid(fm)
rr
## Recursive CUSUM test
rcus <- efp(expenditure ~ income, data = USConsump1993)
plot(rcus)
sctest(rcus)
## Harvey-Collier test
harvtest(fm)
## NOTE" Mistake in Baltagi (2002) who computes
## the t-statistic incorrectly as 0.0733 via
mean(rr)/sd(rr)/sqrt(length(rr))
## whereas it should be (as in harvtest)
mean(rr)/sd(rr) * sqrt(length(rr))
## Rainbow test
raintest(fm, center = 23)
## Chapter 14
## ACF and PACF for expenditures and first differences
exps <- USConsump1993[, "expenditure"]
(acf(exps))
(pacf(exps))
(acf(diff(exps)))
(pacf(diff(exps)))
Description
Cross-section data originating from 99 US oil field postings.
Usage
data("USCrudes")
Format
A data frame containing 99 observations on 3 variables.
180 USGasB
Source
The data is from Baltagi (2002).
References
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
See Also
Baltagi2002
Examples
data("USCrudes")
plot(price ~ gravity, data = USCrudes)
plot(price ~ sulphur, data = USCrudes)
fm <- lm(price ~ sulphur + gravity, data = USCrudes)
## 3D Visualization
library("scatterplot3d")
s3d <- scatterplot3d(USCrudes[, 3:1], pch = 16)
s3d$plane3d(fm, lty.box = "solid", col = 4)
Description
Time series data on the US gasoline market.
Usage
data("USGasB")
Format
An annual multiple time series from 1950 to 1987 with 6 variables.
cars Stock of cars.
gas Consumption of motor gasoline (in 1000 gallons).
price Retail price of motor gasoline.
population Population.
gnp Real gross national product (in 1982 dollars).
deflator GNP deflator (1982 = 100).
USGasG 181
Source
The data are from Baltagi (2002).
References
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
See Also
Baltagi2002, USGasG
Examples
data("USGasB")
plot(USGasB)
Description
Time series data on the US gasoline market.
Usage
data("USGasG")
Format
An annual multiple time series from 1960 to 1995 with 10 variables.
gas Total US gasoline consumption (computed as total expenditure divided by price index).
price Price index for gasoline.
income Per capita disposable income.
newcar Price index for new cars.
usedcar Price index for used cars.
transport Price index for public transportation.
durable Aggregate price index for consumer durables.
nondurable Aggregate price index for consumer nondurables.
service Aggregate price index for consumer services.
population US total population in millions.
Source
Online complements to Greene (2003). Table F2.2.
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
182 USGasG
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003, USGasB
Examples
## Greene (2003)
## Example 2.3
fm <- lm(log(gas/population) ~ log(price) + log(income) + log(newcar) + log(usedcar),
data = as.data.frame(USGasG))
summary(fm)
## Example 4.4
## estimates and standard errors (note different offset for intercept)
coef(fm)
sqrt(diag(vcov(fm)))
## confidence interval
confint(fm, parm = "log(income)")
## test linear hypothesis
linearHypothesis(fm, "log(income) = 1")
## Example 7.6
## re-used in Example 8.3
trend <- 1:nrow(USGasG)
shock <- factor(time(USGasG) > 1973, levels = c(FALSE, TRUE),
labels = c("before", "after"))
## 1960-1995
fm1 <- lm(log(gas/population) ~ log(income) + log(price) + log(newcar) +
log(usedcar) + trend, data = as.data.frame(USGasG))
summary(fm1)
## pooled
fm2 <- lm(log(gas/population) ~ shock + log(income) + log(price) + log(newcar) +
log(usedcar) + trend, data = as.data.frame(USGasG))
summary(fm2)
## segmented
fm3 <- lm(log(gas/population) ~ shock/(log(income) + log(price) + log(newcar) +
log(usedcar) + trend), data = as.data.frame(USGasG))
summary(fm3)
## Chow test
anova(fm3, fm1)
library("strucchange")
sctest(log(gas/population) ~ log(income) + log(price) + log(newcar) +
log(usedcar) + trend, data = USGasG, point = c(1973, 1), type = "Chow")
USInvest 183
Description
Usage
data("USInvest")
Format
Source
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003
184 USMacroB
Examples
data("USInvest")
## p. 22-24
coef(lm(invest ~ trend + gnp, data = us))
coef(lm(invest ~ gnp, data = us))
## Table 3.4
fm <- lm(invest ~ trend + gnp + interest + inflation, data = us)
fm1 <- lm(invest ~ 1, data = us)
anova(fm1, fm)
Description
Time series data on 3 US macroeconomic variables for 1959–1995, extracted from the Citibank
data base.
Usage
data("USMacroB")
Format
A quarterly multiple time series from 1959(1) to 1995(2) with 3 variables.
gnp Gross national product.
mbase Average of the seasonally adjusted monetary base.
tbill Average of 3 month treasury-bill rate (per annum).
USMacroG 185
Source
The data is from Baltagi (2002).
References
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
See Also
Baltagi2002, USMacroSW, USMacroSWQ, USMacroSWM, USMacroG
Examples
data("USMacroB")
plot(USMacroB)
Description
Time series data on 12 US macroeconomic variables for 1950–2000.
Usage
data("USMacroG")
Format
A quarterly multiple time series from 1950(1) to 2000(4) with 12 variables.
Source
Online complements to Greene (2003). Table F5.1.
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003, USMacroSW, USMacroSWQ, USMacroSWM, USMacroB
Examples
## Example 6.1
## Table 6.1
library("dynlm")
fm6.1 <- dynlm(log(invest) ~ tbill + inflation + log(gdp) + ltrend, data = USMacroG)
fm6.3 <- dynlm(log(invest) ~ I(tbill - inflation) + log(gdp) + ltrend, data = USMacroG)
summary(fm6.1)
summary(fm6.3)
deviance(fm6.1)
deviance(fm6.3)
vcov(fm6.1)[2,3]
## F test
linearHypothesis(fm6.1, "tbill + inflation = 0")
## alternatively
anova(fm6.1, fm6.3)
## t statistic
sqrt(anova(fm6.1, fm6.3)[2,5])
## Example 8.2
## Ct = b0 + b1*Yt + b2*Y(t-1) + v
fm1 <- dynlm(consumption ~ dpi + L(dpi), data = USMacroG)
## Ct = a0 + a1*Yt + a2*C(t-1) + u
fm2 <- dynlm(consumption ~ dpi + L(consumption), data = USMacroG)
Description
Time series data on 7 (mostly) US macroeconomic variables for 1957–2005.
Usage
data("USMacroSW")
Format
A quarterly multiple time series from 1957(1) to 2005(1) with 7 variables.
Details
The US Consumer Price Index is measured using monthly surveys and is compiled by the Bureau
of Labor Statistics (BLS). The unemployment rate is computed from the BLS’s Current Population.
The quarterly data used here were computed by averaging the monthly values. The interest data are
the monthly average of daily rates as reported by the Federal Reserve and the dollar-pound exchange
rate data are the monthly average of daily rates; both are for the final month in the quarter. Japanese
real GDP data were obtained from the OECD.
Source
Online complements to Stock and Watson (2007).
References
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
188 USMacroSWM
See Also
StockWatson2007, USMacroSWM, USMacroSWQ, USMacroB, USMacroG
Examples
Description
Time series data on 4 US macroeconomic variables for 1947–2004.
USMacroSWQ 189
Usage
data("USMacroSWM")
Format
A monthly multiple time series from 1947(1) to 2004(4) with 4 variables.
production index of industrial production.
oil oil price shocks, starting 1948(1).
cpi all-items consumer price index.
expenditure personal consumption expenditures price deflator, starting 1959(1).
Source
Online complements to Stock and Watson (2007).
References
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007, USMacroSW, USMacroSWQ, USMacroB, USMacroG
Examples
data("USMacroSWM")
plot(USMacroSWM)
Description
Time series data on 2 US macroeconomic variables for 1947–2004.
Usage
data("USMacroSWQ")
Format
A quarterly multiple time series from 1947(1) to 2004(4) with 2 variables.
gdp real GDP for the United States in billions of chained (2000) dollars seasonally adjusted, annual
rate.
tbill 3-month treasury bill rate. Quarterly averages of daily dates in percentage points at an annual
rate.
190 USMoney
Source
Online complements to Stock and Watson (2007).
References
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007, USMacroSW, USMacroSWM, USMacroB, USMacroG
Examples
data("USMacroSWQ")
plot(USMacroSWQ)
USMoney USMoney
Description
Money, output and price deflator time series data, 1950–1983.
Usage
data("USMoney")
Format
A quarterly multiple time series from 1950 to 1983 with 3 variables.
gnp nominal GNP.
m1 M1 measure of money stock.
deflator implicit price deflator for GNP.
Source
Online complements to Greene (2003), Table F20.2.
https://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003
USProdIndex 191
Examples
data("USMoney")
plot(USMoney)
Description
Index of US industrial production (1985 = 100).
Usage
data("USProdIndex")
Format
A quarterly multiple time series from 1960(1) to 1981(4) with 2 variables.
unadjusted raw index of industrial production,
adjusted seasonally adjusted index.
Source
Online complements to Franses (1998).
References
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
See Also
Franses1998
Examples
data("USProdIndex")
plot(USProdIndex, plot.type = "single", col = 1:2)
Description
Balanced panel data for the years 1983–1997 from 50 US States, plus the District of Columbia, for
assessing traffic fatalities and seat belt usage.
Usage
data("USSeatBelts")
Format
A data frame containing 765 observations on 12 variables.
Details
Some data series from Cohen and Einav (2003) have not been included in the data frame.
USStocksSW 193
Source
Online complements to Stock and Watson (2007).
References
Cohen, A., and Einav, L. (2003). The Effects of Mandatory Seat Belt Laws on Driving Behavior
and Traffic Fatalities. The Review of Economics and Statistics, 85, 828–843
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("USSeatBelts")
summary(USSeatBelts)
library("lattice")
xyplot(fatalities ~ as.numeric(as.character(year)) | state, data = USSeatBelts, type = "l")
Description
Monthly data from 1931–2002 for US stock prices, measured by the broad-based (NYSE and
AMEX) value-weighted index of stock prices as constructed by the Center for Research in Security
Prices (CRSP).
Usage
data("USStocksSW")
Format
A monthly multiple time series from 1931(1) to 2002(12) with 2 variables.
returns monthly excess returns. The monthly return on stocks (in percentage terms) minus the
return on a safe asset (in this case: US treasury bill). The return on the stocks includes the
price changes plus any dividends you receive during the month.
dividend 100 times log(dividend yield). (Multiplication by 100 means the changes are interpreted
as percentage points). It is calculated as the dividends over the past 12 months, divided by the
price in the current month.
194 WeakInstrument
Source
References
Campbell, J.Y., and Yogo, M. (2006). Efficient Tests of Stock Return Predictability Journal of
Financial Economics, 81, 27–60.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("USStocksSW")
plot(USStocksSW)
Description
Usage
data("WeakInstrument")
WinkelmannBoes2009 195
Format
y dependent variable.
x regressor variable.
z instrument variable.
Source
References
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("WeakInstrument")
fm <- ivreg(y ~ x | z, data = WeakInstrument)
summary(fm)
Description
This manual page collects a list of examples from the book. Some solutions might not be exact and
the list is not complete. If you have suggestions for improvement (preferably in the form of code),
please contact the package maintainer.
References
Winkelmann, R., and Boes, S. (2009). Analysis of Microdata, 2nd ed. Berlin and Heidelberg:
Springer-Verlag.
See Also
Examples
#########################################
## US General Social Survey 1974--2002 ##
#########################################
## data
data("GSS7402", package = "AER")
## Chapter 1
## Table 1.1
gss_kids <- table(gss40$kids)
cbind(absolute = gss_kids,
relative = round(prop.table(gss_kids) * 100, digits = 2))
## Table 1.2
sd1 <- function(x) sd(x) / sqrt(length(x))
with(gss40, round(cbind(
"obs" = tapply(kids, year, length),
"av kids" = tapply(kids, year, mean),
" " = tapply(kids, year, sd1),
"prop childless" = tapply(kids, year, function(x) mean(x <= 0)),
" " = tapply(kids, year, function(x) sd1(x <= 0)),
"av schooling" = tapply(education, year, mean),
" " = tapply(education, year, sd1)
), digits = 2))
## Table 1.3
gss40$trend <- gss40$year - 1974
kids_lm1 <- lm(kids ~ factor(year), data = gss40)
kids_lm2 <- lm(kids ~ trend, data = gss40)
kids_lm3 <- lm(kids ~ trend + education, data = gss40)
## Chapter 2
## Table 2.1
kids_tab <- prop.table(xtabs(~ kids + year, data = gss40), 2) * 100
round(kids_tab[,c(4, 8)], digits = 2)
## Figure 2.1
barplot(t(kids_tab[, c(4, 8)]), beside = TRUE, legend = TRUE)
## p. 87
lrtest(nokids_p1, nokids_p2, nokids_p3)
## Example 4.3
## Table 4.1
nokids_l1 <- glm(nokids ~ 1, data = gss40, family = binomial(link = "logit"))
nokids_l3 <- glm(nokids ~ trend + education + ethnicity + siblings,
data = gss40, family = binomial(link = "logit"))
lrtest(nokids_p3)
lrtest(nokids_l3)
## Table 4.2
nokids_xbar <- colMeans(model.matrix(nokids_l3))
sum(coef(nokids_p3) * nokids_xbar)
sum(coef(nokids_l3) * nokids_xbar)
dnorm(sum(coef(nokids_p3) * nokids_xbar))
dlogis(sum(coef(nokids_l3) * nokids_xbar))
dnorm(sum(coef(nokids_p3) * nokids_xbar)) * coef(nokids_p3)[3]
dlogis(sum(coef(nokids_l3) * nokids_xbar)) * coef(nokids_l3)[3]
exp(coef(nokids_l3)[3])
## Figure 4.4
## everything by hand (for ethnicity = "cauc" group)
nokids_xbar <- as.vector(nokids_xbar)
nokids_nd <- data.frame(education = seq(0, 20, by = 0.5), trend = nokids_xbar[2],
ethnicity = "cauc", siblings = nokids_xbar[4])
nokids_p3_fit <- predict(nokids_p3, newdata = nokids_nd,
type = "response", se.fit = TRUE)
plot(nokids_nd$education, nokids_p3_fit$fit, type = "l",
xlab = "education", ylab = "predicted probability", ylim = c(0, 0.3))
polygon(c(nokids_nd$education, rev(nokids_nd$education)),
c(nokids_p3_fit$fit + 1.96 * nokids_p3_fit$se.fit,
rev(nokids_p3_fit$fit - 1.96 * nokids_p3_fit$se.fit)),
col = "lightgray", border = "lightgray")
lines(nokids_nd$education, nokids_p3_fit$fit)
## Table 4.6
## McFadden's R^2
1 - as.numeric( logLik(nokids_p3) / logLik(nokids_p1) )
1 - as.numeric( logLik(nokids_l3) / logLik(nokids_l1) )
## McKelvey and Zavoina R^2
r2mz <- function(obj) {
ystar <- predict(obj)
sse <- sum((ystar - mean(ystar))^2)
s2 <- switch(obj$family$link, "probit" = 1, "logit" = pi^2/3, NA)
n <- length(residuals(obj))
sse / (n * s2 + sse)
}
r2mz(nokids_p3)
r2mz(nokids_l3)
## AUC
library("ROCR")
nokids_p3_pred <- prediction(fitted(nokids_p3), gss40$nokids)
nokids_l3_pred <- prediction(fitted(nokids_l3), gss40$nokids)
plot(performance(nokids_p3_pred, "tpr", "fpr"))
abline(0, 1, lty = 2)
performance(nokids_p3_pred, "auc")
plot(performance(nokids_l3_pred, "tpr", "fpr"))
abline(0, 1, lty = 2)
performance(nokids_l3_pred, "auc")@y.values
## Chapter 7
## Table 7.3
## subset selection
gss02 <- subset(GSS7402, year == 2002 & (age < 40 | !is.na(agefirstbirth)))
#Z# This selection conforms with top of page 229. However, there
#Z# are too many observations: 1374. Furthermore, there are six
#Z# observations with agefirstbirth <= 14 which will cause problems in
#Z# taking logs!
## Chapter 8
## Example 8.3
gss2002 <- subset(GSS7402, year == 2002 & (agefirstbirth < 40 | age < 40))
gss2002$afb <- with(gss2002, Surv(ifelse(kids > 0, agefirstbirth, age), kids > 0))
afb_km <- survfit(afb ~ 1, data = gss2002)
WinkelmannBoes2009 199
## Example 8.9
library("survival")
afb_ex <- survreg(
afb ~ education + siblings + ethnicity + immigrant + lowincome16 + city16,
data = gss2002, dist = "exponential")
afb_wb <- survreg(
afb ~ education + siblings + ethnicity + immigrant + lowincome16 + city16,
data = gss2002, dist = "weibull")
afb_ln <- survreg(
afb ~ education + siblings + ethnicity + immigrant + lowincome16 + city16,
data = gss2002, dist = "lognormal")
## Example 8.11
kids_pois <- glm(kids ~ education + trend + ethnicity + immigrant + lowincome16 + city16,
data = gss40, family = poisson)
library("MASS")
kids_nb <- glm.nb(kids ~ education + trend + ethnicity + immigrant + lowincome16 + city16,
data = gss40)
lrtest(kids_pois, kids_nb)
############################################
## German Socio-Economic Panel 1994--2002 ##
############################################
## data
data("GSOEP9402", package = "AER")
## Chapter 1
## Table 1.4 plus visualizations
gsoep_tab <- xtabs(~ meducation2 + school, data = gsoep)
round(prop.table(gsoep_tab, 1) * 100, digits = 2)
spineplot(gsoep_tab)
plot(school ~ meducation, data = gsoep, breaks = c(7, 10.25, 12.25, 18))
plot(school ~ meducation, data = gsoep, breaks = c(7, 9, 10.5, 11.5, 12.5, 15, 18))
## Chapter 5
## Table 5.1
library("nnet")
gsoep_mnl <- multinom(
school ~ meducation + memployment + log(income) + log(size) + parity + year2,
200 WinkelmannBoes2009
data = gsoep)
coeftest(gsoep_mnl)[c(1:6, 1:6 + 14),]
## alternatively
library("mlogit")
gsoep_mnl2 <- mlogit(school ~ 0 | meducation + memployment + log(income) +
log(size) + parity + year2, data = gsoep, shape = "wide", reflevel = "Hauptschule")
coeftest(gsoep_mnl2)[1:12,]
## Table 5.2
library("effects")
gsoep_eff <- effect("meducation", gsoep_mnl,
xlevels = list(meducation = sort(unique(gsoep$meducation))))
gsoep_eff$prob
plot(gsoep_eff, confint = FALSE)
## all effects
eff_mnl <- allEffects(gsoep_mnl)
plot(eff_mnl, ask = FALSE, confint = FALSE)
plot(eff_mnl, ask = FALSE, style = "stacked", colors = gray.colors(3))
## omit year
gsoep_mnl1 <- multinom(
school ~ meducation + memployment + log(income) + log(size) + parity,
data = gsoep)
lrtest(gsoep_mnl, gsoep_mnl1)
eff_mnl1 <- allEffects(gsoep_mnl1)
plot(eff_mnl1, ask = FALSE, confint = FALSE)
plot(eff_mnl1, ask = FALSE, style = "stacked", colors = gray.colors(3))
## Chapter 6
## Table 6.1
library("MASS")
gsoep$munemp <- factor(gsoep$memployment != "none",
levels = c(FALSE, TRUE), labels = c("no", "yes"))
gsoep_pop <- polr(school ~ meducation + munemp + log(income) + log(size) + parity + year2,
data = gsoep, method = "probit", Hess = TRUE)
gsoep_pol <- polr(school ~ meducation + munemp + log(income) + log(size) + parity + year2,
data = gsoep, Hess = TRUE)
lrtest(gsoep_pop)
lrtest(gsoep_pol)
## Table 6.2
## todo
eff_pol <- allEffects(gsoep_pol)
plot(eff_pol, ask = FALSE, confint = FALSE)
plot(eff_pol, ask = FALSE, style = "stacked", colors = gray.colors(3))
WinkelmannBoes2009 201
####################################
## Labor Force Participation Data ##
####################################
## Mroz data
data("PSID1976", package = "AER")
PSID1976$nwincome <- with(PSID1976, (fincome - hours * wage)/1000)
## visualizations
plot(hours ~ nwincome, data = PSID1976,
xlab = "Non-wife income (in USD 1000)",
ylab = "Hours of work in 1975")
## Chapter 1, p. 18
hours_lm <- lm(hours ~ wage + nwincome + youngkids + oldkids, data = PSID1976,
subset = participation == "yes")
## Chapter 7
## Example 7.2, Table 7.1
hours_tobit <- tobit(hours ~ nwincome + education + experience + I(experience^2) +
age + youngkids + oldkids, data = PSID1976)
hours_ols1 <- lm(hours ~ nwincome + education + experience + I(experience^2) +
age + youngkids + oldkids, data = PSID1976)
hours_ols2 <- lm(hours ~ nwincome + education + experience + I(experience^2) +
age + youngkids + oldkids, data = PSID1976, subset = participation == "yes")
library("sampleSelection")
wage_ghr <- selection(participation ~ nwincome + age + youngkids + oldkids +
education + experience + I(experience^2),
log(wage) ~ education + experience + I(experience^2), data = PSID1976)
## Exercise 7.13
hours_cragg1 <- glm(participation ~ nwincome + education +
experience + I(experience^2) + age + youngkids + oldkids,
data = PSID1976, family = binomial(link = "probit"))
library("truncreg")
hours_cragg2 <- truncreg(hours ~ nwincome + education +
experience + I(experience^2) + age + youngkids + oldkids,
data = PSID1976, subset = participation == "yes")
## Exercise 7.15
wage_olscoef <- sapply(c(-Inf, 0.5, 1, 1.5, 2), function(censpoint)
coef(lm(log(wage) ~ education + experience + I(experience^2),
data = PSID1976[log(PSID1976$wage) > censpoint,])))
wage_mlcoef <- sapply(c(0.5, 1, 1.5, 2), function(censpoint)
202 WinkelmannBoes2009
##################################
## Choice of Brand for Crackers ##
##################################
## data
library("mlogit")
data("Cracker", package = "mlogit")
head(Cracker, 3)
crack <- mlogit.data(Cracker, varying = 2:13, shape = "wide", choice = "choice")
head(crack, 12)
## IIA test
crack_mlogit_all <- update(crack_mlogit2, reflevel = "nabisco")
crack_mlogit_res <- update(crack_mlogit_all,
alt.subset = c("keebler", "nabisco", "sunshine"))
hmftest(crack_mlogit_all, crack_mlogit_res)
Index
∗ datasets GSOEP9402, 84
Affairs, 4 GSS7402, 86
ArgentinaCPI, 6 Guns, 89
Baltagi2002, 7 HealthInsurance, 90
BankWages, 10 HMDA, 91
BenderlyZwick, 11 HousePrices, 93
BondYield, 13 Journals, 98
CameronTrivedi1998, 13 KleinI, 100
CartelStability, 17 Longley, 101
CASchools, 18 ManufactCosts, 102
ChinaIncome, 19 MarkDollar, 103
CigarettesB, 20 MarkPound, 104
CigarettesSW, 22 MASchools, 105
CollegeDistance, 23 Medicaid1986, 107
ConsumerGood, 25 Mortgage, 109
CPS1985, 26 MotorCycles, 110
CPS1988, 27 MotorCycles2, 111
CPSSW, 29 MSCISwitzerland, 112
CreditCard, 31 Municipalities, 114
DJFranses, 34 MurderRates, 115
DJIA8012, 35 NaturalGas, 116
DoctorVisits, 36 NMES1988, 117
DutchAdvert, 38 NYSESW, 120
DutchSales, 39 OECDGas, 121
Electricity1955, 40 OECDGrowth, 122
Electricity1970, 41 OlympicTV, 124
EquationCitations, 43 OrangeCounty, 125
Equipment, 45 Parade2005, 125
EuroEnergy, 47 PepperPrice, 127
Fatalities, 48 PhDPublications, 128
Fertility, 51 ProgramEffectiveness, 129
Franses1998, 53 PSID1976, 130
FrozenJuice, 54 PSID1982, 134
GermanUnemployment, 56 PSID7682, 135
GoldSilver, 57 RecreationDemand, 137
Greene2003, 59 ResumeNames, 139
GrowthDJ, 79 ShipAccidents, 141
GrowthSW, 80 SIC33, 143
Grunfeld, 81 SmokeBan, 144
203
204 INDEX
yearqtr, 147