Aer
Aer
Aer
January 7, 2017
Version 1.2-5
Date 2017-01-06
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. (See the vignette ``AER'' for a package overview.)
LazyLoad yes
Depends R (>= 2.13.0), car (>= 2.0-19), lmtest, sandwich, 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, truncreg, tseries, urca,
vars
Imports stats, Formula (>= 0.2-0)
License GPL-2 | GPL-3
NeedsCompilation no
Author Christian Kleiber [aut],
Achim Zeileis [aut, cre]
Maintainer Achim Zeileis <Achim.Zeileis@R-project.org>
Repository CRAN
Date/Publication 2017-01-07 00:11:57
R topics documented:
Affairs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
ArgentinaCPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Baltagi2002 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
BankWages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
BenderlyZwick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1
2 R topics documented:
BondYield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
CameronTrivedi1998 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
CartelStability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
CASchools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
ChinaIncome . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
CigarettesB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
CigarettesSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
CollegeDistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
ConsumerGood . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
CPS1985 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
CPS1988 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
CPSSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
CreditCard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
dispersiontest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
DJFranses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
DJIA8012 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
DoctorVisits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
DutchAdvert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
DutchSales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Electricity1955 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Electricity1970 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
EquationCitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Equipment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
EuroEnergy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Fatalities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Fertility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Franses1998 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
FrozenJuice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
GermanUnemployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
GoldSilver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Greene2003 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
GrowthDJ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
GrowthSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Grunfeld . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
GSOEP9402 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
GSS7402 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Guns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
HealthInsurance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
HMDA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
HousePrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
ivreg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
ivreg.fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Journals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
KleinI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Longley . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
ManufactCosts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
MarkDollar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
MarkPound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
R topics documented: 3
MASchools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Medicaid1986 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Mortgage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
MotorCycles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
MotorCycles2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
MSCISwitzerland . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Municipalities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
MurderRates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
NaturalGas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
NMES1988 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
NYSESW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
OECDGas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
OECDGrowth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
OlympicTV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
OrangeCounty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Parade2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
PepperPrice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
PhDPublications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
ProgramEffectiveness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
PSID1976 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
PSID1982 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
PSID7682 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
RecreationDemand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
ResumeNames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
ShipAccidents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
SIC33 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
SmokeBan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
SportsCards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
STAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
StockWatson2007 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
StrikeDuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
summary.ivreg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
SwissLabor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
TeachingRatings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
TechChange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
tobit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
TradeCredit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
TravelMode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
UKInflation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
UKNonDurables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
USAirlines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
USConsump1950 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
USConsump1979 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
USConsump1993 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
USCrudes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
USGasB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
USGasG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
USInvest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
4 Affairs
USMacroB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
USMacroG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
USMacroSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
USMacroSWM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
USMacroSWQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
USMoney . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
USProdIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
USSeatBelts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
USStocksSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
WeakInstrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
WinkelmannBoes2009 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Index 202
Description
Infidelity data, known as Fairs 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?
gender factor indicating gender.
age numeric variable coding age in years: 17.5 = under 20, 22 = 2024, 27 = 2529, 32 = 3034,
37 = 3539, 42 = 4044, 47 = 4549, 52 = 5054, 57 = 55 or over.
yearsmarried numeric variable coding number of years married: 0.125 = 3 months or less, 0.417
= 46 months, 0.75 = 6 months1 year, 1.5 = 12 years, 4 = 35 years, 7 = 68 years, 10 =
911 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 = masters degree, 20
= Ph.D., M.D., or other advanced degree.
occupation numeric variable coding occupation according to Hollingshead classification (reverse
numbering).
rating numeric variable coding self rating of marriage: 1 = very unhappy, 2 = somewhat unhappy,
3 = average, 4 = happier than average, 5 = very happy.
ArgentinaCPI 5
Source
Online complements to Greene (2003). Table F22.2.
http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
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, 4561.
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)
Description
Time series of consumer price index (CPI) in Argentina (index with 1969(4) = 1).
6 Baltagi2002
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 19701989.
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")
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.
Baltagi2002 7
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)
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)
library("dynlm")
fm1 <- dynlm(expenditure ~ income + L(income), data = USConsump1993)
fm2 <- dynlm(expenditure ~ income + L(expenditure), data = USConsump1993)
jtest(fm1, fm2)
## 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")
10 BankWages
## 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
Usage
data("BankWages")
Format
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).
http://www.oup.com/uk/booksites/content/0199268010/datasets/ch6/xr614bwa.asc
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.
BenderlyZwick 11
Examples
data("BankWages")
BenderlyZwick Benderly and Zwick Data: Inflation, Growth and Stock Returns
Description
Time series data, 19521982.
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).
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
12 BondYield
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
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
Benderly, J., and Zwick, B. (1985). Inflation, Real Balances, Output and Real Stock Returns.
American Economic Review, 75, 11151123.
Lott, W.F., and Ray, S.C. (1992). Applied Econometrics: Problems with Data Sets. New York: The
Dryden Press.
Zaman, A., Rousseeuw, P.J., and Orhan, M. (2001). Econometric Applications of High-Breakdown
Robust Regression Techniques. Economics Letters, 71, 18.
See Also
Baltagi2002
Examples
data("BenderlyZwick")
plot(BenderlyZwick)
Description
Monthly averages of the yield on a Moodys Aaa rated corporate bond (in percent/year).
Usage
data("BondYield")
CameronTrivedi1998 13
Format
A monthly univariate time series from 1990(1) to 1994(12).
Source
Online complements to Greene (2003), Table F20.1.
http://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.
See Also
DoctorVisits, NMES1988, RecreationDemand
Examples
library("MASS")
library("pscl")
###########################################
## Australian health service utilization ##
###########################################
14 CameronTrivedi1998
## 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
## 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")
AIC(nmes_h)
AIC(nmes_h, k = log(nrow(nmes)))
## 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)
## 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")
16 CartelStability
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 <- hurdle(trips ~ ., data = RecreationDemand,
dist = "negbin", zero = "negbin", start = sval)
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 18801886, for a total of 326 weeks.
Usage
data("CartelStability")
CASchools 17
Format
Source
References
Porter, R. H. (1983). A Study of Cartel Stability: The Joint Executive Committee, 18801886. The
Bell Journal of Economics, 14, 301314.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("CartelStability")
summary(CartelStability)
Description
The dataset contains data on test performance, school characteristics and student demographic back-
grounds for school districts in California.
Usage
data("CASchools")
18 CASchools
Format
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
References
Stock, J. H. and Watson, M. W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007, MASchools
ChinaIncome 19
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")
Format
An annual multiple time series from 1952 to 1988 with 5 variables.
Source
Online complements to Franses (1998).
References
Chow, G.C. (1993). Capital Formation and Economic Growth in China. Quarterly Journal of
Economics, 103, 809842.
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.
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, 321335.
CigarettesSW 21
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 19851995.
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
Examples
## Stock and Watson (2007)
## data and transformations
data("CigarettesSW")
CigarettesSW$rprice <- with(CigarettesSW, price/cpi)
CigarettesSW$rincome <- with(CigarettesSW, income/population/cpi)
CigarettesSW$tdiff <- with(CigarettesSW, (taxs - tax)/cpi)
c1985 <- subset(CigarettesSW, year == "1985")
c1995 <- subset(CigarettesSW, year == "1995")
## Equations 12.9--12.11
fm_s1 <- lm(log(rprice) ~ tdiff, data = c1995)
coeftest(fm_s1, vcov = hc1)
fm_s2 <- lm(log(packs) ~ fitted(fm_s1), data = c1995)
fm_ivreg <- ivreg(log(packs) ~ log(rprice) | tdiff, data = c1995)
coeftest(fm_ivreg, vcov = hc1)
## Equation 12.15
fm_ivreg2 <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff, data = c1995)
coeftest(fm_ivreg2, vcov = hc1)
## Equation 12.16
fm_ivreg3 <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + I(tax/cpi),
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")
Format
A data frame containing 4,739 observations on 14 variables.
gender factor indicating gender.
ethnicity factor indicating ethnicity (African-American, Hispanic or other).
score base year composite test score. These are achievement tests given to high school seniors in
the sample.
fcollege factor. Is the father a college graduate?
mcollege factor. Is the mother a college graduate?
home factor. Does the family own their home?
urban factor. Is the school in an urban area?
unemp county unemployment rate in 1980.
wage state hourly wage in manufacturing in 1980.
distance distance from 4-year college (in 10 miles).
24 ConsumerGood
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, 217224.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
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.
CPS1985 25
Usage
data("ConsumerGood")
Format
distribution Distribution.
share Market share.
price Price.
Source
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)
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")
26 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
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),
CPS1988 27
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")
Format
A data frame containing 28,155 observations on 7 variables.
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 cus-
tomary 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
http://www.personal.psu.edu/hxb11/MEDIAN.HTM
References
Bierens, H.J., and Ginther, D. (2001). Integrated Conditional Moment Testing of Quantile Regres-
sion Models. Empirical Economics, 26, 307324.
Buchinsky, M. (1998). Recent Advances in Quantile Regression Models: A Practical Guide for
Empirical Research. Journal of Human Resources, 33, 88126.
See Also
CPS1985, CPSSW
Examples
## data and packages
library("quantreg")
data("CPS1988")
CPS1988$region <- relevel(CPS1988$region, ref = "south")
## OLS and LAD fits (for LAD see Bierens and Ginter, Tables 1-3.A.)
mincer_ols <- lm(mincer, data = CPS1988)
mincer_lad <- rq(mincer, data = CPS1988)
quart_ols <- lm(quart, data = CPS1988)
quart_lad <- rq(quart, data = CPS1988)
buchinsky_ols <- lm(buchinsky, data = CPS1988)
buchinsky_lad <- rq(buchinsky, data = CPS1988)
CPSSW 29
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 (http://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).
30 CreditCard
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 bachelors 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 2534. CPSSW04 is a subset of CPSSW9204 and provides the distribution of
earnings in the US in 2004 for college-educated full-time workers aged 2534. 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 2930. CPSSW8 contains a larger sample with workers
aged 2164, 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 2534 (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.
CreditCard 31
Usage
data("CreditCard")
Format
Details
According to Greene (2003, p. 952) dependents equals 1 + number of dependents, our calcu-
lations 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
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003
32 dispersiontest
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"))
dispersiontest 33
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. Oth-
erwise, if trafo is specified, the test is formulated in terms of the parameter . The transfor-
mation 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 formu-
lations respectively.
Value
An object of class "htest".
References
Cameron, A.C. and Trivedi, P.K. (1990). Regression-based Tests for Overdispersion in the Poisson
Model. Journal of Econometrics, 46, 347364.
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
34 DJFranses
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")
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
DJIA8012 35
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).
http://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-ec
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.
Examples
data("DJIA8012")
plot(DJIA8012)
Description
Cross-section data originating from the 19771978 Australian Health Survey.
Usage
data("DoctorVisits")
Format
A data frame containing 5,190 observations on 12 variables.
visits Number of doctor visits in past 2 weeks.
gender Factor indicating gender.
age Age in years divided by 100.
income Annual income in tens of thousands of dollars.
illness Number of illnesses in past 2 weeks.
reduced Number of days of reduced activity in past 2 weeks due to illness or injury.
health General health questionnaire score using Goldbergs method.
private Factor. Does the individual have private health insurance?
freepoor Factor. Does the individual have free government health insurance due to low income?
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
Journal of Applied Econometrics Data Archive.
http://qed.econ.queensu.ca/jae/1997-v12.3/mullahy/
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, 2953.
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, 337350.
DutchAdvert 37
See Also
CameronTrivedi1998
Examples
data("DoctorVisits", package = "AER")
library("MASS")
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.
tv Television advertising expenditures.
radio Radio advertising expenditures.
Source
Originally available as an online supplement to Franses (1998). Now available via online comple-
ments to Franses, van Dijk and Opschoor (2014).
http://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-ec
time-series-models-business-and-economic-forecasting-2nd-edition
38 DutchSales
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).
Electricity1955 39
Source
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
Usage
data("Electricity1955")
40 Electricity1955
Format
A data frame containing 159 observations on 8 variables.
cost total cost.
output total output.
labor wage rate.
laborshare cost share for labor.
capital capital price index.
capitalshare cost share for capital.
fuel fuel price.
fuelshare cost share for fuel.
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.
http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
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
Cross-section data, at the firm level, on electric power generation.
Usage
data("Electricity1970")
Format
A data frame containing 158 cross-section observations on 9 variables.
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
Online complements to Greene (2003), Table F5.2.
http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
42 EquationCitations
References
Christensen, L. and Greene, W.H. (1976). Economies of Scale in U.S. Electric Power Generation.
Journal of Political Economy, 84, 655676.
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.
EquationCitations 43
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).
http://www.pnas.org/lookup/suppl/doi:10.1073/pnas.1205259109/-/DCSupplemental
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, 1173511739. http://dx.doi.org/10.1073/pnas.1205259109
See Also
PhDPublications
Examples
## load data and MASS package
data("EquationCitations", package = "AER")
library("MASS")
#################
## Replication ##
#################
## Table 1
m1a <- glm.nb(othercites ~ I(equations/pages) * pages + journal,
data = EquationCitations)
m1b <- update(m1a, nontheocites ~ .)
m1c <- update(m1a, theocites ~ .)
44 Equipment
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 ##
###############
Description
Statewide data on transportation equipment manufacturing for 25 US states.
Equipment 45
Usage
data("Equipment")
Format
A data frame containing 25 observations on 4 variables.
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.
http://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, 241250.
Zellner, A. and Ryu, H. (1998). Alternative Functional Forms for Production, Cost and Returns to
Scale Functions. Journal of Applied Econometrics, 13, 101127.
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")
Fatalities 47
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).
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 states 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.
Fatalities 49
Source
Online complements to Stock and Watson (2007).
References
Ruhm, C. J. (1996). Alcohol Policies and Highway Vehicle Fatalities. Journal of Health Economics,
15, 435454.
Stock, J. H. and Watson, M. W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
## data from Stock and Watson (2007)
data("Fatalities", package = "AER")
## add fatality rate (number of traffic deaths
## per 10,000 people living in that state in that year)
Fatalities$frate <- with(Fatalities, fatal/pop * 10000)
## add discretized version of minimum legal drinking age
Fatalities$drinkagec <- cut(Fatalities$drinkage,
breaks = 18:22, include.lowest = TRUE, right = FALSE)
Fatalities$drinkagec <- relevel(Fatalities$drinkagec, ref = 4)
## any punishment?
Fatalities$punish <- with(Fatalities,
factor(jail == "yes" | service == "yes", labels = c("no", "yes")))
## plm package
library("plm")
Description
Cross-section data from the 1980 US Census on married women aged 2135 with two or more
children.
Usage
data("Fertility")
data("Fertility2")
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, 450477.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
52 Franses1998
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 ##
###########################################
54 FrozenJuice
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.
GermanUnemployment 55
See Also
StockWatson2007
Examples
## load data
data("FrozenJuice")
Description
Time series of unemployment rate (in percent) in Germany.
Usage
data("GermanUnemployment")
56 GoldSilver
Format
A quarterly multiple time series from 1962(1) to 1991(4) with 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("GermanUnemployment")
plot(GermanUnemployment, plot.type = "single", col = 1:2)
Description
Time series of gold and silver prices.
Usage
data("GoldSilver")
Format
A daily multiple time series from 1977-12-30 to 2012-12-31 (of class "zoo" with "Date" index).
Source
Online complements to Franses, van Dijk and Opschoor (2014).
http://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-ec
time-series-models-business-and-economic-forecasting-2nd-edition
GoldSilver 57
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.
Examples
data("GoldSilver", package = "AER")
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 http://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) ##
#####################################
## Example 1.1
Greene2003 59
#####################################
## 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)
#########################################
Greene2003 61
## 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,
data = USGasG, point = c(1973, 1), type = "Chow")
62 Greene2003
## 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
library("dynlm")
Greene2003 63
## 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
fs <- Fstats(log(m1/cpi) ~ log(gdp) + tbill, data = USMacroG,
64 Greene2003
## 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
data("SIC33", package = "AER")
66 Greene2003
## 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)
library("plm")
usair <- plm.data(USAirlines, c("firm", "year"))
fm_full2 <- plm(log(cost) ~ log(output) + I(log(output)^2) + log(price) + load,
data = usair, model = "within", effect = "twoways")
fm_time2 <- plm(log(cost) ~ log(output) + I(log(output)^2) + log(price) + load,
data = usair, model = "within", effect = "time")
fm_firm2 <- plm(log(cost) ~ log(output) + I(log(output)^2) + log(price) + load,
data = usair, model = "within", effect = "individual")
fm_no2 <- plm(log(cost) ~ log(output) + I(log(output)^2) + log(price) + load,
data = usair, model = "pooling")
pFtest(fm_full2, fm_time2)
pFtest(fm_full2, fm_firm2)
pFtest(fm_full2, fm_no2)
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
fm_all <- lm(log(cost/fuel) ~ log(output) + log(labor/fuel) + log(capital/fuel),
68 Greene2003
data = Electricity)
summary(fm_all)
## 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")))
## 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 ##
###################################
library("tseries")
mp_garch <- garch(mp, grad = "numerical")
summary(mp_garch)
logLik(mp_garch)
## Greene (2003) also includes a constant and uses different
## standard errors (presumably computed from Hessian), here
## OPG standard errors are used. garchFit() in "fGarch"
## implements the approach used by Greene (2003).
################################
## 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")
library("dynlm")
fm_cons <- dynlm(consumption ~ cprofits + L(cprofits) + I(pwage + gwage), data = KleinI)
fm_inv <- dynlm(invest ~ cprofits + L(cprofits) + capital, data = KleinI)
fm_pwage <- dynlm(pwage ~ gnp + L(gnp) + I(time(gnp) - 1931), data = KleinI)
summary(fm_cons)
summary(fm_inv)
summary(fm_pwage)
## Notes:
## - capital refers to previous year's capital stock -> no lag needed!
## - trend used by Greene (p. 381, "time trend measured as years from 1931")
## Maddala uses years since 1919
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 ##
############################
Greene2003 75
## 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)
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
data("Affairs", package = "AER")
GrowthDJ 77
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 Banks 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, 365384.
Koenker, R., and Zeileis, A. (2009). On Reproducible Econometric Research. Journal of Applied
Econometrics, 24(5), 833847.
Mankiw, N.G, Romer, D., and Weil, D.N. (1992). A Contribution to the Empirics of Economic
Growth. Quarterly Journal of Economics, 107, 407437.
Masanjala, W.H., and Papageorgiou, C. (2004). The Solow Model with CES Technology: Nonlin-
earities and Parameter Heterogeneity. Journal of Applied Econometrics, 19, 171201.
GrowthSW 79
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 19601995 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.
80 Grunfeld
revolutions average annual number of revolutions, insurrections (successful or not) and coup detats
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, 261300.
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 19351954.
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).
Grunfeld 81
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 29 and 1113).
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),
404417. http://dx.doi.org/10.1111/j.1468-0475.2010.00513.x
See Also
Baltagi2002, Greene2003
Examples
data("Grunfeld", package = "AER")
## 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)
ggr[32, 3] <- 232.6
82 Grunfeld
## equivalently
library("plm")
pggr <- plm.data(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 <- plm.data(subset(Grunfeld, firm != "American Steel"), c("firm", "year"))
rbind(
"OLS(pooled)" = coef(fm_ols),
"FE" = c(NA, coef(fm_fe)),
"RE-SwAr" = coef(fm_reswar),
"RE-Amemiya" = coef(fm_ream),
"RE-WalHus" = coef(fm_rewh),
"RE-Nerlove" = coef(fm_rener))
## 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).
http://econsites.uzh.ch/rwinke/microdata.zip
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
if(require("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.
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 Womans 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).
http://econsites.uzh.ch/rwinke/microdata.zip
References
Winkelmann, R., and Boes, S. (2009). Analysis of Microdata, 2nd ed. Berlin and Heidelberg:
Springer-Verlag.
See Also
WinkelmannBoes2009
GSS7402 87
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 19771999.
Usage
data("Guns")
Format
A data frame containing 1,173 observations on 13 variables.
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).
HealthInsurance 89
References
Ayres, I., and Donohue, J.J. (2003). Shooting Down the More Guns Less Crime Hypothesis.
Stanford Law Review, 55, 11931312.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
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")
90 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)
HMDA 91
Description
Cross-section data on the Home Mortgage Disclosure Act (HMDA).
Usage
data("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 applicants 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, 2553.
Stock, J. H. and Watson, M. W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
92 HousePrices
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?
ivreg 93
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, 633648.
Verbeek, M. (2004). A Guide to Modern Econometrics, 2nd ed. Chichester, UK: John Wiley.
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, ...)
94 ivreg
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.
subset an optional vector specifying a subset of observations to be used in fitting the
model.
na.action a function that indicates what should happen when the data contain NAs. The
default is set by the na.action option.
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.
contrasts an optional list. See the contrasts.arg of model.matrix.default.
model, x, y logicals. If TRUE the corresponding components of the fit (the model frame, the
model matrices , the response) are returned.
... further arguments passed to ivreg.fit.
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:
References
See Also
Examples
## data
data("CigarettesSW", package = "AER")
CigarettesSW$rprice <- with(CigarettesSW, price/cpi)
CigarettesSW$rincome <- with(CigarettesSW, income/population/cpi)
CigarettesSW$tdiff <- with(CigarettesSW, (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)
96 ivreg.fit
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.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 link[stats]{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:
coefficients parameter estimates.
residuals a vector of residuals.
fitted.values a vector of predicted means.
weights either the vector of weights used (if any) or NULL (if none).
offset either the offset used (if any) or NULL (if none).
estfun a matrix containing the empirical estimating functions.
n number of observations.
nobs number of observations with non-zero weights.
rank the numeric rank of the fitted linear model.
df.residual residual degrees of freedom for fitted model.
cov.unscaled unscaled covariance matrix for the coefficients.
sigma residual standard error.
Journals 97
See Also
ivreg, lm.fit
Examples
## data
data("CigarettesSW")
CigarettesSW$rprice <- with(CigarettesSW, price/cpi)
CigarettesSW$rincome <- with(CigarettesSW, income/population/cpi)
CigarettesSW$tdiff <- with(CigarettesSW, (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.
title Journal title.
publisher factor with publisher name.
society factor. Is the journal published by a scholarly society?
price Library subscription price.
pages Number of pages.
charpp Characters per page.
citations Total number of citations.
foundingyear Year journal was founded.
subs Number of library subscriptions.
field factor with field description.
98 Journals
Details
Data on 180 economic journals, collected in particular for analyzing journal pricing. See also
http://www.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,
183198.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
## data and transformed variables
data("Journals")
journals <- Journals[, c("subs", "price")]
journals$citeprice <- Journals$price/Journals$citations
journals$age <- 2000 - Journals$foundingyear
journals$chars <- Journals$charpp*Journals$pages/10^6
Description
Kleins 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 years capital stock.
gnp Gross national product.
gwage Government wage bill.
gexpenditure Government spending.
taxes Taxes.
Source
Online complements to Greene (2003). Table F15.1.
http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
100 Longley
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
Klein, L. (1950). Economic Fluctuations in the United States, 19211941. New York: John Wiley.
Maddala, G.S. (1977). Econometrics. New York: McGraw-Hill.
See Also
Greene2003
Examples
data("KleinI", package = "AER")
plot(KleinI)
Description
US macroeconomic time series, 19471962.
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.
http://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, 819841.
See Also
longley, Greene2003
Examples
data("Longley")
library("dynlm")
Description
US time series data on prices and cost shares in manufacturing, 19471971.
Usage
data("ManufactCosts")
102 MarkDollar
Format
An annual multiple time series from 1947 to 1971 with 9 variables.
Source
Online complements to Greene (2003).
http://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, 376384.
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")
MarkPound 103
Format
A univariate time series of 518 returns (exact dates unknown) for the DEM/USD exchange rate.
Source
References
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.
104 MarkPound
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).
Source
Journal of Business \& Economic Statistics Data Archive.
http://www.amstat.org/publications/jbes/upload/index.cfm?fuseaction=ViewArticles&pub=JBES&issue=96-
2-APR
References
Bollerslev, T., and Ghysels, E. (1996). Periodic Autoregressive Conditional Heteroskedasticity.
Journal of Business \& Economic Statistics, 14, 139151.
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003, MarkDollar
Examples
## data as given by Greene (2003)
data("MarkPound")
mp <- round(MarkPound, digits = 6)
Description
The dataset contains data on test performance, school characteristics and student demographic back-
grounds for school districts in Massachusetts.
Usage
data("MASchools")
Format
A data frame containing 220 observations on 16 variables.
district character. District code.
municipality character. Municipality name.
expreg Expenditures per pupil, regular.
expspecial Expenditures per pupil, special needs.
expbil Expenditures per pupil, bilingual.
expocc Expenditures per pupil, occupational.
exptot Expenditures per pupil, total.
scratio Students per computer.
special Special education students (per cent).
lunch Percent qualifying for reduced-price lunch.
stratio Student-teacher ratio.
income Per capita income.
score4 4th grade score (math + English + science).
score8 8th grade score (math + English + science).
salary Average teacher salary.
english Percent of English learners.
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 19971998 school year and were obtained from the Massachusetts
department of education. Data on average district income are from the 1990 US Census.
106 Medicaid1986
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, 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")
Medicaid1986 107
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.
age Age of the respondent.
income Annual household income (average of income range in million USD).
health1 The first principal component (divided by 1000) of three health-status variables: functional
limitations, acute conditions, and chronic conditions.
health2 The second principal component (divided by 1000) of three health-status variables: func-
tional limitations, acute conditions, and chronic conditions.
access Availability of health services (0 = low access, 1 = high access).
married Factor. Is the individual married?
gender Factor indicating gender.
ethnicity Factor indicating ethnicity ("cauc" or "other").
school Number of years completed in school.
enroll Factor. Is the individual enrolled in a demonstration program?
program Factor indicating the managed care demonstration program: Aid to Families with De-
pendent Children ("afdc") or non-institutionalized Supplementary Security Income ("ssi").
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, 225242.
Examples
## data and packages
data("Medicaid1986")
library("MASS")
library("pscl")
## 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)]
108 Mortgage
## Gurmu (1997):
## Table VI., Poisson and negbin models
afdc_pois <- glm(visits ~ ., data = afdc, family = poisson)
summary(afdc_pois)
coeftest(afdc_pois, vcov = sandwich)
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.
MotorCycles 109
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, 260267.
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")
110 MotorCycles2
Format
An annual univariate time series from 1946 to 1993.
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.
MSCISwitzerland 111
Source
Online complements to Franses, van Dijk and Opschoor (2014).
http://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-ec
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, MotorCycles
Examples
data("MotorCycles2")
plot(MotorCycles2)
Description
Time series of the MSCI Switzerland index.
Usage
data("MSCISwitzerland")
Format
A daily univariate time series from 1994-12-30 to 2012-12-31 (of class "zoo" with "Date" index).
Source
Online complements to Franses, van Dijk and Opschoor (2014).
http://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-ec
time-series-models-business-and-economic-forecasting-2nd-edition
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), 83106.
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.
112 MSCISwitzerland
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*
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.
municipality factor with ID number for municipality.
year factor coding year.
expenditures total expenditures.
revenues total own-source revenues.
grants intergovernmental grants received by the municipality.
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/
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, 401416.
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
114 MurderRates
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
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 Researchers Prior Beliefs. Journal of Political Economy, 93, 417425.
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, 307320.
NaturalGas 115
Examples
data("MurderRates")
Description
Panel data originating from 6 US states over the period 19671989.
Usage
data("NaturalGas")
Format
A data frame containing 138 observations on 10 variables.
Source
References
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")
NMES1988 117
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, 313336.
Zeileis, A., Kleiber, C., and Jackman, S. (2008). Regression Models for Count Data in R. Journal
of Statistical Software, 27(8). URL http://www.jstatsoft.org/v27/i08/.
See Also
CameronTrivedi1998
118 NMES1988
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,
data = nmes, dist = "negbin")
NYSESW 119
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).
120 OECDGas
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, 19601978.
Usage
data("OECDGas")
Format
A data frame containing 342 observations on 6 variables.
Source
The data is from Baltagi (2002).
OECDGrowth 121
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, 117137.
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 (19601985).
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 19601985).
popgrowth annual population growth 19601985, 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.
122 OECDGrowth
References
Mankiw, N.G., Romer, D., and Weil, D.N. (1992). A Contribution to the Empirics of Economic
Growth. Quarterly Journal of Economics, 107, 407437.
Nonneman, W., and Vanhoudt, P. (1996). A Further Augmentation of the Solow Model and the
Empirics of Economic Growth. Quarterly Journal of Economics, 111, 943953.
Zaman, A., Rousseeuw, P.J., and Orhan, M. (2001). Econometric Applications of High-Breakdown
Robust Regression Techniques. Economics Letters, 71, 18.
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]
## bad leverage
OlympicTV 123
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)
124 Parade2005
Description
Quarterly time series data on employment in Orange county, 19651983.
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")
Parade2005 125
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)
126 PepperPrice
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).
http://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-ec
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")
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).
http://www.indiana.edu/~jslsoc/research_rm4cldvs.htm
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, 12971315.
128 ProgramEffectiveness
Examples
## from Long (1997)
data("PhDPublications")
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).
http://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, 3744.
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 Wifes hours of work in 1975.
130 PSID1976
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, 199218.
Mroz, T.A. (1987). The Sensitivity of an Empirical Model of Married Womens Hours of Work to
Economic and Statistical Assumptions. Econometrica, 55, 765799.
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
## data and transformations
data("PSID1976")
PSID1976$kids <- with(PSID1976, factor((youngkids + oldkids) > 0,
levels = c(FALSE, TRUE), labels = c("no", "yes")))
PSID1976$nwincome <- with(PSID1976, (fincome - hours * wage)/1000)
PSID1976$partnum <- as.numeric(PSID1976$participation) - 1
###################
## 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)
lrtest(gr_probit1)
## Chow-type test
lrtest(gr_probit2, gr_probit3)
## equivalently:
anova(gr_probit2, gr_probit3, test = "Chisq")
## Table 21.3
summary(gr_probit1)
#######################
## 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.
Details
PSID1982 is the cross-section for the year 1982 taken from a larger panel data set PSID7682 for the
years 19761982, 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, 149155.
See Also
PSID7682, Baltagi2002
Examples
data("PSID1982")
plot(density(PSID1982$wage, bw = "SJ"))
Description
Panel data on earnings of 595 individuals for the years 19761982, originating from the Panel Study
of Income Dynamics.
Usage
data("PSID7682")
PSID7682 135
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.
http://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, 401406.
Baltagi, B.H. (2001). Econometric Analysis of Panel Data, 2nd ed. Chichester, UK: John Wiley.
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
136 RecreationDemand
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, 149155.
Greene, W.H. (2008). Econometric Analysis, 6th ed. Upper Saddle River, NJ: Prentice Hall.
See Also
PSID1982, Baltagi2002
Examples
data("PSID7682")
library("plm")
psid <- plm.data(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.
RecreationDemand 137
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-OCT
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, 469477.
Ozuna, T. and Gomez, I.A. (1995). Specification and Testing of Count Data Recreation Demand
Functions. Empirical Economics, 20, 543550.
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, 156175.
See Also
CameronTrivedi1998
138 ResumeNames
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")
ResumeNames 139
Format
A data frame containing 4,870 observations on 27 variables.
name factor indicating applicants 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 applicants 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.
140 ShipAccidents
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,
9911013.
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.
ShipAccidents 141
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).
http://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.
http://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("SIC33")
vcov(fm_cb)
## 3D Visualization
if(require("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]
rgl.open()
rgl.bbox()
rgl.spheres(x, y, z, radius = 0.15)
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)))
rgl.surface(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, masters degree (or higher).
144 SportsCards
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
Online complements to Stock and Watson (2007).
References
Evans, W. N., Farrelly, M.C., and Montgomery, E. (1999). Do Workplace Smoking Bans Reduce
Smoking? American Economic Review, 89, 728747.
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")
SportsCards 145
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, 4171.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("SportsCards")
summary(SportsCards)
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 students gender.
ethnicity factor indicating students ethnicity with levels "cauc" (Caucasian), "afam" (African-
American), "asian" (Asian), "hispanic" (Hispanic), "amindian" (American-Indian) or "other".
birth students 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".
STAR 147
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 teachers career ladder level in kindergarten: "level1", "level2", "level3",
"apprentice", "probation" or "pending".
ladder1 factor indicating teachers career ladder level in 1st grade: "level1", "level2", "level3",
"apprentice", "probation" or "noladder".
ladder2 factor indicating teachers career ladder level in 2nd grade: "level1", "level2", "level3",
"apprentice", "probation" or "noladder".
ladder3 factor indicating teachers career ladder level in 3rd grade: "level1", "level2", "level3",
"apprentice", "probation" or "noladder".
experiencek years of teachers total teaching experience in kindergarten.
experience1 years of teachers total teaching experience in 1st grade.
experience2 years of teachers total teaching experience in 2nd grade.
experience3 years of teachers total teaching experience in 3rd grade.
tethnicityk factor indicating teachers ethnicity in kindergarten with levels "cauc" (Caucasian) or
"afam" (African-American).
tethnicity1 factor indicating teachers ethnicity in 1st grade with levels "cauc" (Caucasian) or
"afam" (African-American).
tethnicity2 factor indicating teachers ethnicity in 2nd grade with levels "cauc" (Caucasian) or
"afam" (African-American).
tethnicity3 factor indicating teachers 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.
148 STAR
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 teachers 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 19851986 to
academic year 19881989. 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 at http://www.
heros-inc.org/star.htm.
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 ##
###############################
150 StockWatson2007
## 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)
#####################################
StockWatson2007 151
###############################
## Massachusetts test scores ##
###############################
##################################
## Home mortgage disclosure act ##
##################################
## data
data("HMDA", package = "AER")
mean(HMDA$hirat)
mean(HMDA$lvrat)
mean(as.numeric(HMDA$chist))
mean(as.numeric(HMDA$mhist))
mean(as.numeric(HMDA$phist)-1)
prop.table(table(HMDA$insurance))
prop.table(table(HMDA$selfemp))
prop.table(table(HMDA$single))
prop.table(table(HMDA$hschool))
mean(HMDA$unemp)
prop.table(table(HMDA$condomin))
prop.table(table(HMDA$afam))
prop.table(table(HMDA$deny))
#########################################################
## 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) ~ tdiff, data = c1995)
coeftest(fm_s1, vcov = hc1)
fm_s2 <- lm(log(packs) ~ fitted(fm_s1), data = c1995)
fm_ivreg <- ivreg(log(packs) ~ log(rprice) | tdiff, data = c1995)
coeftest(fm_ivreg, vcov = hc1)
## Equation 12.15
fm_ivreg2 <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff,
data = c1995)
coeftest(fm_ivreg2, vcov = hc1)
## Equation 12.16
fm_ivreg3 <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + I(tax/cpi),
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
star$id <- factor(star$id)
star$grade <- factor(star$grade, levels = lev,
labels = c("kindergarten", "1st", "2nd", "3rd"))
rm(nam, lev)
## (d) model fitting
158 StockWatson2007
#################################################
## 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) ##
##########################################
##################################
## Price of frozen orange juice ##
##################################
## load data
data("FrozenJuice")
160 StrikeDuration
#############################################
## 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))
Description
Data on the duration of strikes in US manufacturing industries, 19681976.
StrikeDuration 161
Usage
data("StrikeDuration")
Format
A data frame containing 62 observations on 2 variables for the period 19681976.
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 Greenes 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
Online complements to Greene (2003).
http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
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, 528.
See Also
Greene2003
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).
df the degrees of freedom to be used. By default this is set to residual degrees of
freedom for which a t or F test is computed. Alternatively, it can be set to Inf
(or equivalently 0) for which a z or Chi-squared test is computed.
diagnostics logical. Should diagnostic tests for the instrumental-variable regression be car-
ried out? These encompass an F test of the first stage regression for weak instru-
ments, a Wu-Hausman test for endogeneity, and a Sargan test of overidentifying
restrictions (only if there are more instruments than regressors).
test character specifying whether to compute the large sample Chi-squared statistic
(with asymptotic Chi-squared distribution) or the finite sample F statistic (with
approximate F distribution).
component character specifying for which component of the terms or model matrix should
be extracted. "projected" gives the matrix of regressors projected on the image
of the instruments.
... currently not used.
SwissLabor 163
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.
See Also
ivreg, lm.fit
Examples
## data
data("CigarettesSW")
CigarettesSW$rprice <- with(CigarettesSW, price/cpi)
CigarettesSW$rincome <- with(CigarettesSW, income/population/cpi)
CigarettesSW$tdiff <- with(CigarettesSW, (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")
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)?
164 TeachingRatings
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, 321339.
Examples
data("SwissLabor")
### alternatively
fm_logit <- glm(participation ~ . + I(age^2), data = SwissLabor,
family = binomial)
summary(fm_logit)
Description
Data on course evaluations, course characteristics, and professor characteristics for 463 courses for
the academic years 20002002 at the University of Texas at Austin.
Usage
data("TeachingRatings")
Format
A data frame containing 463 observations on 13 variables.
division factor. Is the course an upper or lower division course? (Lower division courses are mainly
large freshman and sophomore courses)?
native factor. Is the instructor a native English speaker?
tenure factor. Is the instructor on tenure track?
students number of students that participated in the evaluation.
allstudents number of students enrolled in the course.
prof factor indicating instructor identifier.
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
References
Hamermesh, D.S., and Parker, A. (2005). Beauty in the Classroom: Instructors Pulchritude and
Putative Pedagogical Productivity. Economics of Education Review, 24, 369376.
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
StockWatson2007
Examples
data("TeachingRatings")
Description
US time series data, 19091949.
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.
Source
Online complements to Greene (2003), Table F7.2.
http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
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, 312320.
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
Fitting and testing tobit regression models for censored data.
Usage
tobit(formula, left = 0, right = Inf, dist = "gaussian",
subset = NULL, data = list(), ...)
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".
168 TradeCredit
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,
2436.
Examples
data("Affairs")
summary(fm.tobit)
summary(fm.tobit2)
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).
TravelMode 169
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)
Description
Data on travel mode choice for travel between Sydney and Melbourne, Australia.
Usage
data("TravelMode")
Format
A data frame containing 840 observations on 4 modes for 210 individuals.
Source
Online complements to Greene (2003).
http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
170 UKInflation
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003
Examples
data("TravelMode")
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.
http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
UKNonDurables 171
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, 341348.
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, 327336.
Franses, P.H. (1998). Time Series Models for Business and Economic Forecasting. Cambridge, UK:
Cambridge University Press.
See Also
Franses1998
172 USAirlines
Examples
data("UKNonDurables")
plot(UKNonDurables)
Description
Cost data for six US airlines in 19701984.
Usage
data("USAirlines")
Format
A data frame containing 90 observations on 6 variables.
Source
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
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, 19401950.
Usage
data("USConsump1950")
Format
An annual multiple time series from 1940 to 1950 with 3 variables.
Source
Online complements to Greene (2003). Table F2.1.
http://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)
USConsump1979 175
## 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
Description
Time series data on US income and consumption expenditure, 19701979.
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.
http://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
176 USConsump1993
Examples
data("USConsump1979")
plot(USConsump1979)
Description
Time series data on US income and consumption expenditure, 19501993.
Usage
data("USConsump1993")
Format
An annual multiple time series from 1950 to 1993 with 2 variables.
income Disposable personal income (in 1987 USD).
expenditure Personal consumption expenditures (in 1987 USD).
Source
The data is from Baltagi (2002).
References
Baltagi, B.H. (2002). Econometrics, 3rd ed. Berlin, Springer.
See Also
Baltagi2002, USConsump1950, USConsump1979
Examples
## data from Baltagi (2002)
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)
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.
178 USGasB
Usage
data("USCrudes")
Format
A data frame containing 99 observations on 3 variables.
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
if(require("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")
USGasG 179
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).
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.
180 USGasG
Source
Online complements to Greene (2003). Table F2.2.
http://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, USGasB
Examples
data("USGasG", package = "AER")
plot(USGasG)
## 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)
USInvest 181
## 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")
## Recursive CUSUM test
rcus <- efp(log(gas/population) ~ log(income) + log(price) + log(newcar) +
log(usedcar) + trend, data = USGasG, type = "Rec-CUSUM")
plot(rcus)
sctest(rcus)
## Note: Greene's remark that the break is in 1984 (where the process crosses its
## boundary) is wrong. The break appears to be no later than 1976.
Description
Time series data on investments in the US, 19681982.
Usage
data("USInvest")
Format
An annual multiple time series from 1968 to 1982 with 4 variables.
gnp Nominal gross national product,
invest Nominal investment,
price Consumer price index,
interest Interest rate (average yearly discount rate at the New York Federal Reserve Bank).
Source
Online complements to Greene (2003). Table F3.1.
http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm
182 USMacroB
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003
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 19591995, extracted from the Citibank
data base.
Usage
data("USMacroB")
USMacroG 183
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).
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 19502000.
Usage
data("USMacroG")
Format
A quarterly multiple time series from 1950(1) to 2000(4) with 12 variables.
gdp Real gross domestic product (in billion USD),
consumption Real consumption expenditures,
invest Real investment by private sector,
government Real government expenditures,
dpi Real disposable personal income,
cpi Consumer price index,
m1 Nominal money stock,
184 USMacroG
Source
Online complements to Greene (2003). Table F5.1.
http://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
## data and trend as used by Greene (2003)
data("USMacroG")
ltrend <- 1:nrow(USMacroG) - 1
## 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)
USMacroSW 185
Description
Time series data on 7 (mostly) US macroeconomic variables for 19572005.
Usage
data("USMacroSW")
Format
A quarterly multiple time series from 1957(1) to 2005(1) with 7 variables.
unemp Unemployment rate.
cpi Consumer price index.
ffrate Federal funds interest rate.
tbill 3-month treasury bill interest rate.
tbond 1-year treasury bond interest rate.
gbpusd GBP/USD exchange rate (US dollar in cents per British pound).
gdpjp GDP for Japan.
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 BLSs 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).
186 USMacroSW
References
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
Examples
## Stock and Watson (2007)
data("USMacroSW", package = "AER")
library("dynlm")
library("strucchange")
usm <- ts.intersect(USMacroSW, 4 * 100 * diff(log(USMacroSW[, "cpi"])))
colnames(usm) <- c(colnames(USMacroSW), "infl")
Description
Usage
data("USMacroSWM")
Format
Source
References
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
Examples
data("USMacroSWM")
plot(USMacroSWM)
188 USMacroSWQ
Description
Usage
data("USMacroSWQ")
Format
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.
Source
References
Stock, J.H. and Watson, M.W. (2007). Introduction to Econometrics, 2nd ed. Boston: Addison
Wesley.
See Also
Examples
data("USMacroSWQ")
plot(USMacroSWQ)
USMoney 189
USMoney USMoney
Description
Usage
data("USMoney")
Format
Source
References
Greene, W.H. (2003). Econometric Analysis, 5th edition. Upper Saddle River, NJ: Prentice Hall.
See Also
Greene2003
Examples
data("USMoney")
plot(USMoney)
190 USProdIndex
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.
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 19831997 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.
state factor indicating US state (abbreviation).
year factor indicating year.
miles millions of traffic miles per year.
fatalities number of fatalities per million of traffic miles (absolute frequencies of fatalities = fatalities
times miles).
seatbelt seat belt usage rate, as self-reported by state population surveyed.
speed65 factor. Is there a 65 mile per hour speed limit?
speed70 factor. Is there a 70 (or higher) mile per hour speed limit?
drinkage factor. Is there a minimum drinking age of 21 years?
alcohol factor. Is there a maximum of 0.08 blood alcohol content?
income median per capita income (in current US dollar).
age mean age.
enforce factor indicating seat belt law enforcement ("no", "primary", "secondary").
Details
Some data series from Cohen and Einav (2003) have not been included in the data frame.
Source
Online complements to Stock and Watson (2007).
192 USStocksSW
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, 828843
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 19312002 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.
Source
Online complements to Stock and Watson (2007).
WeakInstrument 193
References
Campbell, J.Y., and Yogo, M. (2006). Efficient Tests of Stock Return Predictability Journal of
Financial Economics, 81, 2760.
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
Artificial data set to illustrate the problem of weak instruments.
Usage
data("WeakInstrument")
Format
A data frame containing 200 observations on 3 variables.
y dependent variable.
x regressor variable.
z instrument variable.
194 WinkelmannBoes2009
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("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
GSS7402, GSOEP9402, PSID1976
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"))
196 WinkelmannBoes2009
## 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)
WinkelmannBoes2009 197
}
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)
afb_skm <- summary(afb_km)
print(afb_skm)
with(afb_skm, plot(n.event/n.risk ~ time, type = "s"))
plot(afb_km, xlim = c(10, 40), conf.int = FALSE)
## 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,
198 WinkelmannBoes2009
## 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,
data = gsoep)
coeftest(gsoep_mnl)[c(1:6, 1:6 + 14),]
## alternatively
if(require("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
WinkelmannBoes2009 199
## 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))
####################################
## 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)
coef(tobit(log(wage) ~ education + experience + I(experience^2),
data = PSID1976, left = censpoint)))
##################################
## Choice of Brand for Crackers ##
##################################
## data
if(require("mlogit")) {
data("Cracker", package = "mlogit")
head(Cracker, 3)
crack <- mlogit.data(Cracker, varying = 2:13, shape = "wide", choice = "choice")
head(crack, 12)
WinkelmannBoes2009 201
## 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
202
INDEX 203
yearqtr, 146