[r-cran-aer] 01/02: New upstream version 1.2-5
Andreas Tille
tille at debian.org
Sun Jan 8 20:03:00 UTC 2017
This is an automated email from the git hooks/post-receive script.
tille pushed a commit to branch master
in repository r-cran-aer.
commit 991cb94d92602698d3e5955cc05b23f932b3082a
Author: Andreas Tille <tille at debian.org>
Date: Sun Jan 8 19:29:19 2017 +0100
New upstream version 1.2-5
---
DESCRIPTION | 27 +
MD5 | 260 +++++++++
NAMESPACE | 52 ++
NEWS | 244 ++++++++
R/coeftest-methods.R | 78 +++
R/dispersiontest.R | 62 ++
R/ivreg.R | 429 ++++++++++++++
R/tobit.R | 279 +++++++++
build/vignette.rds | Bin 0 -> 323 bytes
data/Affairs.rda | Bin 0 -> 3391 bytes
data/ArgentinaCPI.rda | Bin 0 -> 538 bytes
data/BankWages.rda | Bin 0 -> 1181 bytes
data/BenderlyZwick.rda | Bin 0 -> 587 bytes
data/BondYield.rda | Bin 0 -> 362 bytes
data/CASchools.rda | Bin 0 -> 16636 bytes
data/CPS1985.rda | Bin 0 -> 4050 bytes
data/CPS1988.rda | Bin 0 -> 99004 bytes
data/CPSSW04.rda | Bin 0 -> 25044 bytes
data/CPSSW3.rda | Bin 0 -> 63312 bytes
data/CPSSW8.rda | Bin 0 -> 203352 bytes
data/CPSSW9204.rda | Bin 0 -> 50156 bytes
data/CPSSW9298.rda | Bin 0 -> 40436 bytes
data/CPSSWEducation.rda | Bin 0 -> 10724 bytes
data/CartelStability.rda | Bin 0 -> 2124 bytes
data/ChinaIncome.rda | Bin 0 -> 812 bytes
data/CigarettesB.rda | Bin 0 -> 1362 bytes
data/CigarettesSW.rda | Bin 0 -> 3135 bytes
data/CollegeDistance.rda | Bin 0 -> 24380 bytes
data/ConsumerGood.rda | Bin 0 -> 2272 bytes
data/CreditCard.rda | Bin 0 -> 23756 bytes
data/DJFranses.rda | Bin 0 -> 2786 bytes
data/DJIA8012.rda | Bin 0 -> 24828 bytes
data/DoctorVisits.rda | Bin 0 -> 15444 bytes
data/DutchAdvert.rda | Bin 0 -> 2549 bytes
data/DutchSales.rda | Bin 0 -> 613 bytes
data/Electricity1955.rda | Bin 0 -> 5349 bytes
data/Electricity1970.rda | Bin 0 -> 6595 bytes
data/EquationCitations.rda | Bin 0 -> 9192 bytes
data/Equipment.rda | Bin 0 -> 940 bytes
data/EuroEnergy.rda | Bin 0 -> 417 bytes
data/Fatalities.rda | Bin 0 -> 20824 bytes
data/Fertility.rda | Bin 0 -> 404533 bytes
data/Fertility2.rda | Bin 0 -> 63108 bytes
data/FrozenJuice.rda | Bin 0 -> 2567 bytes
data/GSOEP9402.rda | Bin 0 -> 9508 bytes
data/GSS7402.rda | Bin 0 -> 34268 bytes
data/GermanUnemployment.rda | Bin 0 -> 521 bytes
data/GoldSilver.rda | Bin 0 -> 41496 bytes
data/GrowthDJ.rda | Bin 0 -> 2628 bytes
data/GrowthSW.rda | Bin 0 -> 2156 bytes
data/Grunfeld.rda | Bin 0 -> 2812 bytes
data/Guns.rda | Bin 0 -> 46868 bytes
data/HMDA.rda | Bin 0 -> 22940 bytes
data/HealthInsurance.rda | Bin 0 -> 23341 bytes
data/HousePrices.rda | Bin 0 -> 4217 bytes
data/Journals.rda | Bin 0 -> 5479 bytes
data/KleinI.rda | Bin 0 -> 750 bytes
data/Longley.rda | Bin 0 -> 446 bytes
data/MASchools.rda | Bin 0 -> 10316 bytes
data/MSCISwitzerland.rda | Bin 0 -> 14664 bytes
data/ManufactCosts.rda | Bin 0 -> 1891 bytes
data/MarkDollar.rda | Bin 0 -> 4131 bytes
data/MarkPound.rda | Bin 0 -> 15254 bytes
data/Medicaid1986.rda | Bin 0 -> 10028 bytes
data/Mortgage.rda | Bin 0 -> 2347 bytes
data/MotorCycles.rda | Bin 0 -> 220 bytes
data/MotorCycles2.rda | Bin 0 -> 295 bytes
data/Municipalities.rda | Bin 0 -> 50372 bytes
data/MurderRates.rda | Bin 0 -> 1517 bytes
data/NMES1988.rda | Bin 0 -> 35156 bytes
data/NYSESW.rda | Bin 0 -> 12164 bytes
data/NaturalGas.rda | Bin 0 -> 3604 bytes
data/OECDGas.rda | Bin 0 -> 9784 bytes
data/OECDGrowth.rda | Bin 0 -> 1029 bytes
data/OlympicTV.rda | Bin 0 -> 349 bytes
data/OrangeCounty.rda | Bin 0 -> 1058 bytes
data/PSID1976.rda | Bin 0 -> 15648 bytes
data/PSID1982.rda | Bin 0 -> 4081 bytes
data/PSID7682.rda | Bin 0 -> 14580 bytes
data/Parade2005.rda | Bin 0 -> 1409 bytes
data/PepperPrice.rda | Bin 0 -> 1879 bytes
data/PhDPublications.rda | Bin 0 -> 3887 bytes
data/ProgramEffectiveness.rda | Bin 0 -> 532 bytes
data/RecreationDemand.rda | Bin 0 -> 8386 bytes
data/ResumeNames.rda | Bin 0 -> 23320 bytes
data/SIC33.rda | Bin 0 -> 650 bytes
data/STAR.rda | Bin 0 -> 221000 bytes
data/ShipAccidents.rda | Bin 0 -> 608 bytes
data/SmokeBan.rda | Bin 0 -> 22688 bytes
data/SportsCards.rda | Bin 0 -> 1325 bytes
data/StrikeDuration.rda | Bin 0 -> 542 bytes
data/SwissLabor.rda | Bin 0 -> 9076 bytes
data/TeachingRatings.rda | Bin 0 -> 5062 bytes
data/TechChange.rda | Bin 0 -> 792 bytes
data/TradeCredit.rda | Bin 0 -> 1018 bytes
data/TravelMode.rda | Bin 0 -> 5738 bytes
data/UKInflation.rda | Bin 0 -> 552 bytes
data/UKNonDurables.rda | Bin 0 -> 523 bytes
data/USAirlines.rda | Bin 0 -> 2761 bytes
data/USConsump1950.rda | Bin 0 -> 259 bytes
data/USConsump1979.rda | Bin 0 -> 266 bytes
data/USConsump1993.rda | Bin 0 -> 435 bytes
data/USCrudes.rda | Bin 0 -> 1144 bytes
data/USGasB.rda | Bin 0 -> 1257 bytes
data/USGasG.rda | Bin 0 -> 1674 bytes
data/USInvest.rda | Bin 0 -> 455 bytes
data/USMacroB.rda | Bin 0 -> 2175 bytes
data/USMacroG.rda | Bin 0 -> 9068 bytes
data/USMacroSW.rda | Bin 0 -> 4218 bytes
data/USMacroSWM.rda | Bin 0 -> 5304 bytes
data/USMacroSWQ.rda | Bin 0 -> 2232 bytes
data/USMoney.rda | Bin 0 -> 1612 bytes
data/USProdIndex.rda | Bin 0 -> 806 bytes
data/USSeatBelts.rda | Bin 0 -> 10860 bytes
data/USStocksSW.rda | Bin 0 -> 8662 bytes
data/WeakInstrument.rda | Bin 0 -> 2890 bytes
data/datalist | 107 ++++
demo/00Index | 7 +
demo/Ch-Basics.R | 794 ++++++++++++++++++++++++++
demo/Ch-Intro.R | 211 +++++++
demo/Ch-LinearRegression.R | 599 ++++++++++++++++++++
demo/Ch-Microeconometrics.R | 390 +++++++++++++
demo/Ch-Programming.R | 245 ++++++++
demo/Ch-TimeSeries.R | 444 +++++++++++++++
demo/Ch-Validation.R | 362 ++++++++++++
inst/CITATION | 18 +
inst/doc/AER.R | 34 ++
inst/doc/AER.Rnw | 281 +++++++++
inst/doc/AER.pdf | Bin 0 -> 87672 bytes
inst/doc/Sweave-journals.R | 17 +
inst/doc/Sweave-journals.Rnw | 23 +
inst/doc/Sweave-journals.pdf | Bin 0 -> 17796 bytes
man/Affairs.Rd | 82 +++
man/ArgentinaCPI.Rd | 44 ++
man/Baltagi2002.Rd | 183 ++++++
man/BankWages.Rd | 61 ++
man/BenderlyZwick.Rd | 65 +++
man/BondYield.Rd | 31 +
man/CASchools.Rd | 82 +++
man/CPS1985.Rd | 85 +++
man/CPS1988.Rd | 72 +++
man/CPSSW.Rd | 111 ++++
man/CameronTrivedi1998.Rd | 172 ++++++
man/CartelStability.Rd | 41 ++
man/ChinaIncome.Rd | 39 ++
man/CigarettesB.Rd | 74 +++
man/CigarettesSW.Rd | 69 +++
man/CollegeDistance.Rd | 69 +++
man/ConsumerGood.Rd | 35 ++
man/CreditCard.Rd | 93 +++
man/DJFranses.Rd | 30 +
man/DJIA8012.Rd | 48 ++
man/DoctorVisits.Rd | 75 +++
man/DutchAdvert.Rd | 58 ++
man/DutchSales.Rd | 48 ++
man/Electricity1955.Rd | 71 +++
man/Electricity1970.Rd | 56 ++
man/EquationCitations.Rd | 126 +++++
man/Equipment.Rd | 102 ++++
man/EuroEnergy.Rd | 32 ++
man/Fatalities.Rd | 166 ++++++
man/Fertility.Rd | 78 +++
man/Franses1998.Rd | 91 +++
man/FrozenJuice.Rd | 85 +++
man/GSOEP9402.Rd | 131 +++++
man/GSS7402.Rd | 114 ++++
man/GermanUnemployment.Rd | 35 ++
man/GoldSilver.Rd | 99 ++++
man/Greene2003.Rd | 1036 ++++++++++++++++++++++++++++++++++
man/GrowthDJ.Rd | 82 +++
man/GrowthSW.Rd | 47 ++
man/Grunfeld.Rd | 152 +++++
man/Guns.Rd | 76 +++
man/HMDA.Rd | 61 ++
man/HealthInsurance.Rd | 55 ++
man/HousePrices.Rd | 69 +++
man/Journals.Rd | 91 +++
man/KleinI.Rd | 60 ++
man/Longley.Rd | 53 ++
man/MASchools.Rd | 85 +++
man/MSCISwitzerland.Rd | 87 +++
man/ManufactCosts.Rd | 43 ++
man/MarkDollar.Rd | 41 ++
man/MarkPound.Rd | 66 +++
man/Medicaid1986.Rd | 94 +++
man/Mortgage.Rd | 52 ++
man/MotorCycles.Rd | 32 ++
man/MotorCycles2.Rd | 37 ++
man/Municipalities.Rd | 57 ++
man/MurderRates.Rd | 71 +++
man/NMES1988.Rd | 148 +++++
man/NYSESW.Rd | 40 ++
man/NaturalGas.Rd | 43 ++
man/OECDGas.Rd | 41 ++
man/OECDGrowth.Rd | 95 ++++
man/OlympicTV.Rd | 33 ++
man/OrangeCounty.Rd | 36 ++
man/PSID1976.Rd | 186 ++++++
man/PSID1982.Rd | 68 +++
man/PSID7682.Rd | 113 ++++
man/Parade2005.Rd | 61 ++
man/PepperPrice.Rd | 60 ++
man/PhDPublications.Rd | 63 +++
man/ProgramEffectiveness.Rd | 50 ++
man/RecreationDemand.Rd | 88 +++
man/ResumeNames.Rd | 81 +++
man/SIC33.Rd | 76 +++
man/STAR.Rd | 166 ++++++
man/ShipAccidents.Rd | 80 +++
man/SmokeBan.Rd | 58 ++
man/SportsCards.Rd | 62 ++
man/StockWatson2007.Rd | 608 ++++++++++++++++++++
man/StrikeDuration.Rd | 62 ++
man/SwissLabor.Rd | 49 ++
man/TeachingRatings.Rd | 75 +++
man/TechChange.Rd | 52 ++
man/TradeCredit.Rd | 43 ++
man/TravelMode.Rd | 58 ++
man/UKInflation.Rd | 36 ++
man/UKNonDurables.Rd | 53 ++
man/USAirlines.Rd | 72 +++
man/USConsump1950.Rd | 65 +++
man/USConsump1979.Rd | 39 ++
man/USConsump1993.Rd | 81 +++
man/USCrudes.Rd | 44 ++
man/USGasB.Rd | 36 ++
man/USGasG.Rd | 92 +++
man/USInvest.Rd | 64 +++
man/USMacroB.Rd | 38 ++
man/USMacroG.Rd | 86 +++
man/USMacroSW.Rd | 88 +++
man/USMacroSWM.Rd | 37 ++
man/USMacroSWQ.Rd | 37 ++
man/USMoney.Rd | 38 ++
man/USProdIndex.Rd | 54 ++
man/USSeatBelts.Rd | 59 ++
man/USStocksSW.Rd | 59 ++
man/WeakInstrument.Rd | 37 ++
man/WinkelmannBoes2009.Rd | 366 ++++++++++++
man/dispersiontest.Rd | 84 +++
man/ivreg.Rd | 109 ++++
man/ivreg.fit.Rd | 72 +++
man/summary.ivreg.Rd | 80 +++
man/tobit.Rd | 84 +++
tests/Ch-Basics.R | 794 ++++++++++++++++++++++++++
tests/Ch-Basics.Rout.save | 992 ++++++++++++++++++++++++++++++++
tests/Ch-Intro.R | 211 +++++++
tests/Ch-Intro.Rout.save | 303 ++++++++++
tests/Ch-LinearRegression.R | 600 ++++++++++++++++++++
tests/Ch-LinearRegression.Rout.save | 967 +++++++++++++++++++++++++++++++
tests/Ch-Microeconometrics.R | 390 +++++++++++++
tests/Ch-Microeconometrics.Rout.save | 758 +++++++++++++++++++++++++
tests/Ch-Programming.R | 245 ++++++++
tests/Ch-Programming.Rout.save | 344 +++++++++++
tests/Ch-TimeSeries.R | 446 +++++++++++++++
tests/Ch-TimeSeries.Rout.save | 641 +++++++++++++++++++++
tests/Ch-Validation.R | 362 ++++++++++++
tests/Ch-Validation.Rout.save | 613 ++++++++++++++++++++
vignettes/AER.Rnw | 281 +++++++++
vignettes/Sweave-journals.Rnw | 23 +
vignettes/aer.bib | 121 ++++
261 files changed, 22859 insertions(+)
diff --git a/DESCRIPTION b/DESCRIPTION
new file mode 100644
index 0000000..b5e3e9d
--- /dev/null
+++ b/DESCRIPTION
@@ -0,0 +1,27 @@
+Package: AER
+Version: 1.2-5
+Date: 2017-01-06
+Title: Applied Econometrics with R
+Authors at R: c(person(given = "Christian", family = "Kleiber", role = "aut", email = "Christian.Kleiber at unibas.ch"),
+ person(given = "Achim", family = "Zeileis", role = c("aut", "cre"), email = "Achim.Zeileis at R-project.org"))
+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
+Packaged: 2017-01-05 23:26:19 UTC; zeileis
+Author: Christian Kleiber [aut],
+ Achim Zeileis [aut, cre]
+Maintainer: Achim Zeileis <Achim.Zeileis at R-project.org>
+Repository: CRAN
+Date/Publication: 2017-01-07 00:11:57
diff --git a/MD5 b/MD5
new file mode 100644
index 0000000..e399f47
--- /dev/null
+++ b/MD5
@@ -0,0 +1,260 @@
+647098439a7f042cd37348735a439b7e *DESCRIPTION
+bba98063e269e7e7b02b2ff7840966ae *NAMESPACE
+a5db1f258bffbb4bdfe3a27ac476c238 *NEWS
+3dd3d9497975612509b765b789beac40 *R/coeftest-methods.R
+c939ea5a5fc99674637505396b5fc14c *R/dispersiontest.R
+1b7095e8261adfbc84d607ffbf249ba8 *R/ivreg.R
+b2a552e2a66cdb3c8df168de3afa3eb0 *R/tobit.R
+2f6a893d7c594a888814ca2afed1c506 *build/vignette.rds
+2f2c5b937422441c5fab92794b2d773a *data/Affairs.rda
+820218e38fbdc143b639e68f864bd88c *data/ArgentinaCPI.rda
+13dfc819ed4e325c751f73b2bf5b28a5 *data/BankWages.rda
+c704bc0a977055648b66ecd4ac0b962d *data/BenderlyZwick.rda
+611ed8b0759e05ce7a0652bef5144bb2 *data/BondYield.rda
+0a7354de74bdd55d7072f1d7069fb356 *data/CASchools.rda
+34b9ebb732561371b08fc2105e317240 *data/CPS1985.rda
+cad2b285281cb980b5d14eebc406f0e7 *data/CPS1988.rda
+009e73107ad77ff4b405bb06b549dac2 *data/CPSSW04.rda
+b0d176a5a2da79289f5a0679339f135d *data/CPSSW3.rda
+504c8af1159d8c64f9a0c624702ab897 *data/CPSSW8.rda
+9ea75e28ded2a80adbe61969cc556bc7 *data/CPSSW9204.rda
+2a29e3d9ca4c53cca325c8bacf33373b *data/CPSSW9298.rda
+8c38db6ecf62f50466042a13fb034b3d *data/CPSSWEducation.rda
+f9c29a0151f7174799223a084dfe84b5 *data/CartelStability.rda
+1e2c2189ea85005a5f980bbce70f741e *data/ChinaIncome.rda
+606b031d57c50268c7e35cb3f7c1ff69 *data/CigarettesB.rda
+4110e2b6cfef642aea515a9baa7281ec *data/CigarettesSW.rda
+fd2eb0c185233f2eb06c3d22f86d01d2 *data/CollegeDistance.rda
+18a039d695b0a01e7d52058ee8c490bf *data/ConsumerGood.rda
+0c442c5d668b104dbc93bc4fa38ea61e *data/CreditCard.rda
+658beeadbfcf60d9fe60ba86d0249f09 *data/DJFranses.rda
+e3390fceac49b678e30b37b6f70d33e8 *data/DJIA8012.rda
+760342f8bd7a478219f2328e6a0bb848 *data/DoctorVisits.rda
+76da0cb07967ca08696b8b15cf6c50da *data/DutchAdvert.rda
+cb9b014592eab96aa72826430e76d2d9 *data/DutchSales.rda
+0aeb8db664b7151c48e6522cdd719471 *data/Electricity1955.rda
+a3a208da54e53492e2fac81bd7bac675 *data/Electricity1970.rda
+392827793185020236728b8f5ce9917f *data/EquationCitations.rda
+522eb338188dcac69110842c2046adf0 *data/Equipment.rda
+af76d9cfaa14f6fb66cc22fd5da23c7f *data/EuroEnergy.rda
+0da145eb573675d8f15a8c150689af01 *data/Fatalities.rda
+888a69a56cc0cea3a15020f76c9698e3 *data/Fertility.rda
+9d1bae0928bdace841cbbd9ad2dfa7f1 *data/Fertility2.rda
+9f0fba47fbbeaf6f7becd4c357b85642 *data/FrozenJuice.rda
+a6bc52dfd6a0059cec82d6d651510140 *data/GSOEP9402.rda
+4484c96f2282e36c32ab5a7c2ae42444 *data/GSS7402.rda
+97a330a3c4cb351389012e3b72ab59cc *data/GermanUnemployment.rda
+877ca44413695b1d42f9eea465b85645 *data/GoldSilver.rda
+60e4b48cef9159b87dcbe697f8ff5fae *data/GrowthDJ.rda
+4ef8f75b0f9b940a334e3eb7d0802c80 *data/GrowthSW.rda
+c0e43d87c2509790735c186c686e7162 *data/Grunfeld.rda
+44acd651ad99b092929286bcd88d7129 *data/Guns.rda
+f95ec95fafe2b4d76896ff4e16c9614f *data/HMDA.rda
+58791f73577bfc90fde7ace020df28ff *data/HealthInsurance.rda
+d04498335be2e96addd4f16abc9e0e96 *data/HousePrices.rda
+d55d67079a428de95e0806ae2195fef2 *data/Journals.rda
+59e18db34a9df3929982e1865803031b *data/KleinI.rda
+9727cddabee8c8110267cd9cdeabdd08 *data/Longley.rda
+6e0a751f3fc3bd7bbac1cc31b3c147d6 *data/MASchools.rda
+da9d4df8f4f57cade1241952996e9713 *data/MSCISwitzerland.rda
+642c145f93cd7962161b83a907bb4542 *data/ManufactCosts.rda
+4ba37601c13d1655852545e5fe1f6339 *data/MarkDollar.rda
+825f340ee84dc836240e7a88d48bdd1d *data/MarkPound.rda
+d273a5db213c9f75e142b2b55e869b65 *data/Medicaid1986.rda
+ce90f4caab41c5e67012dfb194cea175 *data/Mortgage.rda
+33f658c917220456c8e72df840ca7bfc *data/MotorCycles.rda
+892c4975d447ddb9b98e6a926587120d *data/MotorCycles2.rda
+6b4aa0909efa221e5c0374d9db1dd9e3 *data/Municipalities.rda
+5dd86167f7f3a9fdf9675a16788ea003 *data/MurderRates.rda
+1e6025d9397f47b32f1dade58ccce45b *data/NMES1988.rda
+cf9681a589336964475dd33099d13e2e *data/NYSESW.rda
+f7125b4de34a4dc8021e45525d8398d3 *data/NaturalGas.rda
+87ff9f615113b4f90b5f9fe0e8d2f4f4 *data/OECDGas.rda
+85c851835ed4b777851d1f14e647c1f6 *data/OECDGrowth.rda
+1f3d224aaa23c59c1ab59a01f8dd96d0 *data/OlympicTV.rda
+0e80389ef9bdeb8430ca98f1fc31dad6 *data/OrangeCounty.rda
+b680ea38613c408c2f681baade263380 *data/PSID1976.rda
+e85f587554735c3e36eed5966329f7e5 *data/PSID1982.rda
+6b0253b1e5a8921d49c1254520b062aa *data/PSID7682.rda
+21039fdf9831fc97be439b88f3169b97 *data/Parade2005.rda
+46394845ba578d718f81031bc5bf1176 *data/PepperPrice.rda
+6901f907c356df1ba15ec475ea0dbe3e *data/PhDPublications.rda
+7f703127bd1697af0358355ff046a143 *data/ProgramEffectiveness.rda
+bb877adb3591226ae66fcb52c7410b12 *data/RecreationDemand.rda
+24e55b793d2c010f4320a706aa9e2d80 *data/ResumeNames.rda
+6ceef9c6e88cf30dc055f70553105d8f *data/SIC33.rda
+854f0b5f8adb13b63941e2eca1b85068 *data/STAR.rda
+cac5ebc0fe1321825cb6e2c99b3128b3 *data/ShipAccidents.rda
+cb5b2663466ef871b596fde14c52e7e2 *data/SmokeBan.rda
+0f5b34b18c5b7f0a56163d81ae0f3667 *data/SportsCards.rda
+21aa25e9d06155821b936bc63777c362 *data/StrikeDuration.rda
+5160c6a9fae884621943f43276ebb975 *data/SwissLabor.rda
+21b02b9371e4617a6edd30de5f500759 *data/TeachingRatings.rda
+f0507f2df80c290a7a7bb9c23fd3378c *data/TechChange.rda
+2b005de5ac81caa2dfa059b5b40292a2 *data/TradeCredit.rda
+08568b4c7ab213845e3679cdff5bbd69 *data/TravelMode.rda
+4759fd96509cdf8106fca78a9ffdeb7a *data/UKInflation.rda
+bb03a206a74e8361da44f43ce19d3ec2 *data/UKNonDurables.rda
+ba6ac55cefc9f42c7caeb6c28b89507d *data/USAirlines.rda
+3eaece4a02675f95dd693b35b9f85824 *data/USConsump1950.rda
+b976aa61d01785ee59b108cbffc7db89 *data/USConsump1979.rda
+619c5110bee6d913dde8ea0007cc06c8 *data/USConsump1993.rda
+d9cdbbdd8f89e3a611fbc67a7af46538 *data/USCrudes.rda
+28b250e5b7f770013fde6c83a8fcb440 *data/USGasB.rda
+afd44453a6ede3166f062b5251ec5a96 *data/USGasG.rda
+f7e41763b102e395a658fb11ac90e8a2 *data/USInvest.rda
+671e7aa481b3d6e64129113a81ac3401 *data/USMacroB.rda
+a5759daee1a498c7a8c2a61a48e2117a *data/USMacroG.rda
+b58e829f067cdc5e012849a28a137fa9 *data/USMacroSW.rda
+76aea794ddf6388197ddafc2aca59bc1 *data/USMacroSWM.rda
+4d3dda39c33e310dc61063520c6c5cd5 *data/USMacroSWQ.rda
+f0ec9d3b3a5527d1f82f0c4440ee0e93 *data/USMoney.rda
+b13744b5f1a3641dff4e9d6a0cadf657 *data/USProdIndex.rda
+8dc15fedfb57d49b2aa2959405387303 *data/USSeatBelts.rda
+6dfb933c083b76877c849b8fd0d63fa3 *data/USStocksSW.rda
+39df7317082a9ece0d44ded5154eae9c *data/WeakInstrument.rda
+78a5e0fe8f528aeb571b7d5501ebcfb0 *data/datalist
+c71c48f13243f39d8c1443d52f6525cd *demo/00Index
+720c95edcee31608ac582992e2acd89d *demo/Ch-Basics.R
+58ecaf2921f34398acc98930713225b2 *demo/Ch-Intro.R
+8ca4e23f04e7713ecf132df7ee4d114f *demo/Ch-LinearRegression.R
+b3cc664c7769b01c12e56723910169a3 *demo/Ch-Microeconometrics.R
+3e4ff0bddc3d416afff15a1604c2622e *demo/Ch-Programming.R
+3c43eb89f2395979202e63eba3b4ac30 *demo/Ch-TimeSeries.R
+3ac1dc4464dfa3a6ecbd2ffb6c216f8e *demo/Ch-Validation.R
+be1c63e8b99a84caf2b69089584c3882 *inst/CITATION
+a1157a7a06453160ff59c84bb67f563a *inst/doc/AER.R
+be86a5d0c92c9b560e26b8de29cf0b74 *inst/doc/AER.Rnw
+11252b866afab9a93e33ff2e673a9f1f *inst/doc/AER.pdf
+55645a67fdf53c524f1352c9ba6a5910 *inst/doc/Sweave-journals.R
+043acb4ba18e012bfc0c60717156d385 *inst/doc/Sweave-journals.Rnw
+bbe1578671657e6675febacc5ba6799e *inst/doc/Sweave-journals.pdf
+cb1bee600eebe1be720241e574985281 *man/Affairs.Rd
+60062af9c93b24cac2b25377dac5e222 *man/ArgentinaCPI.Rd
+5bc41ae3501ce458b8638d76e7d57f02 *man/Baltagi2002.Rd
+4c64198cc6ad5689d4c0eca87ad3ab5c *man/BankWages.Rd
+efecbe83ff32c1034b7bf64455c764a2 *man/BenderlyZwick.Rd
+3d193966356f54b8877a777c80bd76f6 *man/BondYield.Rd
+efafc0f9f858f879f259c0453fe66949 *man/CASchools.Rd
+356cdd226d939950a6d9c9effc7016f8 *man/CPS1985.Rd
+4008ca71755918fcb811451086192cca *man/CPS1988.Rd
+adf8734b0d57d79707ff7c8147c67aac *man/CPSSW.Rd
+813f614835c345bc4dac436a6dcaeff6 *man/CameronTrivedi1998.Rd
+171262b9838be0f53717c7849d148067 *man/CartelStability.Rd
+30a7589b2ba71fbd36977ca87e913860 *man/ChinaIncome.Rd
+cdc5730180e062893c138fd2901f9193 *man/CigarettesB.Rd
+947ee53ac127065ac1178df1470e190f *man/CigarettesSW.Rd
+4ca48c726409424e3f1aefaaef6b11d8 *man/CollegeDistance.Rd
+aca94e85997fd6c37cdd4ea0520009d6 *man/ConsumerGood.Rd
+c71ab901dd51cd800879f891c24a08b9 *man/CreditCard.Rd
+ea5a4e5332109264bd36abea390b08fe *man/DJFranses.Rd
+da44a2f2450254516333e21f646bb92d *man/DJIA8012.Rd
+7d1f0ec4515443b68417d4062bdd61cb *man/DoctorVisits.Rd
+dd3b5d79204dd747f0b2bafc4fcd3da6 *man/DutchAdvert.Rd
+7289cda1e03ae07c24773ab8f922776e *man/DutchSales.Rd
+1c67de99cc85c020c6342e7b29f724cb *man/Electricity1955.Rd
+10acb9ae3f2559939eb58eef8a0257fb *man/Electricity1970.Rd
+8cc46e5ee4dd0f56ba7d00676e2a2bd3 *man/EquationCitations.Rd
+45c0e4f347873eb32698828f441feaf0 *man/Equipment.Rd
+ab5f2a4d9ad6a0a7534a9b8eccbee1f3 *man/EuroEnergy.Rd
+db79598603da2f3cf7c956165cd0ea28 *man/Fatalities.Rd
+7c7eefb57dd2dbdb2fb4e1ca10d8aeae *man/Fertility.Rd
+904781049293273a1ab2d20d8d448da2 *man/Franses1998.Rd
+2849a01bd2934f5752e415d15219b0c7 *man/FrozenJuice.Rd
+1f01d858f7db917006d41efb75b99804 *man/GSOEP9402.Rd
+b5f4330dea3b78362340ef6b03fd01b6 *man/GSS7402.Rd
+7bf20d8a813160c889fd7697e63f8bb2 *man/GermanUnemployment.Rd
+1abbd7b19e3ca5d8a4c3187ae6002195 *man/GoldSilver.Rd
+f7d3626acf9532acf6f50c3a31671b29 *man/Greene2003.Rd
+52a150f4696edd6dcd103977288262d9 *man/GrowthDJ.Rd
+bf5417c5c842b9ab575851990514dfb8 *man/GrowthSW.Rd
+b4f788ca699fcd96f39d028babc4c311 *man/Grunfeld.Rd
+fd0681261e0aba5bfcf5ec60c9511f9f *man/Guns.Rd
+11c77404c24500db3e75ad6d724d9bf6 *man/HMDA.Rd
+cca440199e06e60a28acf081b8e80404 *man/HealthInsurance.Rd
+e8970093ff06e7b7433e12a66c5aad05 *man/HousePrices.Rd
+e80684b5f684e7126bd75bba70ce106b *man/Journals.Rd
+766829114a4b292c1f9e42d82a4672f6 *man/KleinI.Rd
+16da462d93863ab069c549a868160546 *man/Longley.Rd
+e2e9097328a005d747b8037a24e04719 *man/MASchools.Rd
+0975ada40a40507fff503d6423b18e61 *man/MSCISwitzerland.Rd
+61510348cb957b1ab181152fcf021ab6 *man/ManufactCosts.Rd
+594ad139d2bfeff7e3317e7c614b0694 *man/MarkDollar.Rd
+070a195dae0b487c188345dbf5b81511 *man/MarkPound.Rd
+a762e77161434ea8b76d0e651d6b2e7d *man/Medicaid1986.Rd
+25cd0df43df78e3c99b8dbf2da16f278 *man/Mortgage.Rd
+958a617bff70fb950d343595676fb5ee *man/MotorCycles.Rd
+76a2176ac57a0c76bce9e2d183a8d98a *man/MotorCycles2.Rd
+dc1b52380811dc1866343e32b41816d2 *man/Municipalities.Rd
+0b130af0c82280b23c0c00e168e6db1a *man/MurderRates.Rd
+299f9664100c41586a1778f5c98fe239 *man/NMES1988.Rd
+256bed985f5d3f35baba7910b2fbe8f9 *man/NYSESW.Rd
+2d8fcd90fb4bec614c47adb396fe1482 *man/NaturalGas.Rd
+bcea0c2d6886108cefee5424427c5e61 *man/OECDGas.Rd
+49a03bae86ac9b04719b6ebce4d6368a *man/OECDGrowth.Rd
+8f90a553c913136affcdc5772104ad13 *man/OlympicTV.Rd
+8c2ae32e2201320f7c29ad34beb124f2 *man/OrangeCounty.Rd
+7adf8c80ee5992d818ccb5ce6f8bf0a6 *man/PSID1976.Rd
+d066e983510ba1d4b50f046967866b96 *man/PSID1982.Rd
+82d122c0df137afab049abde7812116f *man/PSID7682.Rd
+6a986a4a57e927c35e4fada0b9ab7458 *man/Parade2005.Rd
+de9d141a4a516ec70e6285b58aa06d77 *man/PepperPrice.Rd
+1ab5bfb5aeb0d7eddf01cc64f457d25c *man/PhDPublications.Rd
+da54ba41002fdb537ede6bf4d5cd299b *man/ProgramEffectiveness.Rd
+5afc39cbe51cea1fe76be6dd22a7c999 *man/RecreationDemand.Rd
+397a0086742c451a00fcd20a35104d55 *man/ResumeNames.Rd
+dc8981942608d0ca0c82fb9a1a49dcff *man/SIC33.Rd
+28d817ab52cf09756abf8b11393fdb75 *man/STAR.Rd
+babeb5ea59d2c8af2ed00bd0f7eab082 *man/ShipAccidents.Rd
+076205d8dfc49748020a5ef3aaf2c620 *man/SmokeBan.Rd
+e294144d4deef9b62c5161a28c8704ac *man/SportsCards.Rd
+4150970b1533efe1b801645fd29bcd5a *man/StockWatson2007.Rd
+d6c70c3c90d5e5bea5f65b76e2166e85 *man/StrikeDuration.Rd
+d6939d092f785fc73e32cee26c3f2469 *man/SwissLabor.Rd
+a08b87f909932943432e5393ed440f3e *man/TeachingRatings.Rd
+172c8d25bad81c7a60f2d037d2374263 *man/TechChange.Rd
+d9b29a0e0525d10e6a75ecb77b9b8c2f *man/TradeCredit.Rd
+0467187ab71fd88d10167b7462ee1663 *man/TravelMode.Rd
+4135ec98f20e266dd7344f4a8de1a225 *man/UKInflation.Rd
+c255f954fd83e016e09a74d941759037 *man/UKNonDurables.Rd
+7b77b68813f31b25211574da0266611d *man/USAirlines.Rd
+a9f647920cd22f4dc11b176919d1a879 *man/USConsump1950.Rd
+5d398fc5cdb0729efe293be1d52d3df3 *man/USConsump1979.Rd
+aaf82b99c08976ebbc4c0ccc5a1a82e0 *man/USConsump1993.Rd
+0f2e4f6b40585ab23a07e8bea1ce46ad *man/USCrudes.Rd
+26c158f5f9e23835039be002bcaf5b28 *man/USGasB.Rd
+d6249a7e020811c5b34ddb742a820db0 *man/USGasG.Rd
+7d4f1bf77d9ee7e0865c1cc743b57e83 *man/USInvest.Rd
+4b7cd39c93401ab570889d96d0ffefab *man/USMacroB.Rd
+a76e81bb48960010b878c815b2b67fca *man/USMacroG.Rd
+9e7f2fc0e112b31bcc1af86ad6090df2 *man/USMacroSW.Rd
+1ad188b409f1d92c9c30f2db27769dfa *man/USMacroSWM.Rd
+7917c3220154ca951ec8329b6162c79a *man/USMacroSWQ.Rd
+80d6e5dc3b32be519d6e78d7e4076a4a *man/USMoney.Rd
+2586374f2eeb930827e00314c043301c *man/USProdIndex.Rd
+cea363bdf59add644251b6a83bf3745a *man/USSeatBelts.Rd
+f80e40d0fe8e8b83a15c0041e64aa30d *man/USStocksSW.Rd
+bb36bfc98d5ff4fddb215e6d00b17b8c *man/WeakInstrument.Rd
+fdd4cba1108159fdfd1eb8e62325f2cf *man/WinkelmannBoes2009.Rd
+1a5d21429e8ad0e04095a91cb7abdac0 *man/dispersiontest.Rd
+c11ba4bc897fa906f13ebf7143d807c7 *man/ivreg.Rd
+cba1d31034db4a70f66d1810c94cb640 *man/ivreg.fit.Rd
+34f4521b3ef26262c0b8ae37e150ce18 *man/summary.ivreg.Rd
+b35acc4f0314e13a53c3d06fc9235327 *man/tobit.Rd
+1f1d8e74adf8dfbb3e3c4b33025fa43b *tests/Ch-Basics.R
+d06bbedd7ec1330c9125554060cd8e7a *tests/Ch-Basics.Rout.save
+d8a5f23b92d461b5e7b96abd1204eba9 *tests/Ch-Intro.R
+67a17f0d39e6de2cd9b476a3ec1d8af8 *tests/Ch-Intro.Rout.save
+dfcf11e91a383c873b9fb7d4e70c5467 *tests/Ch-LinearRegression.R
+4a38b59a41509ae828118e853f5926cc *tests/Ch-LinearRegression.Rout.save
+5bbb2262141d16159ba5a513359454bd *tests/Ch-Microeconometrics.R
+a3f1dfbcde3e40b8e6a7b2e4339276cc *tests/Ch-Microeconometrics.Rout.save
+8f1fe2e6e2cab08feb3d529d88008abd *tests/Ch-Programming.R
+981f265dd6a90f9929c4f99ced322074 *tests/Ch-Programming.Rout.save
+e9a4332ae100101fde16958b05fed907 *tests/Ch-TimeSeries.R
+bc2e95eb128e98fffe36cd382aa10da0 *tests/Ch-TimeSeries.Rout.save
+05193cbe97bcda2a699987a3ff3dea49 *tests/Ch-Validation.R
+0dfbb2c7b8ce72543d29a2dd81c5dcd0 *tests/Ch-Validation.Rout.save
+be86a5d0c92c9b560e26b8de29cf0b74 *vignettes/AER.Rnw
+043acb4ba18e012bfc0c60717156d385 *vignettes/Sweave-journals.Rnw
+386ee733a919767e4cc3c57c1bd5e8b7 *vignettes/aer.bib
diff --git a/NAMESPACE b/NAMESPACE
new file mode 100644
index 0000000..b4ef07d
--- /dev/null
+++ b/NAMESPACE
@@ -0,0 +1,52 @@
+## imports
+import("stats")
+import("Formula")
+import("zoo")
+
+importFrom("lmtest", "coeftest", "waldtest", "waldtest.default", "lrtest", "lrtest.default")
+importFrom("car", "linearHypothesis")
+importFrom("sandwich", "bread", "estfun")
+importFrom("survival", "Surv", "survreg", "survreg.distributions")
+
+## exported functions of AER
+export(
+ "dispersiontest",
+ "tobit",
+ "ivreg",
+ "ivreg.fit"
+)
+
+## methods for class tobit
+S3method("print", "tobit")
+S3method("print", "summary.tobit")
+S3method("summary", "tobit")
+S3method("formula", "tobit")
+S3method("update", "tobit")
+S3method("model.frame", "tobit")
+S3method("waldtest", "tobit")
+S3method("lrtest", "tobit")
+S3method("linearHypothesis", "tobit")
+
+## methods for class ivreg
+S3method("print", "ivreg")
+S3method("print", "summary.ivreg")
+S3method("summary", "ivreg")
+S3method("vcov", "ivreg")
+S3method("bread", "ivreg")
+S3method("estfun", "ivreg")
+S3method("hatvalues", "ivreg")
+S3method("predict", "ivreg")
+S3method("anova", "ivreg")
+S3method("terms", "ivreg")
+S3method("model.matrix", "ivreg")
+
+## methods for class survreg
+S3method("deviance", "survreg")
+S3method("fitted", "survreg")
+S3method("nobs", "survreg")
+S3method("weights", "survreg")
+
+## methods for class multinom, polr, fitdistr
+S3method("coeftest", "multinom")
+S3method("coeftest", "polr")
+S3method("lrtest", "fitdistr")
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..b0fd6ad
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,244 @@
+Changes in Version 1.2-5
+
+ o Support for aliased coefficients in ivreg() (suggested and tested by
+ Liviu Andronic).
+
+ o New data sets GoldSilver, MotorCycles2 and MSCISwitzerland, taken from
+ Franses, van Dijk, Opschoor (2014): "Time Series Models for Business and
+ Economic Forecasting", 2nd ed. For replication of the corresponding
+ examples, several packages were added to the list of 'suggested' packages
+ (including fGarch, forecast, longmemo, rugarch, vars).
+
+ o Small improvements in DESCRIPTION/Imports and NAMESPACE for R CMD check.
+
+
+Changes in Version 1.2-4
+
+ o Reference output updated for recent versions of R.
+
+
+Changes in Version 1.2-3
+
+ o Package "splines" is loaded explicitly if needed (rather than assuming
+ that it is loaded along with "survival").
+
+ o Some URLs in the manual pages had been outdated and are updated (or omitted)
+ now.
+
+
+Changes in Version 1.2-2
+
+ o Another bug fix in the new summary(ivreg_object, diagnostics = TRUE). If
+ sandwich standard errors (or other vcov) were used, the chi-squared form
+ rather than the F form of the diagnostic Wald tests was computed and hence
+ the p-values were incorrect.
+
+ o If there is more than one endogenous variable, summary(ivreg_object,
+ diagnostics = TRUE) now reports separate tests of weak instruments for
+ each endogenous variable.
+
+
+Changes in Version 1.2-1
+
+ o Bug fix in the new summary(ivreg_object, diagnostics = TRUE). If there
+ is more than one endogenous variable, the degrees of freedom (and hence
+ the associated p-values) for the Sargan test were too large.
+
+ o The examples employing "rgl" for 3d visualizations (e.g., for the SIC33
+ data) are not tested anymore in R CMD check (as "rgl" currently has some
+ problems on CRAN's checks for OS X).
+
+
+Changes in Version 1.2-0
+
+ o The summary() method for ivreg() now has a diagnostics=FALSE argument.
+ If set to TRUE, three diagnostic tests are performed: an F test of
+ the first stage regression for weak instruments, a Wu-Hausman test
+ for endogeneity, and a Sargan test of overidentifying restrictions
+ (only if there are more instruments than regressors).
+
+ o Added new data set EquationCitations provided by Fawcett & Higginson
+ (2012, PNAS).
+
+ o Changes in Depends/Imports/Suggests due to new CRAN check requirements.
+ In particular, the "Formula" package is now only imported (but not
+ loaded into the search path).
+
+
+Changes in Version 1.1-9
+
+ o Recompressed data sets in package to reduce file storage requirements.
+
+ o ivreg() failed when used without instruments. Now fixed.
+
+ o The summary() for ivreg() displayed the degrees of freedom of the
+ overall Wald test incorrectly (although the p-value was computed
+ correctly).
+
+ o Some technical changes for new R 2.14.0, e.g., adding Authors at R in
+ DESCRIPTION, recompressing data, etc.
+
+
+Changes in Version 1.1-8
+
+ o The hat values for instrumental variables regressions are now
+ computed in the hatvalues() method and not within ivreg.fit()
+ to save computation time for large data sets.
+
+ o Added nobs() method for "survreg" objects (and thus "tobit" objects).
+ Modified "ivreg" objects so that default nobs() methods works.
+
+ o Labeling in coeftest() method for "multinom" objects with
+ binary responses has been fixed.
+
+ o Example 21.4 in ?Greene2003 now employs the scaled regressor
+ fincome/10000.
+
+
+Changes in Version 1.1-7
+
+ o Adapted some example in ?Greene2003 in order to work both with
+ the old and new "dynlm" package. dynlm() now provides convenient
+ support for linear time trends via dynlm(y ~ trend(y)) etc.
+
+
+Changes in Version 1.1-6
+
+ o Adapted code/examples/tests to new car version which has deprecated
+ linear.hypothesis() in favor of linearHypothesis().
+
+
+Changes in Version 1.1-5
+
+ o CPS1985 now has 534 observations (not 533 as in prior releases),
+ the original observation 1 had been omitted inadvertently. See
+ also the errata in vignette("AER", package = "AER").
+
+ o Data and examples for Winkelmann and Boes (2009),
+ "Analysis of Microdata" (2nd ed.) have been added. For details and
+ extensive (but not quite complete) replication code see
+ help("WinkelmannBoes2009") as well as help("GSS7402") and
+ help("GSOEP9402").
+
+ o As announced in the changes for version 1.1-0 of the "AER" package,
+ the variable "earnings" has now been removed from the
+ PSID1976 (aka Mroz) data. In 1.1-0 it was renamed to "wage"
+ to avoid confusion with other data sets.
+
+ o The coeftest() method for "polr" objects used to return wrong
+ standard errors (and hence wrong z tests) for the last intercept.
+ This was caused by an inconsistency between the summary() and
+ vcov() methods for "polr" objects which has been improved in
+ recent versions of the "MASS" package. The correct results are
+ computed by coeftest() for "polr" objects computed with MASS
+ version >= 7.3-6. See also the errata in vignette("AER",
+ package = "AER")
+
+ o The paper describing the various versions of the Grunfeld data
+ has been accepted for publication in the German Economic Review.
+ An updated version of the manuscript and associated replication
+ files -- mostly based on data("Grunfeld", package = "AER") --
+ is available from http://statmath.wu.ac.at/~zeileis/grunfeld/.
+
+ o Added lrtest() method for "fitdistr" objects with intelligible
+ model name (instead of the usual formula for formula-based models).
+
+
+Changes in Version 1.1-4
+
+ o ivreg() now uses the "Formula" package (>= 0.2-0) for processing
+ of its model formulas. However, this only affects the internal
+ computations, the user interface has remained unchanged.
+
+ o Numerous spelling improvements in the documentation (thanks to
+ the new aspell() functionality in base R).
+
+
+Changes in Version 1.1-3
+
+ o Added PSID7682 data set which contains the full Cornwell & Rupert
+ (1988) panel data for the years 1976-1982. This should be used
+ for estimation of the Hausman-Taylor model in Exercise 6 from
+ Chapter 3 (instead of PSID1982 which does not provide panel data
+ but only the cross-section for 1982). See the errata and the
+ manual page for more details.
+
+ o Fixed overall Wald test in summary() for "tobit" models
+ with intercept only.
+
+
+Changes in Version 1.1-2
+
+ o New errata item in vignette("AER", package = "AER"): The comment
+ regarding the output from the Johansen test (p. 169) is in error.
+ The null hypothesis of no cointegration is not rejected at the
+ 10% level (only at 15% level).
+
+ o Enhancements of the CigarettesSW examples from Stock & Watson.
+
+ o Fixed overall Wald test in summary() for "tobit" models
+ without intercept.
+
+ o Improved "rgl" code in the SIC33 example.
+
+ o The variable "gender" in the Parade2005 data set was
+ wrong for observation 70. It is now "male" (not "female").
+
+
+Changes in Version 1.1-1
+
+ o A new improved version of the "plm" package is available
+ from CRAN (version 1.1-1). This fixes a bug in the summary()
+ of "plm" objects, see the vignette/errata for details.
+ Furthermore, there is now a vcovHC() method for "panelmodel"
+ objects: It gives equivalent results to pvcovHC() but
+ is now the recommended user interface and hence used
+ in the examples of some manual pages (see e.g. ?Fatalities).
+
+
+Changes in Version 1.1-0
+
+ o Some variable names in the PSID1976 (aka Mroz) data
+ have been renamed: "earnings" is now called "wage"
+ (to avoid confusion with other data sets), the previous
+ variable "wage" is renamed as "repwage" (reported wage).
+ Currently, "earnings" is kept; it will be removed in future
+ releases.
+
+ o Documentation of the Grunfeld data has been enhanced and
+ updated. Much more details are available in a recent
+ technical report: Kleiber and Zeileis (2008), "The
+ Grunfeld Data at 50", available from http://epub.wu-wien.ac.at/.
+
+ o Multinomial logit examples using Yves Croissant's "mlogit"
+ package have been added for the TravelMode and BankWages
+ data sets.
+
+ o Vignette/errata updated.
+
+
+Changes in Version 1.0-1
+
+ o Small changes for R 2.8.0.
+
+
+Changes in Version 1.0-0
+
+ o official version accompanying the release of the
+ book (contains all code from the book in demos
+ and tests)
+
+ o See the new
+ vignette("AER", package = "AER")
+ for an overview of the package and a list of errata.
+
+
+Changes in Version 0.9-0
+
+ o release of the version used for compiling the final
+ version of the book for Springer
+
+
+Changes in Version 0.2-0
+
+ o first CRAN release of the AER package
diff --git a/R/coeftest-methods.R b/R/coeftest-methods.R
new file mode 100644
index 0000000..81ebebc
--- /dev/null
+++ b/R/coeftest-methods.R
@@ -0,0 +1,78 @@
+coeftest.multinom <- function(x, vcov. = NULL, df = NULL, ...)
+{
+ ## extract coefficients
+ est <- coef(x)
+ if(!is.null(dim(est))) {
+ est <- structure(as.vector(t(est)),
+ names = as.vector(t(outer(rownames(est), colnames(est), paste, sep = ":"))))
+ }
+
+ ## process vcov.
+ if(is.null(vcov.)) vc <- vcov(x) else {
+ if(is.function(vcov.)) vc <- vcov.(x)
+ else vc <- vcov.
+ }
+ se <- sqrt(diag(vc))
+ tval <- as.vector(est)/se
+
+ ## process degrees of freedom
+ if(is.null(df)) df <- Inf
+
+ if(is.finite(df) && df > 0) {
+ pval <- 2 * pt(abs(tval), df = df, lower.tail = FALSE)
+ cnames <- c("Estimate", "Std. Error", "t value", "Pr(>|t|)")
+ mthd <- "t"
+ } else {
+ pval <- 2 * pnorm(abs(tval), lower.tail = FALSE)
+ cnames <- c("Estimate", "Std. Error", "z value", "Pr(>|z|)")
+ mthd <- "z"
+ }
+ rval <- cbind(est, se, tval, pval)
+ colnames(rval) <- cnames
+ class(rval) <- "coeftest"
+ attr(rval, "method") <- paste(mthd, "test of coefficients")
+ return(rval)
+}
+
+coeftest.polr <- function(x, vcov. = NULL, df = NULL, ...)
+{
+ ## extract coefficients
+ est <- c(x$coefficients, x$zeta)
+
+ ## process vcov.
+ if(is.null(vcov.)) vc <- vcov(x) else {
+ if(is.function(vcov.)) vc <- vcov.(x)
+ else vc <- vcov.
+ }
+ se <- sqrt(diag(vc))
+ tval <- as.vector(est)/se
+
+ ## process degrees of freedom
+ if(is.null(df)) df <- Inf
+
+ if(is.finite(df) && df > 0) {
+ pval <- 2 * pt(abs(tval), df = df, lower.tail = FALSE)
+ cnames <- c("Estimate", "Std. Error", "t value", "Pr(>|t|)")
+ mthd <- "t"
+ } else {
+ pval <- 2 * pnorm(abs(tval), lower.tail = FALSE)
+ cnames <- c("Estimate", "Std. Error", "z value", "Pr(>|z|)")
+ mthd <- "z"
+ }
+ rval <- cbind(est, se, tval, pval)
+ colnames(rval) <- cnames
+ class(rval) <- "coeftest"
+ attr(rval, "method") <- paste(mthd, "test of coefficients")
+ return(rval)
+}
+
+lrtest.fitdistr <- function(object, ..., name = NULL)
+{
+ if(is.null(name)) name <- function(x) if(is.null(names(x$estimate))) {
+ paste(round(x$estimate, digits = max(getOption("digits") - 3, 2)), collapse = ", ")
+ } else {
+ paste(names(x$estimate), "=", round(x$estimate, digits = max(getOption("digits") - 3, 2)), collapse = ", ")
+ }
+ lrtest.default(object, ..., name = name)
+}
+
diff --git a/R/dispersiontest.R b/R/dispersiontest.R
new file mode 100644
index 0000000..a7a186b
--- /dev/null
+++ b/R/dispersiontest.R
@@ -0,0 +1,62 @@
+dispersiontest <- function(object, trafo = NULL, alternative = c("greater", "two.sided", "less"))
+{
+ if(!inherits(object, "glm") || family(object)$family != "poisson")
+ stop("only Poisson GLMs can be tested")
+ alternative <- match.arg(alternative)
+ otrafo <- trafo
+ if(is.numeric(otrafo)) trafo <- function(x) x^otrafo
+
+ y <- if(is.null(object$y)) model.response(model.frame(object)) else object$y
+ yhat <- fitted(object)
+ aux <- ((y - yhat)^2 - y)/yhat
+
+ if(is.null(trafo)) {
+ STAT <- sqrt(length(aux)) * mean(aux)/sd(aux)
+ NVAL <- c(dispersion = 1)
+ EST <- c(dispersion = mean(aux) + 1)
+ } else {
+ auxreg <- lm(aux ~ 0 + I(trafo(yhat)/yhat))
+ STAT <- as.vector(summary(auxreg)$coef[1,3])
+ NVAL <- c(alpha = 0)
+ EST <- c(alpha = as.vector(coef(auxreg)[1]))
+ }
+
+ rval <- list(statistic = c(z = STAT),
+ p.value = switch(alternative,
+ "greater" = pnorm(STAT, lower.tail = FALSE),
+ "two.sided" = pnorm(abs(STAT), lower.tail = FALSE)*2,
+ "less" = pnorm(STAT)),
+ estimate = EST,
+ null.value = NVAL,
+ alternative = alternative,
+ method = switch(alternative,
+ "greater" = "Overdispersion test",
+ "two.sided" = "Dispersion test",
+ "less" = "Underdispersion test"),
+ data.name = deparse(substitute(object)))
+ class(rval) <- "htest"
+ return(rval)
+}
+
+
+## NB. score tests a la DCluster now implemented in countreg
+##
+## TODO:
+## LRT for Poi vs NB2.
+## fix DCluster::test.nb.pois() and pscl::odTest()
+## proposed interface:
+## poistest(object, object2 = NULL)
+## where either a "negbin" and a "glm" object have to be
+## supplied or only one of them, then update via either
+## cl <- object$call
+## cl[[1]] <- as.name("glm.nb")
+## cl$link <- object$family$link
+## cl$family <- NULL
+## or
+## cl <- object$call
+## cl[[1]] <- as.name("glm")
+## cl$family <- call("poisson")
+## cl$family$link <- object$family$link
+## cl$link <- NULL
+## cl$init.theta <- NULL
+## and evaluate the call "cl" appropriately.
diff --git a/R/ivreg.R b/R/ivreg.R
new file mode 100644
index 0000000..470dcdd
--- /dev/null
+++ b/R/ivreg.R
@@ -0,0 +1,429 @@
+ivreg <- function(formula, instruments, data, subset, na.action, weights, offset,
+ contrasts = NULL, model = TRUE, y = TRUE, x = FALSE, ...)
+{
+ ## set up model.frame() call
+ cl <- match.call()
+ if(missing(data)) data <- environment(formula)
+ mf <- match.call(expand.dots = FALSE)
+ m <- match(c("formula", "data", "subset", "na.action", "weights", "offset"), names(mf), 0)
+ mf <- mf[c(1, m)]
+ mf$drop.unused.levels <- TRUE
+
+ ## handle instruments for backward compatibility
+ if(!missing(instruments)) {
+ formula <- Formula::as.Formula(formula, instruments)
+ cl$instruments <- NULL
+ cl$formula <- formula(formula)
+ } else {
+ formula <- Formula::as.Formula(formula)
+ }
+ stopifnot(length(formula)[1] == 1L, length(formula)[2] %in% 1:2)
+
+ ## try to handle dots in formula
+ has_dot <- function(formula) inherits(try(terms(formula), silent = TRUE), "try-error")
+ if(has_dot(formula)) {
+ f1 <- formula(formula, rhs = 1)
+ f2 <- formula(formula, lhs = 0, rhs = 2)
+ if(!has_dot(f1) & has_dot(f2)) formula <- Formula::as.Formula(f1,
+ update(formula(formula, lhs = 0, rhs = 1), f2))
+ }
+
+ ## call model.frame()
+ mf$formula <- formula
+ mf[[1]] <- as.name("model.frame")
+ mf <- eval(mf, parent.frame())
+
+ ## extract response, terms, model matrices
+ Y <- model.response(mf, "numeric")
+ mt <- terms(formula, data = data)
+ mtX <- terms(formula, data = data, rhs = 1)
+ X <- model.matrix(mtX, mf, contrasts)
+ if(length(formula)[2] < 2L) {
+ mtZ <- NULL
+ Z <- NULL
+ } else {
+ mtZ <- delete.response(terms(formula, data = data, rhs = 2))
+ Z <- model.matrix(mtZ, mf, contrasts)
+ }
+
+ ## weights and offset
+ weights <- model.weights(mf)
+ offset <- model.offset(mf)
+ if(is.null(offset)) offset <- 0
+ if(length(offset) == 1) offset <- rep(offset, NROW(Y))
+ offset <- as.vector(offset)
+
+ ## call default interface
+ rval <- ivreg.fit(X, Y, Z, weights, offset, ...)
+
+ ## enhance information stored in fitted model object
+ rval$call <- cl
+ rval$formula <- formula(formula)
+ rval$terms <- list(regressors = mtX, instruments = mtZ, full = mt)
+ rval$na.action <- attr(mf, "na.action")
+ rval$levels <- .getXlevels(mt, mf)
+ rval$contrasts <- list(regressors = attr(X, "contrasts"), instruments = attr(Z, "contrasts"))
+ if(model) rval$model <- mf
+ if(y) rval$y <- Y
+ if(x) rval$x <- list(regressors = X, instruments = Z, projected = rval$x)
+ else rval$x <- NULL
+
+ class(rval) <- "ivreg"
+ return(rval)
+}
+
+ivreg.fit <- function(x, y, z, weights, offset, ...)
+{
+ ## model dimensions
+ n <- NROW(y)
+ p <- ncol(x)
+
+ ## defaults
+ if(missing(z)) z <- NULL
+ if(missing(weights)) weights <- NULL
+ if(missing(offset)) offset <- rep(0, n)
+
+ ## sanity checks
+ stopifnot(n == nrow(x))
+ if(!is.null(z)) stopifnot(n == nrow(z))
+ if(!is.null(weights)) stopifnot(n == NROW(weights))
+ stopifnot(n == NROW(offset))
+
+ ## project regressors x on image of instruments z
+ if(!is.null(z)) {
+ if(ncol(z) < ncol(x)) warning("more regressors than instruments")
+ auxreg <- if(is.null(weights)) lm.fit(z, x, ...) else lm.wfit(z, x, weights, ...)
+ xz <- as.matrix(auxreg$fitted.values)
+ # pz <- z %*% chol2inv(auxreg$qr$qr) %*% t(z)
+ colnames(xz) <- colnames(x)
+ } else {
+ xz <- x
+ # pz <- diag(NROW(x))
+ # colnames(pz) <- rownames(pz) <- rownames(x)
+ }
+
+ ## main regression
+ fit <- if(is.null(weights)) lm.fit(xz, y, offset = offset, ...)
+ else lm.wfit(xz, y, weights, offset = offset, ...)
+
+ ## model fit information
+ ok <- which(!is.na(fit$coefficients))
+ yhat <- drop(x[, ok, drop = FALSE] %*% fit$coefficients[ok])
+ names(yhat) <- names(y)
+ res <- y - yhat
+ ucov <- chol2inv(fit$qr$qr[1:length(ok), 1:length(ok), drop = FALSE])
+ colnames(ucov) <- rownames(ucov) <- names(fit$coefficients[ok])
+ rss <- if(is.null(weights)) sum(res^2) else sum(weights * res^2)
+ ## hat <- diag(x %*% ucov %*% t(x) %*% pz)
+ ## names(hat) <- rownames(x)
+
+ rval <- list(
+ coefficients = fit$coefficients,
+ residuals = res,
+ fitted.values = yhat,
+ weights = weights,
+ offset = if(identical(offset, rep(0, n))) NULL else offset,
+ n = n,
+ nobs = if(is.null(weights)) n else sum(weights > 0),
+ rank = fit$rank,
+ df.residual = fit$df.residual,
+ cov.unscaled = ucov,
+ sigma = sqrt(rss/fit$df.residual), ## NOTE: Stata divides by n here and uses z tests rather than t tests...
+ # hatvalues = hat,
+ x = xz
+ )
+
+ return(rval)
+}
+
+vcov.ivreg <- function(object, ...)
+ object$sigma^2 * object$cov.unscaled
+
+bread.ivreg <- function (x, ...)
+ x$cov.unscaled * x$nobs
+
+estfun.ivreg <- function (x, ...)
+{
+ xmat <- model.matrix(x)
+ if(any(alias <- is.na(coef(x)))) xmat <- xmat[, !alias, drop = FALSE]
+ wts <- weights(x)
+ if(is.null(wts)) wts <- 1
+ res <- residuals(x)
+ rval <- as.vector(res) * wts * xmat
+ attr(rval, "assign") <- NULL
+ attr(rval, "contrasts") <- NULL
+ return(rval)
+}
+
+hatvalues.ivreg <- function(model, ...) {
+ xz <- model.matrix(model, component = "projected")
+ x <- model.matrix(model, component = "regressors")
+ z <- model.matrix(model, component = "instruments")
+ solve_qr <- function(x) chol2inv(qr.R(qr(x)))
+ diag(x %*% solve_qr(xz) %*% t(x) %*% z %*% solve_qr(z) %*% t(z))
+}
+
+terms.ivreg <- function(x, component = c("regressors", "instruments"), ...)
+ x$terms[[match.arg(component)]]
+
+model.matrix.ivreg <- function(object, component = c("projected", "regressors", "instruments"), ...) {
+ component <- match.arg(component)
+ if(!is.null(object$x)) rval <- object$x[[component]]
+ else if(!is.null(object$model)) {
+ X <- model.matrix(object$terms$regressors, object$model, contrasts = object$contrasts$regressors)
+ Z <- if(is.null(object$terms$instruments)) NULL
+ else model.matrix(object$terms$instruments, object$model, contrasts = object$contrasts$instruments)
+ w <- weights(object)
+ XZ <- if(is.null(Z)) X
+ else if(is.null(w)) lm.fit(Z, X)$fitted.values else lm.wfit(Z, X, w)$fitted.values
+ rval <- switch(component,
+ "regressors" = X,
+ "instruments" = Z,
+ "projected" = XZ)
+ } else stop("not enough information in fitted model to return model.matrix")
+ return(rval)
+}
+
+predict.ivreg <- function(object, newdata, na.action = na.pass, ...)
+{
+ if(missing(newdata)) fitted(object)
+ else {
+ mf <- model.frame(delete.response(object$terms$full), newdata,
+ na.action = na.action, xlev = object$levels)
+ X <- model.matrix(delete.response(object$terms$regressors), mf,
+ contrasts = object$contrasts$regressors)
+ ok <- !is.na(object$coefficients)
+ drop(X[, ok, drop = FALSE] %*% object$coefficients[ok])
+ }
+}
+
+print.ivreg <- function(x, digits = max(3, getOption("digits") - 3), ...)
+{
+ cat("\nCall:\n", deparse(x$call), "\n\n", sep = "")
+ cat("Coefficients:\n")
+ print.default(format(coef(x), digits = digits), print.gap = 2, quote = FALSE)
+ cat("\n")
+ invisible(x)
+}
+
+summary.ivreg <- function(object, vcov. = NULL, df = NULL, diagnostics = FALSE, ...)
+{
+ ## weighted residuals
+ res <- object$residuals
+ y <- object$fitted.values + res
+ n <- NROW(res)
+ w <- object$weights
+ if(is.null(w)) w <- rep(1, n)
+ res <- res * sqrt(w)
+
+ ## R-squared
+ rss <- sum(res^2)
+ if(attr(object$terms$regressors, "intercept")) {
+ tss <- sum(w * (y - weighted.mean(y, w))^2)
+ dfi <- 1
+ } else {
+ tss <- sum(w * y^2)
+ dfi <- 0
+ }
+ r.squared <- 1 - rss/tss
+ adj.r.squared <- 1 - (1 - r.squared) * ((n - dfi)/object$df.residual)
+
+ ## degrees of freedom (for z vs. t test)
+ if(is.null(df)) df <- object$df.residual
+ if(!is.finite(df)) df <- 0
+ if(df > 0 & (df != object$df.residual)) {
+ df <- object$df.residual
+ }
+
+ ## covariance matrix
+ if(is.null(vcov.))
+ vc <- vcov(object)
+ else {
+ if(is.function(vcov.)) vc <- vcov.(object)
+ else vc <- vcov.
+ }
+
+ ## Wald test of each coefficient
+ cf <- lmtest::coeftest(object, vcov. = vc, df = df, ...)
+ attr(cf, "method") <- NULL
+ class(cf) <- "matrix"
+
+ ## Wald test of all coefficients
+ Rmat <- if(attr(object$terms$regressors, "intercept"))
+ cbind(0, diag(length(na.omit(coef(object)))-1)) else diag(length(na.omit(coef(object))))
+ waldtest <- car::linearHypothesis(object, Rmat, vcov. = vcov., test = ifelse(df > 0, "F", "Chisq"), singular.ok = TRUE)
+ waldtest <- c(waldtest[2,3], waldtest[2,4], abs(waldtest[2,2]), if(df > 0) waldtest[2,1] else NULL)
+
+ ## diagnostic tests
+ diag <- if(diagnostics) ivdiag(object, vcov. = vcov.) else NULL
+
+ rval <- list(
+ call = object$call,
+ terms = object$terms,
+ residuals = res,
+ weights <- object$weights,
+ coefficients = cf,
+ sigma = object$sigma,
+ df = c(object$rank, if(df > 0) df else Inf, object$rank), ## aliasing
+ r.squared = r.squared,
+ adj.r.squared = adj.r.squared,
+ waldtest = waldtest,
+ vcov = vc,
+ diagnostics = diag)
+
+ class(rval) <- "summary.ivreg"
+ return(rval)
+}
+
+print.summary.ivreg <- function(x, digits = max(3, getOption("digits") - 3),
+ signif.stars = getOption("show.signif.stars"), ...)
+{
+ cat("\nCall:\n")
+ cat(paste(deparse(x$call), sep = "\n", collapse = "\n"), "\n\n", sep = "")
+
+ cat(if(!is.null(x$weights) && diff(range(x$weights))) "Weighted ", "Residuals:\n", sep = "")
+ if(NROW(x$residuals) > 5L) {
+ nam <- c("Min", "1Q", "Median", "3Q", "Max")
+ rq <- if(length(dim(x$residuals)) == 2)
+ structure(apply(t(x$residuals), 1, quantile), dimnames = list(nam, dimnames(x$residuals)[[2]]))
+ else structure(quantile(x$residuals), names = nam)
+ print(rq, digits = digits, ...)
+ } else {
+ print(x$residuals, digits = digits, ...)
+ }
+
+ cat("\nCoefficients:\n")
+ printCoefmat(x$coefficients, digits = digits, signif.stars = signif.stars,
+ signif.legend = signif.stars & is.null(x$diagnostics), na.print = "NA", ...)
+
+ if(!is.null(x$diagnostics)) {
+ cat("\nDiagnostic tests:\n")
+ printCoefmat(x$diagnostics, cs.ind = 1L:2L, tst.ind = 3L,
+ has.Pvalue = TRUE, P.values = TRUE, digits = digits,
+ signif.stars = signif.stars, na.print = "NA", ...)
+ }
+
+ cat("\nResidual standard error:", format(signif(x$sigma, digits)),
+ "on", x$df[2L], "degrees of freedom\n")
+
+ cat("Multiple R-Squared:", formatC(x$r.squared, digits = digits))
+ cat(",\tAdjusted R-squared:", formatC(x$adj.r.squared, digits = digits),
+ "\nWald test:", formatC(x$waldtest[1L], digits = digits),
+ "on", x$waldtest[3L], if(length(x$waldtest) > 3L) c("and", x$waldtest[4L]) else NULL,
+ "DF, p-value:", format.pval(x$waldtest[2L], digits = digits), "\n\n")
+
+ invisible(x)
+}
+
+anova.ivreg <- function(object, object2, test = "F", vcov = NULL, ...)
+{
+ rval <- waldtest(object, object2, test = test, vcov = vcov)
+ if(is.null(vcov)) {
+ head <- attr(rval, "heading")
+ head[1] <- "Analysis of Variance Table\n"
+ rss <- sapply(list(object, object2), function(x) sum(residuals(x)^2))
+ dss <- c(NA, -diff(rss))
+ rval <- cbind(rval, cbind("RSS" = rss, "Sum of Sq" = dss))[,c(1L, 5L, 2L, 6L, 3L:4L)]
+ attr(rval, "heading") <- head
+ class(rval) <- c("anova", "data.frame")
+ }
+ return(rval)
+}
+
+ivdiag <- function(obj, vcov. = NULL) {
+ ## extract data
+ y <- model.response(model.frame(obj))
+ x <- model.matrix(obj, component = "regressors")
+ z <- model.matrix(obj, component = "instruments")
+
+ ## endogenous/instrument variables
+ endo <- which(!(colnames(x) %in% colnames(z)))
+ inst <- which(!(colnames(z) %in% colnames(x)))
+ if((length(endo) <= 0L) | (length(inst) <= 0L))
+ stop("no endogenous/instrument variables")
+
+ ## return value
+ rval <- matrix(NA, nrow = length(endo) + 2L, ncol = 4L)
+ colnames(rval) <- c("df1", "df2", "statistic", "p-value")
+ rownames(rval) <- c(if(length(endo) > 1L) paste0("Weak instruments (", colnames(x)[endo], ")") else "Weak instruments",
+ "Wu-Hausman", "Sargan")
+
+ ## convenience functions
+ lmfit <- function(x, y) {
+ rval <- lm.fit(x, y)
+ rval$x <- x
+ rval$y <- y
+ return(rval)
+ }
+ rss <- function(obj) sum(obj$residuals^2)
+ wald <- function(obj0, obj1, vcov. = NULL) {
+ df <- c(obj1$rank - obj0$rank, obj1$df.residual)
+ if(!is.function(vcov.)) {
+ w <- ((rss(obj0) - rss(obj1)) / df[1L]) / (rss(obj1)/df[2L])
+ } else {
+ if(NCOL(obj0$coefficients) > 1L) {
+ cf0 <- structure(as.vector(obj0$coefficients),
+ .Names = c(outer(rownames(obj0$coefficients), colnames(obj0$coefficients), paste, sep = ":")))
+ cf1 <- structure(as.vector(obj1$coefficients),
+ .Names = c(outer(rownames(obj1$coefficients), colnames(obj1$coefficients), paste, sep = ":")))
+ } else {
+ cf0 <- obj0$coefficients
+ cf1 <- obj1$coefficients
+ }
+ cf0 <- na.omit(cf0)
+ cf1 <- na.omit(cf1)
+ ovar <- which(!(names(cf1) %in% names(cf0)))
+ vc <- vcov.(lm(obj1$y ~ 0 + obj1$x))
+ w <- t(cf1[ovar]) %*% solve(vc[ovar,ovar]) %*% cf1[ovar]
+ w <- w / df[1L]
+ }
+ pval <- pf(w, df[1L], df[2L], lower.tail = FALSE)
+ c(df, w, pval)
+ }
+
+ # Test for weak instruments
+ for(i in seq_along(endo)) {
+ aux0 <- lmfit(z[, -inst, drop = FALSE], x[, endo[i]])
+ aux1 <- lmfit(z, x[, endo[i]])
+ rval[i, ] <- wald(aux0, aux1, vcov. = vcov.)
+ }
+
+ ## Wu-Hausman test for endogeneity
+ if(length(endo) > 1L) aux1 <- lmfit(z, x[, endo])
+ xfit <- as.matrix(aux1$fitted.values)
+ colnames(xfit) <- paste("fit", colnames(xfit), sep = "_")
+ auxo <- lmfit( x, y)
+ auxe <- lmfit(cbind(x, xfit), y)
+ rval[nrow(rval) - 1L, ] <- wald(auxo, auxe, vcov. = vcov.)
+
+ ## Sargan test of overidentifying restrictions
+ r <- residuals(obj)
+ auxs <- lmfit(z, r)
+ rval[nrow(rval), 1L] <- length(inst) - length(endo)
+ if(rval[nrow(rval), 1L] > 0L) {
+ rval[nrow(rval), 3L] <- length(r) * (1 - rss(auxs)/sum((r - mean(r))^2))
+ rval[nrow(rval), 4L] <- pchisq(rval[nrow(rval), 3L], rval[nrow(rval), 1L], lower.tail = FALSE)
+ }
+
+ return(rval)
+}
+
+## If #Instruments = #Regressors then
+## b = (Z'X)^{-1} Z'y
+## and solves the estimating equations
+## Z' (y - X beta) = 0
+## For
+## cov(y) = Omega
+## the following holds
+## cov(b) = (Z'X)^{-1} Z' Omega Z (X'Z)^{-1}
+##
+## Generally:
+## b = (X' P_Z X)^{-1} X' P_Z y
+## with estimating equations
+## X' P_Z (y - X beta) = 0
+## where P_Z is the usual projector (hat matrix wrt Z) and
+## cov(b) = (X' P_Z X)^{-1} X' P_Z Omega P_Z X (X' P_Z X)^{-1}
+## Thus meat is X' P_Z Omega P_Z X and bread i (X' P_Z X)^{-1}
+##
+## See
+## http://www.stata.com/support/faqs/stat/2sls.html
diff --git a/R/tobit.R b/R/tobit.R
new file mode 100644
index 0000000..1a0bae3
--- /dev/null
+++ b/R/tobit.R
@@ -0,0 +1,279 @@
+## some convenience functions generally applicable to survreg
+## hopefully in survival soon
+
+deviance.survreg <- function(object, ...)
+ sum(residuals(object, type = "deviance")^2)
+
+fitted.survreg <- function(object, ...)
+ predict(object, type = "response", se.fit = FALSE)
+
+nobs.survreg <- function(object, ...)
+ length(object$linear.predictors)
+
+weights.survreg <- function(object, ...)
+ model.weights(model.frame(object))
+
+
+## convenience tobit() interface to survreg()
+
+tobit <- function(formula, left = 0, right = Inf, dist = "gaussian", subset = NULL, data = list(), ...)
+{
+ ## remember original environment
+ oenv <- environment(formula)
+ oformula <- eval(formula)
+
+ ## process censoring
+ stopifnot(all(left < right))
+ lfin <- any(is.finite(left))
+ rfin <- any(is.finite(right))
+
+ ## formula processing: replace dependent variable
+ ## original
+ y <- formula[[2]]
+ if(lfin & rfin) {
+ ## interval censoring
+ formula[[2]] <- call("Surv", call("ifelse", call(">=", y, substitute(right)), substitute(right),
+ call("ifelse", call("<=", y, substitute(left)), substitute(left), y)), time2 = substitute(right),
+ call("ifelse", call(">=", y, substitute(right)), 0, call("ifelse", call("<=", y, substitute(left)), 2, 1)),
+ type = "interval")
+ } else if(!rfin) {
+ ## left censoring
+ formula[[2]] <- call("Surv", call("ifelse", call("<=", y, substitute(left)), substitute(left), y),
+ call(">", y, substitute(left)) , type = "left")
+ } else {
+ ## right censoring
+ formula[[2]] <- call("Surv", call("ifelse", call(">=", y, substitute(right)), substitute(right), y),
+ call("<", y, substitute(right)) , type = "right")
+ }
+
+ ## call survreg
+ cl <- ocl <- match.call()
+ cl$formula <- formula
+ cl$left <- NULL
+ cl$right <- NULL
+ cl$dist <- dist
+ cl[[1]] <- as.name("survreg")
+ rval <- eval(cl, oenv)
+
+ ## slightly modify result
+ class(rval) <- c("tobit", class(rval))
+ ocl$formula <- oformula
+ rval$call <- ocl
+ rval$formula <- formula
+ return(rval)
+}
+
+
+## add printing and summary methods that are more similar to
+## the corresponding methods for lm objects
+
+print.tobit <- function(x, digits = max(3, getOption("digits") - 3), ...)
+{
+ ## failure
+ if(!is.null(x$fail)) {
+ cat("tobit/survreg failed.", x$fail, "\n")
+ return(invisible(x))
+ }
+
+ ## call
+ cat("\nCall:\n")
+ cat(paste(deparse(x$call), sep = "\n", collapse = "\n"), "\n\n", sep = "")
+
+ ## coefficients
+ coef <- x$coefficients
+ if(any(nas <- is.na(coef))) {
+ if (is.null(names(coef))) names(coef) <- paste("b", 1:length(coef), sep = "")
+ cat("Coefficients: (", sum(nas), " not defined because of singularities)\n", sep = "")
+ } else cat("Coefficients:\n")
+ print.default(format(coef, digits = digits), print.gap = 2, quote = FALSE)
+
+ ## scale
+ if(nrow(x$var) == length(coef))
+ cat("\nScale fixed at", format(x$scale, digits = digits), "\n")
+ else if (length(x$scale) == 1)
+ cat("\nScale:", format(x$scale, digits = digits), "\n")
+ else {
+ cat("\nScale:\n")
+ print(format(x$scale, digits = digits), ...)
+ }
+
+ ## return
+ cat("\n")
+ invisible(x)
+}
+
+summary.tobit <- function(object, correlation = FALSE, symbolic.cor = FALSE, vcov. = NULL, ...)
+{
+ ## failure
+ if(!is.null(object$fail)) {
+ warning("tobit/survreg failed.", object$fail, " No summary provided\n")
+ return(invisible(object))
+ }
+
+ ## rank
+ if(all(is.na(object$coefficients))) {
+ warning("This model has zero rank --- no summary is provided")
+ return(invisible(object))
+ }
+
+ ## vcov
+ if(is.null(vcov.)) vcov. <- vcov(object)
+ else {
+ if(is.function(vcov.)) vcov. <- vcov.(object)
+ }
+
+ ## coefmat
+ coef <- coeftest(object, vcov. = vcov., ...)
+ attr(coef, "method") <- NULL
+
+ ## Wald test
+ nc <- length(coef(object))
+ has_intercept <- attr(terms(object), "intercept") > 0.5
+ wald <- if(nc <= has_intercept) NULL else linearHypothesis(object,
+ if(has_intercept) cbind(0, diag(nc-1)) else diag(nc),
+ vcov. = vcov.)[2,3]
+ ## instead of: waldtest(object, vcov = vcov.)
+
+ ## correlation
+ correlation <- if(correlation) cov2cor(vcov.) else NULL
+
+ ## distribution
+ dist <- object$dist
+ if(is.character(dist)) sd <- survreg.distributions[[dist]]
+ else sd <- dist
+ if(length(object$parms)) pprint <- paste(sd$name, "distribution: parmameters =", object$parms)
+ else pprint <- paste(sd$name, "distribution")
+
+ ## number of observations
+ nobs <- as.vector(table(factor(object$y[,2], levels = 2:0)))
+ nobs <- c(sum(nobs), nobs)
+ names(nobs) <- c("Total", "Left-censored", "Uncensored", "Right-censored")
+
+ rval <- object[match(c("call", "df", "loglik", "iter", "na.action", "idf", "scale"),
+ names(object), nomatch = 0)]
+ rval <- c(rval, list(coefficients = coef, correlation = correlation,
+ symbolic.cor = symbolic.cor, parms = pprint, n = nobs, wald = wald))
+
+ class(rval) <- "summary.tobit"
+ return(rval)
+}
+
+print.summary.tobit <- function(x, digits = max(3, getOption("digits") - 3), ...)
+{
+ ## call
+ cat("\nCall:\n")
+ cat(paste(deparse(x$call), sep = "\n", collapse = "\n"), "\n\n", sep = "")
+
+ ## observations and censoring
+ if(length(x$na.action)) cat("Observations: (", naprint(x$na.action), ")\n", sep = "")
+ else cat("Observations:\n")
+ print(x$n)
+
+ ## coefficients
+ if(any(nas <- is.na(x$coefficients[,1])))
+ cat("\nCoefficients: (", sum(nas), " not defined because of singularities)\n", sep = "")
+ else cat("\nCoefficients:\n")
+ printCoefmat(x$coefficients, digits = digits, ...)
+
+ ## scale
+ if("Log(scale)" %in% rownames(x$coefficients))
+ cat("\nScale:", format(x$scale, digits = digits), "\n")
+ else
+ cat("\nScale fixed at", format(x$scale, digits = digits), "\n")
+
+ ## logLik and Chi-squared test
+ cat(paste("\n", x$parms, "\n", sep = ""))
+ cat("Number of Newton-Raphson Iterations:", format(trunc(x$iter)), "\n")
+ cat("Log-likelihood:", formatC(x$loglik[2], digits = digits), "on", x$df, "Df\n")
+ if(!is.null(x$wald)) cat("Wald-statistic:", formatC(x$wald, digits = digits),
+ "on", sum(x$df) - x$idf, "Df, p-value:",
+ format.pval(pchisq(x$wald, sum(x$df) - x$idf, lower.tail = FALSE)), "\n")
+
+ ## correlation
+ correl <- x$correlation
+ if (!is.null(correl)) {
+ p <- NCOL(correl)
+ if (p > 1) {
+ cat("\nCorrelation of Coefficients:\n")
+ if (is.logical(x$symbolic.cor) && x$symbolic.cor) {
+ print(symnum(correl, abbr.colnames = NULL))
+ }
+ else {
+ correl <- format(round(correl, 2), nsmall = 2, digits = digits)
+ correl[!lower.tri(correl)] <- ""
+ print(correl[-1, -p, drop = FALSE], quote = FALSE)
+ }
+ }
+ }
+
+ ## return
+ cat("\n")
+ invisible(x)
+}
+
+
+## as the apparent y ~ ... and actual Surv(y) ~ ... formula
+## differ, some standard functionality has to be done by work-arounds
+
+formula.tobit <- function(x, ...) x$formula
+
+model.frame.tobit <- function(formula, ...)
+{
+ Call <- formula$call
+ Call[[1]] <- as.name("model.frame")
+ Call <- Call[match(c("", "formula", "data", "weights", "subset", "na.action"), names(Call), 0)]
+ dots <- list(...)
+ nargs <- dots[match(c("data", "na.action", "subset"), names(dots), 0)]
+ Call[names(nargs)] <- nargs
+ Call$formula <- formula$formula
+ env <- environment(formula$terms)
+ if(is.null(env)) env <- parent.frame()
+ eval(Call, env)
+}
+
+update.tobit <- function(object, formula., ..., evaluate = TRUE)
+{
+ call <- object$call
+ extras <- match.call(expand.dots = FALSE)$...
+ if(!missing(formula.)) {
+ ff <- formula(object)
+ ff[[2]] <- call$formula[[2]]
+ call$formula <- update.formula(ff, formula.)
+ }
+ if (length(extras) > 0) {
+ existing <- !is.na(match(names(extras), names(call)))
+ for (a in names(extras)[existing]) call[[a]] <- extras[[a]]
+ if (any(!existing)) {
+ call <- c(as.list(call), extras[!existing])
+ call <- as.call(call)
+ }
+ }
+ if(evaluate) eval(call, parent.frame())
+ else call
+}
+
+waldtest.tobit <- function(object, ..., test = c("Chisq", "F"), name = NULL)
+{
+ if(is.null(name)) name <- function(x) paste(deparse(x$call$formula), collapse="\n")
+ waldtest.default(object, ..., test = match.arg(test), name = name)
+}
+
+lrtest.tobit <- function(object, ..., name = NULL)
+{
+ if(is.null(name)) name <- function(x) paste(deparse(x$call$formula), collapse="\n")
+ lrtest.default(object, ..., name = name)
+}
+
+linearHypothesis.tobit <- function(model, hypothesis.matrix,
+ rhs = NULL, vcov. = NULL, ...)
+{
+ if(is.null(vcov.)) {
+ vcov. <- vcov(model)
+ } else {
+ if(is.function(vcov.)) vcov. <- vcov.(model)
+ }
+ vcov. <- vcov.[-nrow(vcov.), -ncol(vcov.)]
+ model$formula <- model$call$formula
+ car::linearHypothesis.default(model,
+ hypothesis.matrix = hypothesis.matrix, rhs = rhs, vcov. = vcov., ...)
+}
diff --git a/build/vignette.rds b/build/vignette.rds
new file mode 100644
index 0000000..e41b5f6
Binary files /dev/null and b/build/vignette.rds differ
diff --git a/data/Affairs.rda b/data/Affairs.rda
new file mode 100644
index 0000000..92a57d8
Binary files /dev/null and b/data/Affairs.rda differ
diff --git a/data/ArgentinaCPI.rda b/data/ArgentinaCPI.rda
new file mode 100644
index 0000000..d896e1a
Binary files /dev/null and b/data/ArgentinaCPI.rda differ
diff --git a/data/BankWages.rda b/data/BankWages.rda
new file mode 100644
index 0000000..0fed5f1
Binary files /dev/null and b/data/BankWages.rda differ
diff --git a/data/BenderlyZwick.rda b/data/BenderlyZwick.rda
new file mode 100644
index 0000000..a9c86a0
Binary files /dev/null and b/data/BenderlyZwick.rda differ
diff --git a/data/BondYield.rda b/data/BondYield.rda
new file mode 100644
index 0000000..af2bde3
Binary files /dev/null and b/data/BondYield.rda differ
diff --git a/data/CASchools.rda b/data/CASchools.rda
new file mode 100644
index 0000000..7198524
Binary files /dev/null and b/data/CASchools.rda differ
diff --git a/data/CPS1985.rda b/data/CPS1985.rda
new file mode 100644
index 0000000..71cdab0
Binary files /dev/null and b/data/CPS1985.rda differ
diff --git a/data/CPS1988.rda b/data/CPS1988.rda
new file mode 100644
index 0000000..5f22224
Binary files /dev/null and b/data/CPS1988.rda differ
diff --git a/data/CPSSW04.rda b/data/CPSSW04.rda
new file mode 100644
index 0000000..c2199fe
Binary files /dev/null and b/data/CPSSW04.rda differ
diff --git a/data/CPSSW3.rda b/data/CPSSW3.rda
new file mode 100644
index 0000000..a4ec986
Binary files /dev/null and b/data/CPSSW3.rda differ
diff --git a/data/CPSSW8.rda b/data/CPSSW8.rda
new file mode 100644
index 0000000..d64e50d
Binary files /dev/null and b/data/CPSSW8.rda differ
diff --git a/data/CPSSW9204.rda b/data/CPSSW9204.rda
new file mode 100644
index 0000000..726b0d1
Binary files /dev/null and b/data/CPSSW9204.rda differ
diff --git a/data/CPSSW9298.rda b/data/CPSSW9298.rda
new file mode 100644
index 0000000..c469caa
Binary files /dev/null and b/data/CPSSW9298.rda differ
diff --git a/data/CPSSWEducation.rda b/data/CPSSWEducation.rda
new file mode 100644
index 0000000..ecb9c77
Binary files /dev/null and b/data/CPSSWEducation.rda differ
diff --git a/data/CartelStability.rda b/data/CartelStability.rda
new file mode 100644
index 0000000..eb96e1e
Binary files /dev/null and b/data/CartelStability.rda differ
diff --git a/data/ChinaIncome.rda b/data/ChinaIncome.rda
new file mode 100644
index 0000000..60fae44
Binary files /dev/null and b/data/ChinaIncome.rda differ
diff --git a/data/CigarettesB.rda b/data/CigarettesB.rda
new file mode 100644
index 0000000..031fd28
Binary files /dev/null and b/data/CigarettesB.rda differ
diff --git a/data/CigarettesSW.rda b/data/CigarettesSW.rda
new file mode 100644
index 0000000..07c3b89
Binary files /dev/null and b/data/CigarettesSW.rda differ
diff --git a/data/CollegeDistance.rda b/data/CollegeDistance.rda
new file mode 100644
index 0000000..c2788dd
Binary files /dev/null and b/data/CollegeDistance.rda differ
diff --git a/data/ConsumerGood.rda b/data/ConsumerGood.rda
new file mode 100644
index 0000000..fa24f48
Binary files /dev/null and b/data/ConsumerGood.rda differ
diff --git a/data/CreditCard.rda b/data/CreditCard.rda
new file mode 100644
index 0000000..739f717
Binary files /dev/null and b/data/CreditCard.rda differ
diff --git a/data/DJFranses.rda b/data/DJFranses.rda
new file mode 100644
index 0000000..ebfa6ed
Binary files /dev/null and b/data/DJFranses.rda differ
diff --git a/data/DJIA8012.rda b/data/DJIA8012.rda
new file mode 100644
index 0000000..9d3e366
Binary files /dev/null and b/data/DJIA8012.rda differ
diff --git a/data/DoctorVisits.rda b/data/DoctorVisits.rda
new file mode 100644
index 0000000..f0c9998
Binary files /dev/null and b/data/DoctorVisits.rda differ
diff --git a/data/DutchAdvert.rda b/data/DutchAdvert.rda
new file mode 100644
index 0000000..59b4a07
Binary files /dev/null and b/data/DutchAdvert.rda differ
diff --git a/data/DutchSales.rda b/data/DutchSales.rda
new file mode 100644
index 0000000..466029c
Binary files /dev/null and b/data/DutchSales.rda differ
diff --git a/data/Electricity1955.rda b/data/Electricity1955.rda
new file mode 100644
index 0000000..6175693
Binary files /dev/null and b/data/Electricity1955.rda differ
diff --git a/data/Electricity1970.rda b/data/Electricity1970.rda
new file mode 100644
index 0000000..bc223a4
Binary files /dev/null and b/data/Electricity1970.rda differ
diff --git a/data/EquationCitations.rda b/data/EquationCitations.rda
new file mode 100644
index 0000000..432fc52
Binary files /dev/null and b/data/EquationCitations.rda differ
diff --git a/data/Equipment.rda b/data/Equipment.rda
new file mode 100644
index 0000000..6d1d6de
Binary files /dev/null and b/data/Equipment.rda differ
diff --git a/data/EuroEnergy.rda b/data/EuroEnergy.rda
new file mode 100644
index 0000000..9e8521e
Binary files /dev/null and b/data/EuroEnergy.rda differ
diff --git a/data/Fatalities.rda b/data/Fatalities.rda
new file mode 100644
index 0000000..3272e3b
Binary files /dev/null and b/data/Fatalities.rda differ
diff --git a/data/Fertility.rda b/data/Fertility.rda
new file mode 100644
index 0000000..67e272e
Binary files /dev/null and b/data/Fertility.rda differ
diff --git a/data/Fertility2.rda b/data/Fertility2.rda
new file mode 100644
index 0000000..6fdb949
Binary files /dev/null and b/data/Fertility2.rda differ
diff --git a/data/FrozenJuice.rda b/data/FrozenJuice.rda
new file mode 100644
index 0000000..05ff322
Binary files /dev/null and b/data/FrozenJuice.rda differ
diff --git a/data/GSOEP9402.rda b/data/GSOEP9402.rda
new file mode 100644
index 0000000..0afe33b
Binary files /dev/null and b/data/GSOEP9402.rda differ
diff --git a/data/GSS7402.rda b/data/GSS7402.rda
new file mode 100644
index 0000000..f19019f
Binary files /dev/null and b/data/GSS7402.rda differ
diff --git a/data/GermanUnemployment.rda b/data/GermanUnemployment.rda
new file mode 100644
index 0000000..6191dec
Binary files /dev/null and b/data/GermanUnemployment.rda differ
diff --git a/data/GoldSilver.rda b/data/GoldSilver.rda
new file mode 100644
index 0000000..5cd3cd7
Binary files /dev/null and b/data/GoldSilver.rda differ
diff --git a/data/GrowthDJ.rda b/data/GrowthDJ.rda
new file mode 100644
index 0000000..095eb06
Binary files /dev/null and b/data/GrowthDJ.rda differ
diff --git a/data/GrowthSW.rda b/data/GrowthSW.rda
new file mode 100644
index 0000000..24c42d1
Binary files /dev/null and b/data/GrowthSW.rda differ
diff --git a/data/Grunfeld.rda b/data/Grunfeld.rda
new file mode 100644
index 0000000..96ff2c5
Binary files /dev/null and b/data/Grunfeld.rda differ
diff --git a/data/Guns.rda b/data/Guns.rda
new file mode 100644
index 0000000..f96f3f0
Binary files /dev/null and b/data/Guns.rda differ
diff --git a/data/HMDA.rda b/data/HMDA.rda
new file mode 100644
index 0000000..ea4a585
Binary files /dev/null and b/data/HMDA.rda differ
diff --git a/data/HealthInsurance.rda b/data/HealthInsurance.rda
new file mode 100644
index 0000000..e65a0c2
Binary files /dev/null and b/data/HealthInsurance.rda differ
diff --git a/data/HousePrices.rda b/data/HousePrices.rda
new file mode 100644
index 0000000..24d7dae
Binary files /dev/null and b/data/HousePrices.rda differ
diff --git a/data/Journals.rda b/data/Journals.rda
new file mode 100644
index 0000000..ca304e6
Binary files /dev/null and b/data/Journals.rda differ
diff --git a/data/KleinI.rda b/data/KleinI.rda
new file mode 100644
index 0000000..1d4a52d
Binary files /dev/null and b/data/KleinI.rda differ
diff --git a/data/Longley.rda b/data/Longley.rda
new file mode 100644
index 0000000..b58769c
Binary files /dev/null and b/data/Longley.rda differ
diff --git a/data/MASchools.rda b/data/MASchools.rda
new file mode 100644
index 0000000..fb76ae0
Binary files /dev/null and b/data/MASchools.rda differ
diff --git a/data/MSCISwitzerland.rda b/data/MSCISwitzerland.rda
new file mode 100644
index 0000000..f69617b
Binary files /dev/null and b/data/MSCISwitzerland.rda differ
diff --git a/data/ManufactCosts.rda b/data/ManufactCosts.rda
new file mode 100644
index 0000000..93b3b6a
Binary files /dev/null and b/data/ManufactCosts.rda differ
diff --git a/data/MarkDollar.rda b/data/MarkDollar.rda
new file mode 100644
index 0000000..c0a8f3b
Binary files /dev/null and b/data/MarkDollar.rda differ
diff --git a/data/MarkPound.rda b/data/MarkPound.rda
new file mode 100644
index 0000000..7790c68
Binary files /dev/null and b/data/MarkPound.rda differ
diff --git a/data/Medicaid1986.rda b/data/Medicaid1986.rda
new file mode 100644
index 0000000..676cd62
Binary files /dev/null and b/data/Medicaid1986.rda differ
diff --git a/data/Mortgage.rda b/data/Mortgage.rda
new file mode 100644
index 0000000..a340327
Binary files /dev/null and b/data/Mortgage.rda differ
diff --git a/data/MotorCycles.rda b/data/MotorCycles.rda
new file mode 100644
index 0000000..3073e19
Binary files /dev/null and b/data/MotorCycles.rda differ
diff --git a/data/MotorCycles2.rda b/data/MotorCycles2.rda
new file mode 100644
index 0000000..a002b0e
Binary files /dev/null and b/data/MotorCycles2.rda differ
diff --git a/data/Municipalities.rda b/data/Municipalities.rda
new file mode 100644
index 0000000..a46b50a
Binary files /dev/null and b/data/Municipalities.rda differ
diff --git a/data/MurderRates.rda b/data/MurderRates.rda
new file mode 100644
index 0000000..37c2a71
Binary files /dev/null and b/data/MurderRates.rda differ
diff --git a/data/NMES1988.rda b/data/NMES1988.rda
new file mode 100644
index 0000000..30b1144
Binary files /dev/null and b/data/NMES1988.rda differ
diff --git a/data/NYSESW.rda b/data/NYSESW.rda
new file mode 100644
index 0000000..41884ee
Binary files /dev/null and b/data/NYSESW.rda differ
diff --git a/data/NaturalGas.rda b/data/NaturalGas.rda
new file mode 100644
index 0000000..dd2a9d5
Binary files /dev/null and b/data/NaturalGas.rda differ
diff --git a/data/OECDGas.rda b/data/OECDGas.rda
new file mode 100644
index 0000000..5144fbc
Binary files /dev/null and b/data/OECDGas.rda differ
diff --git a/data/OECDGrowth.rda b/data/OECDGrowth.rda
new file mode 100644
index 0000000..5cdeda5
Binary files /dev/null and b/data/OECDGrowth.rda differ
diff --git a/data/OlympicTV.rda b/data/OlympicTV.rda
new file mode 100644
index 0000000..28b02e4
Binary files /dev/null and b/data/OlympicTV.rda differ
diff --git a/data/OrangeCounty.rda b/data/OrangeCounty.rda
new file mode 100644
index 0000000..d5a9bf0
Binary files /dev/null and b/data/OrangeCounty.rda differ
diff --git a/data/PSID1976.rda b/data/PSID1976.rda
new file mode 100644
index 0000000..e55e206
Binary files /dev/null and b/data/PSID1976.rda differ
diff --git a/data/PSID1982.rda b/data/PSID1982.rda
new file mode 100644
index 0000000..67252b9
Binary files /dev/null and b/data/PSID1982.rda differ
diff --git a/data/PSID7682.rda b/data/PSID7682.rda
new file mode 100644
index 0000000..b2b1854
Binary files /dev/null and b/data/PSID7682.rda differ
diff --git a/data/Parade2005.rda b/data/Parade2005.rda
new file mode 100644
index 0000000..573f600
Binary files /dev/null and b/data/Parade2005.rda differ
diff --git a/data/PepperPrice.rda b/data/PepperPrice.rda
new file mode 100644
index 0000000..68a0e12
Binary files /dev/null and b/data/PepperPrice.rda differ
diff --git a/data/PhDPublications.rda b/data/PhDPublications.rda
new file mode 100644
index 0000000..5d4faed
Binary files /dev/null and b/data/PhDPublications.rda differ
diff --git a/data/ProgramEffectiveness.rda b/data/ProgramEffectiveness.rda
new file mode 100644
index 0000000..976e962
Binary files /dev/null and b/data/ProgramEffectiveness.rda differ
diff --git a/data/RecreationDemand.rda b/data/RecreationDemand.rda
new file mode 100644
index 0000000..5c186f2
Binary files /dev/null and b/data/RecreationDemand.rda differ
diff --git a/data/ResumeNames.rda b/data/ResumeNames.rda
new file mode 100644
index 0000000..2523e80
Binary files /dev/null and b/data/ResumeNames.rda differ
diff --git a/data/SIC33.rda b/data/SIC33.rda
new file mode 100644
index 0000000..d65547e
Binary files /dev/null and b/data/SIC33.rda differ
diff --git a/data/STAR.rda b/data/STAR.rda
new file mode 100644
index 0000000..af9afb8
Binary files /dev/null and b/data/STAR.rda differ
diff --git a/data/ShipAccidents.rda b/data/ShipAccidents.rda
new file mode 100644
index 0000000..eee022c
Binary files /dev/null and b/data/ShipAccidents.rda differ
diff --git a/data/SmokeBan.rda b/data/SmokeBan.rda
new file mode 100644
index 0000000..95d15a5
Binary files /dev/null and b/data/SmokeBan.rda differ
diff --git a/data/SportsCards.rda b/data/SportsCards.rda
new file mode 100644
index 0000000..576a45a
Binary files /dev/null and b/data/SportsCards.rda differ
diff --git a/data/StrikeDuration.rda b/data/StrikeDuration.rda
new file mode 100644
index 0000000..ee4289c
Binary files /dev/null and b/data/StrikeDuration.rda differ
diff --git a/data/SwissLabor.rda b/data/SwissLabor.rda
new file mode 100644
index 0000000..e5deac7
Binary files /dev/null and b/data/SwissLabor.rda differ
diff --git a/data/TeachingRatings.rda b/data/TeachingRatings.rda
new file mode 100644
index 0000000..eecc6ae
Binary files /dev/null and b/data/TeachingRatings.rda differ
diff --git a/data/TechChange.rda b/data/TechChange.rda
new file mode 100644
index 0000000..4402252
Binary files /dev/null and b/data/TechChange.rda differ
diff --git a/data/TradeCredit.rda b/data/TradeCredit.rda
new file mode 100644
index 0000000..9526949
Binary files /dev/null and b/data/TradeCredit.rda differ
diff --git a/data/TravelMode.rda b/data/TravelMode.rda
new file mode 100644
index 0000000..803c02f
Binary files /dev/null and b/data/TravelMode.rda differ
diff --git a/data/UKInflation.rda b/data/UKInflation.rda
new file mode 100644
index 0000000..7d97710
Binary files /dev/null and b/data/UKInflation.rda differ
diff --git a/data/UKNonDurables.rda b/data/UKNonDurables.rda
new file mode 100644
index 0000000..1df9cf4
Binary files /dev/null and b/data/UKNonDurables.rda differ
diff --git a/data/USAirlines.rda b/data/USAirlines.rda
new file mode 100644
index 0000000..6c6b186
Binary files /dev/null and b/data/USAirlines.rda differ
diff --git a/data/USConsump1950.rda b/data/USConsump1950.rda
new file mode 100644
index 0000000..df32613
Binary files /dev/null and b/data/USConsump1950.rda differ
diff --git a/data/USConsump1979.rda b/data/USConsump1979.rda
new file mode 100644
index 0000000..7a2e129
Binary files /dev/null and b/data/USConsump1979.rda differ
diff --git a/data/USConsump1993.rda b/data/USConsump1993.rda
new file mode 100644
index 0000000..7621ef6
Binary files /dev/null and b/data/USConsump1993.rda differ
diff --git a/data/USCrudes.rda b/data/USCrudes.rda
new file mode 100644
index 0000000..e6cad06
Binary files /dev/null and b/data/USCrudes.rda differ
diff --git a/data/USGasB.rda b/data/USGasB.rda
new file mode 100644
index 0000000..30cf851
Binary files /dev/null and b/data/USGasB.rda differ
diff --git a/data/USGasG.rda b/data/USGasG.rda
new file mode 100644
index 0000000..940f5e3
Binary files /dev/null and b/data/USGasG.rda differ
diff --git a/data/USInvest.rda b/data/USInvest.rda
new file mode 100644
index 0000000..b295cc8
Binary files /dev/null and b/data/USInvest.rda differ
diff --git a/data/USMacroB.rda b/data/USMacroB.rda
new file mode 100644
index 0000000..87f5caa
Binary files /dev/null and b/data/USMacroB.rda differ
diff --git a/data/USMacroG.rda b/data/USMacroG.rda
new file mode 100644
index 0000000..dbac004
Binary files /dev/null and b/data/USMacroG.rda differ
diff --git a/data/USMacroSW.rda b/data/USMacroSW.rda
new file mode 100644
index 0000000..6ccfcd7
Binary files /dev/null and b/data/USMacroSW.rda differ
diff --git a/data/USMacroSWM.rda b/data/USMacroSWM.rda
new file mode 100644
index 0000000..f8f0e22
Binary files /dev/null and b/data/USMacroSWM.rda differ
diff --git a/data/USMacroSWQ.rda b/data/USMacroSWQ.rda
new file mode 100644
index 0000000..757d994
Binary files /dev/null and b/data/USMacroSWQ.rda differ
diff --git a/data/USMoney.rda b/data/USMoney.rda
new file mode 100644
index 0000000..9c21159
Binary files /dev/null and b/data/USMoney.rda differ
diff --git a/data/USProdIndex.rda b/data/USProdIndex.rda
new file mode 100644
index 0000000..45f185b
Binary files /dev/null and b/data/USProdIndex.rda differ
diff --git a/data/USSeatBelts.rda b/data/USSeatBelts.rda
new file mode 100644
index 0000000..6dee3c5
Binary files /dev/null and b/data/USSeatBelts.rda differ
diff --git a/data/USStocksSW.rda b/data/USStocksSW.rda
new file mode 100644
index 0000000..d7923d0
Binary files /dev/null and b/data/USStocksSW.rda differ
diff --git a/data/WeakInstrument.rda b/data/WeakInstrument.rda
new file mode 100644
index 0000000..2851bbf
Binary files /dev/null and b/data/WeakInstrument.rda differ
diff --git a/data/datalist b/data/datalist
new file mode 100644
index 0000000..4cd6d5c
--- /dev/null
+++ b/data/datalist
@@ -0,0 +1,107 @@
+Affairs
+ArgentinaCPI
+BankWages
+BenderlyZwick
+BondYield
+CASchools
+CPS1985
+CPS1988
+CPSSW04
+CPSSW3
+CPSSW8
+CPSSW9204
+CPSSW9298
+CPSSWEducation
+CartelStability
+ChinaIncome
+CigarettesB
+CigarettesSW
+CollegeDistance
+ConsumerGood
+CreditCard
+DJFranses
+DJIA8012
+DoctorVisits
+DutchAdvert
+DutchSales
+Electricity1955
+Electricity1970
+EquationCitations
+Equipment
+EuroEnergy
+Fatalities
+Fertility
+Fertility2
+FrozenJuice
+GSOEP9402
+GSS7402
+GermanUnemployment
+GoldSilver
+GrowthDJ
+GrowthSW
+Grunfeld
+Guns
+HMDA
+HealthInsurance
+HousePrices
+Journals
+KleinI
+Longley
+MASchools
+MSCISwitzerland
+ManufactCosts
+MarkDollar
+MarkPound
+Medicaid1986
+Mortgage
+MotorCycles
+MotorCycles2
+Municipalities
+MurderRates
+NMES1988
+NYSESW
+NaturalGas
+OECDGas
+OECDGrowth
+OlympicTV
+OrangeCounty
+PSID1976
+PSID1982
+PSID7682
+Parade2005
+PepperPrice
+PhDPublications
+ProgramEffectiveness
+RecreationDemand
+ResumeNames
+SIC33
+STAR
+ShipAccidents
+SmokeBan
+SportsCards
+StrikeDuration
+SwissLabor
+TeachingRatings
+TechChange
+TradeCredit
+TravelMode
+UKInflation
+UKNonDurables
+USAirlines
+USConsump1950
+USConsump1979
+USConsump1993
+USCrudes
+USGasB
+USGasG
+USInvest
+USMacroB
+USMacroG
+USMacroSW
+USMacroSWM
+USMacroSWQ
+USMoney
+USProdIndex
+USSeatBelts
+USStocksSW
+WeakInstrument
diff --git a/demo/00Index b/demo/00Index
new file mode 100644
index 0000000..1cac8d2
--- /dev/null
+++ b/demo/00Index
@@ -0,0 +1,7 @@
+Ch-Intro Chapter 1: Introduction
+Ch-Basics Chapter 2: Basics
+Ch-LinearRegression Chapter 3: Linear Regression
+Ch-Validation Chapter 4: Diagnostics and Alternative Methods of Regression
+Ch-Microeconometrics Chapter 5: Models of Microeconometrics
+Ch-TimeSeries Chapter 6: Time Series
+Ch-Programming Chapter 7: Programming Your Own Analysis
diff --git a/demo/Ch-Basics.R b/demo/Ch-Basics.R
new file mode 100644
index 0000000..5321b3d
--- /dev/null
+++ b/demo/Ch-Basics.R
@@ -0,0 +1,794 @@
+###################################################
+### chunk number 1: setup
+###################################################
+options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+
+options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
+
+library("AER")
+
+set.seed(1071)
+
+
+###################################################
+### chunk number 2: calc1
+###################################################
+1 + 1
+2^3
+
+
+###################################################
+### chunk number 3: calc2
+###################################################
+log(exp(sin(pi/4)^2) * exp(cos(pi/4)^2))
+
+
+###################################################
+### chunk number 4: vec1
+###################################################
+x <- c(1.8, 3.14, 4, 88.169, 13)
+
+
+###################################################
+### chunk number 5: length
+###################################################
+length(x)
+
+
+###################################################
+### chunk number 6: vec2
+###################################################
+2 * x + 3
+5:1 * x + 1:5
+
+
+###################################################
+### chunk number 7: vec3
+###################################################
+log(x)
+
+
+###################################################
+### chunk number 8: subset1
+###################################################
+x[c(1, 4)]
+
+
+###################################################
+### chunk number 9: subset2
+###################################################
+x[-c(2, 3, 5)]
+
+
+###################################################
+### chunk number 10: pattern1
+###################################################
+ones <- rep(1, 10)
+even <- seq(from = 2, to = 20, by = 2)
+trend <- 1981:2005
+
+
+###################################################
+### chunk number 11: pattern2
+###################################################
+c(ones, even)
+
+
+###################################################
+### chunk number 12: matrix1
+###################################################
+A <- matrix(1:6, nrow = 2)
+
+
+###################################################
+### chunk number 13: matrix2
+###################################################
+t(A)
+
+
+###################################################
+### chunk number 14: matrix3
+###################################################
+dim(A)
+nrow(A)
+ncol(A)
+
+
+###################################################
+### chunk number 15: matrix-subset
+###################################################
+A1 <- A[1:2, c(1, 3)]
+
+
+###################################################
+### chunk number 16: matrix4
+###################################################
+solve(A1)
+
+
+###################################################
+### chunk number 17: matrix-solve
+###################################################
+A1 %*% solve(A1)
+
+
+###################################################
+### chunk number 18: diag
+###################################################
+diag(4)
+
+
+###################################################
+### chunk number 19: matrix-combine1
+###################################################
+cbind(1, A1)
+
+
+###################################################
+### chunk number 20: matrix-combine2
+###################################################
+rbind(A1, diag(4, 2))
+
+
+###################################################
+### chunk number 21: vector-mode
+###################################################
+x <- c(1.8, 3.14, 4, 88.169, 13)
+
+
+###################################################
+### chunk number 22: logical
+###################################################
+x > 3.5
+
+
+###################################################
+### chunk number 23: names
+###################################################
+names(x) <- c("a", "b", "c", "d", "e")
+x
+
+
+###################################################
+### chunk number 24: subset-more
+###################################################
+x[3:5]
+x[c("c", "d", "e")]
+x[x > 3.5]
+
+
+###################################################
+### chunk number 25: list1
+###################################################
+mylist <- list(sample = rnorm(5),
+ family = "normal distribution",
+ parameters = list(mean = 0, sd = 1))
+mylist
+
+
+###################################################
+### chunk number 26: list2
+###################################################
+mylist[[1]]
+mylist[["sample"]]
+mylist$sample
+
+
+###################################################
+### chunk number 27: list3
+###################################################
+mylist[[3]]$sd
+
+
+###################################################
+### chunk number 28: logical2
+###################################################
+x <- c(1.8, 3.14, 4, 88.169, 13)
+x > 3 & x <= 4
+
+
+###################################################
+### chunk number 29: logical3
+###################################################
+which(x > 3 & x <= 4)
+
+
+###################################################
+### chunk number 30: logical4
+###################################################
+all(x > 3)
+any(x > 3)
+
+
+###################################################
+### chunk number 31: logical5
+###################################################
+(1.5 - 0.5) == 1
+(1.9 - 0.9) == 1
+
+
+###################################################
+### chunk number 32: logical6
+###################################################
+all.equal(1.9 - 0.9, 1)
+
+
+###################################################
+### chunk number 33: logical7
+###################################################
+7 + TRUE
+
+
+###################################################
+### chunk number 34: coercion1
+###################################################
+is.numeric(x)
+is.character(x)
+as.character(x)
+
+
+###################################################
+### chunk number 35: coercion2
+###################################################
+c(1, "a")
+
+
+###################################################
+### chunk number 36: rng1
+###################################################
+set.seed(123)
+rnorm(2)
+rnorm(2)
+set.seed(123)
+rnorm(2)
+
+
+###################################################
+### chunk number 37: rng2
+###################################################
+sample(1:5)
+sample(c("male", "female"), size = 5, replace = TRUE,
+ prob = c(0.2, 0.8))
+
+
+###################################################
+### chunk number 38: flow1
+###################################################
+x <- c(1.8, 3.14, 4, 88.169, 13)
+if(rnorm(1) > 0) sum(x) else mean(x)
+
+
+###################################################
+### chunk number 39: flow2
+###################################################
+ifelse(x > 4, sqrt(x), x^2)
+
+
+###################################################
+### chunk number 40: flow3
+###################################################
+for(i in 2:5) {
+ x[i] <- x[i] - x[i-1]
+}
+x[-1]
+
+
+###################################################
+### chunk number 41: flow4
+###################################################
+while(sum(x) < 100) {
+ x <- 2 * x
+}
+x
+
+
+###################################################
+### chunk number 42: cmeans
+###################################################
+cmeans <- function(X) {
+ rval <- rep(0, ncol(X))
+ for(j in 1:ncol(X)) {
+ mysum <- 0
+ for(i in 1:nrow(X)) mysum <- mysum + X[i,j]
+ rval[j] <- mysum/nrow(X)
+ }
+ return(rval)
+}
+
+
+###################################################
+### chunk number 43: colmeans1
+###################################################
+X <- matrix(1:20, ncol = 2)
+cmeans(X)
+
+
+###################################################
+### chunk number 44: colmeans2
+###################################################
+colMeans(X)
+
+
+###################################################
+### chunk number 45: colmeans3
+###################################################
+X <- matrix(rnorm(2*10^6), ncol = 2)
+system.time(colMeans(X))
+system.time(cmeans(X))
+
+
+###################################################
+### chunk number 46: colmeans4
+###################################################
+cmeans2 <- function(X) {
+ rval <- rep(0, ncol(X))
+ for(j in 1:ncol(X)) rval[j] <- mean(X[,j])
+ return(rval)
+}
+
+
+###################################################
+### chunk number 47: colmeans5
+###################################################
+system.time(cmeans2(X))
+
+
+###################################################
+### chunk number 48: colmeans6 eval=FALSE
+###################################################
+## apply(X, 2, mean)
+
+
+###################################################
+### chunk number 49: colmeans7
+###################################################
+system.time(apply(X, 2, mean))
+
+
+###################################################
+### chunk number 50: formula1
+###################################################
+f <- y ~ x
+class(f)
+
+
+###################################################
+### chunk number 51: formula2
+###################################################
+x <- seq(from = 0, to = 10, by = 0.5)
+y <- 2 + 3 * x + rnorm(21)
+
+
+###################################################
+### chunk number 52: formula3 eval=FALSE
+###################################################
+## plot(y ~ x)
+## lm(y ~ x)
+
+
+###################################################
+### chunk number 53: formula3a
+###################################################
+print(lm(y ~ x))
+
+
+###################################################
+### chunk number 54: formula3b
+###################################################
+plot(y ~ x)
+
+
+###################################################
+### chunk number 55: formula3c
+###################################################
+fm <- lm(y ~ x)
+
+
+###################################################
+### chunk number 56: mydata1
+###################################################
+mydata <- data.frame(one = 1:10, two = 11:20, three = 21:30)
+
+
+###################################################
+### chunk number 57: mydata1a
+###################################################
+mydata <- as.data.frame(matrix(1:30, ncol = 3))
+names(mydata) <- c("one", "two", "three")
+
+
+###################################################
+### chunk number 58: mydata2
+###################################################
+mydata$two
+mydata[, "two"]
+mydata[, 2]
+
+
+###################################################
+### chunk number 59: attach
+###################################################
+attach(mydata)
+mean(two)
+detach(mydata)
+
+
+###################################################
+### chunk number 60: with
+###################################################
+with(mydata, mean(two))
+
+
+###################################################
+### chunk number 61: mydata-subset
+###################################################
+mydata.sub <- subset(mydata, two <= 16, select = -two)
+
+
+###################################################
+### chunk number 62: write-table
+###################################################
+write.table(mydata, file = "mydata.txt", col.names = TRUE)
+
+
+###################################################
+### chunk number 63: read-table
+###################################################
+newdata <- read.table("mydata.txt", header = TRUE)
+
+
+###################################################
+### chunk number 64: save
+###################################################
+save(mydata, file = "mydata.rda")
+
+
+###################################################
+### chunk number 65: load
+###################################################
+load("mydata.rda")
+
+
+###################################################
+### chunk number 66: file-remove
+###################################################
+file.remove("mydata.rda")
+
+
+###################################################
+### chunk number 67: data
+###################################################
+data("Journals", package = "AER")
+
+
+###################################################
+### chunk number 68: foreign
+###################################################
+library("foreign")
+write.dta(mydata, file = "mydata.dta")
+
+
+###################################################
+### chunk number 69: read-dta
+###################################################
+mydata <- read.dta("mydata.dta")
+
+
+###################################################
+### chunk number 70: cleanup
+###################################################
+file.remove("mydata.dta")
+
+
+###################################################
+### chunk number 71: factor
+###################################################
+g <- rep(0:1, c(2, 4))
+g <- factor(g, levels = 0:1, labels = c("male", "female"))
+g
+
+
+###################################################
+### chunk number 72: na1
+###################################################
+newdata <- read.table("mydata.txt", na.strings = "-999")
+
+
+###################################################
+### chunk number 73: na2
+###################################################
+file.remove("mydata.txt")
+
+
+###################################################
+### chunk number 74: oop1
+###################################################
+x <- c(1.8, 3.14, 4, 88.169, 13)
+g <- factor(rep(c(0, 1), c(2, 4)), levels = c(0, 1),
+ labels = c("male", "female"))
+
+
+###################################################
+### chunk number 75: oop2
+###################################################
+summary(x)
+summary(g)
+
+
+###################################################
+### chunk number 76: oop3
+###################################################
+class(x)
+class(g)
+
+
+###################################################
+### chunk number 77: oop4
+###################################################
+summary
+
+
+###################################################
+### chunk number 78: oop5
+###################################################
+normsample <- function(n, ...) {
+ rval <- rnorm(n, ...)
+ class(rval) <- "normsample"
+ return(rval)
+}
+
+
+###################################################
+### chunk number 79: oop6
+###################################################
+set.seed(123)
+x <- normsample(10, mean = 5)
+class(x)
+
+
+###################################################
+### chunk number 80: oop7
+###################################################
+summary.normsample <- function(object, ...) {
+ rval <- c(length(object), mean(object), sd(object))
+ names(rval) <- c("sample size","mean","standard deviation")
+ return(rval)
+}
+
+
+###################################################
+### chunk number 81: oop8
+###################################################
+summary(x)
+
+
+###################################################
+### chunk number 82: journals-data eval=FALSE
+###################################################
+## data("Journals")
+## Journals$citeprice <- Journals$price/Journals$citations
+## attach(Journals)
+## plot(log(subs), log(citeprice))
+## rug(log(subs))
+## rug(log(citeprice), side = 2)
+## detach(Journals)
+
+
+###################################################
+### chunk number 83: journals-data1
+###################################################
+data("Journals")
+Journals$citeprice <- Journals$price/Journals$citations
+attach(Journals)
+plot(log(subs), log(citeprice))
+rug(log(subs))
+rug(log(citeprice), side = 2)
+detach(Journals)
+
+
+###################################################
+### chunk number 84: plot-formula
+###################################################
+plot(log(subs) ~ log(citeprice), data = Journals)
+
+
+###################################################
+### chunk number 85: graphics1
+###################################################
+plot(log(subs) ~ log(citeprice), data = Journals, pch = 20,
+ col = "blue", ylim = c(0, 8), xlim = c(-7, 4),
+ main = "Library subscriptions")
+
+
+###################################################
+### chunk number 86: graphics2
+###################################################
+pdf("myfile.pdf", height = 5, width = 6)
+plot(1:20, pch = 1:20, col = 1:20, cex = 2)
+dev.off()
+
+
+###################################################
+### chunk number 87: dnorm-annotate eval=FALSE
+###################################################
+## curve(dnorm, from = -5, to = 5, col = "slategray", lwd = 3,
+## main = "Density of the standard normal distribution")
+## text(-5, 0.3, expression(f(x) == frac(1, sigma ~~
+## sqrt(2*pi)) ~~ e^{-frac((x - mu)^2, 2*sigma^2)}), adj = 0)
+
+
+###################################################
+### chunk number 88: dnorm-annotate1
+###################################################
+curve(dnorm, from = -5, to = 5, col = "slategray", lwd = 3,
+ main = "Density of the standard normal distribution")
+text(-5, 0.3, expression(f(x) == frac(1, sigma ~~
+ sqrt(2*pi)) ~~ e^{-frac((x - mu)^2, 2*sigma^2)}), adj = 0)
+
+
+###################################################
+### chunk number 89: eda1
+###################################################
+data("CPS1985")
+str(CPS1985)
+
+
+###################################################
+### chunk number 90: eda2
+###################################################
+head(CPS1985)
+
+
+###################################################
+### chunk number 91: eda3
+###################################################
+levels(CPS1985$occupation)[c(2, 6)] <- c("techn", "mgmt")
+attach(CPS1985)
+
+
+###################################################
+### chunk number 92: eda4
+###################################################
+summary(wage)
+
+
+###################################################
+### chunk number 93: eda5
+###################################################
+mean(wage)
+median(wage)
+
+
+###################################################
+### chunk number 94: eda6
+###################################################
+var(wage)
+sd(wage)
+
+
+###################################################
+### chunk number 95: wage-hist
+###################################################
+hist(wage, freq = FALSE)
+hist(log(wage), freq = FALSE)
+lines(density(log(wage)), col = 4)
+
+
+###################################################
+### chunk number 96: wage-hist1
+###################################################
+hist(wage, freq = FALSE)
+hist(log(wage), freq = FALSE)
+lines(density(log(wage)), col = 4)
+
+
+###################################################
+### chunk number 97: occ-table
+###################################################
+summary(occupation)
+
+
+###################################################
+### chunk number 98: occ-table
+###################################################
+tab <- table(occupation)
+prop.table(tab)
+
+
+###################################################
+### chunk number 99: occ-barpie
+###################################################
+barplot(tab)
+pie(tab)
+
+
+###################################################
+### chunk number 100: occ-barpie
+###################################################
+par(mar = c(4, 3, 1, 1))
+barplot(tab, las = 3)
+par(mar = c(2, 3, 1, 3))
+pie(tab, radius = 1)
+
+
+###################################################
+### chunk number 101: xtabs
+###################################################
+xtabs(~ gender + occupation, data = CPS1985)
+
+
+###################################################
+### chunk number 102: spine eval=FALSE
+###################################################
+## plot(gender ~ occupation, data = CPS1985)
+
+
+###################################################
+### chunk number 103: spine1
+###################################################
+plot(gender ~ occupation, data = CPS1985)
+
+
+###################################################
+### chunk number 104: wageeduc-cor
+###################################################
+cor(log(wage), education)
+cor(log(wage), education, method = "spearman")
+
+
+###################################################
+### chunk number 105: wageeduc-scatter eval=FALSE
+###################################################
+## plot(log(wage) ~ education)
+
+
+###################################################
+### chunk number 106: wageeduc-scatter1
+###################################################
+plot(log(wage) ~ education)
+
+
+###################################################
+### chunk number 107: tapply
+###################################################
+tapply(log(wage), gender, mean)
+
+
+###################################################
+### chunk number 108: boxqq1 eval=FALSE
+###################################################
+## plot(log(wage) ~ gender)
+
+
+###################################################
+### chunk number 109: boxqq2 eval=FALSE
+###################################################
+## mwage <- subset(CPS1985, gender == "male")$wage
+## fwage <- subset(CPS1985, gender == "female")$wage
+## qqplot(mwage, fwage, xlim = range(wage), ylim = range(wage),
+## xaxs = "i", yaxs = "i", xlab = "male", ylab = "female")
+## abline(0, 1)
+
+
+###################################################
+### chunk number 110: qq
+###################################################
+plot(log(wage) ~ gender)
+mwage <- subset(CPS1985, gender == "male")$wage
+fwage <- subset(CPS1985, gender == "female")$wage
+qqplot(mwage, fwage, xlim = range(wage), ylim = range(wage),
+ xaxs = "i", yaxs = "i", xlab = "male", ylab = "female")
+abline(0, 1)
+
+
+###################################################
+### chunk number 111: detach
+###################################################
+detach(CPS1985)
+
+
diff --git a/demo/Ch-Intro.R b/demo/Ch-Intro.R
new file mode 100644
index 0000000..4c27a01
--- /dev/null
+++ b/demo/Ch-Intro.R
@@ -0,0 +1,211 @@
+###################################################
+### chunk number 1: setup
+###################################################
+options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+
+options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
+
+library("AER")
+
+set.seed(1071)
+
+
+###################################################
+### chunk number 2: journals-data
+###################################################
+data("Journals", package = "AER")
+
+
+###################################################
+### chunk number 3: journals-dim
+###################################################
+dim(Journals)
+names(Journals)
+
+
+###################################################
+### chunk number 4: journals-plot eval=FALSE
+###################################################
+## plot(log(subs) ~ log(price/citations), data = Journals)
+
+
+###################################################
+### chunk number 5: journals-lm eval=FALSE
+###################################################
+## j_lm <- lm(log(subs) ~ log(price/citations), data = Journals)
+## abline(j_lm)
+
+
+###################################################
+### chunk number 6: journals-lmplot
+###################################################
+plot(log(subs) ~ log(price/citations), data = Journals)
+j_lm <- lm(log(subs) ~ log(price/citations), data = Journals)
+abline(j_lm)
+
+
+###################################################
+### chunk number 7: journals-lm-summary
+###################################################
+summary(j_lm)
+
+
+###################################################
+### chunk number 8: cps-data
+###################################################
+data("CPS1985", package = "AER")
+cps <- CPS1985
+
+
+###################################################
+### chunk number 9: cps-data1 eval=FALSE
+###################################################
+## data("CPS1985", package = "AER")
+## cps <- CPS1985
+
+
+###################################################
+### chunk number 10: cps-reg
+###################################################
+library("quantreg")
+cps_lm <- lm(log(wage) ~ experience + I(experience^2) +
+ education, data = cps)
+cps_rq <- rq(log(wage) ~ experience + I(experience^2) +
+ education, data = cps, tau = seq(0.2, 0.8, by = 0.15))
+
+
+###################################################
+### chunk number 11: cps-predict
+###################################################
+cps2 <- data.frame(education = mean(cps$education),
+ experience = min(cps$experience):max(cps$experience))
+cps2 <- cbind(cps2, predict(cps_lm, newdata = cps2,
+ interval = "prediction"))
+cps2 <- cbind(cps2,
+ predict(cps_rq, newdata = cps2, type = ""))
+
+
+###################################################
+### chunk number 12: rq-plot eval=FALSE
+###################################################
+## plot(log(wage) ~ experience, data = cps)
+## for(i in 6:10) lines(cps2[,i] ~ experience,
+## data = cps2, col = "red")
+
+
+###################################################
+### chunk number 13: rq-plot1
+###################################################
+plot(log(wage) ~ experience, data = cps)
+for(i in 6:10) lines(cps2[,i] ~ experience,
+ data = cps2, col = "red")
+
+
+###################################################
+### chunk number 14: srq-plot eval=FALSE
+###################################################
+## plot(summary(cps_rq))
+
+
+###################################################
+### chunk number 15: srq-plot1
+###################################################
+plot(summary(cps_rq))
+
+
+###################################################
+### chunk number 16: bkde-fit
+###################################################
+library("KernSmooth")
+cps_bkde <- bkde2D(cbind(cps$experience, log(cps$wage)),
+ bandwidth = c(3.5, 0.5), gridsize = c(200, 200))
+
+
+###################################################
+### chunk number 17: bkde-plot eval=FALSE
+###################################################
+## image(cps_bkde$x1, cps_bkde$x2, cps_bkde$fhat,
+## col = rev(gray.colors(10, gamma = 1)),
+## xlab = "experience", ylab = "log(wage)")
+## box()
+## lines(fit ~ experience, data = cps2)
+## lines(lwr ~ experience, data = cps2, lty = 2)
+## lines(upr ~ experience, data = cps2, lty = 2)
+
+
+###################################################
+### chunk number 18: bkde-plot1
+###################################################
+image(cps_bkde$x1, cps_bkde$x2, cps_bkde$fhat,
+ col = rev(gray.colors(10, gamma = 1)),
+ xlab = "experience", ylab = "log(wage)")
+box()
+lines(fit ~ experience, data = cps2)
+lines(lwr ~ experience, data = cps2, lty = 2)
+lines(upr ~ experience, data = cps2, lty = 2)
+
+
+###################################################
+### chunk number 19: install eval=FALSE
+###################################################
+## install.packages("AER")
+
+
+###################################################
+### chunk number 20: library
+###################################################
+library("AER")
+
+
+###################################################
+### chunk number 21: objects
+###################################################
+objects()
+
+
+###################################################
+### chunk number 22: search
+###################################################
+search()
+
+
+###################################################
+### chunk number 23: assignment
+###################################################
+x <- 2
+objects()
+
+
+###################################################
+### chunk number 24: remove
+###################################################
+remove(x)
+objects()
+
+
+###################################################
+### chunk number 25: log eval=FALSE
+###################################################
+## log(16, 2)
+## log(x = 16, 2)
+## log(16, base = 2)
+## log(base = 2, x = 16)
+
+
+###################################################
+### chunk number 26: q eval=FALSE
+###################################################
+## q()
+
+
+###################################################
+### chunk number 27: apropos
+###################################################
+apropos("help")
+
+
diff --git a/demo/Ch-LinearRegression.R b/demo/Ch-LinearRegression.R
new file mode 100644
index 0000000..cd67d9b
--- /dev/null
+++ b/demo/Ch-LinearRegression.R
@@ -0,0 +1,599 @@
+###################################################
+### chunk number 1: setup
+###################################################
+options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+
+options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
+
+library("AER")
+
+set.seed(1071)
+
+
+###################################################
+### chunk number 2: data-journals
+###################################################
+data("Journals")
+journals <- Journals[, c("subs", "price")]
+journals$citeprice <- Journals$price/Journals$citations
+summary(journals)
+
+
+###################################################
+### chunk number 3: linreg-plot eval=FALSE
+###################################################
+## plot(log(subs) ~ log(citeprice), data = journals)
+## jour_lm <- lm(log(subs) ~ log(citeprice), data = journals)
+## abline(jour_lm)
+
+
+###################################################
+### chunk number 4: linreg-plot1
+###################################################
+plot(log(subs) ~ log(citeprice), data = journals)
+jour_lm <- lm(log(subs) ~ log(citeprice), data = journals)
+abline(jour_lm)
+
+
+###################################################
+### chunk number 5: linreg-class
+###################################################
+class(jour_lm)
+
+
+###################################################
+### chunk number 6: linreg-names
+###################################################
+names(jour_lm)
+
+
+###################################################
+### chunk number 7: linreg-summary
+###################################################
+summary(jour_lm)
+
+
+###################################################
+### chunk number 8: linreg-summary
+###################################################
+jour_slm <- summary(jour_lm)
+class(jour_slm)
+names(jour_slm)
+
+
+###################################################
+### chunk number 9: linreg-coef
+###################################################
+jour_slm$coefficients
+
+
+###################################################
+### chunk number 10: linreg-anova
+###################################################
+anova(jour_lm)
+
+
+###################################################
+### chunk number 11: journals-coef
+###################################################
+coef(jour_lm)
+
+
+###################################################
+### chunk number 12: journals-confint
+###################################################
+confint(jour_lm, level = 0.95)
+
+
+###################################################
+### chunk number 13: journals-predict
+###################################################
+predict(jour_lm, newdata = data.frame(citeprice = 2.11),
+ interval = "confidence")
+predict(jour_lm, newdata = data.frame(citeprice = 2.11),
+ interval = "prediction")
+
+
+###################################################
+### chunk number 14: predict-plot eval=FALSE
+###################################################
+## lciteprice <- seq(from = -6, to = 4, by = 0.25)
+## jour_pred <- predict(jour_lm, interval = "prediction",
+## newdata = data.frame(citeprice = exp(lciteprice)))
+## plot(log(subs) ~ log(citeprice), data = journals)
+## lines(jour_pred[, 1] ~ lciteprice, col = 1)
+## lines(jour_pred[, 2] ~ lciteprice, col = 1, lty = 2)
+## lines(jour_pred[, 3] ~ lciteprice, col = 1, lty = 2)
+
+
+###################################################
+### chunk number 15: predict-plot1
+###################################################
+lciteprice <- seq(from = -6, to = 4, by = 0.25)
+jour_pred <- predict(jour_lm, interval = "prediction",
+ newdata = data.frame(citeprice = exp(lciteprice)))
+plot(log(subs) ~ log(citeprice), data = journals)
+lines(jour_pred[, 1] ~ lciteprice, col = 1)
+lines(jour_pred[, 2] ~ lciteprice, col = 1, lty = 2)
+lines(jour_pred[, 3] ~ lciteprice, col = 1, lty = 2)
+
+
+###################################################
+### chunk number 16: journals-plot eval=FALSE
+###################################################
+## par(mfrow = c(2, 2))
+## plot(jour_lm)
+## par(mfrow = c(1, 1))
+
+
+###################################################
+### chunk number 17: journals-plot1
+###################################################
+par(mfrow = c(2, 2))
+plot(jour_lm)
+par(mfrow = c(1, 1))
+
+
+###################################################
+### chunk number 18: journal-lht
+###################################################
+linearHypothesis(jour_lm, "log(citeprice) = -0.5")
+
+
+###################################################
+### chunk number 19: CPS-data
+###################################################
+data("CPS1988")
+summary(CPS1988)
+
+
+###################################################
+### chunk number 20: CPS-base
+###################################################
+cps_lm <- lm(log(wage) ~ experience + I(experience^2) +
+ education + ethnicity, data = CPS1988)
+
+
+###################################################
+### chunk number 21: CPS-visualization-unused eval=FALSE
+###################################################
+## ex <- 0:56
+## ed <- with(CPS1988, tapply(education,
+## list(ethnicity, experience), mean))[, as.character(ex)]
+## fm <- cps_lm
+## wago <- predict(fm, newdata = data.frame(experience = ex,
+## ethnicity = "cauc", education = as.numeric(ed["cauc",])))
+## wagb <- predict(fm, newdata = data.frame(experience = ex,
+## ethnicity = "afam", education = as.numeric(ed["afam",])))
+## plot(log(wage) ~ experience, data = CPS1988, pch = ".",
+## col = as.numeric(ethnicity))
+## lines(ex, wago)
+## lines(ex, wagb, col = 2)
+
+
+###################################################
+### chunk number 22: CPS-summary
+###################################################
+summary(cps_lm)
+
+
+###################################################
+### chunk number 23: CPS-noeth
+###################################################
+cps_noeth <- lm(log(wage) ~ experience + I(experience^2) +
+ education, data = CPS1988)
+anova(cps_noeth, cps_lm)
+
+
+###################################################
+### chunk number 24: CPS-anova
+###################################################
+anova(cps_lm)
+
+
+###################################################
+### chunk number 25: CPS-noeth2 eval=FALSE
+###################################################
+## cps_noeth <- update(cps_lm, formula = . ~ . - ethnicity)
+
+
+###################################################
+### chunk number 26: CPS-waldtest
+###################################################
+waldtest(cps_lm, . ~ . - ethnicity)
+
+
+###################################################
+### chunk number 27: CPS-spline
+###################################################
+cps_plm <- lm(log(wage) ~ bs(experience, df = 5) +
+ education + ethnicity, data = CPS1988)
+
+
+###################################################
+### chunk number 28: CPS-spline-summary eval=FALSE
+###################################################
+## summary(cps_plm)
+
+
+###################################################
+### chunk number 29: CPS-BIC
+###################################################
+cps_bs <- lapply(3:10, function(i) lm(log(wage) ~
+ bs(experience, df = i) + education + ethnicity,
+ data = CPS1988))
+structure(sapply(cps_bs, AIC, k = log(nrow(CPS1988))),
+ .Names = 3:10)
+
+
+###################################################
+### chunk number 30: plm-plot eval=FALSE
+###################################################
+## cps <- data.frame(experience = -2:60, education =
+## with(CPS1988, mean(education[ethnicity == "cauc"])),
+## ethnicity = "cauc")
+## cps$yhat1 <- predict(cps_lm, newdata = cps)
+## cps$yhat2 <- predict(cps_plm, newdata = cps)
+##
+## plot(log(wage) ~ jitter(experience, factor = 3), pch = 19,
+## col = rgb(0.5, 0.5, 0.5, alpha = 0.02), data = CPS1988)
+## lines(yhat1 ~ experience, data = cps, lty = 2)
+## lines(yhat2 ~ experience, data = cps)
+## legend("topleft", c("quadratic", "spline"), lty = c(2,1),
+## bty = "n")
+
+
+###################################################
+### chunk number 31: plm-plot1
+###################################################
+cps <- data.frame(experience = -2:60, education =
+ with(CPS1988, mean(education[ethnicity == "cauc"])),
+ ethnicity = "cauc")
+cps$yhat1 <- predict(cps_lm, newdata = cps)
+cps$yhat2 <- predict(cps_plm, newdata = cps)
+
+plot(log(wage) ~ jitter(experience, factor = 3), pch = 19,
+ col = rgb(0.5, 0.5, 0.5, alpha = 0.02), data = CPS1988)
+lines(yhat1 ~ experience, data = cps, lty = 2)
+lines(yhat2 ~ experience, data = cps)
+legend("topleft", c("quadratic", "spline"), lty = c(2,1),
+ bty = "n")
+
+
+###################################################
+### chunk number 32: CPS-int
+###################################################
+cps_int <- lm(log(wage) ~ experience + I(experience^2) +
+ education * ethnicity, data = CPS1988)
+coeftest(cps_int)
+
+
+###################################################
+### chunk number 33: CPS-int2 eval=FALSE
+###################################################
+## cps_int <- lm(log(wage) ~ experience + I(experience^2) +
+## education + ethnicity + education:ethnicity,
+## data = CPS1988)
+
+
+###################################################
+### chunk number 34: CPS-sep
+###################################################
+cps_sep <- lm(log(wage) ~ ethnicity /
+ (experience + I(experience^2) + education) - 1,
+ data = CPS1988)
+
+
+###################################################
+### chunk number 35: CPS-sep-coef
+###################################################
+cps_sep_cf <- matrix(coef(cps_sep), nrow = 2)
+rownames(cps_sep_cf) <- levels(CPS1988$ethnicity)
+colnames(cps_sep_cf) <- names(coef(cps_lm))[1:4]
+cps_sep_cf
+
+
+###################################################
+### chunk number 36: CPS-sep-anova
+###################################################
+anova(cps_sep, cps_lm)
+
+
+###################################################
+### chunk number 37: CPS-sep-visualization-unused eval=FALSE
+###################################################
+## ex <- 0:56
+## ed <- with(CPS1988, tapply(education, list(ethnicity,
+## experience), mean))[, as.character(ex)]
+## fm <- cps_lm
+## wago <- predict(fm, newdata = data.frame(experience = ex,
+## ethnicity = "cauc", education = as.numeric(ed["cauc",])))
+## wagb <- predict(fm, newdata = data.frame(experience = ex,
+## ethnicity = "afam", education = as.numeric(ed["afam",])))
+## plot(log(wage) ~ jitter(experience, factor = 2),
+## data = CPS1988, pch = ".", col = as.numeric(ethnicity))
+##
+##
+## plot(log(wage) ~ as.factor(experience), data = CPS1988,
+## pch = ".")
+## lines(ex, wago, lwd = 2)
+## lines(ex, wagb, col = 2, lwd = 2)
+## fm <- cps_sep
+## wago <- predict(fm, newdata = data.frame(experience = ex,
+## ethnicity = "cauc", education = as.numeric(ed["cauc",])))
+## wagb <- predict(fm, newdata = data.frame(experience = ex,
+## ethnicity = "afam", education = as.numeric(ed["afam",])))
+## lines(ex, wago, lty = 2, lwd = 2)
+## lines(ex, wagb, col = 2, lty = 2, lwd = 2)
+
+
+###################################################
+### chunk number 38: CPS-region
+###################################################
+CPS1988$region <- relevel(CPS1988$region, ref = "south")
+cps_region <- lm(log(wage) ~ ethnicity + education +
+ experience + I(experience^2) + region, data = CPS1988)
+coef(cps_region)
+
+
+###################################################
+### chunk number 39: wls1
+###################################################
+jour_wls1 <- lm(log(subs) ~ log(citeprice), data = journals,
+ weights = 1/citeprice^2)
+
+
+###################################################
+### chunk number 40: wls2
+###################################################
+jour_wls2 <- lm(log(subs) ~ log(citeprice), data = journals,
+ weights = 1/citeprice)
+
+
+###################################################
+### chunk number 41: journals-wls1 eval=FALSE
+###################################################
+## plot(log(subs) ~ log(citeprice), data = journals)
+## abline(jour_lm)
+## abline(jour_wls1, lwd = 2, lty = 2)
+## abline(jour_wls2, lwd = 2, lty = 3)
+## legend("bottomleft", c("OLS", "WLS1", "WLS2"),
+## lty = 1:3, lwd = 2, bty = "n")
+
+
+###################################################
+### chunk number 42: journals-wls11
+###################################################
+plot(log(subs) ~ log(citeprice), data = journals)
+abline(jour_lm)
+abline(jour_wls1, lwd = 2, lty = 2)
+abline(jour_wls2, lwd = 2, lty = 3)
+legend("bottomleft", c("OLS", "WLS1", "WLS2"),
+ lty = 1:3, lwd = 2, bty = "n")
+
+
+###################################################
+### chunk number 43: fgls1
+###################################################
+auxreg <- lm(log(residuals(jour_lm)^2) ~ log(citeprice),
+ data = journals)
+jour_fgls1 <- lm(log(subs) ~ log(citeprice),
+ weights = 1/exp(fitted(auxreg)), data = journals)
+
+
+###################################################
+### chunk number 44: fgls2
+###################################################
+gamma2i <- coef(auxreg)[2]
+gamma2 <- 0
+while(abs((gamma2i - gamma2)/gamma2) > 1e-7) {
+ gamma2 <- gamma2i
+ fglsi <- lm(log(subs) ~ log(citeprice), data = journals,
+ weights = 1/citeprice^gamma2)
+ gamma2i <- coef(lm(log(residuals(fglsi)^2) ~
+ log(citeprice), data = journals))[2]
+}
+jour_fgls2 <- lm(log(subs) ~ log(citeprice), data = journals,
+ weights = 1/citeprice^gamma2)
+
+
+###################################################
+### chunk number 45: fgls2-coef
+###################################################
+coef(jour_fgls2)
+
+
+###################################################
+### chunk number 46: journals-fgls
+###################################################
+plot(log(subs) ~ log(citeprice), data = journals)
+abline(jour_lm)
+abline(jour_fgls2, lty = 2, lwd = 2)
+
+
+###################################################
+### chunk number 47: usmacro-plot eval=FALSE
+###################################################
+## data("USMacroG")
+## plot(USMacroG[, c("dpi", "consumption")], lty = c(3, 1),
+## plot.type = "single", ylab = "")
+## legend("topleft", legend = c("income", "consumption"),
+## lty = c(3, 1), bty = "n")
+
+
+###################################################
+### chunk number 48: usmacro-plot1
+###################################################
+data("USMacroG")
+plot(USMacroG[, c("dpi", "consumption")], lty = c(3, 1),
+ plot.type = "single", ylab = "")
+legend("topleft", legend = c("income", "consumption"),
+ lty = c(3, 1), bty = "n")
+
+
+###################################################
+### chunk number 49: usmacro-fit
+###################################################
+library("dynlm")
+cons_lm1 <- dynlm(consumption ~ dpi + L(dpi), data = USMacroG)
+cons_lm2 <- dynlm(consumption ~ dpi + L(consumption),
+ data = USMacroG)
+
+
+###################################################
+### chunk number 50: usmacro-summary1
+###################################################
+summary(cons_lm1)
+
+
+###################################################
+### chunk number 51: usmacro-summary2
+###################################################
+summary(cons_lm2)
+
+
+###################################################
+### chunk number 52: dynlm-plot eval=FALSE
+###################################################
+## plot(merge(as.zoo(USMacroG[,"consumption"]), fitted(cons_lm1),
+## fitted(cons_lm2), 0, residuals(cons_lm1),
+## residuals(cons_lm2)), screens = rep(1:2, c(3, 3)),
+## lty = rep(1:3, 2), ylab = c("Fitted values", "Residuals"),
+## xlab = "Time", main = "")
+## legend(0.05, 0.95, c("observed", "cons_lm1", "cons_lm2"),
+## lty = 1:3, bty = "n")
+
+
+###################################################
+### chunk number 53: dynlm-plot1
+###################################################
+plot(merge(as.zoo(USMacroG[,"consumption"]), fitted(cons_lm1),
+ fitted(cons_lm2), 0, residuals(cons_lm1),
+ residuals(cons_lm2)), screens = rep(1:2, c(3, 3)),
+ lty = rep(1:3, 2), ylab = c("Fitted values", "Residuals"),
+ xlab = "Time", main = "")
+legend(0.05, 0.95, c("observed", "cons_lm1", "cons_lm2"),
+ lty = 1:3, bty = "n")
+
+
+###################################################
+### chunk number 54: encompassing1
+###################################################
+cons_lmE <- dynlm(consumption ~ dpi + L(dpi) +
+ L(consumption), data = USMacroG)
+
+
+###################################################
+### chunk number 55: encompassing2
+###################################################
+anova(cons_lm1, cons_lmE, cons_lm2)
+
+
+###################################################
+### chunk number 56: encompassing3
+###################################################
+encomptest(cons_lm1, cons_lm2)
+
+
+###################################################
+### chunk number 57: plm-data
+###################################################
+data("Grunfeld", package = "AER")
+library("plm")
+gr <- subset(Grunfeld, firm %in% c("General Electric",
+ "General Motors", "IBM"))
+pgr <- plm.data(gr, index = c("firm", "year"))
+
+
+###################################################
+### chunk number 58: plm-pool
+###################################################
+gr_pool <- plm(invest ~ value + capital, data = pgr,
+ model = "pooling")
+
+
+###################################################
+### chunk number 59: plm-FE
+###################################################
+gr_fe <- plm(invest ~ value + capital, data = pgr,
+ model = "within")
+summary(gr_fe)
+
+
+###################################################
+### chunk number 60: plm-pFtest
+###################################################
+pFtest(gr_fe, gr_pool)
+
+
+###################################################
+### chunk number 61: plm-RE
+###################################################
+gr_re <- plm(invest ~ value + capital, data = pgr,
+ model = "random", random.method = "walhus")
+summary(gr_re)
+
+
+###################################################
+### chunk number 62: plm-plmtest
+###################################################
+plmtest(gr_pool)
+
+
+###################################################
+### chunk number 63: plm-phtest
+###################################################
+phtest(gr_re, gr_fe)
+
+
+###################################################
+### chunk number 64: EmplUK-data
+###################################################
+data("EmplUK", package = "plm")
+form <- log(emp) ~ log(wage) + log(capital) + log(output)
+
+
+###################################################
+### chunk number 65: plm-AB
+###################################################
+empl_ab <- pgmm(dynformula(form, list(2, 1, 0, 1)),
+ data = EmplUK, index = c("firm", "year"),
+ effect = "twoways", model = "twosteps",
+ gmm.inst = ~ log(emp), lag.gmm = list(c(2, 99)))
+
+
+###################################################
+### chunk number 66: plm-AB-summary
+###################################################
+summary(empl_ab)
+
+
+###################################################
+### chunk number 67: systemfit
+###################################################
+library("systemfit")
+gr2 <- subset(Grunfeld, firm %in% c("Chrysler", "IBM"))
+pgr2 <- plm.data(gr2, c("firm", "year"))
+
+
+###################################################
+### chunk number 68: SUR
+###################################################
+gr_sur <- systemfit(invest ~ value + capital,
+ method = "SUR", data = pgr2)
+summary(gr_sur, residCov = FALSE, equations = FALSE)
+
+
+###################################################
+### chunk number 69: nlme eval=FALSE
+###################################################
+## library("nlme")
+## g1 <- subset(Grunfeld, firm == "Westinghouse")
+## gls(invest ~ value + capital, data = g1, correlation = corAR1())
+
+
diff --git a/demo/Ch-Microeconometrics.R b/demo/Ch-Microeconometrics.R
new file mode 100644
index 0000000..05999e6
--- /dev/null
+++ b/demo/Ch-Microeconometrics.R
@@ -0,0 +1,390 @@
+###################################################
+### chunk number 1: setup
+###################################################
+options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+
+options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
+
+library("AER")
+
+set.seed(1071)
+
+
+###################################################
+### chunk number 2: swisslabor-data
+###################################################
+data("SwissLabor")
+swiss_probit <- glm(participation ~ . + I(age^2),
+ data = SwissLabor, family = binomial(link = "probit"))
+summary(swiss_probit)
+
+
+###################################################
+### chunk number 3: swisslabor-plot eval=FALSE
+###################################################
+## plot(participation ~ age, data = SwissLabor, ylevels = 2:1)
+
+
+###################################################
+### chunk number 4: swisslabor-plot-refined
+###################################################
+plot(participation ~ education, data = SwissLabor, ylevels = 2:1)
+fm <- glm(participation ~ education + I(education^2), data = SwissLabor, family = binomial)
+edu <- sort(unique(SwissLabor$education))
+prop <- sapply(edu, function(x) mean(SwissLabor$education <= x))
+lines(predict(fm, newdata = data.frame(education = edu), type = "response") ~ prop, col = 2)
+
+plot(participation ~ age, data = SwissLabor, ylevels = 2:1)
+fm <- glm(participation ~ age + I(age^2), data = SwissLabor, family = binomial)
+ag <- sort(unique(SwissLabor$age))
+prop <- sapply(ag, function(x) mean(SwissLabor$age <= x))
+lines(predict(fm, newdata = data.frame(age = ag), type = "response") ~ prop, col = 2)
+
+
+###################################################
+### chunk number 5: effects1
+###################################################
+fav <- mean(dnorm(predict(swiss_probit, type = "link")))
+fav * coef(swiss_probit)
+
+
+###################################################
+### chunk number 6: effects2
+###################################################
+av <- colMeans(SwissLabor[, -c(1, 7)])
+av <- data.frame(rbind(swiss = av, foreign = av),
+ foreign = factor(c("no", "yes")))
+av <- predict(swiss_probit, newdata = av, type = "link")
+av <- dnorm(av)
+av["swiss"] * coef(swiss_probit)[-7]
+
+
+###################################################
+### chunk number 7: effects3
+###################################################
+av["foreign"] * coef(swiss_probit)[-7]
+
+
+###################################################
+### chunk number 8: mcfadden
+###################################################
+swiss_probit0 <- update(swiss_probit, formula = . ~ 1)
+1 - as.vector(logLik(swiss_probit)/logLik(swiss_probit0))
+
+
+###################################################
+### chunk number 9: confusion-matrix
+###################################################
+table(true = SwissLabor$participation,
+ pred = round(fitted(swiss_probit)))
+
+
+###################################################
+### chunk number 10: confusion-matrix1
+###################################################
+tab <- table(true = SwissLabor$participation,
+ pred = round(fitted(swiss_probit)))
+tabp <- round(100 * c(tab[1,1] + tab[2,2], tab[2,1] + tab[1,2])/sum(tab), digits = 2)
+
+
+###################################################
+### chunk number 11: roc-plot eval=FALSE
+###################################################
+## library("ROCR")
+## pred <- prediction(fitted(swiss_probit),
+## SwissLabor$participation)
+## plot(performance(pred, "acc"))
+## plot(performance(pred, "tpr", "fpr"))
+## abline(0, 1, lty = 2)
+
+
+###################################################
+### chunk number 12: roc-plot1
+###################################################
+library("ROCR")
+pred <- prediction(fitted(swiss_probit),
+ SwissLabor$participation)
+plot(performance(pred, "acc"))
+plot(performance(pred, "tpr", "fpr"))
+abline(0, 1, lty = 2)
+
+
+###################################################
+### chunk number 13: rss
+###################################################
+deviance(swiss_probit)
+sum(residuals(swiss_probit, type = "deviance")^2)
+sum(residuals(swiss_probit, type = "pearson")^2)
+
+
+###################################################
+### chunk number 14: coeftest eval=FALSE
+###################################################
+## coeftest(swiss_probit, vcov = sandwich)
+
+
+###################################################
+### chunk number 15: murder
+###################################################
+data("MurderRates")
+murder_logit <- glm(I(executions > 0) ~ time + income +
+ noncauc + lfp + southern, data = MurderRates,
+ family = binomial)
+
+
+###################################################
+### chunk number 16: murder-coeftest
+###################################################
+coeftest(murder_logit)
+
+
+###################################################
+### chunk number 17: murder2
+###################################################
+murder_logit2 <- glm(I(executions > 0) ~ time + income +
+ noncauc + lfp + southern, data = MurderRates,
+ family = binomial, control = list(epsilon = 1e-15,
+ maxit = 50, trace = FALSE))
+
+
+###################################################
+### chunk number 18: murder2-coeftest
+###################################################
+coeftest(murder_logit2)
+
+
+###################################################
+### chunk number 19: separation
+###################################################
+table(I(MurderRates$executions > 0), MurderRates$southern)
+
+
+###################################################
+### chunk number 20: countreg-pois
+###################################################
+data("RecreationDemand")
+rd_pois <- glm(trips ~ ., data = RecreationDemand,
+ family = poisson)
+
+
+###################################################
+### chunk number 21: countreg-pois-coeftest
+###################################################
+coeftest(rd_pois)
+
+
+###################################################
+### chunk number 22: countreg-pois-logLik
+###################################################
+logLik(rd_pois)
+
+
+###################################################
+### chunk number 23: countreg-odtest1
+###################################################
+dispersiontest(rd_pois)
+
+
+###################################################
+### chunk number 24: countreg-odtest2
+###################################################
+dispersiontest(rd_pois, trafo = 2)
+
+
+###################################################
+### chunk number 25: countreg-nbin
+###################################################
+library("MASS")
+rd_nb <- glm.nb(trips ~ ., data = RecreationDemand)
+coeftest(rd_nb)
+logLik(rd_nb)
+
+
+###################################################
+### chunk number 26: countreg-se
+###################################################
+round(sqrt(rbind(diag(vcov(rd_pois)),
+ diag(sandwich(rd_pois)))), digits = 3)
+
+
+###################################################
+### chunk number 27: countreg-sandwich
+###################################################
+coeftest(rd_pois, vcov = sandwich)
+
+
+###################################################
+### chunk number 28: countreg-OPG
+###################################################
+round(sqrt(diag(vcovOPG(rd_pois))), 3)
+
+
+###################################################
+### chunk number 29: countreg-plot
+###################################################
+plot(table(RecreationDemand$trips), ylab = "")
+
+
+###################################################
+### chunk number 30: countreg-zeros
+###################################################
+rbind(obs = table(RecreationDemand$trips)[1:10], exp = round(
+ sapply(0:9, function(x) sum(dpois(x, fitted(rd_pois))))))
+
+
+###################################################
+### chunk number 31: countreg-pscl
+###################################################
+library("pscl")
+
+
+###################################################
+### chunk number 32: countreg-zinb
+###################################################
+rd_zinb <- zeroinfl(trips ~ . | quality + income,
+ data = RecreationDemand, dist = "negbin")
+
+
+###################################################
+### chunk number 33: countreg-zinb-summary
+###################################################
+summary(rd_zinb)
+
+
+###################################################
+### chunk number 34: countreg-zinb-expected
+###################################################
+round(colSums(predict(rd_zinb, type = "prob")[,1:10]))
+
+
+###################################################
+### chunk number 35: countreg-hurdle
+###################################################
+rd_hurdle <- hurdle(trips ~ . | quality + income,
+ data = RecreationDemand, dist = "negbin")
+summary(rd_hurdle)
+
+
+###################################################
+### chunk number 36: countreg-hurdle-expected
+###################################################
+round(colSums(predict(rd_hurdle, type = "prob")[,1:10]))
+
+
+###################################################
+### chunk number 37: tobit1
+###################################################
+data("Affairs")
+aff_tob <- tobit(affairs ~ age + yearsmarried +
+ religiousness + occupation + rating, data = Affairs)
+summary(aff_tob)
+
+
+###################################################
+### chunk number 38: tobit2
+###################################################
+aff_tob2 <- update(aff_tob, right = 4)
+summary(aff_tob2)
+
+
+###################################################
+### chunk number 39: tobit3
+###################################################
+linearHypothesis(aff_tob, c("age = 0", "occupation = 0"),
+ vcov = sandwich)
+
+
+###################################################
+### chunk number 40: numeric-response
+###################################################
+SwissLabor$partnum <- as.numeric(SwissLabor$participation) - 1
+
+
+###################################################
+### chunk number 41: kleinspady eval=FALSE
+###################################################
+## library("np")
+## swiss_bw <- npindexbw(partnum ~ income + age + education +
+## youngkids + oldkids + foreign + I(age^2), data = SwissLabor,
+## method = "kleinspady", nmulti = 5)
+
+
+###################################################
+### chunk number 42: kleinspady-bw eval=FALSE
+###################################################
+## summary(swiss_bw)
+
+
+###################################################
+### chunk number 43: kleinspady-summary eval=FALSE
+###################################################
+## swiss_ks <- npindex(bws = swiss_bw, gradients = TRUE)
+## summary(swiss_ks)
+
+
+###################################################
+### chunk number 44: probit-confusion
+###################################################
+table(Actual = SwissLabor$participation, Predicted =
+ round(predict(swiss_probit, type = "response")))
+
+
+###################################################
+### chunk number 45: bw-tab
+###################################################
+data("BankWages")
+edcat <- factor(BankWages$education)
+levels(edcat)[3:10] <- rep(c("14-15", "16-18", "19-21"),
+ c(2, 3, 3))
+tab <- xtabs(~ edcat + job, data = BankWages)
+prop.table(tab, 1)
+
+
+###################################################
+### chunk number 46: bw-plot eval=FALSE
+###################################################
+## plot(job ~ edcat, data = BankWages, off = 0)
+
+
+###################################################
+### chunk number 47: bw-plot1
+###################################################
+plot(job ~ edcat, data = BankWages, off = 0)
+box()
+
+
+###################################################
+### chunk number 48: bw-multinom
+###################################################
+library("nnet")
+bank_mnl <- multinom(job ~ education + minority,
+ data = BankWages, subset = gender == "male", trace = FALSE)
+
+
+###################################################
+### chunk number 49: bw-multinom-coeftest
+###################################################
+coeftest(bank_mnl)
+
+
+###################################################
+### chunk number 50: bw-polr
+###################################################
+library("MASS")
+bank_polr <- polr(job ~ education + minority,
+ data = BankWages, subset = gender == "male", Hess = TRUE)
+coeftest(bank_polr)
+
+
+###################################################
+### chunk number 51: bw-AIC
+###################################################
+AIC(bank_mnl)
+AIC(bank_polr)
+
+
diff --git a/demo/Ch-Programming.R b/demo/Ch-Programming.R
new file mode 100644
index 0000000..7f0eb56
--- /dev/null
+++ b/demo/Ch-Programming.R
@@ -0,0 +1,245 @@
+###################################################
+### chunk number 1: setup
+###################################################
+options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+
+options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
+
+library("AER")
+
+set.seed(1071)
+
+
+###################################################
+### chunk number 2: DGP
+###################################################
+dgp <- function(nobs = 15, model = c("trend", "dynamic"),
+ corr = 0, coef = c(0.25, -0.75), sd = 1)
+{
+ model <- match.arg(model)
+ coef <- rep(coef, length.out = 2)
+
+ err <- as.vector(filter(rnorm(nobs, sd = sd), corr,
+ method = "recursive"))
+ if(model == "trend") {
+ x <- 1:nobs
+ y <- coef[1] + coef[2] * x + err
+ } else {
+ y <- rep(NA, nobs)
+ y[1] <- coef[1] + err[1]
+ for(i in 2:nobs)
+ y[i] <- coef[1] + coef[2] * y[i-1] + err[i]
+ x <- c(0, y[1:(nobs-1)])
+ }
+ return(data.frame(y = y, x = x))
+}
+
+
+###################################################
+### chunk number 3: simpower
+###################################################
+simpower <- function(nrep = 100, size = 0.05, ...)
+{
+ pval <- matrix(rep(NA, 2 * nrep), ncol = 2)
+ colnames(pval) <- c("dwtest", "bgtest")
+ for(i in 1:nrep) {
+ dat <- dgp(...)
+ pval[i,1] <- dwtest(y ~ x, data = dat,
+ alternative = "two.sided")$p.value
+ pval[i,2] <- bgtest(y ~ x, data = dat)$p.value
+ }
+ return(colMeans(pval < size))
+}
+
+
+###################################################
+### chunk number 4: simulation-function
+###################################################
+simulation <- function(corr = c(0, 0.2, 0.4, 0.6, 0.8,
+ 0.9, 0.95, 0.99), nobs = c(15, 30, 50),
+ model = c("trend", "dynamic"), ...)
+{
+ prs <- expand.grid(corr = corr, nobs = nobs, model = model)
+ nprs <- nrow(prs)
+
+ pow <- matrix(rep(NA, 2 * nprs), ncol = 2)
+ for(i in 1:nprs) pow[i,] <- simpower(corr = prs[i,1],
+ nobs = prs[i,2], model = as.character(prs[i,3]), ...)
+
+ rval <- rbind(prs, prs)
+ rval$test <- factor(rep(1:2, c(nprs, nprs)),
+ labels = c("dwtest", "bgtest"))
+ rval$power <- c(pow[,1], pow[,2])
+ rval$nobs <- factor(rval$nobs)
+ return(rval)
+}
+
+
+###################################################
+### chunk number 5: simulation
+###################################################
+set.seed(123)
+psim <- simulation()
+
+
+###################################################
+### chunk number 6: simulation-table
+###################################################
+tab <- xtabs(power ~ corr + test + model + nobs, data = psim)
+ftable(tab, row.vars = c("model", "nobs", "test"),
+ col.vars = "corr")
+
+
+###################################################
+### chunk number 7: simulation-visualization
+###################################################
+library("lattice")
+xyplot(power ~ corr | model + nobs, groups = ~ test,
+ data = psim, type = "b")
+
+
+###################################################
+### chunk number 8: simulation-visualization1
+###################################################
+library("lattice")
+trellis.par.set(theme = canonical.theme(color = FALSE))
+print(xyplot(power ~ corr | model + nobs, groups = ~ test, data = psim, type = "b"))
+
+
+###################################################
+### chunk number 9: journals-lm
+###################################################
+data("Journals")
+journals <- Journals[, c("subs", "price")]
+journals$citeprice <- Journals$price/Journals$citations
+jour_lm <- lm(log(subs) ~ log(citeprice), data = journals)
+
+
+###################################################
+### chunk number 10: journals-residuals-based-resampling-unused eval=FALSE
+###################################################
+## refit <- function(data, i) {
+## d <- data
+## d$subs <- exp(d$fitted + d$res[i])
+## coef(lm(log(subs) ~ log(citeprice), data = d))
+## }
+
+
+###################################################
+### chunk number 11: journals-case-based-resampling
+###################################################
+refit <- function(data, i)
+ coef(lm(log(subs) ~ log(citeprice), data = data[i,]))
+
+
+###################################################
+### chunk number 12: journals-boot
+###################################################
+library("boot")
+set.seed(123)
+jour_boot <- boot(journals, refit, R = 999)
+
+
+###################################################
+### chunk number 13: journals-boot-print
+###################################################
+jour_boot
+
+
+###################################################
+### chunk number 14: journals-lm-coeftest
+###################################################
+coeftest(jour_lm)
+
+
+###################################################
+### chunk number 15: journals-boot-ci
+###################################################
+boot.ci(jour_boot, index = 2, type = "basic")
+
+
+###################################################
+### chunk number 16: journals-lm-ci
+###################################################
+confint(jour_lm, parm = 2)
+
+
+###################################################
+### chunk number 17: ml-loglik
+###################################################
+data("Equipment", package = "AER")
+
+nlogL <- function(par) {
+ beta <- par[1:3]
+ theta <- par[4]
+ sigma2 <- par[5]
+
+ Y <- with(Equipment, valueadded/firms)
+ K <- with(Equipment, capital/firms)
+ L <- with(Equipment, labor/firms)
+
+ rhs <- beta[1] + beta[2] * log(K) + beta[3] * log(L)
+ lhs <- log(Y) + theta * Y
+
+ rval <- sum(log(1 + theta * Y) - log(Y) +
+ dnorm(lhs, mean = rhs, sd = sqrt(sigma2), log = TRUE))
+ return(-rval)
+}
+
+
+###################################################
+### chunk number 18: ml-0
+###################################################
+fm0 <- lm(log(valueadded/firms) ~ log(capital/firms) +
+ log(labor/firms), data = Equipment)
+
+
+###################################################
+### chunk number 19: ml-0-coef
+###################################################
+par0 <- as.vector(c(coef(fm0), 0, mean(residuals(fm0)^2)))
+
+
+###################################################
+### chunk number 20: ml-optim
+###################################################
+opt <- optim(par0, nlogL, hessian = TRUE)
+
+
+###################################################
+### chunk number 21: ml-optim-output
+###################################################
+opt$par
+sqrt(diag(solve(opt$hessian)))[1:4]
+-opt$value
+
+
+###################################################
+### chunk number 22: Sweave eval=FALSE
+###################################################
+## Sweave("Sweave-journals.Rnw")
+
+
+###################################################
+### chunk number 23: Stangle eval=FALSE
+###################################################
+## Stangle("Sweave-journals.Rnw")
+
+
+###################################################
+### chunk number 24: texi2dvi eval=FALSE
+###################################################
+## texi2dvi("Sweave-journals.tex", pdf = TRUE)
+
+
+###################################################
+### chunk number 25: vignette eval=FALSE
+###################################################
+## vignette("Sweave-journals", package = "AER")
+
+
diff --git a/demo/Ch-TimeSeries.R b/demo/Ch-TimeSeries.R
new file mode 100644
index 0000000..df68eb5
--- /dev/null
+++ b/demo/Ch-TimeSeries.R
@@ -0,0 +1,444 @@
+###################################################
+### chunk number 1: setup
+###################################################
+options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+
+options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
+
+library("AER")
+
+set.seed(1071)
+
+
+###################################################
+### chunk number 2: options
+###################################################
+options(digits = 6)
+
+
+###################################################
+### chunk number 3: ts-plot eval=FALSE
+###################################################
+## data("UKNonDurables")
+## plot(UKNonDurables)
+
+
+###################################################
+### chunk number 4: UKNonDurables-data
+###################################################
+data("UKNonDurables")
+
+
+###################################################
+### chunk number 5: tsp
+###################################################
+tsp(UKNonDurables)
+
+
+###################################################
+### chunk number 6: window
+###################################################
+window(UKNonDurables, end = c(1956, 4))
+
+
+###################################################
+### chunk number 7: filter eval=FALSE
+###################################################
+## data("UKDriverDeaths")
+## plot(UKDriverDeaths)
+## lines(filter(UKDriverDeaths, c(1/2, rep(1, 11), 1/2)/12),
+## col = 2)
+
+
+###################################################
+### chunk number 8: ts-plot1
+###################################################
+data("UKNonDurables")
+plot(UKNonDurables)
+data("UKDriverDeaths")
+plot(UKDriverDeaths)
+lines(filter(UKDriverDeaths, c(1/2, rep(1, 11), 1/2)/12),
+ col = 2)
+
+
+###################################################
+### chunk number 9: filter1 eval=FALSE
+###################################################
+## data("UKDriverDeaths")
+## plot(UKDriverDeaths)
+## lines(filter(UKDriverDeaths, c(1/2, rep(1, 11), 1/2)/12),
+## col = 2)
+
+
+###################################################
+### chunk number 10: rollapply
+###################################################
+plot(rollapply(UKDriverDeaths, 12, sd))
+
+
+###################################################
+### chunk number 11: ar-sim
+###################################################
+set.seed(1234)
+x <- filter(rnorm(100), 0.9, method = "recursive")
+
+
+###################################################
+### chunk number 12: decompose
+###################################################
+dd_dec <- decompose(log(UKDriverDeaths))
+dd_stl <- stl(log(UKDriverDeaths), s.window = 13)
+
+
+###################################################
+### chunk number 13: decompose-components
+###################################################
+plot(dd_dec$trend, ylab = "trend")
+lines(dd_stl$time.series[,"trend"], lty = 2, lwd = 2)
+
+
+###################################################
+### chunk number 14: seat-mean-sd
+###################################################
+plot(dd_dec$trend, ylab = "trend")
+lines(dd_stl$time.series[,"trend"], lty = 2, lwd = 2)
+plot(rollapply(UKDriverDeaths, 12, sd))
+
+
+###################################################
+### chunk number 15: stl
+###################################################
+plot(dd_stl)
+
+
+###################################################
+### chunk number 16: Holt-Winters
+###################################################
+dd_past <- window(UKDriverDeaths, end = c(1982, 12))
+dd_hw <- HoltWinters(dd_past)
+dd_pred <- predict(dd_hw, n.ahead = 24)
+
+
+###################################################
+### chunk number 17: Holt-Winters-plot
+###################################################
+plot(dd_hw, dd_pred, ylim = range(UKDriverDeaths))
+lines(UKDriverDeaths)
+
+
+###################################################
+### chunk number 18: Holt-Winters-plot1
+###################################################
+plot(dd_hw, dd_pred, ylim = range(UKDriverDeaths))
+lines(UKDriverDeaths)
+
+
+###################################################
+### chunk number 19: acf eval=FALSE
+###################################################
+## acf(x)
+## pacf(x)
+
+
+###################################################
+### chunk number 20: acf1
+###################################################
+acf(x, ylim = c(-0.2, 1))
+pacf(x, ylim = c(-0.2, 1))
+
+
+###################################################
+### chunk number 21: ar
+###################################################
+ar(x)
+
+
+###################################################
+### chunk number 22: window-non-durab
+###################################################
+nd <- window(log(UKNonDurables), end = c(1970, 4))
+
+
+###################################################
+### chunk number 23: non-durab-acf
+###################################################
+acf(diff(nd), ylim = c(-1, 1))
+pacf(diff(nd), ylim = c(-1, 1))
+acf(diff(diff(nd, 4)), ylim = c(-1, 1))
+pacf(diff(diff(nd, 4)), ylim = c(-1, 1))
+
+
+###################################################
+### chunk number 24: non-durab-acf1
+###################################################
+acf(diff(nd), ylim = c(-1, 1))
+pacf(diff(nd), ylim = c(-1, 1))
+acf(diff(diff(nd, 4)), ylim = c(-1, 1))
+pacf(diff(diff(nd, 4)), ylim = c(-1, 1))
+
+
+###################################################
+### chunk number 25: arima-setup
+###################################################
+nd_pars <- expand.grid(ar = 0:2, diff = 1, ma = 0:2,
+ sar = 0:1, sdiff = 1, sma = 0:1)
+nd_aic <- rep(0, nrow(nd_pars))
+for(i in seq(along = nd_aic)) nd_aic[i] <- AIC(arima(nd,
+ unlist(nd_pars[i, 1:3]), unlist(nd_pars[i, 4:6])),
+ k = log(length(nd)))
+nd_pars[which.min(nd_aic),]
+
+
+###################################################
+### chunk number 26: arima
+###################################################
+nd_arima <- arima(nd, order = c(0,1,1), seasonal = c(0,1,1))
+nd_arima
+
+
+###################################################
+### chunk number 27: tsdiag
+###################################################
+tsdiag(nd_arima)
+
+
+###################################################
+### chunk number 28: tsdiag1
+###################################################
+tsdiag(nd_arima)
+
+
+###################################################
+### chunk number 29: arima-predict
+###################################################
+nd_pred <- predict(nd_arima, n.ahead = 18 * 4)
+
+
+###################################################
+### chunk number 30: arima-compare
+###################################################
+plot(log(UKNonDurables))
+lines(nd_pred$pred, col = 2)
+
+
+###################################################
+### chunk number 31: arima-compare1
+###################################################
+plot(log(UKNonDurables))
+lines(nd_pred$pred, col = 2)
+
+
+###################################################
+### chunk number 32: pepper
+###################################################
+data("PepperPrice")
+plot(PepperPrice, plot.type = "single", col = 1:2)
+legend("topleft", c("black", "white"), bty = "n",
+col = 1:2, lty = rep(1,2))
+
+
+###################################################
+### chunk number 33: pepper1
+###################################################
+data("PepperPrice")
+plot(PepperPrice, plot.type = "single", col = 1:2)
+legend("topleft", c("black", "white"), bty = "n",
+col = 1:2, lty = rep(1,2))
+
+
+###################################################
+### chunk number 34: adf1
+###################################################
+library("tseries")
+adf.test(log(PepperPrice[, "white"]))
+
+
+###################################################
+### chunk number 35: adf1
+###################################################
+adf.test(diff(log(PepperPrice[, "white"])))
+
+
+###################################################
+### chunk number 36: pp
+###################################################
+pp.test(log(PepperPrice[, "white"]), type = "Z(t_alpha)")
+
+
+###################################################
+### chunk number 37: urca eval=FALSE
+###################################################
+## library("urca")
+## pepper_ers <- ur.ers(log(PepperPrice[, "white"]),
+## type = "DF-GLS", model = "const", lag.max = 4)
+## summary(pepper_ers)
+
+
+###################################################
+### chunk number 38: kpss
+###################################################
+kpss.test(log(PepperPrice[, "white"]))
+
+
+###################################################
+### chunk number 39: po
+###################################################
+po.test(log(PepperPrice))
+
+
+###################################################
+### chunk number 40: joh-trace
+###################################################
+library("urca")
+pepper_jo <- ca.jo(log(PepperPrice), ecdet = "const",
+ type = "trace")
+summary(pepper_jo)
+
+
+###################################################
+### chunk number 41: joh-lmax eval=FALSE
+###################################################
+## pepper_jo2 <- ca.jo(log(PepperPrice), ecdet = "const", type = "eigen")
+## summary(pepper_jo2)
+
+
+###################################################
+### chunk number 42: dynlm-by-hand
+###################################################
+dd <- log(UKDriverDeaths)
+dd_dat <- ts.intersect(dd, dd1 = lag(dd, k = -1),
+ dd12 = lag(dd, k = -12))
+lm(dd ~ dd1 + dd12, data = dd_dat)
+
+
+###################################################
+### chunk number 43: dynlm
+###################################################
+library("dynlm")
+dynlm(dd ~ L(dd) + L(dd, 12))
+
+
+###################################################
+### chunk number 44: efp
+###################################################
+library("strucchange")
+dd_ocus <- efp(dd ~ dd1 + dd12, data = dd_dat,
+ type = "OLS-CUSUM")
+
+
+###################################################
+### chunk number 45: efp-test
+###################################################
+sctest(dd_ocus)
+
+
+###################################################
+### chunk number 46: efp-plot eval=FALSE
+###################################################
+## plot(dd_ocus)
+
+
+###################################################
+### chunk number 47: Fstats
+###################################################
+dd_fs <- Fstats(dd ~ dd1 + dd12, data = dd_dat, from = 0.1)
+plot(dd_fs)
+sctest(dd_fs)
+
+
+###################################################
+### chunk number 48: ocus-supF
+###################################################
+plot(dd_ocus)
+plot(dd_fs, main = "supF test")
+
+
+###################################################
+### chunk number 49: GermanM1
+###################################################
+data("GermanM1")
+LTW <- dm ~ dy2 + dR + dR1 + dp + m1 + y1 + R1 + season
+
+
+###################################################
+### chunk number 50: re eval=FALSE
+###################################################
+## m1_re <- efp(LTW, data = GermanM1, type = "RE")
+## plot(m1_re)
+
+
+###################################################
+### chunk number 51: re1
+###################################################
+m1_re <- efp(LTW, data = GermanM1, type = "RE")
+plot(m1_re)
+
+
+###################################################
+### chunk number 52: dating
+###################################################
+dd_bp <- breakpoints(dd ~ dd1 + dd12, data = dd_dat, h = 0.1)
+
+
+###################################################
+### chunk number 53: dating-coef
+###################################################
+coef(dd_bp, breaks = 2)
+
+
+###################################################
+### chunk number 54: dating-plot eval=FALSE
+###################################################
+## plot(dd)
+## lines(fitted(dd_bp, breaks = 2), col = 4)
+## lines(confint(dd_bp, breaks = 2))
+
+
+###################################################
+### chunk number 55: dating-plot1
+###################################################
+plot(dd_bp, legend = FALSE, main = "")
+plot(dd)
+lines(fitted(dd_bp, breaks = 2), col = 4)
+lines(confint(dd_bp, breaks = 2))
+
+
+###################################################
+### chunk number 56: StructTS
+###################################################
+dd_struct <- StructTS(log(UKDriverDeaths))
+
+
+###################################################
+### chunk number 57: StructTS-plot eval=FALSE
+###################################################
+## plot(cbind(fitted(dd_struct), residuals(dd_struct)))
+
+
+###################################################
+### chunk number 58: StructTS-plot1
+###################################################
+dd_struct_plot <- cbind(fitted(dd_struct), residuals = residuals(dd_struct))
+colnames(dd_struct_plot) <- c("level", "slope", "season", "residuals")
+plot(dd_struct_plot, main = "")
+
+
+###################################################
+### chunk number 59: garch-plot
+###################################################
+data("MarkPound")
+plot(MarkPound, main = "")
+
+
+###################################################
+### chunk number 60: garch
+###################################################
+mp <- garch(MarkPound, grad = "numerical", trace = FALSE)
+summary(mp)
+
+
diff --git a/demo/Ch-Validation.R b/demo/Ch-Validation.R
new file mode 100644
index 0000000..8a99f14
--- /dev/null
+++ b/demo/Ch-Validation.R
@@ -0,0 +1,362 @@
+###################################################
+### chunk number 1: setup
+###################################################
+options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+
+options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
+
+library("AER")
+
+set.seed(1071)
+
+
+###################################################
+### chunk number 2: ps-summary
+###################################################
+data("PublicSchools")
+summary(PublicSchools)
+
+
+###################################################
+### chunk number 3: ps-plot eval=FALSE
+###################################################
+## ps <- na.omit(PublicSchools)
+## ps$Income <- ps$Income / 10000
+## plot(Expenditure ~ Income, data = ps, ylim = c(230, 830))
+## ps_lm <- lm(Expenditure ~ Income, data = ps)
+## abline(ps_lm)
+## id <- c(2, 24, 48)
+## text(ps[id, 2:1], rownames(ps)[id], pos = 1, xpd = TRUE)
+
+
+###################################################
+### chunk number 4: ps-plot1
+###################################################
+ps <- na.omit(PublicSchools)
+ps$Income <- ps$Income / 10000
+plot(Expenditure ~ Income, data = ps, ylim = c(230, 830))
+ps_lm <- lm(Expenditure ~ Income, data = ps)
+abline(ps_lm)
+id <- c(2, 24, 48)
+text(ps[id, 2:1], rownames(ps)[id], pos = 1, xpd = TRUE)
+
+
+###################################################
+### chunk number 5: ps-lmplot eval=FALSE
+###################################################
+## plot(ps_lm, which = 1:6)
+
+
+###################################################
+### chunk number 6: ps-lmplot1
+###################################################
+plot(ps_lm, which = 1:6)
+
+
+###################################################
+### chunk number 7: ps-hatvalues eval=FALSE
+###################################################
+## ps_hat <- hatvalues(ps_lm)
+## plot(ps_hat)
+## abline(h = c(1, 3) * mean(ps_hat), col = 2)
+## id <- which(ps_hat > 3 * mean(ps_hat))
+## text(id, ps_hat[id], rownames(ps)[id], pos = 1, xpd = TRUE)
+
+
+###################################################
+### chunk number 8: ps-hatvalues1
+###################################################
+ps_hat <- hatvalues(ps_lm)
+plot(ps_hat)
+abline(h = c(1, 3) * mean(ps_hat), col = 2)
+id <- which(ps_hat > 3 * mean(ps_hat))
+text(id, ps_hat[id], rownames(ps)[id], pos = 1, xpd = TRUE)
+
+
+###################################################
+### chunk number 9: influence-measures1 eval=FALSE
+###################################################
+## influence.measures(ps_lm)
+
+
+###################################################
+### chunk number 10: which-hatvalues
+###################################################
+which(ps_hat > 3 * mean(ps_hat))
+
+
+###################################################
+### chunk number 11: influence-measures2
+###################################################
+summary(influence.measures(ps_lm))
+
+
+###################################################
+### chunk number 12: ps-noinf eval=FALSE
+###################################################
+## plot(Expenditure ~ Income, data = ps, ylim = c(230, 830))
+## abline(ps_lm)
+## id <- which(apply(influence.measures(ps_lm)$is.inf, 1, any))
+## text(ps[id, 2:1], rownames(ps)[id], pos = 1, xpd = TRUE)
+## ps_noinf <- lm(Expenditure ~ Income, data = ps[-id,])
+## abline(ps_noinf, lty = 2)
+
+
+###################################################
+### chunk number 13: ps-noinf1
+###################################################
+plot(Expenditure ~ Income, data = ps, ylim = c(230, 830))
+abline(ps_lm)
+id <- which(apply(influence.measures(ps_lm)$is.inf, 1, any))
+text(ps[id, 2:1], rownames(ps)[id], pos = 1, xpd = TRUE)
+ps_noinf <- lm(Expenditure ~ Income, data = ps[-id,])
+abline(ps_noinf, lty = 2)
+
+
+###################################################
+### chunk number 14: journals-age
+###################################################
+data("Journals")
+journals <- Journals[, c("subs", "price")]
+journals$citeprice <- Journals$price/Journals$citations
+journals$age <- 2000 - Journals$foundingyear
+
+
+###################################################
+### chunk number 15: journals-lm
+###################################################
+jour_lm <- lm(log(subs) ~ log(citeprice), data = journals)
+
+
+###################################################
+### chunk number 16: bptest1
+###################################################
+bptest(jour_lm)
+
+
+###################################################
+### chunk number 17: bptest2
+###################################################
+bptest(jour_lm, ~ log(citeprice) + I(log(citeprice)^2),
+ data = journals)
+
+
+###################################################
+### chunk number 18: gqtest
+###################################################
+gqtest(jour_lm, order.by = ~ citeprice, data = journals)
+
+
+###################################################
+### chunk number 19: resettest
+###################################################
+resettest(jour_lm)
+
+
+###################################################
+### chunk number 20: raintest
+###################################################
+raintest(jour_lm, order.by = ~ age, data = journals)
+
+
+###################################################
+### chunk number 21: harvtest
+###################################################
+harvtest(jour_lm, order.by = ~ age, data = journals)
+
+
+###################################################
+### chunk number 22:
+###################################################
+library("dynlm")
+
+
+###################################################
+### chunk number 23: usmacro-dynlm
+###################################################
+data("USMacroG")
+consump1 <- dynlm(consumption ~ dpi + L(dpi),
+ data = USMacroG)
+
+
+###################################################
+### chunk number 24: dwtest
+###################################################
+dwtest(consump1)
+
+
+###################################################
+### chunk number 25: Box-test
+###################################################
+Box.test(residuals(consump1), type = "Ljung-Box")
+
+
+###################################################
+### chunk number 26: bgtest
+###################################################
+bgtest(consump1)
+
+
+###################################################
+### chunk number 27: vcov
+###################################################
+vcov(jour_lm)
+vcovHC(jour_lm)
+
+
+###################################################
+### chunk number 28: coeftest
+###################################################
+coeftest(jour_lm, vcov = vcovHC)
+
+
+###################################################
+### chunk number 29: sandwiches
+###################################################
+t(sapply(c("const", "HC0", "HC1", "HC2", "HC3", "HC4"),
+ function(x) sqrt(diag(vcovHC(jour_lm, type = x)))))
+
+
+###################################################
+### chunk number 30: ps-anova
+###################################################
+ps_lm <- lm(Expenditure ~ Income, data = ps)
+ps_lm2 <- lm(Expenditure ~ Income + I(Income^2), data = ps)
+anova(ps_lm, ps_lm2)
+
+
+###################################################
+### chunk number 31: ps-waldtest
+###################################################
+waldtest(ps_lm, ps_lm2, vcov = vcovHC(ps_lm2, type = "HC4"))
+
+
+###################################################
+### chunk number 32: vcovHAC
+###################################################
+rbind(SE = sqrt(diag(vcov(consump1))),
+ QS = sqrt(diag(kernHAC(consump1))),
+ NW = sqrt(diag(NeweyWest(consump1))))
+
+
+###################################################
+### chunk number 33: solow-lm
+###################################################
+data("OECDGrowth")
+solow_lm <- lm(log(gdp85/gdp60) ~ log(gdp60) +
+ log(invest) + log(popgrowth + .05), data = OECDGrowth)
+summary(solow_lm)
+
+
+###################################################
+### chunk number 34: solow-plot eval=FALSE
+###################################################
+## plot(solow_lm)
+
+
+###################################################
+### chunk number 35: solow-lts
+###################################################
+library("MASS")
+solow_lts <- lqs(log(gdp85/gdp60) ~ log(gdp60) +
+ log(invest) + log(popgrowth + .05), data = OECDGrowth,
+ psamp = 13, nsamp = "exact")
+
+
+###################################################
+### chunk number 36: solow-smallresid
+###################################################
+smallresid <- which(
+ abs(residuals(solow_lts)/solow_lts$scale[2]) <= 2.5)
+
+
+###################################################
+### chunk number 37: solow-nohighlev
+###################################################
+X <- model.matrix(solow_lm)[,-1]
+Xcv <- cov.rob(X, nsamp = "exact")
+nohighlev <- which(
+ sqrt(mahalanobis(X, Xcv$center, Xcv$cov)) <= 2.5)
+
+
+###################################################
+### chunk number 38: solow-goodobs
+###################################################
+goodobs <- unique(c(smallresid, nohighlev))
+
+
+###################################################
+### chunk number 39: solow-badobs
+###################################################
+rownames(OECDGrowth)[-goodobs]
+
+
+###################################################
+### chunk number 40: solow-rob
+###################################################
+solow_rob <- update(solow_lm, subset = goodobs)
+summary(solow_rob)
+
+
+###################################################
+### chunk number 41: quantreg
+###################################################
+library("quantreg")
+
+
+###################################################
+### chunk number 42: cps-lad
+###################################################
+library("quantreg")
+data("CPS1988")
+cps_f <- log(wage) ~ experience + I(experience^2) + education
+cps_lad <- rq(cps_f, data = CPS1988)
+summary(cps_lad)
+
+
+###################################################
+### chunk number 43: cps-rq
+###################################################
+cps_rq <- rq(cps_f, tau = c(0.25, 0.75), data = CPS1988)
+summary(cps_rq)
+
+
+###################################################
+### chunk number 44: cps-rqs
+###################################################
+cps_rq25 <- rq(cps_f, tau = 0.25, data = CPS1988)
+cps_rq75 <- rq(cps_f, tau = 0.75, data = CPS1988)
+anova(cps_rq25, cps_rq75)
+
+
+###################################################
+### chunk number 45: cps-rq-anova
+###################################################
+anova(cps_rq25, cps_rq75, joint = FALSE)
+
+
+###################################################
+### chunk number 46: rqbig
+###################################################
+cps_rqbig <- rq(cps_f, tau = seq(0.05, 0.95, by = 0.05),
+ data = CPS1988)
+cps_rqbigs <- summary(cps_rqbig)
+
+
+###################################################
+### chunk number 47: rqbig-plot eval=FALSE
+###################################################
+## plot(cps_rqbigs)
+
+
+###################################################
+### chunk number 48: rqbig-plot1
+###################################################
+plot(cps_rqbigs)
+
+
diff --git a/inst/CITATION b/inst/CITATION
new file mode 100644
index 0000000..359b4b9
--- /dev/null
+++ b/inst/CITATION
@@ -0,0 +1,18 @@
+citEntry(entry = "Book",
+ title = "Applied Econometrics with {R}",
+ author = personList(as.person("Christian Kleiber"),
+ as.person("Achim Zeileis")),
+ year = "2008",
+ publisher = "Springer-Verlag",
+ address = "New York",
+ note = "{ISBN} 978-0-387-77316-2",
+ url = "https://CRAN.R-project.org/package=AER",
+
+ textVersion =
+ paste("Christian Kleiber and Achim Zeileis (2008).",
+ "Applied Econometrics with R.",
+ "New York: Springer-Verlag. ISBN 978-0-387-77316-2.",
+ "URL https://CRAN.R-project.org/package=AER"),
+
+ header = "To cite AER, please use:"
+)
diff --git a/inst/doc/AER.R b/inst/doc/AER.R
new file mode 100644
index 0000000..ce6431f
--- /dev/null
+++ b/inst/doc/AER.R
@@ -0,0 +1,34 @@
+### R code from vignette source 'AER.Rnw'
+
+###################################################
+### code chunk number 1: options
+###################################################
+options(prompt = "R> ", digits = 4, show.signif.stars = FALSE)
+
+
+###################################################
+### code chunk number 2: demo (eval = FALSE)
+###################################################
+## demo("Ch-Intro", package = "AER")
+
+
+###################################################
+### code chunk number 3: data (eval = FALSE)
+###################################################
+## data(package = "AER")
+
+
+###################################################
+### code chunk number 4: help (eval = FALSE)
+###################################################
+## help("Greene2003", package = "AER")
+
+
+###################################################
+### code chunk number 5: pgmm-new (eval = FALSE)
+###################################################
+## empl_ab <- pgmm(log(emp) ~ lag(log(emp), 1:2) + lag(log(wage), 0:1)
+## + log(capital) + lag(log(output), 0:1) | lag(log(emp), 2:99),
+## data = EmplUK, effect = "twoways", model = "twosteps")
+
+
diff --git a/inst/doc/AER.Rnw b/inst/doc/AER.Rnw
new file mode 100644
index 0000000..604fb8f
--- /dev/null
+++ b/inst/doc/AER.Rnw
@@ -0,0 +1,281 @@
+\documentclass[nojss]{jss}
+
+%% need no \usepackage{Sweave}
+\usepackage{thumbpdf}
+
+%% new commands
+\newcommand{\class}[1]{``\code{#1}''}
+\newcommand{\fct}[1]{\code{#1()}}
+
+\SweaveOpts{engine=R, eps=FALSE, keep.source = TRUE}
+<<options, echo=FALSE>>=
+options(prompt = "R> ", digits = 4, show.signif.stars = FALSE)
+@
+%%\VignetteIndexEntry{Applied Econometrics with R: Package Vignette and Errata}
+%%\VignettePackage{AER}
+%%\VignetteDepends{AER}
+%%\VignetteKeywords{econometrics, statistical software, R}
+
+\author{Christian Kleiber\\Universit\"at Basel
+ \And Achim Zeileis\\Universit\"at Innsbruck}
+\Plainauthor{Christian Kleiber, Achim Zeileis}
+\title{Applied Econometrics with \proglang{R}:\\Package Vignette and Errata}
+\Plaintitle{Applied Econometrics with R: Package Vignette and Errata}
+\Shorttitle{\pkg{AER}: Package Vignette and Errata}
+
+\Keywords{econometrics, statistical software, \proglang{R}}
+\Plainkeywords{econometrics, statistical software, R}
+
+\Abstract{
+ ``Applied Econometrics with \proglang{R}''
+ \citep[Springer-Verlag, ISBN~978-0-387-77316-2, pp.~vii+222]{aer:Kleiber+Zeileis:2008}
+ is the first book on applied econometrics using the \proglang{R}~system
+ for statistical computing and graphics \citep{aer:R:2016}.
+ It presents hands-on examples for a
+ wide range of econometric models, from classical linear regression models for
+ cross-section, time series or panel data and the common non-linear models of
+ microeconometrics, such as logit, probit, tobit models as well as regression
+ models for count data, to recent
+ semiparametric extensions. In addition, it provides a chapter on programming,
+ including simulations, optimization and an introduction to \proglang{R} tools
+ enabling reproducible econometric research.
+ The methods are presented by illustrating, among other things, the fitting
+ of wage equations, growth regressions, dynamic
+ regressions and time series models as well as various models of microeconometrics.
+
+ The book is accompanied by the \proglang{R} package
+ \pkg{AER} \citep{aer:Kleiber+Zeileis:2016} which contains some new \proglang{R}
+ functionality, some 100 data sets
+ taken from a wide variety of sources, the full source code for all examples
+ used in the book, as well as further worked examples, e.g., from popular textbooks.
+
+ This vignette provides an overview of the package contents and contains
+ a list of errata for the book.
+}
+
+\Address{
+ Christian Kleiber\\
+ Faculty of Business and Economics\\
+ Universit\"at Basel\\
+ Peter Merian-Weg 6\\
+ 4002 Basel, Switzerland\\
+ E-mail: \email{Christian.Kleiber at unibas.ch}\\
+ URL: \url{https://wwz.unibas.ch/kleiber/}\\
+
+ Achim Zeileis\\
+ Department of Statistics\\
+ Faculty of Economics and Statistics\\
+ Universit\"at Innsbruck\\
+ Universit\"atsstr.~15\\
+ 6020 Innsbruck, Austria\\
+ E-mail: \email{Achim.Zeileis at R-project.org}\\
+ URL: \url{https://eeecon.uibk.ac.at/~zeileis/}
+}
+
+\begin{document}
+
+\section{Package overview}
+
+\subsection[R code from the book]{\proglang{R} code from the book}
+
+The full \proglang{R} code from the book is provided in the demos for the package \pkg{AER}.
+The source scripts can be found in the \code{demo}
+directory of the package and executed interactively by calling
+\fct{demo}, as in
+%
+<<demo, eval=FALSE>>=
+demo("Ch-Intro", package = "AER")
+@
+%
+One demo per chapter is provided:
+\begin{itemize}
+ \item \code{Ch-Intro} (Chapter~1: Introduction),
+ \item \code{Ch-Basics} (Chapter~2: Basics),
+ \item \code{Ch-LinearRegression} (Chapter~3: Linear Regression),
+ \item \code{Ch-Validation} (Chapter~4: Diagnostics and Alternative Methods of Regression),
+ \item \code{Ch-Microeconometrics} (Chapter~5: Models of Microeconometrics),
+ \item \code{Ch-TimeSeries} (Chapter~6: Time Series),
+ \item \code{Ch-Programming} (Chapter~7: Programming Your Own Analysis).
+\end{itemize}
+This list of demos is also shown by \code{demo(package = "AER")}.
+
+The same scripts are contained in the \code{tests} directory of the package
+so that they are automatically checked and compared with the desired output
+provided in \code{.Rout.save} files.
+
+To make the code fully reproducible and to avoid some lengthy computations
+in the daily checks, a few selected code chunks are commented out in the
+scripts. Also, for technical reasons, some graphics code chunks are repeated,
+once commented out and once without comments.
+
+
+\subsection{Data sets}
+
+The \pkg{AER} package includes some 100 data sets from leading applied
+econometrics journals and popular econometrics textbooks. Many data sets
+have been obtained from the data archive of the \emph{Journal of Applied
+Econometrics} and the (now defunct) data archive of the
+\emph{Journal of Business \& Economic Statistics} (see note below).
+Some of these are used in recent textbooks, among them
+\cite{aer:Baltagi:2002}, \cite{aer:Davidson+MacKinnon:2004}, \cite{aer:Greene:2003},
+\cite{aer:Stock+Watson:2007}, and \cite{aer:Verbeek:2004}. In addition, we provide
+all further data sets from \cite{aer:Baltagi:2002}, \cite{aer:Franses:1998},
+\cite{aer:Greene:2003}, \cite{aer:Stock+Watson:2007}, and \cite{aer:Winkelmann+Boes:2009}.
+Selected data sets from \cite{aer:Franses+vanDijk+Opschoor:2014} are also included.
+
+Detailed information about the source of each data set, descriptions of
+the variables included, and usually also examples for typical analyses
+are provided on the respective manual pages. A full list of all data sets
+in \pkg{AER} can be obtained via
+%
+<<data, eval=FALSE>>=
+data(package = "AER")
+@
+%
+In addition, manual pages corresponding to selected textbooks are available.
+They list all data sets from the respective book and provide extensive
+code for replicating many of the empirical examples. See, for example,
+<<help, eval=FALSE>>=
+help("Greene2003", package = "AER")
+@
+for data sets and code for \cite{aer:Greene:2003}.
+Currently available manual pages are:
+
+\begin{itemize}
+ \item \code{Baltagi2002} for \cite{aer:Baltagi:2002},
+ \item \code{CameronTrivedi1998} for \cite{aer:Cameron+Trivedi:1998},
+ \item \code{Franses1998} for \cite{aer:Franses:1998},
+ \item \code{Greene2003} for \cite{aer:Greene:2003},
+ \item \code{StockWatson2007} for \cite{aer:Stock+Watson:2007}.
+ \item \code{WinkelmannBoes2009} for \cite{aer:Winkelmann+Boes:2009}.
+\end{itemize}
+
+
+\subsection[New R functions]{New \proglang{R} functions}
+
+\pkg{AER} provides a few new \proglang{R} functions extending
+or complementing methods previously available in \proglang{R}:
+\begin{itemize}
+ \item \fct{tobit} is a convenience interface to \fct{survreg}
+ from package \pkg{survival} for fitting tobit regressions
+ to censored data. In addition to the fitting function itself,
+ the usual set of accessor and extractor functions is
+ provided, e.g., \fct{print}, \fct{summary}, \fct{logLik},
+ etc. For more details see \code{?tobit}.
+ \item \fct{ivreg} fits instrumental-variable regressions
+ via two-stage least squares. It provides a formula
+ interface and calls the workhorse function \fct{ivreg.fit}
+ which in turn calls \fct{lm.fit} twice. In addition to the fitting functions,
+ the usual set of accessor and extractor functions is
+ provided, e.g., \fct{print}, \fct{summary}, \fct{anova}, etc.
+ For more details see \code{?ivreg}, \code{?ivreg.fit},
+ and \code{?summary.ivreg}, respectively.
+ \item \fct{dispersiontest} tests the null hypothesis of
+ equidispersion in Poisson regressions against the alternative
+ of overdispersion and/or underdispersion. For more details
+ see \code{?dispersiontest}.
+\end{itemize}
+
+
+
+\section{Errata and comments}
+
+Below we list the errors that have been found in the book so far. Please report any further errors you find to us.
+
+We also provide some comments, for example on functions whose interface has changed.
+
+\begin{itemize}
+ \item p.~5--9, 46--53: There are now very minor differences in the plots pertaining to
+ Example~2 (Determinants of wages) in Chapter~1.1 and Chapter~2.8 (Exploratory Data Analysis with \proglang{R})
+ due to a missing observation. Specifically, the version of the \code{CPS1985} data used
+ for the book contained only 533~observations, the original observation~1 had been omitted inadvertently.
+ \item p.~38, 48, 85: By default there is less rounding in calls to \code{summary()} starting from
+ \proglang{R}~3.4.0.
+ \item p.~63--65, 130, 143: The function \fct{linear.hypothesis} from the \pkg{car} package has
+ been renamed to \fct{linearHypothesis} starting from \pkg{car}~2.0-0. The old interface
+ is currently still supported but results in a warning.
+ \item p.~85--86: Due to a bug in the \code{summary()} method for ``\code{plm}'' objects,
+ the degrees of freedom reported for the $F$~statistics were interchanged and thus the
+ $p$~values were not correct. Therefore, the $p$~values printed in the book at the end
+ of \code{summary(gr_fe)} and \code{summary(gr_re)} are not correct,
+ they should both be \code{< 2.22e-16}. Using \pkg{plm} 1.1-1 or higher, the code produces
+ the correct output.
+ \item pp.~88--89: As of version 1.3-1 of the \pkg{plm} package, summaries of ``\code{pgmm}''
+ objects provide robust standard errors by default. The output presented on pp.~88--89 is
+ still available, but now requires \code{summary(empl_ab, robust = FALSE)}.
+
+ Also, the formula interface for \fct{pgmm} has changed. Using the new interface,
+ the function call for the Arellano-Bond example is
+%
+<<pgmm-new, eval=FALSE>>=
+empl_ab <- pgmm(log(emp) ~ lag(log(emp), 1:2) + lag(log(wage), 0:1)
+ + log(capital) + lag(log(output), 0:1) | lag(log(emp), 2:99),
+ data = EmplUK, effect = "twoways", model = "twosteps")
+@
+%
+ The function call given in the book is still valid though.
+
+ \item p.~92: Exercise~6 cannot be solved using \code{PSID1982} since that data set only
+ contains a cross-section while Hausman-Taylor requires panel data. A panel version has
+ been available in the \pkg{plm} package under the name \code{Wages}; we have now added
+ \code{PSID7682} to \pkg{AER} for completeness (and consistent naming conventions).
+ Use \code{PSID7682} for the exercise.
+ \item pp.~98--100: \proglang{R} only provides a function \code{dffits()} but not \code{dffit()}
+ as claimed on p.~99. Somewhat confusingly the corresponding column in the output of
+ \code{influence.measures()} (as shown on p.~100) is called \code{dffit} by \proglang{R}
+ (rather than \code{dffits}).
+ \item p.~141: The log-likelihood for the tobit model lacked a minus sign. The correct version is
+%
+\[
+\ell(\beta, \sigma^2)
+= \sum_{y_i > 0} \left( \log\phi\{(y_i - x_i^\top \beta)/\sigma\} - \log\sigma \right)
+ + \sum_{y_i = 0} \log \Phi( - x_i^\top \beta /\sigma).
+\]
+%
+ \item p.~149: The standard error (and hence the corresponding $z$~test) of \code{admin|manage}
+ in the output of \code{coeftest(bank_polr)} is wrong, it should be \code{1.4744}.
+ This was caused by an inconsistency between \fct{polr} and its \fct{vcov} method which
+ has now been improved in the \pkg{MASS} package ($\ge$ 7.3-6).
+ \item p.~169: The comment regarding the output from the Johansen test is in error.
+ The null hypothesis of no cointegration is not rejected at the 10\% level. Nonetheless,
+ the table corresponding to Case~2 in \citet[][p.~420]{aer:Juselius:2006} reveals that the
+ trace statistic is significant at the 15\% level, thus the Johansen test weakly confirms
+ the initial two-step approach.
+ \item p.~179: For consistency, the GARCH code should be preceded by \code{data("MarkPound")}.
+
+ \item p.~192: The likelihood for the generalized production function was in error (code and computations were correct though).
+
+The correct likelihood for the model is
+%
+\[
+\mathcal{L} =
+\prod_{i=1}^n \left\{ \frac{1}{\sigma} \phi \left(\frac{\varepsilon_i}{\sigma}\right) \cdot \frac{1 + \theta Y_i}{Y_i} \right\} .
+\]
+%
+giving the log-likelihood
+%
+\[
+\ell = \sum_{i=1}^n \left\{ \log (1 + \theta Y_i) - \log Y_i \right\}
+ - n \log \sigma + \sum_{i=1}^n \log \phi (\varepsilon_i/\sigma) .
+\]
+
+ \item p.~205: The reference for Henningsen (2008) should be: %% FIXME: will be package vignette
+ \begin{quote}
+ Henningsen A (2008). ``Demand Analysis with the Almost Ideal Demand System
+ in \proglang{R}: Package \pkg{micEcon},'' Unpublished.
+ URL~\url{http://CRAN.R-project.org/package=micEcon}.
+ \end{quote}
+\end{itemize}
+
+
+\emph{Note:} Currently, all links on manual pages corresponding to data sets taken from
+the Journal of Business \& Economic Statistics (JBES) archive are broken (data sets
+\code{MarkPound}, and \code{RecreationDemand}). The reason is the redesign of the American
+Statistical Association (ASA) website, rendering the old ASA data archive nonfunctional.
+The ASA journals manager currently appears to supply data on a case-by-case basis.
+The problem awaits a more permanent solution.
+
+
+\bibliography{aer}
+
+\end{document}
diff --git a/inst/doc/AER.pdf b/inst/doc/AER.pdf
new file mode 100644
index 0000000..5b40e19
Binary files /dev/null and b/inst/doc/AER.pdf differ
diff --git a/inst/doc/Sweave-journals.R b/inst/doc/Sweave-journals.R
new file mode 100644
index 0000000..4dec578
--- /dev/null
+++ b/inst/doc/Sweave-journals.R
@@ -0,0 +1,17 @@
+### R code from vignette source 'Sweave-journals.Rnw'
+
+###################################################
+### code chunk number 1: Sweave-journals.Rnw:8-11
+###################################################
+data("Journals", package = "AER")
+journals_lm <- lm(log(subs) ~ log(price/citations), data = Journals)
+journals_lm
+
+
+###################################################
+### code chunk number 2: Sweave-journals.Rnw:17-19
+###################################################
+plot(log(subs) ~ log(price/citations), data = Journals)
+abline(journals_lm)
+
+
diff --git a/inst/doc/Sweave-journals.Rnw b/inst/doc/Sweave-journals.Rnw
new file mode 100644
index 0000000..4a08ff3
--- /dev/null
+++ b/inst/doc/Sweave-journals.Rnw
@@ -0,0 +1,23 @@
+%\VignetteIndexEntry{Sweave Example: Linear Regression for Economics Journals Data}
+\documentclass[a4paper]{article}
+
+\begin{document}
+
+We fit a linear regression for the economic journals demand model.
+
+<<>>=
+data("Journals", package = "AER")
+journals_lm <- lm(log(subs) ~ log(price/citations), data = Journals)
+journals_lm
+@
+
+A scatter plot with the fitted regression line is shown below.
+
+\begin{center}
+<<fig=TRUE, echo=FALSE>>=
+plot(log(subs) ~ log(price/citations), data = Journals)
+abline(journals_lm)
+@
+\end{center}
+
+\end{document}
diff --git a/inst/doc/Sweave-journals.pdf b/inst/doc/Sweave-journals.pdf
new file mode 100644
index 0000000..404758d
Binary files /dev/null and b/inst/doc/Sweave-journals.pdf differ
diff --git a/man/Affairs.Rd b/man/Affairs.Rd
new file mode 100644
index 0000000..d75ae42
--- /dev/null
+++ b/man/Affairs.Rd
@@ -0,0 +1,82 @@
+\name{Affairs}
+\alias{Affairs}
+\title{Fair's Extramarital Affairs Data}
+
+\description{
+Infidelity data, known as Fair's Affairs. Cross-section data from a survey
+conducted by Psychology Today in 1969.
+}
+
+\usage{data("Affairs")}
+
+\format{
+A data frame containing 601 observations on 9 variables.
+\describe{
+ \item{affairs}{numeric. How often engaged in extramarital sexual intercourse
+ during the past year?}
+ \item{gender}{factor indicating gender.}
+ \item{age}{numeric variable coding age in years: \code{17.5} = under 20, \code{22} = 20--24,
+ \code{27} = 25--29, \code{32} = 30--34, \code{37} = 35--39, \code{42} = 40--44,
+ \code{47} = 45--49, \code{52} = 50--54, \code{57} = 55 or over.}
+ \item{yearsmarried}{numeric variable coding number of years married: \code{0.125} = 3 months or less,
+ \code{0.417} = 4--6 months, \code{0.75} = 6 months--1 year, \code{1.5} = 1--2 years,
+ \code{4} = 3--5 years, \code{7} = 6--8 years, \code{10} = 9--11 years, \code{15} = 12 or more years.}
+ \item{children}{factor. Are there children in the marriage?}
+ \item{religiousness}{numeric variable coding religiousness: \code{1} = anti, \code{2} = not at all,
+ \code{3} = slightly, \code{4} = somewhat, \code{5} = very.}
+ \item{education}{numeric variable coding level of education: \code{9} = grade school,
+ \code{12} = high school graduate, \code{14} = some college, \code{16} = college graduate,
+ \code{17} = some graduate work, \code{18} = master's degree, \code{20} = Ph.D., M.D., or
+ other advanced degree.}
+ \item{occupation}{numeric variable coding occupation according to Hollingshead classification
+ (reverse numbering).}
+ \item{rating}{numeric variable coding self rating of marriage: \code{1} = very unhappy,
+ \code{2} = somewhat unhappy, \code{3} = average, \code{4} = happier than average,
+ \code{5} = very happy.}
+}
+}
+
+\source{
+Online complements to Greene (2003). Table F22.2.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+
+Fair, R.C. (1978). A Theory of Extramarital Affairs. \emph{Journal of Political Economy},
+\bold{86}, 45--61.
+}
+
+\seealso{\code{\link{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"))
+
+fm_tobit <- tobit(affairs ~ age + yearsmarried + religiousness + occupation + rating,
+ data = Affairs)
+fm_tobit2 <- tobit(affairs ~ age + yearsmarried + religiousness + occupation + rating,
+ right = 4, data = Affairs)
+
+fm_pois <- glm(affairs ~ age + yearsmarried + religiousness + occupation + rating,
+ data = Affairs, family = poisson)
+
+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)
+}
+
+\keyword{datasets}
diff --git a/man/ArgentinaCPI.Rd b/man/ArgentinaCPI.Rd
new file mode 100644
index 0000000..9d44e3f
--- /dev/null
+++ b/man/ArgentinaCPI.Rd
@@ -0,0 +1,44 @@
+\name{ArgentinaCPI}
+\alias{ArgentinaCPI}
+\title{Consumer Price Index in Argentina}
+\description{
+Time series of consumer price index (CPI) in Argentina (index with 1969(4) = 1).
+}
+\usage{data("ArgentinaCPI")}
+
+\format{
+A quarterly univariate time series from 1970(1) to 1989(4).
+}
+
+\source{
+Online complements to Franses (1998).
+}
+
+\references{
+De Ruyter van Steveninck, M.A. (1996). \emph{The Impact of Capital Imports; Argentina 1970--1989}.
+Amsterdam: Thesis Publishers.
+
+Franses, P.H. (1998). \emph{Time Series Models for Business and Economic Forecasting}.
+Cambridge, UK: Cambridge University Press.
+}
+
+\seealso{\code{\link{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))
+
+## eq. (3.90), p.54
+acpi_ols <- dynlm(d(log(acpi)) ~ L(d(log(acpi))))
+summary(acpi_ols)
+
+## alternatively
+ar(diff(log(acpi)), order.max = 1, method = "ols")
+}
+
+\keyword{datasets}
diff --git a/man/Baltagi2002.Rd b/man/Baltagi2002.Rd
new file mode 100644
index 0000000..8650cc3
--- /dev/null
+++ b/man/Baltagi2002.Rd
@@ -0,0 +1,183 @@
+\name{Baltagi2002}
+\alias{Baltagi2002}
+
+\title{Data and Examples from Baltagi (2002)}
+
+\description{
+This manual page collects a list of examples from the book. Some
+solutions might not be exact and the list is certainly not complete.
+If you have suggestions for improvement (preferably in the form of code),
+please contact the package maintainer.
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed., Berlin: Springer-Verlag.
+}
+
+\seealso{\code{\link{BenderlyZwick}}, \code{\link{CigarettesB}}, \code{\link{EuroEnergy}},
+ \code{\link{Grunfeld}}, \code{\link{Mortgage}}, \code{\link{NaturalGas}},
+ \code{\link{OECDGas}}, \code{\link{OrangeCounty}}, \code{\link{PSID1982}},
+ \code{\link{TradeCredit}}, \code{\link{USConsump1993}}, \code{\link{USCrudes}},
+ \code{\link{USGasB}}, \code{\link{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)
+
+## Chapter 5: diagnostic tests (p. 111-115)
+cig_lm2 <- lm(packs ~ price + income, data = CigarettesB)
+summary(cig_lm2)
+## Glejser tests (p. 112)
+ares <- abs(residuals(cig_lm2))
+summary(lm(ares ~ income, data = CigarettesB))
+summary(lm(ares ~ I(1/income), data = CigarettesB))
+summary(lm(ares ~ I(1/sqrt(income)), data = CigarettesB))
+summary(lm(ares ~ sqrt(income), data = CigarettesB))
+## Goldfeld-Quandt test (p. 112)
+gqtest(cig_lm2, order.by = ~ income, data = CigarettesB, fraction = 12, alternative = "less")
+## NOTE: Baltagi computes the test statistic as mss1/mss2,
+## i.e., tries to find decreasing variances. gqtest() always uses
+## mss2/mss1 and has an "alternative" argument.
+
+## Spearman rank correlation test (p. 113)
+cor.test(~ ares + income, data = CigarettesB, method = "spearman")
+## Breusch-Pagan test (p. 113)
+bptest(cig_lm2, varformula = ~ income, data = CigarettesB, student = FALSE)
+## White test (Table 5.1, p. 113)
+bptest(cig_lm2, ~ income * price + I(income^2) + I(price^2), data = CigarettesB)
+## White HC standard errors (Table 5.2, p. 114)
+coeftest(cig_lm2, vcov = vcovHC(cig_lm2, type = "HC1"))
+## Jarque-Bera test (Figure 5.2, p. 115)
+hist(residuals(cig_lm2), breaks = 16, ylim = c(0, 10), col = "lightgray")
+library("tseries")
+jarque.bera.test(residuals(cig_lm2))
+
+## Tables 8.1 and 8.2
+influence.measures(cig_lm2)
+
+
+#####################################
+## US consumption data (1950-1993) ##
+#####################################
+
+## data
+data("USConsump1993", package = "AER")
+plot(USConsump1993, plot.type = "single", col = 1:2)
+
+## Chapter 5 (p. 122-125)
+fm <- lm(expenditure ~ income, data = USConsump1993)
+summary(fm)
+## Durbin-Watson test (p. 122)
+dwtest(fm)
+## Breusch-Godfrey test (Table 5.4, p. 124)
+bgtest(fm)
+## Newey-West standard errors (Table 5.5, p. 125)
+coeftest(fm, vcov = NeweyWest(fm, lag = 3, prewhite = FALSE, adjust = TRUE))
+
+## 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)
+
+## J test for non-nested models
+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)))
+
+## dynamic regressions, eq. (14.8)
+fm <- dynlm(d(exps) ~ I(time(exps) - 1949) + L(exps))
+summary(fm)
+
+
+################################
+## Grunfeld's investment data ##
+################################
+
+## select the first three companies (as panel data)
+data("Grunfeld", package = "AER")
+pgr <- subset(Grunfeld, firm \%in\% levels(Grunfeld$firm)[1:3])
+library("plm")
+pgr <- plm.data(pgr, c("firm", "year"))
+
+## Ex. 10.9
+library("systemfit")
+gr_ols <- systemfit(invest ~ value + capital, method = "OLS", data = pgr)
+gr_sur <- systemfit(invest ~ value + capital, method = "SUR", data = pgr)
+
+
+#########################################
+## Panel study on income dynamics 1982 ##
+#########################################
+
+## data
+data("PSID1982", package = "AER")
+
+## Table 4.1
+earn_lm <- lm(log(wage) ~ . + I(experience^2), data = PSID1982)
+summary(earn_lm)
+
+## Table 13.1
+union_lpm <- lm(I(as.numeric(union) - 1) ~ . - wage, data = PSID1982)
+union_probit <- glm(union ~ . - wage, data = PSID1982, family = binomial(link = "probit"))
+union_logit <- glm(union ~ . - wage, data = PSID1982, family = binomial)
+## probit OK, logit and LPM rather different.
+}
+
+\keyword{datasets}
diff --git a/man/BankWages.Rd b/man/BankWages.Rd
new file mode 100644
index 0000000..a3cce8e
--- /dev/null
+++ b/man/BankWages.Rd
@@ -0,0 +1,61 @@
+\name{BankWages}
+\alias{BankWages}
+\title{Bank Wages}
+
+\description{Wages of employees of a US bank.
+}
+
+\usage{data("BankWages")}
+
+\format{
+A data frame containing 474 observations on 4 variables.
+\describe{
+ \item{job}{Ordered factor indicating job category, with levels \code{"custodial"},
+ \code{"admin"} and \code{"manage"}.}
+ \item{education}{Education in years.}
+ \item{gender}{Factor indicating gender.}
+ \item{minority}{Factor. Is the employee member of a minority?}
+}
+}
+
+\source{
+Online complements to Heij, de Boer, Franses, Kloek, and van Dijk (2004).
+
+\url{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).
+\emph{Econometric Methods with Applications in Business and Economics}.
+Oxford: Oxford University Press.
+}
+
+\examples{
+data("BankWages")
+
+## exploratory analysis of job ~ education
+## (tables and spine plots, some education levels merged)
+xtabs(~ education + job, data = BankWages)
+edcat <- factor(BankWages$education)
+levels(edcat)[3:10] <- rep(c("14-15", "16-18", "19-21"), c(2, 3, 3))
+tab <- xtabs(~ edcat + job, data = BankWages)
+prop.table(tab, 1)
+spineplot(tab, off = 0)
+plot(job ~ edcat, data = BankWages, off = 0)
+
+## fit multinomial model for male employees
+library("nnet")
+fm_mnl <- multinom(job ~ education + minority, data = BankWages,
+ subset = gender == "male", trace = FALSE)
+summary(fm_mnl)
+confint(fm_mnl)
+
+## same with mlogit package
+if(require("mlogit")) {
+fm_mlogit <- mlogit(job ~ 1 | education + minority, data = BankWages,
+ subset = gender == "male", shape = "wide", reflevel = "custodial")
+summary(fm_mlogit)
+}
+}
+
+\keyword{datasets}
diff --git a/man/BenderlyZwick.Rd b/man/BenderlyZwick.Rd
new file mode 100644
index 0000000..2ba7d35
--- /dev/null
+++ b/man/BenderlyZwick.Rd
@@ -0,0 +1,65 @@
+\name{BenderlyZwick}
+\alias{BenderlyZwick}
+
+\title{Benderly and Zwick Data: Inflation, Growth and Stock Returns}
+
+\description{
+Time series data, 1952--1982.
+}
+\usage{data("BenderlyZwick")}
+\format{
+An annual multiple time series from 1952 to 1982 with 5 variables.
+\describe{
+ \item{returns}{real annual returns on stocks, measured using
+ the Ibbotson-Sinquefeld data base.}
+ \item{growth}{annual growth rate of output, measured by real GNP
+ (from the given year to the next year).}
+ \item{inflation}{inflation rate, measured as growth of price
+ rate (from December of the previous year to December of the present year).}
+ \item{growth2}{annual growth rate of real GNP as given by Baltagi.}
+ \item{inflation2}{inflation rate as given by Baltagi}
+}
+}
+
+\source{
+The first three columns of the data are from Table 1 in Benderly and Zwick (1985).
+The remaining columns are taken from the online complements of Baltagi (2002).
+The first column is identical in both sources, the other two variables differ
+in their numeric values and additionally the growth series seems to be lagged
+differently. Baltagi (2002) states Lott and Ray (1992) as the source for his
+version of the data set.
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed. Berlin, Springer.
+
+Benderly, J., and Zwick, B. (1985). Inflation, Real Balances, Output and Real Stock
+Returns. \emph{American Economic Review}, \bold{75}, 1115--1123.
+
+Lott, W.F., and Ray, S.C. (1992). \emph{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. \emph{Economics Letters}, \bold{71}, 1--8.
+}
+
+\seealso{\code{\link{Baltagi2002}}}
+
+\examples{
+data("BenderlyZwick")
+plot(BenderlyZwick)
+
+## Benderly and Zwick (1985), p. 1116
+library("dynlm")
+bz_ols <- dynlm(returns ~ growth + inflation,
+ data = BenderlyZwick/100, start = 1956, end = 1981)
+summary(bz_ols)
+
+## Zaman, Rousseeuw and Orhan (2001)
+## use larger period, without scaling
+bz_ols2 <- dynlm(returns ~ growth + inflation,
+ data = BenderlyZwick, start = 1954, end = 1981)
+summary(bz_ols2)
+}
+
+\keyword{datasets}
diff --git a/man/BondYield.Rd b/man/BondYield.Rd
new file mode 100644
index 0000000..f243175
--- /dev/null
+++ b/man/BondYield.Rd
@@ -0,0 +1,31 @@
+\name{BondYield}
+\alias{BondYield}
+\title{Bond Yield Data}
+
+\description{
+Monthly averages of the yield on a Moody's Aaa rated corporate bond (in percent/year).
+}
+
+\usage{data("BondYield")}
+\format{
+A monthly univariate time series from 1990(1) to 1994(12).
+}
+
+\source{
+Online complements to Greene (2003), Table F20.1.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}}
+
+\examples{
+data("BondYield")
+plot(BondYield)
+}
+
+\keyword{datasets}
diff --git a/man/CASchools.Rd b/man/CASchools.Rd
new file mode 100644
index 0000000..8d09ad3
--- /dev/null
+++ b/man/CASchools.Rd
@@ -0,0 +1,82 @@
+\name{CASchools}
+\alias{CASchools}
+\title{California Test Score Data}
+
+\description{The dataset contains data on test performance, school
+characteristics and student demographic backgrounds for school districts in California.}
+
+\usage{data("CASchools")}
+
+\format{
+A data frame containing 420 observations on 14 variables.
+\describe{
+ \item{district}{character. District code.}
+ \item{school}{character. School name.}
+ \item{county}{factor indicating county.}
+ \item{grades}{factor indicating grade span of district.}
+ \item{students}{Total enrollment.}
+ \item{teachers}{Number of teachers.}
+ \item{calworks}{Percent qualifying for CalWorks (income assistance).}
+ \item{lunch}{Percent qualifying for reduced-price lunch.}
+ \item{computer}{Number of computers.}
+ \item{expenditure}{Expenditure per student.}
+ \item{income}{District average income (in USD 1,000).}
+ \item{english}{Percent of English learners.}
+ \item{read}{Average reading score.}
+ \item{math}{Average math score.}
+}
+}
+
+\details{
+The data used here are from all 420 K-6 and K-8 districts in California
+with data available for 1998 and 1999. Test scores are on the Stanford
+9 standardized test administered to 5th grade students.
+School characteristics (averaged across the district) include enrollment,
+number of teachers (measured as \dQuote{full-time equivalents}, number of
+computers per classroom, and expenditures per student. Demographic
+variables for the students are averaged across the district.
+The demographic variables include the percentage of students in the
+public assistance program CalWorks (formerly AFDC), the percentage
+of students that qualify for a reduced price lunch, and the
+percentage of students that are English learners (that is, students
+for whom English is a second language).
+}
+
+\source{
+Online complements to Stock and Watson (2007).
+}
+
+\references{
+Stock, J. H. and Watson, M. W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}, \code{\link{MASchools}}}
+
+\examples{
+## data and transformations
+data("CASchools")
+CASchools$stratio <- with(CASchools, students/teachers)
+CASchools$score <- with(CASchools, (math + read)/2)
+
+## Stock and Watson (2007)
+## 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)
+
+## Table 7.1, p. 242 (numbers refer to columns)
+fmc3 <- lm(score ~ stratio + english + lunch, data = CASchools)
+fmc4 <- lm(score ~ stratio + english + calworks, data = CASchools)
+fmc5 <- lm(score ~ stratio + english + lunch + calworks, data = CASchools)
+
+## More examples can be found in:
+## help("StockWatson2007")
+}
+
+\keyword{datasets}
diff --git a/man/CPS1985.Rd b/man/CPS1985.Rd
new file mode 100644
index 0000000..0736b58
--- /dev/null
+++ b/man/CPS1985.Rd
@@ -0,0 +1,85 @@
+\name{CPS1985}
+\alias{CPS1985}
+\title{Determinants of Wages Data (CPS 1985)}
+
+\description{
+Cross-section data originating from the May 1985 Current Population Survey
+by the US Census Bureau (random sample drawn for Berndt 1991).
+}
+
+\usage{data("CPS1985")}
+
+\format{
+A data frame containing 534 observations on 11 variables.
+\describe{
+ \item{wage}{Wage (in dollars per hour).}
+ \item{education}{Number of years of education.}
+ \item{experience}{Number of years of potential work experience
+ (\code{age - education - 6}).}
+ \item{age}{Age in years.}
+ \item{ethnicity}{Factor with levels \code{"cauc"}, \code{"hispanic"},
+ \code{"other"}.}
+ \item{region}{Factor. Does the individual live in the South?}
+ \item{gender}{Factor indicating gender.}
+ \item{occupation}{Factor with levels \code{"worker"} (tradesperson or assembly line worker),
+ \code{"technical"} (technical or professional worker), \code{"services"} (service
+ worker), \code{"office"} (office and clerical worker), \code{"sales"} (sales worker),
+ \code{"management"} (management and administration).}
+ \item{sector}{Factor with levels \code{"manufacturing"} (manufacturing or mining),
+ \code{"construction"}, \code{"other"}.}
+ \item{union}{Factor. Does the individual work on a union job?}
+ \item{married}{Factor. Is the individual married?}
+}
+}
+
+\source{
+StatLib.
+
+\url{http://lib.stat.cmu.edu/datasets/CPS_85_Wages}
+}
+
+\references{
+Berndt, E.R. (1991). \emph{The Practice of Econometrics}. New York: Addison-Wesley.
+}
+
+\seealso{\code{\link{CPS1988}}, \code{\link{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),
+ 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"))
+}
+
+\keyword{datasets}
diff --git a/man/CPS1988.Rd b/man/CPS1988.Rd
new file mode 100644
index 0000000..5b0a8c1
--- /dev/null
+++ b/man/CPS1988.Rd
@@ -0,0 +1,72 @@
+\name{CPS1988}
+\alias{CPS1988}
+\title{Determinants of Wages Data (CPS 1988)}
+
+\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.
+\describe{
+ \item{wage}{Wage (in dollars per week).}
+ \item{education}{Number of years of education.}
+ \item{experience}{Number of years of potential work experience.}
+ \item{ethnicity}{Factor with levels \code{"cauc"} and \code{"afam"} (African-American).}
+ \item{smsa}{Factor. Does the individual reside in a Standard Metropolitan Statistical Area (SMSA)?}
+ \item{region}{Factor with levels \code{"northeast"}, \code{"midwest"}, \code{"south"}, \code{"west"}.}
+ \item{parttime}{Factor. Does the individual work part-time?}
+}
+}
+
+\details{
+A sample of men aged 18 to 70 with positive annual income greater than USD 50 in 1992,
+who are not self-employed nor working without pay. Wages are deflated by the deflator of
+Personal Consumption Expenditure for 1992.
+
+A problem with CPS data is that it does not provide actual work experience.
+It is therefore customary to compute experience as \code{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{
+\url{http://www.personal.psu.edu/hxb11/MEDIAN.HTM}
+}
+
+\references{
+Bierens, H.J., and Ginther, D. (2001). Integrated Conditional Moment Testing of Quantile Regression Models.
+\emph{Empirical Economics}, \bold{26}, 307--324.
+
+Buchinsky, M. (1998). Recent Advances in Quantile Regression Models: A Practical Guide for Empirical Research.
+\emph{Journal of Human Resources}, \bold{33}, 88--126.
+}
+
+\seealso{\code{\link{CPS1985}}, \code{\link{CPSSW}}}
+
+\examples{
+## data and packages
+library("quantreg")
+data("CPS1988")
+CPS1988$region <- relevel(CPS1988$region, ref = "south")
+
+## Model equations: Mincer-type, quartic, Buchinsky-type
+mincer <- log(wage) ~ ethnicity + education + experience + I(experience^2)
+quart <- log(wage) ~ ethnicity + education + experience + I(experience^2) +
+ I(experience^3) + I(experience^4)
+buchinsky <- log(wage) ~ ethnicity * (education + experience + parttime) +
+ region*smsa + I(experience^2) + I(education^2) + I(education*experience)
+
+## 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)
+}
+
+\keyword{datasets}
diff --git a/man/CPSSW.Rd b/man/CPSSW.Rd
new file mode 100644
index 0000000..3fc20ea
--- /dev/null
+++ b/man/CPSSW.Rd
@@ -0,0 +1,111 @@
+\name{CPSSW}
+\alias{CPSSW}
+\alias{CPSSW9298}
+\alias{CPSSW9204}
+\alias{CPSSW04}
+\alias{CPSSW3}
+\alias{CPSSW8}
+\alias{CPSSWEducation}
+
+\title{Stock and Watson CPS Data Sets}
+
+\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{
+\code{CPSSW9298}: A data frame containing 13,501 observations on 5 variables.
+\code{CPSSW9204}: A data frame containing 15,588 observations on 5 variables.
+\code{CPSSW04}: A data frame containing 7,986 observations on 4 variables.
+\code{CPSSW3}: A data frame containing 20,999 observations on 3 variables.
+\code{CPSSW8}: A data frame containing 61,395 observations on 5 variables.
+\code{CPSSWEducation}: A data frame containing 2,950 observations on 4 variables.
+\describe{
+ \item{year}{factor indicating year.}
+ \item{earnings}{average hourly earnings (sum of annual pretax wages, salaries, tips,
+ and bonuses, divided by the number of hours worked annually).}
+ \item{education}{number of years of education.}
+ \item{degree}{factor indicating highest educational degree (\code{"bachelor"}
+ or\code{"highschool"}).}
+ \item{gender}{factor indicating gender.}
+ \item{age}{age in years.}
+ \item{region}{factor indicating region of residence
+ (\code{"Northeast"}, \code{"Midwest"}, \code{"South"}, \code{"West"}).}
+}
+}
+
+\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 (\url{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).
+
+If education is given, it is for full-time workers, defined as
+workers employed more than 35 hours per week for at least 48 weeks in the
+previous year. Data are provided for workers whose
+highest educational achievement is a high school diploma and a bachelor's degree.
+
+Earnings for years earlier than 2004 were adjusted for inflation by putting them
+in 2004 USD using the Consumer Price Index (CPI). From 1992 to 2004, the
+price of the CPI market basket rose by 34.6\%. To make earnings in 1992 and 2004
+comparable, 1992 earnings are inflated by the amount of overall CPI price
+inflation, by multiplying 1992 earnings by 1.346 to put them into 2004 dollars.
+
+\code{CPSSW9204} provides the distribution of earnings in the US in 1992 and 2004
+for college-educated full-time workers aged 25--34.
+\code{CPSSW04} is a subset of \code{CPSSW9204} and provides the distribution of
+earnings in the US in 2004 for college-educated full-time workers aged 25--34.
+\code{CPSSWEducation} is similar (but not a true subset) and contains the
+distribution of earnings in the US in 2004 for college-educated full-time workers
+aged 29--30.
+\code{CPSSW8} contains a larger sample with workers aged 21--64, additionally
+providing information about the region of residence.
+\code{CPSSW9298} is similar to \code{CPSSW9204} providing data from 1992 and 1998
+(with the 1992 subsets not being exactly identical).
+\code{CPSSW3} provides trends (from 1992 to 2004) in hourly earnings in the US of
+working college graduates aged 25--34 (in 2004 USD).
+}
+
+\source{
+Online complements to Stock and Watson (2007).
+}
+
+\references{
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}, \code{\link{CPS1985}}, \code{\link{CPS1988}}}
+
+\examples{
+data("CPSSW3")
+with(CPSSW3, interaction.plot(year, gender, earnings))
+
+## Stock and Watson, p. 165
+data("CPSSWEducation")
+plot(earnings ~ education, data = CPSSWEducation)
+fm <- lm(earnings ~ education, data = CPSSWEducation)
+coeftest(fm, vcov = sandwich)
+abline(fm)
+}
+
+\keyword{datasets}
diff --git a/man/CameronTrivedi1998.Rd b/man/CameronTrivedi1998.Rd
new file mode 100644
index 0000000..925921a
--- /dev/null
+++ b/man/CameronTrivedi1998.Rd
@@ -0,0 +1,172 @@
+\name{CameronTrivedi1998}
+\alias{CameronTrivedi1998}
+
+\title{Data and Examples from Cameron and Trivedi (1998)}
+
+\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). \emph{Regression Analysis of Count Data}.
+Cambridge: Cambridge University Press.
+}
+
+\seealso{\code{\link{DoctorVisits}}, \code{\link{NMES1988}}, \code{\link{RecreationDemand}}}
+
+\examples{
+library("MASS")
+library("pscl")
+
+###########################################
+## Australian health service utilization ##
+###########################################
+
+## data
+data("DoctorVisits", package = "AER")
+
+## Poisson regression
+dv_pois <- glm(visits ~ . + I(age^2), data = DoctorVisits, family = poisson)
+dv_qpois <- glm(visits ~ . + I(age^2), data = DoctorVisits, family = quasipoisson)
+
+## Table 3.3
+round(cbind(
+ Coef = coef(dv_pois),
+ MLH = sqrt(diag(vcov(dv_pois))),
+ MLOP = sqrt(diag(vcovOPG(dv_pois))),
+ NB1 = sqrt(diag(vcov(dv_qpois))),
+ RS = sqrt(diag(sandwich(dv_pois)))
+), digits = 3)
+
+## Table 3.4
+## NM2-ML
+dv_nb <- glm.nb(visits ~ . + I(age^2), data = DoctorVisits)
+summary(dv_nb)
+## NB1-GLM = quasipoisson
+summary(dv_qpois)
+
+## overdispersion tests (page 79)
+lrtest(dv_pois, dv_nb) ## p-value would need to be halved
+dispersiontest(dv_pois, trafo = 1)
+dispersiontest(dv_pois, trafo = 2)
+
+
+##########################################
+## Demand for medical care in NMES 1988 ##
+##########################################
+
+## select variables for analysis
+data("NMES1988", package = "AER")
+nmes <- NMES1988[,-(2:6)]
+
+## 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")
+
+## from Table 6.3
+lrtest(nmes_nb, nmes_h)
+
+## from Table 6.4
+AIC(nmes_nb)
+AIC(nmes_nb, k = log(nrow(nmes)))
+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")
+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))
+
+fm_hgnb <- hurdle(trips ~ ., data = RecreationDemand, dist = "negbin", zero = "geometric")
+summary(fm_hgnb)
+logLik(fm_hgnb)
+
+## logLik with starting values from Gurmu + Trivedi 1996
+fm_hgnb96 <- hurdle(trips ~ ., data = RecreationDemand, dist = "negbin", zero = "geometric",
+ start = sval96, maxit = 0)
+logLik(fm_hgnb96)
+
+## logit-negbin
+fm_hgnb2 <- hurdle(trips ~ ., data = RecreationDemand, dist = "negbin")
+summary(fm_hgnb2)
+logLik(fm_hgnb2)
+
+## Note: quasi-complete separation
+with(RecreationDemand, table(trips > 0, userfee))
+}
+
+\keyword{datasets}
diff --git a/man/CartelStability.Rd b/man/CartelStability.Rd
new file mode 100644
index 0000000..cf3fa73
--- /dev/null
+++ b/man/CartelStability.Rd
@@ -0,0 +1,41 @@
+\name{CartelStability}
+\alias{CartelStability}
+
+\title{CartelStability}
+
+\description{
+Weekly observations on prices and other factors from 1880--1886, for a total of 326 weeks.
+}
+
+\usage{data("CartelStability")}
+
+\format{
+A data frame containing 328 observations on 5 variables.
+\describe{
+ \item{price}{weekly index of price of shipping a ton of grain by rail.}
+ \item{cartel}{factor. Is a railroad cartel operative?}
+ \item{quantity}{total tonnage of grain shipped in the week.}
+ \item{season}{factor indicating season of year. To match the weekly data,
+ the calendar has been divided into 13 periods, each approximately 4 weeks long.}
+ \item{ice}{factor. Are the Great Lakes innavigable because of ice?}
+}
+}
+
+\source{
+Online complements to Stock and Watson (2007).
+}
+
+\references{
+Porter, R. H. (1983). A Study of Cartel Stability: The Joint Executive Committee, 1880--1886. \emph{The Bell Journal of Economics}, \bold{14}, 301--314.
+
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+data("CartelStability")
+summary(CartelStability)
+}
+
+\keyword{datasets}
diff --git a/man/ChinaIncome.Rd b/man/ChinaIncome.Rd
new file mode 100644
index 0000000..b85dd2e
--- /dev/null
+++ b/man/ChinaIncome.Rd
@@ -0,0 +1,39 @@
+\name{ChinaIncome}
+\alias{ChinaIncome}
+\title{Chinese Real National Income Data}
+\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.
+\describe{
+ \item{agriculture}{Real national income in agriculture sector.}
+ \item{industry}{Real national income in industry sector.}
+ \item{construction}{Real national income in construction sector.}
+ \item{transport}{Real national income in transport sector.}
+ \item{commerce}{Real national income in commerce sector.}
+}
+}
+
+\source{
+Online complements to Franses (1998).
+}
+
+\seealso{\code{\link{Franses1998}}}
+
+\references{
+Chow, G.C. (1993). Capital Formation and Economic Growth in China.
+\emph{Quarterly Journal of Economics}, \bold{103}, 809--842.
+
+Franses, P.H. (1998). \emph{Time Series Models for Business and Economic Forecasting}.
+Cambridge, UK: Cambridge University Press.
+}
+
+\examples{
+data("ChinaIncome")
+plot(ChinaIncome)
+}
+
+\keyword{datasets}
diff --git a/man/CigarettesB.Rd b/man/CigarettesB.Rd
new file mode 100644
index 0000000..7287004
--- /dev/null
+++ b/man/CigarettesB.Rd
@@ -0,0 +1,74 @@
+\name{CigarettesB}
+\alias{CigarettesB}
+\title{Cigarette Consumption Data}
+\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.
+\describe{
+\item{packs}{Logarithm of cigarette consumption (in packs) per person of smoking age (> 16 years).}
+\item{price}{Logarithm of real price of cigarette in each state.}
+\item{income}{Logarithm of real disposable income (per capita) in each state.}
+}
+}
+
+\source{
+The data are from Baltagi (2002).
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed. Berlin, Springer.
+
+Baltagi, B.H. and Levin, D. (1992). Cigarette Taxation: Raising Revenues and Reducing Consumption.
+\emph{Structural Change and Economic Dynamics}, \bold{3}, 321--335.
+}
+
+\seealso{\code{\link{Baltagi2002}}, \code{\link{CigarettesSW}}}
+
+\examples{
+data("CigarettesB")
+
+## Baltagi (2002)
+## Table 3.3
+cig_lm <- lm(packs ~ price, data = CigarettesB)
+summary(cig_lm)
+
+## Chapter 5: diagnostic tests (p. 111-115)
+cig_lm2 <- lm(packs ~ price + income, data = CigarettesB)
+summary(cig_lm2)
+## Glejser tests (p. 112)
+ares <- abs(residuals(cig_lm2))
+summary(lm(ares ~ income, data = CigarettesB))
+summary(lm(ares ~ I(1/income), data = CigarettesB))
+summary(lm(ares ~ I(1/sqrt(income)), data = CigarettesB))
+summary(lm(ares ~ sqrt(income), data = CigarettesB))
+## Goldfeld-Quandt test (p. 112)
+gqtest(cig_lm2, order.by = ~ income, data = CigarettesB, fraction = 12, alternative = "less")
+## NOTE: Baltagi computes the test statistic as mss1/mss2,
+## i.e., tries to find decreasing variances. gqtest() always uses
+## mss2/mss1 and has an "alternative" argument.
+
+## Spearman rank correlation test (p. 113)
+cor.test(~ ares + income, data = CigarettesB, method = "spearman")
+## Breusch-Pagan test (p. 113)
+bptest(cig_lm2, varformula = ~ income, data = CigarettesB, student = FALSE)
+## White test (Table 5.1, p. 113)
+bptest(cig_lm2, ~ income * price + I(income^2) + I(price^2), data = CigarettesB)
+## White HC standard errors (Table 5.2, p. 114)
+coeftest(cig_lm2, vcov = vcovHC(cig_lm2, type = "HC1"))
+## Jarque-Bera test (Figure 5.2, p. 115)
+hist(residuals(cig_lm2), breaks = 16, ylim = c(0, 10), col = "lightgray")
+library("tseries")
+jarque.bera.test(residuals(cig_lm2))
+
+## Tables 8.1 and 8.2
+influence.measures(cig_lm2)
+
+## More examples can be found in:
+## help("Baltagi2002")
+}
+
+\keyword{datasets}
diff --git a/man/CigarettesSW.Rd b/man/CigarettesSW.Rd
new file mode 100644
index 0000000..3b94247
--- /dev/null
+++ b/man/CigarettesSW.Rd
@@ -0,0 +1,69 @@
+\name{CigarettesSW}
+\alias{CigarettesSW}
+\title{Cigarette Consumption Panel Data}
+
+\description{
+Panel data on cigarette consumption for the 48 continental US States from 1985--1995.
+}
+
+\usage{data("CigarettesSW")}
+
+\format{
+A data frame containing 48 observations on 7 variables for 2 periods.
+\describe{
+\item{state}{Factor indicating state.}
+\item{year}{Factor indicating year.}
+\item{cpi}{Consumer price index.}
+\item{population}{State population.}
+\item{packs}{Number of packs per capita.}
+\item{income}{State personal income (total, nominal).}
+\item{tax}{Average state, federal and average local excise taxes for fiscal year.}
+\item{price}{Average price during fiscal year, including sales tax.}
+\item{taxs}{Average excise taxes for fiscal year, including sales tax.}
+}
+}
+
+\source{
+Online complements to Stock and Watson (2007).
+}
+
+\references{
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics},
+2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}, \code{\link{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")
+
+## convenience function: HC1 covariances
+hc1 <- function(x) vcovHC(x, type = "HC1")
+
+## 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)
+
+## More examples can be found in:
+## help("StockWatson2007")
+}
+
+\keyword{datasets}
diff --git a/man/CollegeDistance.Rd b/man/CollegeDistance.Rd
new file mode 100644
index 0000000..f10899a
--- /dev/null
+++ b/man/CollegeDistance.Rd
@@ -0,0 +1,69 @@
+\name{CollegeDistance}
+\alias{CollegeDistance}
+
+\title{College Distance Data}
+
+\description{
+Cross-section data from the High School and Beyond survey conducted by the
+Department of Education 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.
+\describe{
+ \item{gender}{factor indicating gender.}
+ \item{ethnicity}{factor indicating ethnicity (African-American, Hispanic or other).}
+ \item{score}{base year composite test score. These are achievement tests given to high
+ school seniors in the sample.}
+ \item{fcollege}{factor. Is the father a college graduate?}
+ \item{mcollege}{factor. Is the mother a college graduate?}
+ \item{home}{factor. Does the family own their home?}
+ \item{urban}{factor. Is the school in an urban area?}
+ \item{unemp}{county unemployment rate in 1980.}
+ \item{wage}{state hourly wage in manufacturing in 1980.}
+ \item{distance}{distance from 4-year college (in 10 miles).}
+ \item{tuition}{average state 4-year college tuition (in 1000 USD).}
+ \item{education}{number of years of education.}
+ \item{income}{factor. Is the family income above USD 25,000 per year?}
+ \item{region}{factor indicating region (West or other).}
+}
+}
+
+\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. \code{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 Educational Attainment. \emph{Journal of Business \& Economic Statistics},
+\bold{12}, 217--224.
+
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+## exclude students from Western states
+data("CollegeDistance")
+cd <- subset(CollegeDistance, region != "west")
+summary(cd)
+}
+
+\keyword{datasets}
diff --git a/man/ConsumerGood.Rd b/man/ConsumerGood.Rd
new file mode 100644
index 0000000..f7478be
--- /dev/null
+++ b/man/ConsumerGood.Rd
@@ -0,0 +1,35 @@
+\name{ConsumerGood}
+\alias{ConsumerGood}
+\title{Properties of a Fast-Moving Consumer Good}
+\description{
+Time series of distribution, market share and price of a fast-moving
+consumer good.
+}
+\usage{data("ConsumerGood")}
+
+\format{
+A weekly multiple time series from 1989(11) to 1991(9) with 3 variables.
+\describe{
+ \item{distribution}{Distribution.}
+ \item{share}{Market share.}
+ \item{price}{Price.}
+}
+}
+
+\source{
+Online complements to Franses (1998).
+}
+
+\references{
+Franses, P.H. (1998). \emph{Time Series Models for Business and Economic Forecasting}.
+Cambridge, UK: Cambridge University Press.
+}
+
+\seealso{\code{\link{Franses1998}}}
+
+\examples{
+data("ConsumerGood")
+plot(ConsumerGood)
+}
+
+\keyword{datasets}
diff --git a/man/CreditCard.Rd b/man/CreditCard.Rd
new file mode 100644
index 0000000..6dddc52
--- /dev/null
+++ b/man/CreditCard.Rd
@@ -0,0 +1,93 @@
+\name{CreditCard}
+\alias{CreditCard}
+\title{Expenditure and Default Data}
+
+\description{
+Cross-section data on the credit history for a sample of applicants for a type of credit card.
+}
+
+\usage{data("CreditCard")}
+
+\format{
+A data frame containing 1,319 observations on 12 variables.
+\describe{
+ \item{card}{Factor. Was the application for a credit card accepted?}
+ \item{reports}{Number of major derogatory reports.}
+ \item{age}{Age in years plus twelfths of a year.}
+ \item{income}{Yearly income (in USD 10,000).}
+ \item{share}{Ratio of monthly credit card expenditure to yearly income.}
+ \item{expenditure}{Average monthly credit card expenditure.}
+ \item{owner}{Factor. Does the individual own their home?}
+ \item{selfemp}{Factor. Is the individual self-employed?}
+ \item{dependents}{Number of dependents.}
+ \item{months}{Months living at current address.}
+ \item{majorcards}{Number of major credit cards held.}
+ \item{active}{Number of active credit accounts.}
+}
+}
+
+\details{
+According to Greene (2003, p. 952) \code{dependents} equals \code{1 + number of dependents},
+our calculations suggest that it equals \code{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 \code{age} has some
+suspiciously low values (below one year) for some applicants. One of these differs
+between the F9.1 and F21.4 version.
+}
+
+\source{
+Online complements to Greene (2003). Table F21.4.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}}
+
+\examples{
+data("CreditCard")
+
+## Greene (2003)
+## extract data set F9.1
+ccard <- CreditCard[1:100,]
+ccard$income <- round(ccard$income, digits = 2)
+ccard$expenditure <- round(ccard$expenditure, digits = 2)
+ccard$age <- round(ccard$age + .01)
+## suspicious:
+CreditCard$age[CreditCard$age < 1]
+## the first of these is also in TableF9.1 with 36 instead of 0.5:
+ccard$age[79] <- 36
+
+## Example 11.1
+ccard <- ccard[order(ccard$income),]
+ccard0 <- subset(ccard, expenditure > 0)
+cc_ols <- lm(expenditure ~ age + owner + income + I(income^2), data = ccard0)
+
+## Figure 11.1
+plot(residuals(cc_ols) ~ income, data = ccard0, pch = 19)
+
+## Table 11.1
+mean(ccard$age)
+prop.table(table(ccard$owner))
+mean(ccard$income)
+
+summary(cc_ols)
+sqrt(diag(vcovHC(cc_ols, type = "HC0")))
+sqrt(diag(vcovHC(cc_ols, type = "HC2")))
+sqrt(diag(vcovHC(cc_ols, type = "HC1")))
+
+bptest(cc_ols, ~ (age + income + I(income^2) + owner)^2 + I(age^2) + I(income^4), data = ccard0)
+gqtest(cc_ols)
+bptest(cc_ols, ~ income + I(income^2), data = ccard0, studentize = FALSE)
+bptest(cc_ols, ~ income + I(income^2), data = ccard0)
+
+## More examples can be found in:
+## help("Greene2003")
+}
+
+\keyword{datasets}
diff --git a/man/DJFranses.Rd b/man/DJFranses.Rd
new file mode 100644
index 0000000..ad5f21f
--- /dev/null
+++ b/man/DJFranses.Rd
@@ -0,0 +1,30 @@
+\name{DJFranses}
+\alias{DJFranses}
+\title{Dow Jones Index Data (Franses)}
+\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). \emph{Time Series Models for Business and Economic Forecasting}.
+Cambridge, UK: Cambridge University Press.
+}
+
+\seealso{\code{\link{Franses1998}}}
+
+\examples{
+data("DJFranses")
+plot(DJFranses)
+}
+
+\keyword{datasets}
diff --git a/man/DJIA8012.Rd b/man/DJIA8012.Rd
new file mode 100644
index 0000000..0771f5f
--- /dev/null
+++ b/man/DJIA8012.Rd
@@ -0,0 +1,48 @@
+\name{DJIA8012}
+\alias{DJIA8012}
+\title{Dow Jones Industrial Average (DJIA) index}
+
+\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 \code{"zoo"} with \code{"Date"} index).
+}
+
+\source{
+Online complements to Franses, van Dijk and Opschoor (2014).
+
+\url{http://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-economics/time-series-models-business-and-economic-forecasting-2nd-edition}
+}
+
+\references{
+Franses, P.H., van Dijk, D. and Opschoor, A. (2014). \emph{Time Series Models for Business and Economic Forecasting}, 2nd ed.
+Cambridge, UK: Cambridge University Press.
+}
+
+\examples{
+data("DJIA8012")
+plot(DJIA8012)
+
+# p.26, Figure 2.18
+dldjia <- diff(log(DJIA8012))
+plot(dldjia)
+
+# p.141, Figure 6.4
+plot(window(dldjia, start = "1987-09-01", end = "1987-12-31"))
+
+# p.167, Figure 7.1
+dldjia9005 <- window(dldjia, start = "1990-01-01", end = "2005-12-31")
+qqnorm(dldjia9005)
+qqline(dldjia9005, lty = 2)
+
+# p.170, Figure 7.4
+acf(dldjia9005, na.action = na.exclude, lag.max = 250, ylim = c(-0.1, 0.25))
+acf(dldjia9005^2, na.action = na.exclude, lag.max = 250, ylim = c(-0.1, 0.25))
+acf(abs(dldjia9005), na.action = na.exclude, lag.max = 250, ylim = c(-0.1, 0.25))
+}
+
+\keyword{datasets}
diff --git a/man/DoctorVisits.Rd b/man/DoctorVisits.Rd
new file mode 100644
index 0000000..990f1c1
--- /dev/null
+++ b/man/DoctorVisits.Rd
@@ -0,0 +1,75 @@
+\name{DoctorVisits}
+\alias{DoctorVisits}
+
+\title{Australian Health Service Utilization Data}
+
+\description{
+Cross-section data originating from the 1977--1978 Australian Health Survey.
+}
+
+\usage{data("DoctorVisits")}
+
+\format{
+A data frame containing 5,190 observations on 12 variables.
+\describe{
+ \item{visits}{Number of doctor visits in past 2 weeks.}
+ \item{gender}{Factor indicating gender.}
+ \item{age}{Age in years divided by 100.}
+ \item{income}{Annual income in tens of thousands of dollars.}
+ \item{illness}{Number of illnesses in past 2 weeks.}
+ \item{reduced}{Number of days of reduced activity in past 2 weeks due to illness or injury.}
+ \item{health}{General health questionnaire score using Goldberg's method.}
+ \item{private}{Factor. Does the individual have private health insurance?}
+ \item{freepoor}{Factor. Does the individual have free government health insurance due to low income?}
+ \item{freerepat}{Factor. Does the individual have free government health insurance due to old age,
+ disability or veteran status?}
+ \item{nchronic}{Factor. Is there a chronic condition not limiting activity?}
+ \item{lchronic}{Factor. Is there a chronic condition limiting activity?}
+}
+}
+
+\source{
+Journal of Applied Econometrics Data Archive.
+
+\url{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.
+\emph{Journal of Applied Econometrics},
+\bold{1}, 29--53.
+
+Cameron, A.C. and Trivedi, P.K. (1998). \emph{Regression Analysis of Count Data}.
+Cambridge: Cambridge University Press.
+
+Mullahy, J. (1997). Heterogeneity, Excess Zeros, and the Structure of Count Data Models.
+\emph{Journal of Applied Econometrics},
+\bold{12}, 337--350.
+}
+
+\seealso{\code{\link{CameronTrivedi1998}}}
+
+\examples{
+data("DoctorVisits", package = "AER")
+library("MASS")
+
+## Cameron and Trivedi (1986), Table III, col. (1)
+dv_lm <- lm(visits ~ . + I(age^2), data = DoctorVisits)
+summary(dv_lm)
+
+## Cameron and Trivedi (1998), Table 3.3
+dv_pois <- glm(visits ~ . + I(age^2), data = DoctorVisits, family = poisson)
+summary(dv_pois) ## MLH standard errors
+coeftest(dv_pois, vcov = vcovOPG) ## MLOP standard errors
+logLik(dv_pois)
+## standard errors denoted RS ("unspecified omega robust sandwich estimate")
+coeftest(dv_pois, vcov = sandwich)
+
+## Cameron and Trivedi (1986), Table III, col. (4)
+dv_nb <- glm.nb(visits ~ . + I(age^2), data = DoctorVisits)
+summary(dv_nb)
+logLik(dv_nb)
+}
+
+\keyword{datasets}
diff --git a/man/DutchAdvert.Rd b/man/DutchAdvert.Rd
new file mode 100644
index 0000000..b93a65d
--- /dev/null
+++ b/man/DutchAdvert.Rd
@@ -0,0 +1,58 @@
+\name{DutchAdvert}
+\alias{DutchAdvert}
+\title{TV and Radio Advertising Expenditures Data}
+
+\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.
+\describe{
+ \item{tv}{Television advertising expenditures.}
+ \item{radio}{Radio advertising expenditures.}
+}
+}
+
+\source{
+Originally available as an online supplement to Franses (1998). Now available via online complements to Franses, van Dijk and Opschoor (2014).
+
+\url{http://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-economics/time-series-models-business-and-economic-forecasting-2nd-edition}
+}
+
+\references{
+Franses, P.H. (1998). \emph{Time Series Models for Business and Economic Forecasting}.
+Cambridge, UK: Cambridge University Press.
+
+Franses, P.H., van Dijk, D. and Opschoor, A. (2014). \emph{Time Series Models for Business and Economic Forecasting}, 2nd ed.
+Cambridge, UK: Cambridge University Press.
+}
+
+\seealso{\code{\link{Franses1998}}}
+
+\examples{
+data("DutchAdvert")
+plot(DutchAdvert)
+
+## EACF tables (Franses 1998, Sec. 5.1, p. 99)
+ctrafo <- function(x) residuals(lm(x ~ factor(cycle(x))))
+ddiff <- function(x) diff(diff(x, frequency(x)), 1)
+eacf <- function(y, lag = 12) {
+ stopifnot(all(lag > 0))
+ if(length(lag) < 2) lag <- 1:lag
+ rval <- sapply(
+ list(y = y, dy = diff(y), cdy = ctrafo(diff(y)),
+ Dy = diff(y, frequency(y)), dDy = ddiff(y)),
+ function(x) acf(x, plot = FALSE, lag.max = max(lag))$acf[lag + 1])
+ rownames(rval) <- lag
+ return(rval)
+}
+
+## Franses (1998, p. 103), Table 5.4
+round(eacf(log(DutchAdvert[,"tv"]), lag = c(1:19, 26, 39)), digits = 3)
+}
+
+\keyword{datasets}
diff --git a/man/DutchSales.Rd b/man/DutchSales.Rd
new file mode 100644
index 0000000..1edc566
--- /dev/null
+++ b/man/DutchSales.Rd
@@ -0,0 +1,48 @@
+\name{DutchSales}
+\alias{DutchSales}
+\title{Dutch Retail Sales Index Data}
+
+\description{
+Time series of retail sales index in The Netherlands.
+}
+
+\usage{data("DutchSales")}
+
+\format{
+A monthly univariate time series from 1960(5) to 1995(9).
+}
+
+\source{
+Online complements to Franses (1998).
+}
+
+\references{
+Franses, P.H. (1998). \emph{Time Series Models for Business and Economic Forecasting}.
+Cambridge, UK: Cambridge University Press.
+}
+
+\seealso{\code{\link{Franses1998}}}
+
+\examples{
+data("DutchSales")
+plot(DutchSales)
+
+## EACF tables (Franses 1998, p. 99)
+ctrafo <- function(x) residuals(lm(x ~ factor(cycle(x))))
+ddiff <- function(x) diff(diff(x, frequency(x)), 1)
+eacf <- function(y, lag = 12) {
+ stopifnot(all(lag > 0))
+ if(length(lag) < 2) lag <- 1:lag
+ rval <- sapply(
+ list(y = y, dy = diff(y), cdy = ctrafo(diff(y)),
+ Dy = diff(y, frequency(y)), dDy = ddiff(y)),
+ function(x) acf(x, plot = FALSE, lag.max = max(lag))$acf[lag + 1])
+ rownames(rval) <- lag
+ return(rval)
+}
+
+## Franses (1998), Table 5.3
+round(eacf(log(DutchSales), lag = c(1:18, 24, 36)), digits = 3)
+}
+
+\keyword{datasets}
diff --git a/man/Electricity1955.Rd b/man/Electricity1955.Rd
new file mode 100644
index 0000000..8d2ff1d
--- /dev/null
+++ b/man/Electricity1955.Rd
@@ -0,0 +1,71 @@
+\name{Electricity1955}
+\alias{Electricity1955}
+
+\title{Cost Function of Electricity Producers (1955, Nerlove Data)}
+
+\description{
+Cost function data for 145 (+14) US electricity producers in 1955.
+}
+
+\usage{data("Electricity1955")}
+
+\format{
+A data frame containing 159 observations on 8 variables.
+\describe{
+ \item{cost}{total cost.}
+ \item{output}{total output.}
+ \item{labor}{wage rate.}
+ \item{laborshare}{cost share for labor.}
+ \item{capital}{capital price index.}
+ \item{capitalshare}{cost share for capital.}
+ \item{fuel}{fuel price.}
+ \item{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.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+
+Nerlove, M. (1963) \dQuote{Returns to Scale in Electricity Supply.}
+In C. Christ (ed.), \emph{Measurement in Economics: Studies in Mathematical Economics
+and Econometrics in Memory of Yehuda Grunfeld}. Stanford University Press, 1963.
+}
+
+\seealso{\code{\link{Greene2003}}, \code{\link{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)
+
+## hypothesis of constant returns to scale
+linearHypothesis(fm_all, "log(output) = 1")
+
+## 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)
+
+## More examples can be found in:
+## help("Greene2003")
+}
+
+\keyword{datasets}
diff --git a/man/Electricity1970.Rd b/man/Electricity1970.Rd
new file mode 100644
index 0000000..b02ddb3
--- /dev/null
+++ b/man/Electricity1970.Rd
@@ -0,0 +1,56 @@
+\name{Electricity1970}
+\alias{Electricity1970}
+
+\title{Cost Function of Electricity Producers 1970}
+
+\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.
+\describe{
+ \item{cost}{total cost.}
+ \item{output}{total output.}
+ \item{labor}{wage rate.}
+ \item{laborshare}{cost share for labor.}
+ \item{capital}{capital price index.}
+ \item{capitalshare}{cost share for capital.}
+ \item{fuel}{fuel price.}
+ \item{fuelshare}{cost share for fuel.}
+}
+}
+
+\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.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Christensen, L. and Greene, W.H. (1976). Economies of Scale in U.S. Electric Power Generation.
+\emph{Journal of Political Economy}, \bold{84}, 655--676.
+
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}, \code{\link{Electricity1955}}}
+
+\examples{
+data("Electricity1970")
+
+## Greene (2003), Ex. 5.6: a generalized Cobb-Douglas cost function
+fm <- lm(log(cost/fuel) ~ log(output) + I(log(output)^2/2) +
+ log(capital/fuel) + log(labor/fuel), data=Electricity1970[1:123,])
+
+}
+
+\keyword{datasets}
diff --git a/man/EquationCitations.Rd b/man/EquationCitations.Rd
new file mode 100644
index 0000000..867fbdc
--- /dev/null
+++ b/man/EquationCitations.Rd
@@ -0,0 +1,126 @@
+\name{EquationCitations}
+\alias{EquationCitations}
+
+\title{Number of Equations and Citations for Evolutionary Biology Publications}
+
+\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.
+\describe{
+ \item{journal}{Factor. Journal in which the paper was published
+ (The American Naturalist, Evolution, Proceedings of the Royal Society
+ of London B: Biological Sciences).}
+ \item{authors}{Character. Names of authors.}
+ \item{volume}{Volume in which the paper was published.}
+ \item{startpage}{Starting page of publication.}
+ \item{pages}{Number of pages.}
+ \item{equations}{Number of equations in total.}
+ \item{mainequations}{Number of equations in main text.}
+ \item{appequations}{Number of equations in appendix.}
+ \item{cites}{Number of citations in total.}
+ \item{selfcites}{Number of citations by the authors themselves.}
+ \item{othercites}{Number of citations by other authors.}
+ \item{theocites}{Number of citations by theoretical papers.}
+ \item{nontheocites}{Number of citations by nontheoretical papers.}
+}
+}
+
+\details{
+ Fawcett and Higginson (2012) investigate the relationship between the
+ number of citations evolutionary 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 number of citations they receive, in particular from
+ nontheoretical papers.
+}
+
+\source{
+Online supplements to Fawcett and Higginson (2012).
+
+\url{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.
+\emph{PNAS -- Proceedings of the National Academy of Sciences of the United States of America},
+\bold{109}, 11735--11739. \url{http://dx.doi.org/10.1073/pnas.1205259109}
+}
+
+\seealso{\code{\link{PhDPublications}}}
+
+\examples{
+## load data and MASS package
+data("EquationCitations", package = "AER")
+library("MASS")
+
+## convenience function for summarizing NB models
+nbtable <- function(obj, digits = 3) round(cbind(
+ "OR" = exp(coef(obj)),
+ "CI" = exp(confint.default(obj)),
+ "Wald z" = coeftest(obj)[,3],
+ "p" = coeftest(obj)[, 4]), digits = digits)
+
+
+#################
+## Replication ##
+#################
+
+## Table 1
+m1a <- glm.nb(othercites ~ I(equations/pages) * pages + journal,
+ data = EquationCitations)
+m1b <- update(m1a, nontheocites ~ .)
+m1c <- update(m1a, theocites ~ .)
+nbtable(m1a)
+nbtable(m1b)
+nbtable(m1c)
+
+## Table 2
+m2a <- glm.nb(
+ othercites ~ (I(mainequations/pages) + I(appequations/pages)) * pages + journal,
+ data = EquationCitations)
+m2b <- update(m2a, nontheocites ~ .)
+m2c <- update(m2a, theocites ~ .)
+nbtable(m2a)
+nbtable(m2b)
+nbtable(m2c)
+
+
+###############
+## Extension ##
+###############
+
+## nonlinear page effect: use log(pages) instead of pages+interaction
+m3a <- glm.nb(othercites ~ I(equations/pages) + log(pages) + journal,
+ data = EquationCitations)
+m3b <- update(m3a, nontheocites ~ .)
+m3c <- update(m3a, theocites ~ .)
+
+## nested models: allow different equation effects over journals
+m4a <- glm.nb(othercites ~ journal / I(equations/pages) + log(pages),
+ data = EquationCitations)
+m4b <- update(m4a, nontheocites ~ .)
+m4c <- update(m4a, theocites ~ .)
+
+## nested model best (wrt AIC) for all responses
+AIC(m1a, m2a, m3a, m4a)
+nbtable(m4a)
+AIC(m1b, m2b, m3b, m4b)
+nbtable(m4b)
+AIC(m1c, m2c, m3c, m4c)
+nbtable(m4c)
+## equation effect by journal/response
+## comb nontheo theo
+## AmNat =/- - +
+## Evolution =/+ = +
+## ProcB - - =/+
+}
+
+\keyword{datasets}
diff --git a/man/Equipment.Rd b/man/Equipment.Rd
new file mode 100644
index 0000000..b0a0a55
--- /dev/null
+++ b/man/Equipment.Rd
@@ -0,0 +1,102 @@
+\name{Equipment}
+\alias{Equipment}
+\title{Transportation Equipment Manufacturing Data}
+
+\description{
+Statewide data on transportation equipment manufacturing for 25 US states.}
+
+\usage{data("Equipment")}
+
+\format{
+A data frame containing 25 observations on 4 variables.
+ \describe{
+ \item{valueadded}{Aggregate output, in millions of 1957 dollars.}
+ \item{capital}{Capital input, in millions of 1957 dollars.}
+ \item{labor}{Aggregate labor input, in millions of man hours.}
+ \item{firms}{Number of firms.}
+ }
+}
+
+
+\source{
+Journal of Applied Econometrics Data Archive.
+
+\url{http://qed.econ.queensu.ca/jae/1998-v13.2/zellner-ryu/}
+
+Online complements to Greene (2003), Table F9.2.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+
+Zellner, A. and Revankar, N. (1969). Generalized Production Functions.
+\emph{Review of Economic Studies}, \bold{36}, 241--250.
+
+Zellner, A. and Ryu, H. (1998). Alternative Functional Forms for Production,
+Cost and Returns to Scale Functions.
+\emph{Journal of Applied Econometrics}, \bold{13}, 101--127.
+}
+
+\seealso{\code{\link{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)
+
+## generalized Cobb-Douglas with Zellner-Revankar trafo
+GCobbDouglas <- function(theta)
+ lm(I(log(valueadded/firms) + theta * valueadded/firms) ~ log(capital/firms) + log(labor/firms),
+ data = Equipment)
+
+## yields classical Cobb-Douglas for theta = 0
+fm_cd0 <- GCobbDouglas(0)
+
+## ML estimation of generalized model
+## choose starting values from classical model
+par0 <- as.vector(c(coef(fm_cd0), 0, mean(residuals(fm_cd0)^2)))
+
+## set up likelihood function
+nlogL <- function(par) {
+ beta <- par[1:3]
+ theta <- par[4]
+ sigma2 <- par[5]
+
+ Y <- with(Equipment, valueadded/firms)
+ K <- with(Equipment, capital/firms)
+ L <- with(Equipment, labor/firms)
+
+ rhs <- beta[1] + beta[2] * log(K) + beta[3] * log(L)
+ lhs <- log(Y) + theta * Y
+
+ rval <- sum(log(1 + theta * Y) - log(Y) +
+ dnorm(lhs, mean = rhs, sd = sqrt(sigma2), log = TRUE))
+ return(-rval)
+}
+
+## 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)))
+
+## fit NLS model
+rss <- function(theta) deviance(GCobbDouglas(theta))
+optim(0, rss)
+opt2 <- optimize(rss, c(-1, 1))
+fm_nls <- GCobbDouglas(opt2$minimum)
+-nlogL(c(coef(fm_nls), opt2$minimum, mean(residuals(fm_nls)^2)))
+}
+
+\keyword{datasets}
diff --git a/man/EuroEnergy.Rd b/man/EuroEnergy.Rd
new file mode 100644
index 0000000..b8b21ab
--- /dev/null
+++ b/man/EuroEnergy.Rd
@@ -0,0 +1,32 @@
+\name{EuroEnergy}
+\alias{EuroEnergy}
+\title{European Energy Consumption Data}
+\description{
+Cross-section data on energy consumption for 20 European countries, for the year 1980.
+}
+\usage{data("EuroEnergy")}
+\format{
+A data frame containing 20 observations on 2 variables.
+\describe{
+\item{gdp}{Real gross domestic product for the year 1980 (in million 1975 US dollars).}
+\item{energy}{Aggregate energy consumption (in million kilograms coal equivalence).}
+}
+}
+
+\source{
+The data are from Baltagi (2002).
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed. Berlin, Springer.
+}
+
+\seealso{\code{\link{Baltagi2002}}}
+
+\examples{
+data("EuroEnergy")
+energy_lm <- lm(log(energy) ~ log(gdp), data = EuroEnergy)
+influence.measures(energy_lm)
+}
+
+\keyword{datasets}
diff --git a/man/Fatalities.Rd b/man/Fatalities.Rd
new file mode 100644
index 0000000..58e3937
--- /dev/null
+++ b/man/Fatalities.Rd
@@ -0,0 +1,166 @@
+\name{Fatalities}
+\alias{Fatalities}
+\title{US Traffic Fatalities}
+
+\description{
+US traffic fatalities panel data for the \dQuote{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.
+\describe{
+ \item{state}{factor indicating state.}
+ \item{year}{factor indicating year.}
+ \item{spirits}{numeric. Spirits consumption.}
+ \item{unemp}{numeric. Unemployment rate.}
+ \item{income}{numeric. Per capita personal income in 1987 dollars.}
+ \item{emppop}{numeric. Employment/population ratio.}
+ \item{beertax}{numeric. Tax on case of beer.}
+ \item{baptist}{numeric. Percent of southern baptist.}
+ \item{mormon}{numeric. Percent of mormon.}
+ \item{drinkage}{numeric. Minimum legal drinking age.}
+ \item{dry}{numeric. Percent residing in \dQuote{dry} countries.}
+ \item{youngdrivers}{numeric. Percent of drivers aged 15--24.}
+ \item{miles}{numeric. Average miles per driver.}
+ \item{breath}{factor. Preliminary breath test law?}
+ \item{jail}{factor. Mandatory jail sentence?}
+ \item{service}{factor. Mandatory community service?}
+ \item{fatal}{numeric. Number of vehicle fatalities.}
+ \item{nfatal}{numeric. Number of night-time vehicle fatalities.}
+ \item{sfatal}{numeric. Number of single vehicle fatalities.}
+ \item{fatal1517}{numeric. Number of vehicle fatalities, 15--17 year olds.}
+ \item{nfatal1517}{numeric. Number of night-time vehicle fatalities, 15--17 year olds.}
+ \item{fatal1820}{numeric. Number of vehicle fatalities, 18--20 year olds.}
+ \item{nfatal1820}{numeric. Number of night-time vehicle fatalities, 18--20 year olds.}
+ \item{fatal2124}{numeric. Number of vehicle fatalities, 21--24 year olds.}
+ \item{nfatal2124}{numeric. Number of night-time vehicle fatalities, 21--24 year olds.}
+ \item{afatal}{numeric. Number of alcohol-involved vehicle fatalities.}
+ \item{pop}{numeric. Population.}
+ \item{pop1517}{numeric. Population, 15--17 year olds.}
+ \item{pop1820}{numeric. Population, 18--20 year olds.}
+ \item{pop2124}{numeric. Population, 21--24 year olds.}
+ \item{milestot}{numeric. Total vehicle miles (millions).}
+ \item{unempus}{numeric. US unemployment rate.}
+ \item{emppopus}{numeric. US employment/population ratio.}
+ \item{gsp}{numeric. GSP rate of change.}
+}
+}
+
+\details{
+Traffic fatalities are from the US Department of
+Transportation Fatal Accident Reporting System. The beer tax is the
+tax on a case of beer, which is an available measure of state
+alcohol taxes more generally. The drinking age variable is a factor
+indicating whether the legal drinking age is 18, 19, or 20.
+The two binary punishment variables describe the state's minimum
+sentencing requirements for an initial drunk driving conviction.
+
+Total vehicle miles traveled annually by state was obtained from
+the Department of Transportation. Personal income was obtained
+from the US Bureau of Economic Analysis, and the unemployment
+rate was obtained from the US Bureau of Labor Statistics.
+}
+
+\source{
+Online complements to Stock and Watson (2007).
+}
+
+\references{
+Ruhm, C. J. (1996). Alcohol Policies and Highway Vehicle Fatalities.
+\emph{Journal of Health Economics}, \bold{15}, 435--454.
+
+Stock, J. H. and Watson, M. W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{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")
+
+## for comparability with Stata we use HC1 below
+## p. 351, Eq. (10.2)
+f1982 <- subset(Fatalities, year == "1982")
+fm_1982 <- lm(frate ~ beertax, data = f1982)
+coeftest(fm_1982, vcov = vcovHC(fm_1982, type = "HC1"))
+
+## p. 353, Eq. (10.3)
+f1988 <- subset(Fatalities, year == "1988")
+fm_1988 <- lm(frate ~ beertax, data = f1988)
+coeftest(fm_1988, vcov = vcovHC(fm_1988, type = "HC1"))
+
+## pp. 355, Eq. (10.8)
+fm_diff <- lm(I(f1988$frate - f1982$frate) ~ I(f1988$beertax - f1982$beertax))
+coeftest(fm_diff, vcov = vcovHC(fm_diff, type = "HC1"))
+
+## pp. 360, Eq. (10.15)
+## (1) via formula
+fm_sfe <- lm(frate ~ beertax + state - 1, data = Fatalities)
+## (2) by hand
+fat <- with(Fatalities,
+ data.frame(frates = frate - ave(frate, state),
+ beertaxs = beertax - ave(beertax, state)))
+fm_sfe2 <- lm(frates ~ beertaxs - 1, data = fat)
+## (3) via plm()
+fm_sfe3 <- plm(frate ~ beertax, data = Fatalities,
+ index = c("state", "year"), model = "within")
+
+coeftest(fm_sfe, vcov = vcovHC(fm_sfe, type = "HC1"))[1,]
+## uses different df in sd and p-value
+coeftest(fm_sfe2, vcov = vcovHC(fm_sfe2, type = "HC1"))[1,]
+## uses different df in p-value
+coeftest(fm_sfe3, vcov = vcovHC(fm_sfe3, type = "HC1", method = "white1"))[1,]
+
+
+## pp. 363, Eq. (10.21)
+## via lm()
+fm_stfe <- lm(frate ~ beertax + state + year - 1, data = Fatalities)
+coeftest(fm_stfe, vcov = vcovHC(fm_stfe, type = "HC1"))[1,]
+## via plm()
+fm_stfe2 <- plm(frate ~ beertax, data = Fatalities,
+ index = c("state", "year"), model = "within", effect = "twoways")
+coeftest(fm_stfe2, vcov = vcovHC) ## different
+
+
+## p. 368, Table 10.1, numbers refer to cols.
+fm1 <- plm(frate ~ beertax, data = Fatalities, index = c("state", "year"), model = "pooling")
+fm2 <- plm(frate ~ beertax, data = Fatalities, index = c("state", "year"), model = "within")
+fm3 <- plm(frate ~ beertax, data = Fatalities, index = c("state", "year"), model = "within",
+ effect = "twoways")
+fm4 <- plm(frate ~ beertax + drinkagec + jail + service + miles + unemp + log(income),
+ data = Fatalities, index = c("state", "year"), model = "within", effect = "twoways")
+fm5 <- plm(frate ~ beertax + drinkagec + jail + service + miles,
+ data = Fatalities, index = c("state", "year"), model = "within", effect = "twoways")
+fm6 <- plm(frate ~ beertax + drinkage + punish + miles + unemp + log(income),
+ data = Fatalities, index = c("state", "year"), model = "within", effect = "twoways")
+fm7 <- plm(frate ~ beertax + drinkagec + jail + service + miles + unemp + log(income),
+ data = Fatalities, index = c("state", "year"), model = "within", effect = "twoways")
+## summaries not too close, s.e.s generally too small
+coeftest(fm1, vcov = vcovHC)
+coeftest(fm2, vcov = vcovHC)
+coeftest(fm3, vcov = vcovHC)
+coeftest(fm4, vcov = vcovHC)
+coeftest(fm5, vcov = vcovHC)
+coeftest(fm6, vcov = vcovHC)
+coeftest(fm7, vcov = vcovHC)
+
+## TODO: Testing exclusion restrictions
+
+}
+
+\keyword{datasets}
diff --git a/man/Fertility.Rd b/man/Fertility.Rd
new file mode 100644
index 0000000..dce8ce6
--- /dev/null
+++ b/man/Fertility.Rd
@@ -0,0 +1,78 @@
+\name{Fertility}
+\alias{Fertility}
+\alias{Fertility2}
+
+\title{Fertility and Women's Labor Supply}
+
+\description{
+Cross-section data from the 1980 US Census on married women
+aged 21--35 with two or more children.
+}
+
+\usage{
+data("Fertility")
+data("Fertility2")
+}
+
+\format{
+A data frame containing 254,654 (and 30,000, respectively) observations on 8 variables.
+\describe{
+ \item{morekids}{factor. Does the mother have more than 2 children?}
+ \item{gender1}{factor indicating gender of first child.}
+ \item{gender2}{factor indicating gender of second child.}
+ \item{age}{age of mother at census.}
+ \item{afam}{factor. Is the mother African-American?}
+ \item{hispanic}{factor. Is the mother Hispanic?}
+ \item{other}{factor. Is the mother's ethnicity neither African-American nor
+ Hispanic, nor Caucasian? (see below)}
+ \item{work}{number of weeks in which the mother worked in 1979.}
+}
+}
+
+\details{
+\code{Fertility2} is a random subset of \code{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
+\emph{American Economic Review}, \bold{88}, 450--477.
+
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+data("Fertility2")
+
+## conflicts in ethnicity coding
+ftable(xtabs(~ afam + hispanic + other, data = Fertility2))
+
+## create convenience variables
+Fertility2$mkids <- with(Fertility2, as.numeric(morekids) - 1)
+Fertility2$samegender <- with(Fertility2, factor(gender1 == gender2))
+Fertility2$twoboys <- with(Fertility2, factor(gender1 == "male" & gender2 == "male"))
+Fertility2$twogirls <- with(Fertility2, factor(gender1 == "female" & gender2 == "female"))
+
+## similar to Angrist and Evans, p. 462
+fm1 <- lm(mkids ~ samegender, data = Fertility2)
+summary(fm1)
+
+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)
+}
+
+\keyword{datasets}
diff --git a/man/Franses1998.Rd b/man/Franses1998.Rd
new file mode 100644
index 0000000..464ff22
--- /dev/null
+++ b/man/Franses1998.Rd
@@ -0,0 +1,91 @@
+\name{Franses1998}
+\alias{Franses1998}
+
+\title{Data and Examples from Franses (1998)}
+
+\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). \emph{Time Series Models for Business and Economic Forecasting}.
+Cambridge, UK: Cambridge University Press.
+}
+
+\seealso{\code{\link{ArgentinaCPI}}, \code{\link{ChinaIncome}}, \code{\link{ConsumerGood}},
+ \code{\link{DJFranses}}, \code{\link{DutchAdvert}}, \code{\link{DutchSales}},
+ \code{\link{GermanUnemployment}}, \code{\link{MotorCycles}}, \code{\link{OlympicTV}},
+ \code{\link{PepperPrice}}, \code{\link{UKNonDurables}}, \code{\link{USProdIndex}}}
+
+\examples{
+###########################
+## Convenience functions ##
+###########################
+
+## EACF tables (Franses 1998, p. 99)
+ctrafo <- function(x) residuals(lm(x ~ factor(cycle(x))))
+ddiff <- function(x) diff(diff(x, frequency(x)), 1)
+eacf <- function(y, lag = 12) {
+ stopifnot(all(lag > 0))
+ if(length(lag) < 2) lag <- 1:lag
+ rval <- sapply(
+ list(y = y, dy = diff(y), cdy = ctrafo(diff(y)),
+ Dy = diff(y, frequency(y)), dDy = ddiff(y)),
+ function(x) acf(x, plot = FALSE, lag.max = max(lag))$acf[lag + 1])
+ rownames(rval) <- lag
+ return(rval)
+}
+
+#######################################
+## Index of US industrial production ##
+#######################################
+
+data("USProdIndex", package = "AER")
+plot(USProdIndex, plot.type = "single", col = 1:2)
+
+## Franses (1998), Table 5.1
+round(eacf(log(USProdIndex[,1])), digits = 3)
+
+## Franses (1998), Equation 5.6: Unrestricted airline model
+## (Franses: ma1 = 0.388 (0.063), ma4 = -0.739 (0.060), ma5 = -0.452 (0.069))
+arima(log(USProdIndex[,1]), c(0, 1, 5), c(0, 1, 0), fixed = c(NA, 0, 0, NA, NA))
+
+###########################################
+## Consumption of non-durables in the UK ##
+###########################################
+
+data("UKNonDurables", package = "AER")
+plot(UKNonDurables)
+
+## Franses (1998), Table 5.2
+round(eacf(log(UKNonDurables)), digits = 3)
+
+## Franses (1998), Equation 5.51
+## (Franses: sma1 = -0.632 (0.069))
+arima(log(UKNonDurables), c(0, 1, 0), c(0, 1, 1))
+
+##############################
+## Dutch retail sales index ##
+##############################
+
+data("DutchSales", package = "AER")
+plot(DutchSales)
+
+## Franses (1998), Table 5.3
+round(eacf(log(DutchSales), lag = c(1:18, 24, 36)), digits = 3)
+
+###########################################
+## TV and radio advertising expenditures ##
+###########################################
+
+data("DutchAdvert", package = "AER")
+plot(DutchAdvert)
+
+## Franses (1998), Table 5.4
+round(eacf(log(DutchAdvert[,"tv"]), lag = c(1:19, 26, 39)), digits = 3)
+}
+
+\keyword{datasets}
diff --git a/man/FrozenJuice.Rd b/man/FrozenJuice.Rd
new file mode 100644
index 0000000..d0fbde5
--- /dev/null
+++ b/man/FrozenJuice.Rd
@@ -0,0 +1,85 @@
+\name{FrozenJuice}
+\alias{FrozenJuice}
+
+\title{Price of Frozen Orange Juice}
+
+\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.
+\describe{
+ \item{price}{Average producer price for frozen orange juice.}
+ \item{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.}
+ \item{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: \code{fdd} = sum(max(0, 32 - minimum daily temperature)),
+ e.g. for February \code{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). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+## load data
+data("FrozenJuice")
+
+## Stock and Watson, p. 594
+library("dynlm")
+fm_dyn <- dynlm(d(100 * log(price/ppi)) ~ fdd, data = FrozenJuice)
+coeftest(fm_dyn, vcov = vcovHC(fm_dyn, type = "HC1"))
+
+## equivalently, returns can be computed 'by hand'
+## (reducing the complexity of the formula notation)
+fj <- ts.union(fdd = FrozenJuice[, "fdd"],
+ ret = 100 * diff(log(FrozenJuice[,"price"]/FrozenJuice[,"ppi"])))
+fm_dyn <- dynlm(ret ~ fdd, data = fj)
+
+## Stock and Watson, p. 595
+fm_dl <- dynlm(ret ~ L(fdd, 0:6), data = fj)
+coeftest(fm_dl, vcov = vcovHC(fm_dl, type = "HC1"))
+
+## Stock and Watson, Table 15.1, p. 620, numbers refer to columns
+## (1) Dynamic Multipliers
+fm1 <- dynlm(ret ~ L(fdd, 0:18), data = fj)
+coeftest(fm1, vcov = NeweyWest(fm1, lag = 7, prewhite = FALSE))
+## (2) Cumulative Multipliers
+fm2 <- dynlm(ret ~ L(d(fdd), 0:17) + L(fdd, 18), data = fj)
+coeftest(fm2, vcov = NeweyWest(fm2, lag = 7, prewhite = FALSE))
+## (3) Cumulative Multipliers, more lags in NW
+coeftest(fm2, vcov = NeweyWest(fm2, lag = 14, prewhite = FALSE))
+## (4) Cumulative Multipliers with monthly indicators
+fm4 <- dynlm(ret ~ L(d(fdd), 0:17) + L(fdd, 18) + season(fdd), data = fj)
+coeftest(fm4, vcov = NeweyWest(fm4, lag = 7, prewhite = FALSE))
+## monthly indicators needed?
+fm4r <- update(fm4, . ~ . - season(fdd))
+waldtest(fm4, fm4r, vcov= NeweyWest(fm4, lag = 7, prewhite = FALSE)) ## close ...
+}
+
+\keyword{datasets}
diff --git a/man/GSOEP9402.Rd b/man/GSOEP9402.Rd
new file mode 100644
index 0000000..a32d0fe
--- /dev/null
+++ b/man/GSOEP9402.Rd
@@ -0,0 +1,131 @@
+\name{GSOEP9402}
+\alias{GSOEP9402}
+
+\title{German Socio-Economic Panel 1994--2002}
+
+\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.
+\describe{
+ \item{school}{factor. Child's secondary school level.}
+ \item{birthyear}{Year of child's birth.}
+ \item{gender}{factor indicating child's gender.}
+ \item{kids}{Total number of kids living in household.}
+ \item{parity}{Birth order.}
+ \item{income}{Household income.}
+ \item{size}{Household size}
+ \item{state}{factor indicating German federal state.}
+ \item{marital}{factor indicating mother's marital status.}
+ \item{meducation}{Mother's educational level in years.}
+ \item{memployment}{factor indicating mother's employment level:
+ full-time, part-time, or not working.}
+ \item{year}{Year of GSOEP wave.}
+}
+}
+
+\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 secondary 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. After that, around the age of ten, students are placed
+into one of three types of secondary school: \code{"Hauptschule"}
+(lower secondary school), \code{"Realschule"} (middle secondary school), or
+\code{"Gymnasium"} (upper secondary school). Only a degree from the latter
+type of school (called Abitur) provides direct 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).
+
+\url{http://econsites.uzh.ch/rwinke/microdata.zip}
+}
+
+\references{
+Winkelmann, R., and Boes, S. (2009). \emph{Analysis of Microdata}, 2nd ed. Berlin and Heidelberg: Springer-Verlag.
+}
+
+\seealso{\code{\link{WinkelmannBoes2009}}}
+
+\examples{
+## data
+data("GSOEP9402", package = "AER")
+
+## some convenience data transformations
+gsoep <- GSOEP9402
+gsoep$year2 <- factor(gsoep$year)
+
+## visualization
+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
+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)
+
+## compare polr and multinom via AIC
+gsoep_pol1 <- polr(
+ school ~ meducation + memployment + log(income) + log(size) + parity,
+ data = gsoep, Hess = TRUE)
+AIC(gsoep_pol1, gsoep_mnl)
+
+## effects
+eff_pol1 <- allEffects(gsoep_pol1)
+plot(eff_pol1, ask = FALSE, confint = FALSE)
+
+
+## More examples can be found in:
+## help("WinkelmannBoes2009")
+}
+
+\keyword{datasets}
diff --git a/man/GSS7402.Rd b/man/GSS7402.Rd
new file mode 100644
index 0000000..b2e0ffa
--- /dev/null
+++ b/man/GSS7402.Rd
@@ -0,0 +1,114 @@
+\name{GSS7402}
+\alias{GSS7402}
+
+\title{US General Social Survey 1974--2002}
+
+\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.
+\describe{
+ \item{kids}{Number of children. This is coded as a numerical variable
+ but note that the value \code{8} actually encompasses 8 or more children.}
+ \item{age}{Age of respondent.}
+ \item{education}{Highest year of school completed.}
+ \item{year}{GSS year for respondent.}
+ \item{siblings}{Number of brothers and sisters.}
+ \item{agefirstbirth}{Woman's age at birth of first child.}
+ \item{ethnicity}{factor indicating ethnicity.
+ Is the individual Caucasian (\code{"cauc"}) or not (\code{"other"})?}
+ \item{city16}{factor. Did the respondent live in a city
+ (with population > 50,000) at age 16?}
+ \item{lowincome16}{factor. Was the income below average at age 16?}
+ \item{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).
+
+\url{http://econsites.uzh.ch/rwinke/microdata.zip}
+}
+
+\references{
+Winkelmann, R., and Boes, S. (2009). \emph{Analysis of Microdata}, 2nd ed. Berlin and Heidelberg: Springer-Verlag.
+}
+
+\seealso{\code{\link{WinkelmannBoes2009}}}
+
+\examples{
+## completed fertility subset
+data("GSS7402", package = "AER")
+gss40 <- subset(GSS7402, age >= 40)
+
+## Chapter 1
+## exploratory statistics
+gss_kids <- prop.table(table(gss40$kids))
+names(gss_kids)[9] <- "8+"
+
+gss_zoo <- as.matrix(with(gss40, cbind(
+ tapply(kids, year, mean),
+ tapply(kids, year, function(x) mean(x <= 0)),
+ tapply(education, year, mean))))
+colnames(gss_zoo) <- c("Number of children",
+ "Proportion childless", "Years of schooling")
+gss_zoo <- zoo(gss_zoo, sort(unique(gss40$year)))
+
+## visualizations instead of tables
+barplot(gss_kids,
+ xlab = "Number of children ever borne to women (age 40+)",
+ ylab = "Relative frequencies")
+
+library("lattice")
+trellis.par.set(theme = canonical.theme(color = FALSE))
+print(xyplot(gss_zoo[,3:1], type = "b", xlab = "Year"))
+
+
+## Chapter 3, Example 3.14
+## Table 3.1
+gss40$nokids <- factor(gss40$kids <= 0, levels = c(FALSE, TRUE), labels = c("no", "yes"))
+gss40$trend <- gss40$year - 1974
+nokids_p1 <- glm(nokids ~ 1, data = gss40, family = binomial(link = "probit"))
+nokids_p2 <- glm(nokids ~ trend, data = gss40, family = binomial(link = "probit"))
+nokids_p3 <- glm(nokids ~ trend + education + ethnicity + siblings,
+ data = gss40, family = binomial(link = "probit"))
+lrtest(nokids_p1, nokids_p2, nokids_p3)
+
+
+## Chapter 4, Figure 4.4
+library("effects")
+nokids_p3_ef <- effect("education", nokids_p3, xlevels = list(education = 0:20))
+plot(nokids_p3_ef, rescale.axis = FALSE, ylim = c(0, 0.3))
+
+
+## Chapter 8, 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)
+
+
+## More examples can be found in:
+## help("WinkelmannBoes2009")
+}
+
+\keyword{datasets}
diff --git a/man/GermanUnemployment.Rd b/man/GermanUnemployment.Rd
new file mode 100644
index 0000000..6689c51
--- /dev/null
+++ b/man/GermanUnemployment.Rd
@@ -0,0 +1,35 @@
+\name{GermanUnemployment}
+\alias{GermanUnemployment}
+\title{Unemployment in Germany Data}
+
+\description{
+Time series of unemployment rate (in percent) in Germany.
+}
+
+\usage{data("GermanUnemployment")}
+
+\format{
+A quarterly multiple time series from 1962(1) to 1991(4) with 2 variables.
+\describe{
+ \item{unadjusted}{Raw unemployment rate,}
+ \item{adjusted}{Seasonally adjusted rate.}
+}
+}
+
+\source{
+Online complements to Franses (1998).
+}
+
+\seealso{\code{\link{Franses1998}}}
+
+\references{
+Franses, P.H. (1998). \emph{Time Series Models for Business and Economic Forecasting}.
+Cambridge, UK: Cambridge University Press.
+}
+
+\examples{
+data("GermanUnemployment")
+plot(GermanUnemployment, plot.type = "single", col = 1:2)
+}
+
+\keyword{datasets}
diff --git a/man/GoldSilver.Rd b/man/GoldSilver.Rd
new file mode 100755
index 0000000..68af256
--- /dev/null
+++ b/man/GoldSilver.Rd
@@ -0,0 +1,99 @@
+\name{GoldSilver}
+\alias{GoldSilver}
+\title{Gold and Silver Prices}
+
+\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 \code{"zoo"} with \code{"Date"} index).
+\describe{
+ \item{gold}{spot price for gold,}
+ \item{silver}{spot price for silver.}
+}
+}
+
+\source{
+Online complements to Franses, van Dijk and Opschoor (2014).
+
+\url{http://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-economics/time-series-models-business-and-economic-forecasting-2nd-edition}
+}
+
+\references{
+Franses, P.H., van Dijk, D. and Opschoor, A. (2014). \emph{Time Series Models for Business and Economic Forecasting}, 2nd ed.
+Cambridge, UK: Cambridge University Press.
+}
+
+\examples{
+data("GoldSilver", package = "AER")
+
+## p.31, daily returns
+lgs <- log(GoldSilver)
+plot(lgs[, c("silver", "gold")])
+
+dlgs <- 100 * diff(lgs)
+plot(dlgs[, c("silver", "gold")])
+
+## p.31, monthly log prices
+lgs7812 <- window(lgs, start = as.Date("1978-01-01"))
+lgs7812m <- aggregate(lgs7812, as.Date(as.yearmon(time(lgs7812))), mean)
+plot(lgs7812m, plot.type = "single", lty = 1:2, lwd = 2)
+
+## p.93, empirical ACF of absolute daily gold returns, 1978-01-01 - 2012-12-31
+absgret <- abs(100 * diff(lgs7812[, "gold"]))
+sacf <- acf(absgret, lag.max = 200, na.action = na.exclude, plot = FALSE)
+plot(1:201, sacf$acf, ylim = c(0.04, 0.28), type = "l", xaxs = "i", yaxs = "i", las = 1)
+
+## ARFIMA(0,1,1) model, eq. (4.44)
+library("longmemo")
+WhittleEst(absgret, model = "fARIMA", p = 0, q = 1, start = list(H = 0.3, MA = .25))
+
+library("forecast")
+arfima(as.vector(absgret), max.p = 0, max.q = 1)
+
+
+## p.254: VAR(2), monthly data for 1986.1 - 2012.12
+library("vars")
+
+lgs8612 <- window(lgs, start = as.Date("1986-01-01"))
+dim(lgs8612)
+
+lgs8612m <- aggregate(lgs8612, as.Date(as.yearmon(time(lgs8612))), mean)
+plot(lgs8612m)
+dim(lgs8612m)
+
+VARselect(lgs8612m, 5)
+gs2 <- VAR(lgs8612m, 2)
+
+summary(gs2)
+summary(gs2)$covres
+
+## ACF of residuals, p.256
+acf(resid(gs2), 2, plot = FALSE)
+
+## Figure 9.1, p.260 (somewhat different)
+plot(irf(gs2, impulse = "gold", n.ahead = 50), ylim = c(-0.02, 0.1))
+plot(irf(gs2, impulse = "silver", n.ahead = 50), ylim = c(-0.02, 0.1))
+
+## Table 9.2, p.261
+fevd(gs2)
+
+## p.266
+ls <- lgs8612[, "silver"]
+lg <- lgs8612[, "gold"]
+
+gsreg <- lm(lg ~ ls)
+summary(gsreg)
+sgreg <- lm(ls ~ lg)
+summary(sgreg)
+
+library("tseries")
+adf.test(resid(gsreg), k = 0)
+adf.test(resid(sgreg), k = 0)
+
+}
+
+\keyword{datasets}
diff --git a/man/Greene2003.Rd b/man/Greene2003.Rd
new file mode 100644
index 0000000..4b552b1
--- /dev/null
+++ b/man/Greene2003.Rd
@@ -0,0 +1,1036 @@
+\name{Greene2003}
+\alias{Greene2003}
+
+\title{Data and Examples from Greene (2003)}
+
+\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). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+URL \url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}.
+}
+
+\seealso{\code{\link{Affairs}}, \code{\link{BondYield}}, \code{\link{CreditCard}},
+ \code{\link{Electricity1955}}, \code{\link{Electricity1970}}, \code{\link{Equipment}},
+ \code{\link{Grunfeld}}, \code{\link{KleinI}}, \code{\link{Longley}},
+ \code{\link{ManufactCosts}}, \code{\link{MarkPound}}, \code{\link{Municipalities}},
+ \code{\link{ProgramEffectiveness}}, \code{\link{PSID1976}}, \code{\link{SIC33}},
+ \code{\link{ShipAccidents}}, \code{\link{StrikeDuration}}, \code{\link{TechChange}},
+ \code{\link{TravelMode}}, \code{\link{UKInflation}}, \code{\link{USConsump1950}},
+ \code{\link{USConsump1979}}, \code{\link{USGasG}}, \code{\link{USAirlines}},
+ \code{\link{USInvest}}, \code{\link{USMacroG}}, \code{\link{USMoney}}}
+
+\examples{
+#####################################
+## US consumption data (1970-1979) ##
+#####################################
+
+## Example 1.1
+data("USConsump1979", package = "AER")
+plot(expenditure ~ income, data = as.data.frame(USConsump1979), pch = 19)
+fm <- lm(expenditure ~ income, data = as.data.frame(USConsump1979))
+summary(fm)
+abline(fm)
+
+
+#####################################
+## US consumption data (1940-1950) ##
+#####################################
+
+## data
+data("USConsump1950", package = "AER")
+usc <- as.data.frame(USConsump1950)
+usc$war <- factor(usc$war, labels = c("no", "yes"))
+
+## Example 2.1
+plot(expenditure ~ income, data = usc, type = "n", xlim = c(225, 375), ylim = c(225, 350))
+with(usc, text(income, expenditure, time(USConsump1950)))
+
+## single model
+fm <- lm(expenditure ~ income, data = usc)
+summary(fm)
+
+## different intercepts for war yes/no
+fm2 <- lm(expenditure ~ income + war, data = usc)
+summary(fm2)
+
+## 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 ##
+########################
+
+data("USInvest", package = "AER")
+
+## Chapter 3 in Greene (2003)
+## transform (and round) data to match Table 3.1
+us <- as.data.frame(USInvest)
+us$invest <- round(0.1 * us$invest/us$price, digits = 3)
+us$gnp <- round(0.1 * us$gnp/us$price, digits = 3)
+us$inflation <- c(4.4, round(100 * diff(us$price)/us$price[-15], digits = 2))
+us$trend <- 1:15
+us <- us[, c(2, 6, 1, 4, 5)]
+
+## p. 22-24
+coef(lm(invest ~ trend + gnp, data = us))
+coef(lm(invest ~ gnp, data = us))
+
+## Example 3.1, Table 3.2
+cor(us)[1,-1]
+pcor <- solve(cor(us))
+dcor <- 1/sqrt(diag(pcor))
+pcor <- (-pcor * (dcor \%o\% dcor))[1,-1]
+
+## 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 ##
+###############################
+
+## package and data
+data("Longley", package = "AER")
+library("dynlm")
+
+## 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)
+
+
+#########################################
+## US gasoline market data (1960-1995) ##
+#########################################
+
+## data
+data("USGasG", package = "AER")
+
+## Greene (2003)
+## Example 2.3
+fm <- lm(log(gas/population) ~ log(price) + log(income) + log(newcar) + log(usedcar),
+ data = as.data.frame(USGasG))
+summary(fm)
+
+## Example 4.4
+## estimates and standard errors (note different offset for intercept)
+coef(fm)
+sqrt(diag(vcov(fm)))
+## confidence interval
+confint(fm, parm = "log(income)")
+## test linear hypothesis
+linearHypothesis(fm, "log(income) = 1")
+
+## Figure 7.5
+plot(price ~ gas, data = as.data.frame(USGasG), pch = 19,
+ col = (time(USGasG) > 1973) + 1)
+legend("topleft", legend = c("after 1973", "up to 1973"), pch = 19, col = 2:1, bty = "n")
+
+## Example 7.6
+## re-used in Example 8.3
+## linear time trend
+ltrend <- 1:nrow(USGasG)
+## shock factor
+shock <- factor(time(USGasG) > 1973, levels = c(FALSE, TRUE), labels = c("before", "after"))
+
+## 1960-1995
+fm1 <- lm(log(gas/population) ~ log(income) + log(price) + log(newcar) + log(usedcar) + ltrend,
+ data = as.data.frame(USGasG))
+summary(fm1)
+## pooled
+fm2 <- lm(
+ log(gas/population) ~ shock + log(income) + log(price) + log(newcar) + log(usedcar) + ltrend,
+ data = as.data.frame(USGasG))
+summary(fm2)
+## segmented
+fm3 <- lm(
+ log(gas/population) ~ shock/(log(income) + log(price) + log(newcar) + log(usedcar) + ltrend),
+ data = as.data.frame(USGasG))
+summary(fm3)
+
+## Chow test
+anova(fm3, fm1)
+library("strucchange")
+sctest(log(gas/population) ~ log(income) + log(price) + log(newcar) + log(usedcar) + ltrend,
+ data = USGasG, point = c(1973, 1), type = "Chow")
+## Recursive CUSUM test
+rcus <- efp(log(gas/population) ~ log(income) + log(price) + log(newcar) + log(usedcar) + ltrend,
+ 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.
+
+## 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
+
+## Table 12.4, OLS
+fm <- dynlm(log(gas/population) ~ log(price) + log(income) + log(newcar) + log(usedcar),
+ data = USGasG)
+summary(fm)
+resplot(fm, bound = FALSE)
+dwtest(fm)
+
+## 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")
+fm_ols <- dynlm(consumption ~ gdp, data = USMacroG)
+fm_iv <- dynlm(consumption ~ gdp | L(consumption) + L(gdp), data = USMacroG)
+
+## Hausman statistic
+library("MASS")
+b_diff <- coef(fm_iv) - coef(fm_ols)
+v_diff <- summary(fm_iv)$cov.unscaled - summary(fm_ols)$cov.unscaled
+(t(b_diff) \%*\% ginv(v_diff) \%*\% b_diff) / summary(fm_ols)$sigma^2
+
+## Wu statistic
+auxreg <- dynlm(gdp ~ L(consumption) + L(gdp), data = USMacroG)
+coeftest(dynlm(consumption ~ gdp + fitted(auxreg), data = USMacroG))[3,3]
+## agrees with Greene (but not with errata)
+
+## Example 6.1
+## Table 6.1
+fm6.1 <- dynlm(log(invest) ~ tbill + inflation + log(gdp) + ltrend, data = USMacroG)
+fm6.3 <- dynlm(log(invest) ~ I(tbill - inflation) + log(gdp) + ltrend, data = USMacroG)
+summary(fm6.1)
+summary(fm6.3)
+deviance(fm6.1)
+deviance(fm6.3)
+vcov(fm6.1)[2,3]
+
+## F test
+linearHypothesis(fm6.1, "tbill + inflation = 0")
+## alternatively
+anova(fm6.1, fm6.3)
+## t statistic
+sqrt(anova(fm6.1, fm6.3)[2,5])
+
+## Example 6.3
+## Distributed lag model:
+## log(Ct) = b0 + b1 * log(Yt) + b2 * log(C(t-1)) + u
+us <- log(USMacroG[, c(2, 5)])
+fm_distlag <- dynlm(log(consumption) ~ log(dpi) + L(log(consumption)),
+ data = USMacroG)
+summary(fm_distlag)
+
+## estimate and test long-run MPC
+coef(fm_distlag)[2]/(1-coef(fm_distlag)[3])
+linearHypothesis(fm_distlag, "log(dpi) + L(log(consumption)) = 1")
+## correct, see errata
+
+## 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,
+ vcov = NeweyWest, from = c(1957, 3), to = c(1991, 3))
+plot(fs)
+## which looks somewhat similar ...
+
+## 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)
+
+## Cox test in both directions:
+coxtest(fm1, fm2)
+## ... and do the same for jtest() and encomptest().
+## Notice that in this particular case two of them are coincident.
+jtest(fm1, fm2)
+encomptest(fm1, fm2)
+## encomptest could also be performed `by hand' via
+fmE <- dynlm(consumption ~ dpi + L(dpi) + L(consumption), data = USMacroG)
+waldtest(fm1, fmE, fm2)
+
+## 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 9.8, Table 9.2
+usm <- USMacroG[, c("m1", "tbill", "gdp")]
+fm_lin <- lm(m1 ~ tbill + gdp, data = usm)
+fm_log <- lm(m1 ~ tbill + gdp, data = log(usm))
+## PE auxiliary regressions
+aux_lin <- lm(m1 ~ tbill + gdp + I(fitted(fm_log) - log(fitted(fm_lin))), data = usm)
+aux_log <- lm(m1 ~ tbill + gdp + I(fitted(fm_lin) - exp(fitted(fm_log))), data = log(usm))
+coeftest(aux_lin)[4,]
+coeftest(aux_log)[4,]
+## matches results from errata
+## With lmtest >= 0.9-24:
+## petest(fm_lin, fm_log)
+
+## 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 ##
+#################################################
+
+## Example 5.6: a generalized Cobb-Douglas cost function
+data("Electricity1970", package = "AER")
+fm <- lm(log(cost/fuel) ~ log(output) + I(log(output)^2/2) +
+ log(capital/fuel) + log(labor/fuel), data=Electricity1970[1:123,])
+
+
+####################################################
+## SIC 33: Production for primary metals industry ##
+####################################################
+
+## data
+data("SIC33", package = "AER")
+
+## 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))
+
+## Table 6.2 in Greene (2003)
+deviance(fm_tl)
+deviance(fm_cb)
+summary(fm_tl)
+summary(fm_cb)
+vcov(fm_tl)
+vcov(fm_cb)
+
+## Cobb-Douglas vs. Translog model
+anova(fm_cb, fm_tl)
+## hypothesis of constant returns
+linearHypothesis(fm_cb, "labor + capital = 1")
+
+
+###############################
+## 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)
+
+## full fitted model
+coef(fm_full)[1:5]
+plot(1970:1984, c(coef(fm_full)[6:19], 0), type = "n",
+ xlab = "Year", ylab = expression(delta(Year)),
+ main = "Estimated Year Specific Effects")
+grid()
+points(1970:1984, c(coef(fm_full)[6:19], 0), pch = 19)
+
+## Table 7.2
+anova(fm_full, fm_time)
+anova(fm_full, fm_firm)
+anova(fm_full, fm_no)
+
+## alternatively, use plm()
+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)
+
+
+## Example 13.1, Table 13.1
+fm_no <- plm(log(cost) ~ log(output) + log(price) + load, data = usair, model = "pooling")
+fm_gm <- plm(log(cost) ~ log(output) + log(price) + load, data = usair, model = "between")
+fm_firm <- plm(log(cost) ~ log(output) + log(price) + load, data = usair, model = "within")
+fm_time <- plm(log(cost) ~ log(output) + log(price) + load, data = usair, model = "within",
+ effect = "time")
+fm_ft <- plm(log(cost) ~ log(output) + log(price) + load, data = usair, model = "within",
+ effect = "twoways")
+
+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),
+ data = Electricity)
+summary(fm_all)
+
+## hypothesis of constant returns to scale
+linearHypothesis(fm_all, "log(output) = 1")
+
+## 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.3 (close, but not quite)
+round(rbind(coef(fm_all)[-1], matrix(coef(fm_group), nrow = 5)[,-1]), digits = 3)
+
+## 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)
+
+## Exercise 7.2 (a) and (c)
+plot(I(output/technology) ~ clr, data = TechChange)
+sctest(I(output/technology) ~ log(clr), data = TechChange,
+ type = "Chow", point = c(1942, 1))
+
+
+##################################
+## Expenditure and default data ##
+##################################
+
+## full data set (F21.4)
+data("CreditCard", package = "AER")
+
+## 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")))
+
+bptest(cc_ols, ~ (age + income + I(income^2) + owner)^2 + I(age^2) + I(income^4),
+ data = ccard0)
+gqtest(cc_ols)
+bptest(cc_ols, ~ income + I(income^2), data = ccard0, studentize = FALSE)
+bptest(cc_ols, ~ income + I(income^2), data = ccard0)
+
+## Table 11.2, WLS and FGLS
+cc_wls1 <- lm(expenditure ~ age + owner + income + I(income^2), weights = 1/income,
+ data = ccard0)
+cc_wls2 <- lm(expenditure ~ age + owner + income + I(income^2), weights = 1/income^2,
+ data = ccard0)
+
+auxreg1 <- lm(log(residuals(cc_ols)^2) ~ log(income), data = ccard0)
+cc_fgls1 <- lm(expenditure ~ age + owner + income + I(income^2),
+ weights = 1/exp(fitted(auxreg1)), data = ccard0)
+
+auxreg2 <- lm(log(residuals(cc_ols)^2) ~ income + I(income^2), data = ccard0)
+cc_fgls2 <- lm(expenditure ~ age + owner + income + I(income^2),
+ weights = 1/exp(fitted(auxreg2)), data = ccard0)
+
+alphai <- coef(lm(log(residuals(cc_ols)^2) ~ log(income), data = ccard0))[2]
+alpha <- 0
+while(abs((alphai - alpha)/alpha) > 1e-7) {
+ alpha <- alphai
+ cc_fgls3 <- lm(expenditure ~ age + owner + income + I(income^2), weights = 1/income^alpha,
+ data = ccard0)
+ alphai <- coef(lm(log(residuals(cc_fgls3)^2) ~ log(income), data = ccard0))[2]
+}
+alpha ## 1.7623 for Greene
+cc_fgls3 <- lm(expenditure ~ age + owner + income + I(income^2), weights = 1/income^alpha,
+ data = ccard0)
+
+llik <- function(alpha)
+ -logLik(lm(expenditure ~ age + owner + income + I(income^2), weights = 1/income^alpha,
+ data = ccard0))
+plot(0:100/20, -sapply(0:100/20, llik), type = "l", xlab = "alpha", ylab = "logLik")
+alpha <- optimize(llik, interval = c(0, 5))$minimum
+cc_fgls4 <- lm(expenditure ~ age + owner + income + I(income^2), weights = 1/income^alpha,
+ data = ccard0)
+
+## Table 11.2
+cc_fit <- list(cc_ols, cc_wls1, cc_wls2, cc_fgls2, cc_fgls1, cc_fgls3, cc_fgls4)
+t(sapply(cc_fit, coef))
+t(sapply(cc_fit, function(obj) sqrt(diag(vcov(obj)))))
+
+## Table 21.21, Poisson and logit models
+cc_pois <- glm(reports ~ age + income + expenditure, data = CreditCard, family = poisson)
+summary(cc_pois)
+logLik(cc_pois)
+xhat <- colMeans(CreditCard[, c("age", "income", "expenditure")])
+xhat <- as.data.frame(t(xhat))
+lambda <- predict(cc_pois, newdata = xhat, type = "response")
+ppois(0, lambda) * nrow(CreditCard)
+
+cc_logit <- glm(factor(reports > 0) ~ age + income + owner,
+ data = CreditCard, family = binomial)
+summary(cc_logit)
+logLik(cc_logit)
+
+## Table 21.21, "split population model"
+library("pscl")
+cc_zip <- zeroinfl(reports ~ age + income + expenditure | age + income + owner,
+ data = CreditCard)
+summary(cc_zip)
+sum(predict(cc_zip, type = "prob")[,1])
+
+
+###################################
+## DEM/GBP exchange rate returns ##
+###################################
+
+## data as given by Greene (2003)
+data("MarkPound")
+mp <- round(MarkPound, digits = 6)
+
+## Figure 11.3 in Greene (2003)
+plot(mp)
+
+## Example 11.8 in Greene (2003), Table 11.5
+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).
+
+## compare Errata to Greene (2003)
+library("dynlm")
+res <- residuals(dynlm(mp ~ 1))^2
+mp_ols <- dynlm(res ~ L(res, 1:10))
+summary(mp_ols)
+logLik(mp_ols)
+summary(mp_ols)$r.squared * length(residuals(mp_ols))
+
+
+################################
+## Grunfeld's investment data ##
+################################
+
+## subset of data with mistakes
+data("Grunfeld", package = "AER")
+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
+
+## 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)
+
+## ML, computed as iterated FGLS
+sigmasi <- fitted(lm(residuals(fm_pfgls)^2 ~ firm - 1 , data = ggr))
+sigmas <- 0
+while(any(abs((sigmasi - sigmas)/sigmas) > 1e-7)) {
+ sigmas <- sigmasi
+ fm_pfgls_i <- lm(invest ~ value + capital, data = ggr, weights = 1/sigmas)
+ sigmasi <- fitted(lm(residuals(fm_pfgls_i)^2 ~ firm - 1 , data = ggr))
+ }
+fm_pmlh <- lm(invest ~ value + capital, data = ggr, weights = 1/sigmas)
+summary(fm_pmlh)
+logLik(fm_pmlh)
+
+## 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))
+
+
+## Chapter 14: explicitly treat as panel data
+library("plm")
+pggr <- plm.data(ggr, c("firm", "year"))
+
+## 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)
+
+## Tab. 14.3 (and Tab 13.4, cross-section ML)
+## (not run due to long computation time)
+\dontrun{
+fm_ml <- systemfit(invest ~ value + capital, data = pggr, method = "SUR",
+ methodResidCov = "noDfCor", maxiter = 1000, tol = 1e-10)
+fm_pml <- systemfit(invest ~ value + capital, data = pggr, method = "SUR", pooled = TRUE,
+ methodResidCov = "noDfCor", residCovWeighted = TRUE, maxiter = 1000, tol = 1e-10)
+}
+
+## 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")
+
+## Tab. 15.3, OLS
+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
+
+## preparation of data frame for systemfit
+KI <- ts.intersect(KleinI, lag(KleinI, k = -1), dframe = TRUE)
+names(KI) <- c(colnames(KleinI), paste("L", colnames(KleinI), sep = ""))
+KI$trend <- (1921:1941) - 1931
+
+library("systemfit")
+system <- list(
+ consumption = consumption ~ cprofits + Lcprofits + I(pwage + gwage),
+ invest = invest ~ cprofits + Lcprofits + capital,
+ pwage = pwage ~ gnp + Lgnp + trend)
+
+## Tab. 15.3 OLS again
+fm_ols <- systemfit(system, method = "OLS", data = KI)
+summary(fm_ols)
+
+## Tab. 15.3 2SLS, 3SLS, I3SLS
+inst <- ~ Lcprofits + capital + Lgnp + gexpenditure + taxes + trend + gwage
+fm_2sls <- systemfit(system, method = "2SLS", inst = inst,
+ methodResidCov = "noDfCor", data = KI)
+
+fm_3sls <- systemfit(system, method = "3SLS", inst = inst,
+ methodResidCov = "noDfCor", data = KI)
+
+fm_i3sls <- systemfit(system, method = "3SLS", inst = inst,
+ methodResidCov = "noDfCor", maxiter = 100, data = KI)
+
+
+############################################
+## 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)
+
+## generalized Cobb-Douglas with Zellner-Revankar trafo
+GCobbDouglas <- function(theta)
+ lm(I(log(valueadded/firms) + theta * valueadded/firms) ~ log(capital/firms) + log(labor/firms),
+ data = Equipment)
+
+## yields classical Cobb-Douglas for theta = 0
+fm_cd0 <- GCobbDouglas(0)
+
+## ML estimation of generalized model
+## choose starting values from classical model
+par0 <- as.vector(c(coef(fm_cd0), 0, mean(residuals(fm_cd0)^2)))
+
+## set up likelihood function
+nlogL <- function(par) {
+ beta <- par[1:3]
+ theta <- par[4]
+ sigma2 <- par[5]
+
+ Y <- with(Equipment, valueadded/firms)
+ K <- with(Equipment, capital/firms)
+ L <- with(Equipment, labor/firms)
+
+ rhs <- beta[1] + beta[2] * log(K) + beta[3] * log(L)
+ lhs <- log(Y) + theta * Y
+
+ rval <- sum(log(1 + theta * Y) - log(Y) +
+ dnorm(lhs, mean = rhs, sd = sqrt(sigma2), log = TRUE))
+ return(-rval)
+}
+
+## 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)))
+
+## fit NLS model
+rss <- function(theta) deviance(GCobbDouglas(theta))
+optim(0, rss)
+opt2 <- optimize(rss, c(-1, 1))
+fm_nls <- GCobbDouglas(opt2$minimum)
+-nlogL(c(coef(fm_nls), opt2$minimum, mean(residuals(fm_nls)^2)))
+
+
+############################
+## Municipal expenditures ##
+############################
+
+## Table 18.2
+data("Municipalities", package = "AER")
+summary(Municipalities)
+
+
+###########################
+## Program effectiveness ##
+###########################
+
+## Table 21.1, col. "Probit"
+data("ProgramEffectiveness", package = "AER")
+fm_probit <- glm(grade ~ average + testscore + participation,
+ data = ProgramEffectiveness, family = binomial(link = "probit"))
+summary(fm_probit)
+
+
+####################################
+## Labor force participation data ##
+####################################
+
+## data and transformations
+data("PSID1976", package = "AER")
+PSID1976$kids <- with(PSID1976, factor((youngkids + oldkids) > 0,
+ levels = c(FALSE, TRUE), labels = c("no", "yes")))
+PSID1976$nwincome <- with(PSID1976, (fincome - hours * wage)/1000)
+
+## Example 4.1, Table 4.2
+## (reproduced in Example 7.1, Table 7.1)
+gr_lm <- lm(log(hours * wage) ~ age + I(age^2) + education + kids,
+ data = PSID1976, subset = participation == "yes")
+summary(gr_lm)
+vcov(gr_lm)
+
+## 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)
+
+## Example 21.4, p. 681, and Tab. 21.3, p. 682
+gr_probit1 <- glm(participation ~ age + I(age^2) + I(fincome/10000) + education + kids,
+ data = PSID1976, family = binomial(link = "probit") )
+gr_probit2 <- glm(participation ~ age + I(age^2) + I(fincome/10000) + education,
+ data = PSID1976, family = binomial(link = "probit"))
+gr_probit3 <- glm(participation ~ kids/(age + I(age^2) + I(fincome/10000) + education),
+ data = PSID1976, family = binomial(link = "probit"))
+## LR test of all coefficients
+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)
+
+## Example 22.8, Table 22.7, p. 786
+library("sampleSelection")
+gr_2step <- selection(participation ~ age + I(age^2) + fincome + education + kids,
+ wage ~ experience + I(experience^2) + education + city,
+ data = PSID1976, method = "2step")
+gr_ml <- selection(participation ~ age + I(age^2) + fincome + education + kids,
+ wage ~ experience + I(experience^2) + education + city,
+ data = PSID1976, method = "ml")
+gr_ols <- lm(wage ~ experience + I(experience^2) + education + city,
+ data = PSID1976, subset = participation == "yes")
+## NOTE: ML estimates agree with Greene, 5e errata.
+## Standard errors are based on the Hessian (here), while Greene has BHHH/OPG.
+
+
+
+####################
+## 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)
+
+sa_notype <- glm(incidents ~ construction + operation, family = poisson,
+ data = sa, offset = log(service))
+summary(sa_notype)
+
+sa_noperiod <- glm(incidents ~ type + operation, family = poisson,
+ data = sa, offset = log(service))
+summary(sa_noperiod)
+
+## model comparison
+anova(sa_full, sa_notype, test = "Chisq")
+anova(sa_full, sa_noperiod, test = "Chisq")
+
+## test for overdispersion
+dispersiontest(sa_full)
+dispersiontest(sa_full, trafo = 2)
+
+
+######################################
+## Fair's extramarital affairs data ##
+######################################
+
+## data
+data("Affairs", package = "AER")
+
+## 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"))
+
+fm_tobit <- tobit(affairs ~ age + yearsmarried + religiousness + occupation + rating,
+ data = Affairs)
+fm_tobit2 <- tobit(affairs ~ age + yearsmarried + religiousness + occupation + rating,
+ right = 4, data = Affairs)
+
+fm_pois <- glm(affairs ~ age + yearsmarried + religiousness + occupation + rating,
+ data = Affairs, family = poisson)
+
+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 ##
+######################
+
+## data and package
+data("StrikeDuration", package = "AER")
+library("MASS")
+
+## 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)
+}
+
+\keyword{datasets}
diff --git a/man/GrowthDJ.Rd b/man/GrowthDJ.Rd
new file mode 100644
index 0000000..084fec4
--- /dev/null
+++ b/man/GrowthDJ.Rd
@@ -0,0 +1,82 @@
+\name{GrowthDJ}
+\alias{GrowthDJ}
+
+\encoding{UTF-8}
+
+\title{Determinants of Economic Growth}
+
+\description{Growth regression data as provided by Durlauf & Johnson (1995).}
+
+\usage{data("GrowthDJ")}
+
+\format{
+A data frame containing 121 observations on 10 variables.
+\describe{
+ \item{oil}{factor. Is the country an oil-producing country?}
+ \item{inter}{factor. Does the country have better quality data?}
+ \item{oecd}{factor. Is the country a member of the OECD?}
+ \item{gdp60}{Per capita GDP in 1960.}
+ \item{gdp85}{Per capita GDP in 1985.}
+ \item{gdpgrowth}{Average growth rate of per capita GDP from 1960 to 1985 (in percent).}
+ \item{popgrowth}{Average growth rate of working-age population 1960 to 1985 (in percent).}
+ \item{invest}{Average ratio of investment (including Government Investment) to GDP
+ from 1960 to 1985 (in percent).}
+ \item{school}{Average fraction of working-age population enrolled in secondary school
+ from 1960 to 1985 (in percent).}
+ \item{literacy60}{Fraction of the population over 15 years old that is able to read
+ and write in 1960 (in percent).}
+}
+}
+
+\details{
+The data are derived from the Penn World Table 4.0 and are given in Mankiw, Romer and Weil (1992),
+except \code{literacy60} that is from the World Bank's World Development Report.
+}
+
+\source{
+Journal of Applied Econometrics Data Archive.
+
+\url{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. \emph{Journal of Applied Econometrics}, \bold{10}, 365--384.
+
+Koenker, R., and Zeileis, A. (2009). On Reproducible Econometric Research.
+\emph{Journal of Applied Econometrics}, \bold{24}(5), 833--847.
+
+Mankiw, N.G, Romer, D., and Weil, D.N. (1992). A Contribution to the Empirics of Economic Growth.
+\emph{Quarterly Journal of Economics}, \bold{107}, 407--437.
+
+Masanjala, W.H., and Papageorgiou, C. (2004). The Solow Model with CES
+Technology: Nonlinearities and Parameter Heterogeneity. \emph{Journal of
+Applied Econometrics}, \bold{19}, 171--201.
+}
+
+\seealso{\code{\link{OECDGrowth}}, \code{\link{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
+
+## Durlauf & Johnson (1995), Table II
+mrw_model <- I(log(gdp85) - log(gdp60)) ~ log(gdp60) +
+ log(invest/100) + log(popgrowth/100 + 0.05) + log(school/100)
+dj_mrw <- lm(mrw_model, data = dj)
+coeftest(dj_mrw)
+
+dj_model <- I(log(gdp85) - log(gdp60)) ~ log(gdp60) +
+ log(invest) + log(popgrowth/100 + 0.05) + log(school)
+dj_sub1 <- lm(dj_model, data = dj, subset = gdp60 < 1800 & literacy60 < 50)
+coeftest(dj_sub1, vcov = sandwich)
+
+dj_sub2 <- lm(dj_model, data = dj, subset = gdp60 >= 1800 & literacy60 >= 50)
+coeftest(dj_sub2, vcov = sandwich)
+}
+
+\keyword{datasets}
diff --git a/man/GrowthSW.Rd b/man/GrowthSW.Rd
new file mode 100644
index 0000000..a8f7c8b
--- /dev/null
+++ b/man/GrowthSW.Rd
@@ -0,0 +1,47 @@
+\name{GrowthSW}
+\alias{GrowthSW}
+
+\title{Determinants of Economic Growth}
+
+\description{
+Data on average growth rates over 1960--1995 for 65 countries, along with
+variables that are potentially related to growth.
+}
+
+\usage{data("GrowthSW")}
+
+\format{
+A data frame containing 65 observations on 6 variables.
+\describe{
+ \item{growth}{average annual percentage growth of real GDP from 1960 to 1995.}
+ \item{rgdp60}{value of GDP per capita in 1960, converted to 1960 US dollars.}
+ \item{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.}
+ \item{education}{average number of years of schooling of adult residents in that country in 1960.}
+ \item{revolutions}{average annual number of revolutions,
+ insurrections (successful or not) and coup d'etats in that country from 1960 to 1995.}
+ \item{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.
+\emph{Journal of Financial Economics}, \bold{58}, 261--300.
+
+Stock, J. H. and Watson, M. W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}, \code{\link{GrowthDJ}}, \code{\link{OECDGrowth}}}
+
+\examples{
+data("GrowthSW")
+summary(GrowthSW)
+}
+
+\keyword{datasets}
diff --git a/man/Grunfeld.Rd b/man/Grunfeld.Rd
new file mode 100644
index 0000000..ea42cae
--- /dev/null
+++ b/man/Grunfeld.Rd
@@ -0,0 +1,152 @@
+\name{Grunfeld}
+\alias{Grunfeld}
+
+\title{Grunfeld's Investment Data}
+
+\description{
+Panel data on 11 large US manufacturing firms over 20 years, for the years 1935--1954.
+}
+
+\usage{data("Grunfeld")}
+
+\format{
+A data frame containing 20 annual observations on 3 variables for 11 firms.
+\describe{
+ \item{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).}
+ \item{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).}
+ \item{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 moving average of wholesale price index of metals and metal products, base 1947).}
+ \item{firm}{factor with 11 levels: \code{"General Motors"}, \code{"US Steel"},
+ \code{"General Electric"}, \code{"Chrysler"}, \code{"Atlantic Refining"}, \code{"IBM"},
+ \code{"Union Oil"}, \code{"Westinghouse"}, \code{"Goodyear"}, \code{"Diamond Match"},
+ \code{"American Steel"}.}
+ \item{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 \code{"US Steel"} (firm 2):
+investment in 1940 is 261.6 (instead of the correct 361.6),
+investment in 1952 is 645.2 (instead of the correct 645.5),
+capital in 1946 is 132.6 (instead of the correct 232.6).
+
+Here, we provide the original data from Grunfeld (1958). The data for
+the first 10 firms are identical to those of Baltagi (2002) or Baltagi (2005),
+now also used by Greene (2008).
+}
+
+\source{
+The data are taken from Grunfeld (1958, Appendix, Tables 2--9 and 11--13).
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed., Berlin: Springer-Verlag.
+
+Baltagi, B.H. (2005). \emph{Econometric Analysis of Panel Data}, 3rd ed. Chichester, UK: John Wiley.
+
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+
+Greene, W.H. (2008). \emph{Econometric Analysis}, 6th edition. Upper Saddle River, NJ: Prentice Hall.
+
+Grunfeld, Y. (1958). \emph{The Determinants of Corporate Investment}.
+ Unpublished Ph.D. Dissertation, University of Chicago.
+
+Kleiber, C., and Zeileis, A. (2010). \dQuote{The Grunfeld Data at 50.}
+ \emph{German Economic Review}, \bold{11}(4), 404--417.
+ \url{http://dx.doi.org/10.1111/j.1468-0475.2010.00513.x}
+}
+
+\seealso{\code{\link{Baltagi2002}}, \code{\link{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
+
+## Tab. 14.2, col. "GM"
+fm_gm <- lm(invest ~ value + capital, data = ggr, subset = firm == "General Motors")
+mean(residuals(fm_gm)^2) ## Greene uses MLE
+
+## Tab. 14.2, col. "Pooled"
+fm_pool <- lm(invest ~ value + capital, data = ggr)
+
+## 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"))
+
+fm_fe <- plm(invest ~ value + capital, model = "within", data = pg)
+summary(fm_fe)
+coeftest(fm_fe, vcov = vcovHC)
+
+fm_reswar <- plm(invest ~ value + capital, data = pg,
+ model = "random", random.method = "swar")
+summary(fm_reswar)
+
+## testing for random effects
+fm_ols <- plm(invest ~ value + capital, data = pg, model = "pooling")
+plmtest(fm_ols, type = "bp")
+plmtest(fm_ols, type = "honda")
+
+## Random effects models
+fm_ream <- plm(invest ~ value + capital, data = pg, model = "random",
+ random.method = "amemiya")
+fm_rewh <- plm(invest ~ value + capital, data = pg, model = "random",
+ random.method = "walhus")
+fm_rener <- plm(invest ~ value + capital, data = pg, model = "random",
+ random.method = "nerlove")
+
+## Baltagi (2005), Tab. 2.1
+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")
+}
+
+\keyword{datasets}
diff --git a/man/Guns.Rd b/man/Guns.Rd
new file mode 100644
index 0000000..67c1dd9
--- /dev/null
+++ b/man/Guns.Rd
@@ -0,0 +1,76 @@
+\name{Guns}
+\alias{Guns}
+
+\title{More Guns, Less Crime?}
+
+\description{
+Guns is a balanced panel of data on 50 US states, plus the District of Columbia (for a
+total of 51 states), by year for 1977--1999.
+}
+
+\usage{data("Guns")}
+
+\format{
+A data frame containing 1,173 observations on 13 variables.
+\describe{
+ \item{state}{factor indicating state.}
+ \item{year}{factor indicating year.}
+ \item{violent}{violent crime rate (incidents per 100,000 members of the population).}
+ \item{murder}{murder rate (incidents per 100,000).}
+ \item{robbery}{robbery rate (incidents per 100,000).}
+ \item{prisoners}{incarceration rate in the state in the previous year
+ (sentenced prisoners per 100,000 residents; value for the previous year).}
+ \item{afam}{percent of state population that is African-American, ages 10 to 64.}
+ \item{cauc}{percent of state population that is Caucasian, ages 10 to 64.}
+ \item{male}{percent of state population that is male, ages 10 to 29.}
+ \item{population}{state population, in millions of people.}
+ \item{income}{real per capita personal income in the state (US dollars).}
+ \item{density}{population per square mile of land area, divided by 1,000.}
+ \item{law}{factor. Does the state have a shall carry law in effect in that year?}
+}
+}
+
+\details{
+Each observation is a given state in a given year.
+There are a total of 51 states times 23 years = 1,173 observations.
+}
+
+\source{
+Online complements to Stock and Watson (2007).
+}
+
+\references{
+Ayres, I., and Donohue, J.J. (2003). Shooting Down the \sQuote{More Guns Less Crime} Hypothesis.
+\emph{Stanford Law Review}, \bold{55}, 1193--1312.
+
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+## data
+data("Guns")
+
+## visualization
+library("lattice")
+xyplot(log(violent) ~ as.numeric(as.character(year)) | state, data = Guns, type = "l")
+
+## Stock & Watson (2007), Empirical Exercise 10.1, pp. 376--377
+fm1 <- lm(log(violent) ~ law, data = Guns)
+coeftest(fm1, vcov = sandwich)
+
+fm2 <- lm(log(violent) ~ law + prisoners + density + income +
+ population + afam + cauc + male, data = Guns)
+coeftest(fm2, vcov = sandwich)
+
+fm3 <- lm(log(violent) ~ law + prisoners + density + income +
+ population + afam + cauc + male + state, data = Guns)
+printCoefmat(coeftest(fm3, vcov = sandwich)[1:9,])
+
+fm4 <- lm(log(violent) ~ law + prisoners + density + income +
+ population + afam + cauc + male + state + year, data = Guns)
+printCoefmat(coeftest(fm4, vcov = sandwich)[1:9,])
+}
+
+\keyword{datasets}
diff --git a/man/HMDA.Rd b/man/HMDA.Rd
new file mode 100644
index 0000000..eef92bc
--- /dev/null
+++ b/man/HMDA.Rd
@@ -0,0 +1,61 @@
+\name{HMDA}
+\alias{HMDA}
+\title{Home Mortgage Disclosure Act Data}
+
+\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.
+\describe{
+ \item{deny}{Factor. Was the mortgage denied?}
+ \item{pirat}{Payments to income ratio.}
+ \item{hirat}{Housing expense to income ratio.}
+ \item{lvrat}{Loan to value ratio.}
+ \item{chist}{Factor. Credit history: consumer payments.}
+ \item{mhist}{Factor. Credit history: mortgage payments.}
+ \item{phist}{Factor. Public bad credit record?}
+ \item{unemp}{1989 Massachusetts unemployment rate in applicant's industry.}
+ \item{selfemp}{Factor. Is the individual self-employed?}
+ \item{insurance}{Factor. Was the individual denied mortgage insurance?}
+ \item{condomin}{Factor. Is the unit a condominium?}
+ \item{afam}{Factor. Is the individual African-American?}
+ \item{single}{Factor. Is the individual single?}
+ \item{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. \emph{American Economic Review}, \bold{86}, 25--53.
+
+Stock, J. H. and Watson, M. W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+data("HMDA")
+
+## Stock and Watson (2007)
+## Equations 11.1, 11.3, 11.7, 11.8 and 11.10, pp. 387--395
+fm1 <- lm(I(as.numeric(deny) - 1) ~ pirat, data = HMDA)
+fm2 <- lm(I(as.numeric(deny) - 1) ~ pirat + afam, data = HMDA)
+fm3 <- glm(deny ~ pirat, family = binomial(link = "probit"), data = HMDA)
+fm4 <- glm(deny ~ pirat + afam, family = binomial(link = "probit"), data = HMDA)
+fm5 <- glm(deny ~ pirat + afam, family = binomial(link = "logit"), data = HMDA)
+
+## More examples can be found in:
+## help("StockWatson2007")
+}
+
+\keyword{datasets}
diff --git a/man/HealthInsurance.Rd b/man/HealthInsurance.Rd
new file mode 100644
index 0000000..5d94419
--- /dev/null
+++ b/man/HealthInsurance.Rd
@@ -0,0 +1,55 @@
+\name{HealthInsurance}
+\alias{HealthInsurance}
+
+\title{Medical Expenditure Panel Survey Data}
+
+\description{
+Cross-section data originating from the Medical Expenditure Panel Survey survey conducted in 1996.
+}
+
+\usage{data("HealthInsurance")}
+
+\format{
+A data frame containing 8,802 observations on 11 variables.
+\describe{
+ \item{health}{factor. Is the self-reported health status \dQuote{healthy}?.}
+ \item{age}{age in years.}
+ \item{limit}{factor. Is there any limitation?}
+ \item{gender}{factor indicating gender.}
+ \item{insurance}{factor. Does the individual have a health insurance?}
+ \item{married}{factor. Is the individual married?}
+ \item{selfemp}{factor. Is the individual self-employed?}
+ \item{family}{family size.}
+ \item{region}{factor indicating region.}
+ \item{ethnicity}{factor indicating ethnicity: African-American, Caucasian, other.}
+ \item{education}{factor indicating highest degree attained:
+ no degree, GED (high school equivalent), high school, bachelor, master, PhD, other.}
+}
+}
+
+\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). \dQuote{The Self-Employed are Less Likely than
+Wage-Earners to Have Health Insurance. So What?} in
+Holtz-Eakin, D. and Rosen, H.S. (eds.), \emph{Entrepeneurship and
+Public Policy}, MIT Press.
+
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+data("HealthInsurance")
+summary(HealthInsurance)
+prop.table(xtabs(~ selfemp + insurance, data = HealthInsurance), 1)
+}
+
+\keyword{datasets}
diff --git a/man/HousePrices.Rd b/man/HousePrices.Rd
new file mode 100644
index 0000000..7bbe423
--- /dev/null
+++ b/man/HousePrices.Rd
@@ -0,0 +1,69 @@
+\name{HousePrices}
+\alias{HousePrices}
+
+\title{House Prices in the City of Windsor, Canada}
+
+\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.
+\describe{
+ \item{price}{Sale price of a house.}
+ \item{lotsize}{Lot size of a property in square feet.}
+ \item{bedrooms}{Number of bedrooms.}
+ \item{bathrooms}{Number of full bathrooms.}
+ \item{stories}{Number of stories excluding basement.}
+ \item{driveway}{Factor. Does the house have a driveway?}
+ \item{recreation}{Factor. Does the house have a recreational room?}
+ \item{fullbase}{Factor. Does the house have a full finished basement?}
+ \item{gasheat}{Factor. Does the house use gas for hot water heating?}
+ \item{aircon}{Factor. Is there central air conditioning?}
+ \item{garage}{Number of garage places.}
+ \item{prefer}{Factor. Is the house located in the preferred neighborhood of the city?}
+}
+}
+
+\source{
+Journal of Applied Econometrics Data Archive.
+
+\url{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.
+\emph{Journal of Applied Econometrics}, \bold{11}, 633--648.
+
+Verbeek, M. (2004). \emph{A Guide to Modern Econometrics}, 2nd ed. Chichester, UK: John Wiley.
+}
+
+\examples{
+data("HousePrices")
+
+### Anglin + Gencay (1996), Table II
+fm_ag <- lm(log(price) ~ driveway + recreation + fullbase + gasheat +
+ aircon + garage + prefer + log(lotsize) + log(bedrooms) +
+ log(bathrooms) + log(stories), data = HousePrices)
+
+### Anglin + Gencay (1996), Table III
+fm_ag2 <- lm(log(price) ~ driveway + recreation + fullbase + gasheat +
+ aircon + garage + prefer + log(lotsize) + bedrooms +
+ bathrooms + stories, data = HousePrices)
+
+### Verbeek (2004), Table 3.1
+fm <- lm(log(price) ~ log(lotsize) + bedrooms + bathrooms + aircon, data = HousePrices)
+summary(fm)
+
+### Verbeek (2004), Table 3.2
+fm_ext <- lm(log(price) ~ . - lotsize + log(lotsize), data = HousePrices)
+summary(fm_ext)
+
+### Verbeek (2004), Table 3.3
+fm_lin <- lm(price ~ . , data = HousePrices)
+summary(fm_lin)
+}
+
+\keyword{datasets}
diff --git a/man/Journals.Rd b/man/Journals.Rd
new file mode 100644
index 0000000..cc420a1
--- /dev/null
+++ b/man/Journals.Rd
@@ -0,0 +1,91 @@
+\name{Journals}
+\alias{Journals}
+\title{Economics Journal Subscription Data}
+\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.
+\describe{
+ \item{title}{Journal title.}
+ \item{publisher}{factor with publisher name.}
+ \item{society}{factor. Is the journal published by a scholarly society?}
+ \item{price}{Library subscription price.}
+ \item{pages}{Number of pages.}
+ \item{charpp}{Characters per page.}
+ \item{citations}{Total number of citations.}
+ \item{foundingyear}{Year journal was founded.}
+ \item{subs}{Number of library subscriptions.}
+ \item{field}{factor with field description.}
+}
+}
+
+\details{
+Data on 180 economic journals, collected in particular for analyzing journal
+pricing. See also \url{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 \dQuote{World Development}. One of these (observation 80)
+seemed to be an error and was changed to \dQuote{The World Economy}.
+}
+
+\source{
+Online complements to Stock and Watson (2007).
+}
+
+\references{
+Bergstrom, T. (2001). Free Labor for Costly Journals? \emph{Journal of Economic Perspectives}, 15, 183--198.
+
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{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
+
+## Stock and Watson (2007)
+## Figure 8.9 (a) and (b)
+plot(subs ~ citeprice, data = journals, pch = 19)
+plot(log(subs) ~ log(citeprice), data = journals, pch = 19)
+fm1 <- lm(log(subs) ~ log(citeprice), data = journals)
+abline(fm1)
+
+## Table 8.2, use HC1 for comparability with Stata
+fm2 <- lm(subs ~ citeprice + age + chars, data = log(journals))
+fm3 <- lm(subs ~ citeprice + I(citeprice^2) + I(citeprice^3) +
+ age + I(age * citeprice) + chars, data = log(journals))
+fm4 <- lm(subs ~ citeprice + age + I(age * citeprice) + chars, data = log(journals))
+coeftest(fm1, vcov = vcovHC(fm1, type = "HC1"))
+coeftest(fm2, vcov = vcovHC(fm2, type = "HC1"))
+coeftest(fm3, vcov = vcovHC(fm3, type = "HC1"))
+coeftest(fm4, vcov = vcovHC(fm4, type = "HC1"))
+waldtest(fm3, fm4, vcov = vcovHC(fm3, type = "HC1"))
+
+## changes with respect to age
+library("strucchange")
+## Nyblom-Hansen test
+scus <- gefp(subs ~ citeprice, data = log(journals), fit = lm, order.by = ~ age)
+plot(scus, functional = meanL2BB)
+## estimate breakpoint(s)
+journals <- journals[order(journals$age),]
+bp <- breakpoints(subs ~ citeprice, data = log(journals), h = 20)
+plot(bp)
+bp.age <- journals$age[bp$breakpoints]
+## visualization
+plot(subs ~ citeprice, data = log(journals), pch = 19, col = (age > log(bp.age)) + 1)
+abline(coef(bp)[1,], col = 1)
+abline(coef(bp)[2,], col = 2)
+legend("bottomleft", legend = c("age > 18", "age < 18"), lty = 1, col = 2:1, bty = "n")
+}
+
+\keyword{datasets}
diff --git a/man/KleinI.Rd b/man/KleinI.Rd
new file mode 100644
index 0000000..58a899b
--- /dev/null
+++ b/man/KleinI.Rd
@@ -0,0 +1,60 @@
+\name{KleinI}
+\alias{KleinI}
+
+\title{Klein Model I}
+
+\description{
+Klein's Model I for the US economy.
+}
+
+\usage{data("KleinI")}
+
+\format{
+An annual multiple time series from 1920 to 1941 with 9 variables.
+ \describe{
+ \item{consumption}{Consumption.}
+ \item{cprofits}{Corporate profits.}
+ \item{pwage}{Private wage bill.}
+ \item{invest}{Investment.}
+ \item{capital}{Previous year's capital stock.}
+ \item{gnp}{Gross national product.}
+ \item{gwage}{Government wage bill.}
+ \item{gexpenditure}{Government spending.}
+ \item{taxes}{Taxes.}
+ }
+}
+
+\source{
+Online complements to Greene (2003). Table F15.1.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+
+Klein, L. (1950). \emph{Economic Fluctuations in the United States, 1921--1941}. New York: John Wiley.
+
+Maddala, G.S. (1977). \emph{Econometrics}. New York: McGraw-Hill.
+}
+
+\seealso{\code{\link{Greene2003}}}
+
+\examples{
+data("KleinI", package = "AER")
+plot(KleinI)
+
+## Greene (2003), Tab. 15.3, OLS
+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)
+
+## More examples can be found in:
+## help("Greene2003")
+}
+
+\keyword{datasets}
diff --git a/man/Longley.Rd b/man/Longley.Rd
new file mode 100644
index 0000000..a0ecc1f
--- /dev/null
+++ b/man/Longley.Rd
@@ -0,0 +1,53 @@
+\name{Longley}
+\alias{Longley}
+\title{Longley's Regression Data}
+\description{
+US macroeconomic time series, 1947--1962.
+}
+\usage{data("Longley")}
+\format{
+An annual multiple time series from 1947 to 1962 with 4 variables.
+ \describe{
+ \item{employment}{Number of people employed (in 1000s).}
+ \item{price}{GNP deflator.}
+ \item{gnp}{Gross national product.}
+ \item{armedforces}{Number of people in the armed forces.}
+ }
+}
+
+\details{
+An extended version of this data set, formatted as a \code{"data.frame"}
+is available as \code{\link[datasets]{longley}} in base R.
+}
+
+\source{
+Online complements to Greene (2003). Table F4.2.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{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.
+\emph{Journal of the American Statistical Association}, \bold{62}, 819--841.
+}
+
+\seealso{\code{\link[datasets]{longley}}, \code{\link{Greene2003}}}
+
+\examples{
+data("Longley")
+library("dynlm")
+
+## Example 4.6 in Greene (2003)
+fm1 <- dynlm(employment ~ time(employment) + price + gnp + armedforces,
+ data = Longley)
+fm2 <- update(fm1, end = 1961)
+cbind(coef(fm2), coef(fm1))
+
+## Figure 4.3 in Greene (2003)
+plot(rstandard(fm2), type = "b", ylim = c(-3, 3))
+abline(h = c(-2, 2), lty = 2)
+}
+
+\keyword{datasets}
diff --git a/man/MASchools.Rd b/man/MASchools.Rd
new file mode 100644
index 0000000..dc732f9
--- /dev/null
+++ b/man/MASchools.Rd
@@ -0,0 +1,85 @@
+\name{MASchools}
+\alias{MASchools}
+\title{Massachusetts Test Score Data}
+
+\description{The dataset contains data on test performance, school
+characteristics and student demographic backgrounds for school districts
+in Massachusetts.
+}
+
+\usage{data("MASchools")}
+
+\format{
+A data frame containing 220 observations on 16 variables.
+\describe{
+ \item{district}{character. District code.}
+ \item{municipality}{character. Municipality name.}
+ \item{expreg}{Expenditures per pupil, regular.}
+ \item{expspecial}{Expenditures per pupil, special needs.}
+ \item{expbil}{Expenditures per pupil, bilingual.}
+ \item{expocc}{Expenditures per pupil, occupational.}
+ \item{exptot}{Expenditures per pupil, total.}
+ \item{scratio}{Students per computer.}
+ \item{special}{Special education students (per cent).}
+ \item{lunch}{Percent qualifying for reduced-price lunch.}
+ \item{stratio}{Student-teacher ratio.}
+ \item{income}{Per capita income.}
+ \item{score4}{4th grade score (math + English + science).}
+ \item{score8}{8th grade score (math + English + science).}
+ \item{salary}{Average teacher salary.}
+ \item{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
+receiving a subsidized lunch and on the percent of students still
+learning english are averages for each elementary school district
+for the 1997--1998 school year and were obtained from the
+Massachusetts department of education. Data on average district
+income are from the 1990 US Census.
+}
+
+\source{
+Online complements to Stock and Watson (2007).
+}
+
+\references{
+Stock, J. H. and Watson, M. W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}, \code{\link{CASchools}}}
+
+\examples{
+## Massachusetts
+data("MASchools")
+
+## compare with California
+data("CASchools")
+CASchools$stratio <- with(CASchools, students/teachers)
+CASchools$score4 <- with(CASchools, (math + read)/2)
+
+## Stock and Watson, parts of Table 9.1, p. 330
+vars <- c("score4", "stratio", "english", "lunch", "income")
+cbind(
+ CA_mean = sapply(CASchools[, vars], mean),
+ CA_sd = sapply(CASchools[, vars], sd),
+ MA_mean = sapply(MASchools[, vars], mean),
+ MA_sd = sapply(MASchools[, vars], sd))
+
+## Stock and Watson, Table 9.2, p. 332, col. (1)
+fm1 <- lm(score4 ~ stratio, data = MASchools)
+coeftest(fm1, vcov = vcovHC(fm1, type = "HC1"))
+
+## More examples, notably the entire Table 9.2, can be found in:
+## help("StockWatson2007")
+}
+
+\keyword{datasets}
diff --git a/man/MSCISwitzerland.Rd b/man/MSCISwitzerland.Rd
new file mode 100755
index 0000000..7e57f1d
--- /dev/null
+++ b/man/MSCISwitzerland.Rd
@@ -0,0 +1,87 @@
+\name{MSCISwitzerland}
+\alias{MSCISwitzerland}
+\title{MSCI Switzerland Index}
+
+\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 \code{"zoo"} with \code{"Date"} index).
+}
+
+\source{
+Online complements to Franses, van Dijk and Opschoor (2014).
+
+\url{http://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-economics/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. \emph{Journal of Empirical Finance}, 1(1), 83--106.
+
+Franses, P.H., van Dijk, D. and Opschoor, A. (2014). \emph{Time Series Models for Business and Economic Forecasting}, 2nd ed.
+Cambridge, UK: Cambridge University Press.
+}
+
+\examples{
+data("MSCISwitzerland", package = "AER")
+
+## p.190, Fig. 7.6
+dlmsci <- 100 * diff(log(MSCISwitzerland))
+plot(dlmsci)
+
+dlmsci9501 <- window(dlmsci, end = as.Date("2001-12-31"))
+
+## Figure 7.7
+plot(acf(dlmsci9501^2, lag.max = 200, na.action = na.exclude),
+ ylim = c(-0.1, 0.3), type = "l")
+
+
+## GARCH(1,1) model, p.190, eq. (7.60)
+
+## standard errors using first derivatives (as apparently used by Franses et al.)
+library("tseries")
+msci9501_g11 <- garch(zooreg(dlmsci9501), trace = FALSE)
+summary(msci9501_g11)
+
+## standard errors using second derivatives
+library("fGarch")
+msci9501_g11a <- garchFit( ~ garch(1,1), include.mean = FALSE,
+ data = dlmsci9501, trace = FALSE)
+summary(msci9501_g11a)
+
+round(msci9501_g11a at fit$coef, 3)
+round(msci9501_g11a at fit$se.coef, 3)
+
+## Fig. 7.8, p.192
+plot(msci9501_g11a, which = 2)
+abline(h = sd(dlmsci9501))
+
+
+## TGARCH model (also known as GJR-GARCH model), p. 191, eq. (7.61)
+msci9501_tg11 <- garchFit( ~ aparch(1,1), include.mean = FALSE,
+ include.delta = FALSE, delta = 2, data = dlmsci9501, trace = FALSE)
+summary(msci9501_tg11)
+
+## 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*
+
+## GARCH and GJR-GARCH with rugarch
+library("rugarch")
+spec_g11 <- ugarchspec(variance.model = list(model = "sGARCH"),
+ mean.model = list(armaOrder = c(0,0), include.mean = FALSE))
+msci9501_g11b <- ugarchfit(spec_g11, data = dlmsci9501)
+msci9501_g11b
+
+spec_gjrg11 <- ugarchspec(variance.model = list(model = "gjrGARCH", garchOrder = c(1,1)),
+ mean.model = list(armaOrder = c(0, 0), include.mean = FALSE))
+msci9501_gjrg11 <- ugarchfit(spec_gjrg11, data = dlmsci9501)
+msci9501_gjrg11
+
+round(coef(msci9501_gjrg11), 3)
+}
+
+\keyword{datasets}
diff --git a/man/ManufactCosts.Rd b/man/ManufactCosts.Rd
new file mode 100644
index 0000000..ffb1d07
--- /dev/null
+++ b/man/ManufactCosts.Rd
@@ -0,0 +1,43 @@
+\name{ManufactCosts}
+\alias{ManufactCosts}
+\title{Manufacturing Costs Data}
+\description{
+US time series data on prices and cost shares in manufacturing, 1947--1971.
+}
+\usage{data("ManufactCosts")}
+\format{
+An annual multiple time series from 1947 to 1971 with 9 variables.
+\describe{
+ \item{cost}{Cost index.}
+ \item{capitalcost}{Capital cost share.}
+ \item{laborcost}{Labor cost share.}
+ \item{energycost}{Energy cost share.}
+ \item{materialscost}{Materials cost share.}
+ \item{capitalprice}{Capital price.}
+ \item{laborprice}{Labor price.}
+ \item{energyprice}{Energy price.}
+ \item{materialsprice}{Materials price.}
+}
+}
+
+\source{
+Online complements to Greene (2003).
+
+\url{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.
+\emph{Review of Economics and Statistics}, \bold{57}, 376--384.
+
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}}
+
+\examples{
+data("ManufactCosts")
+plot(ManufactCosts)
+}
+
+\keyword{datasets}
diff --git a/man/MarkDollar.Rd b/man/MarkDollar.Rd
new file mode 100644
index 0000000..e63d42a
--- /dev/null
+++ b/man/MarkDollar.Rd
@@ -0,0 +1,41 @@
+\name{MarkDollar}
+\alias{MarkDollar}
+
+\title{DEM/USD Exchange Rate Returns}
+
+\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")}
+
+\format{
+A univariate time series of 518 returns (exact dates unknown) for the DEM/USD exchange rate.
+}
+
+\source{
+Journal of Business \& Economic Statistics Data Archive.
+
+\verb{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.
+\emph{Journal of Business \& Economic Statistics},
+\bold{14}, 139--151.
+}
+
+\seealso{\code{\link{MarkPound}}}
+
+\examples{
+library("tseries")
+data("MarkDollar")
+
+## GARCH(1,1)
+fm <- garch(MarkDollar, grad = "numerical")
+summary(fm)
+logLik(fm)
+}
+
+\keyword{datasets}
diff --git a/man/MarkPound.Rd b/man/MarkPound.Rd
new file mode 100644
index 0000000..6a40a67
--- /dev/null
+++ b/man/MarkPound.Rd
@@ -0,0 +1,66 @@
+\name{MarkPound}
+\alias{MarkPound}
+
+\title{DEM/GBP Exchange Rate Returns}
+
+\description{
+A daily time series of percentage returns of Deutsche mark/British pound (DEM/GBP)
+exchange rates from 1984-01-03 through 1991-12-31.
+}
+
+\usage{data("MarkPound")}
+\format{
+A univariate time series of 1974 returns (exact dates unknown) for the DEM/GBP exchange rate.
+}
+
+\details{
+Greene (2003, Table F11.1) rounded the series to six digits while eight digits are given in
+Bollerslev and Ghysels (1996). Here, we provide the original data. Using \code{\link{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.
+
+\verb{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.
+\emph{Journal of Business \& Economic Statistics},
+\bold{14}, 139--151.
+
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}, \code{\link{MarkDollar}}}
+
+\examples{
+## data as given by Greene (2003)
+data("MarkPound")
+mp <- round(MarkPound, digits = 6)
+
+## Figure 11.3 in Greene (2003)
+plot(mp)
+
+## Example 11.8 in Greene (2003), Table 11.5
+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).
+
+## compare Errata to Greene (2003)
+library("dynlm")
+res <- residuals(dynlm(mp ~ 1))^2
+mp_ols <- dynlm(res ~ L(res, 1:10))
+summary(mp_ols)
+logLik(mp_ols)
+summary(mp_ols)$r.squared * length(residuals(mp_ols))
+}
+
+\keyword{datasets}
diff --git a/man/Medicaid1986.Rd b/man/Medicaid1986.Rd
new file mode 100644
index 0000000..7bd6769
--- /dev/null
+++ b/man/Medicaid1986.Rd
@@ -0,0 +1,94 @@
+\name{Medicaid1986}
+\alias{Medicaid1986}
+\title{Medicaid Utilization Data}
+\description{
+Cross-section data originating from the 1986 Medicaid Consumer Survey. The data comprise
+two groups of Medicaid eligibles at two sites in California (Santa Barbara and Ventura
+counties): a group enrolled in a managed care demonstration program and a fee-for-service
+comparison group of non-enrollees.
+}
+\usage{data("Medicaid1986")}
+
+\format{
+A data frame containing 996 observations on 14 variables.
+\describe{
+ \item{visits}{Number of doctor visits.}
+ \item{exposure}{Length of observation period for ambulatory care (days).}
+ \item{children}{Total number of children in the household.}
+ \item{age}{Age of the respondent.}
+ \item{income}{Annual household income (average of income range in million USD).}
+ \item{health1}{The first principal component (divided by 1000) of three
+ health-status variables: functional limitations, acute conditions, and chronic
+ conditions.}
+ \item{health2}{The second principal component (divided by 1000) of three
+ health-status variables: functional limitations, acute conditions, and chronic
+ conditions.}
+ \item{access}{Availability of health services (0 = low access, 1 = high access).}
+ \item{married}{Factor. Is the individual married?}
+ \item{gender}{Factor indicating gender.}
+ \item{ethnicity}{Factor indicating ethnicity (\code{"cauc"} or \code{"other"}).}
+ \item{school}{Number of years completed in school.}
+ \item{enroll}{Factor. Is the individual enrolled in a demonstration program?}
+ \item{program}{Factor indicating the managed care demonstration program:
+ Aid to Families with Dependent Children (\code{"afdc"}) or
+ non-institutionalized Supplementary Security Income (\code{"ssi"}).}
+}
+}
+
+\source{
+Journal of Applied Econometrics Data Archive.
+
+\url{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. \emph{Journal of Applied Econometrics},
+\bold{12}, 225--242.
+}
+
+\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)]
+
+## Gurmu (1997):
+## Table VI., Poisson and negbin models
+afdc_pois <- glm(visits ~ ., data = afdc, family = poisson)
+summary(afdc_pois)
+coeftest(afdc_pois, vcov = sandwich)
+
+afdc_nb <- glm.nb(visits ~ ., data = afdc)
+ssi_pois <- glm(visits ~ ., data = ssi, family = poisson)
+ssi_nb <- glm.nb(visits ~ ., data = ssi)
+
+## Table VII., Hurdle models (without semi-parametric effects)
+afdc_hurdle <- hurdle(visits ~ . | . - access, data = afdc, dist = "negbin")
+ssi_hurdle <- hurdle(visits ~ . | . - access, data = ssi, dist = "negbin")
+
+## Table VIII., Observed and expected frequencies
+round(cbind(
+ Observed = table(afdc$visits)[1:8],
+ Poisson = sapply(0:7, function(x) sum(dpois(x, fitted(afdc_pois)))),
+ Negbin = sapply(0:7, function(x) sum(dnbinom(x, mu = fitted(afdc_nb), size = afdc_nb$theta))),
+ Hurdle = colSums(predict(afdc_hurdle, type = "prob")[,1:8])
+ )/nrow(afdc), digits = 3) * 100
+round(cbind(
+ Observed = table(ssi$visits)[1:8],
+ Poisson = sapply(0:7, function(x) sum(dpois(x, fitted(ssi_pois)))),
+ Negbin = sapply(0:7, function(x) sum(dnbinom(x, mu = fitted(ssi_nb), size = ssi_nb$theta))),
+ Hurdle = colSums(predict(ssi_hurdle, type = "prob")[,1:8])
+ )/nrow(ssi), digits = 3) * 100
+}
+
+\keyword{datasets}
diff --git a/man/Mortgage.Rd b/man/Mortgage.Rd
new file mode 100644
index 0000000..e371763
--- /dev/null
+++ b/man/Mortgage.Rd
@@ -0,0 +1,52 @@
+\name{Mortgage}
+\alias{Mortgage}
+\title{Fixed versus Adjustable Mortgages}
+\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.
+\describe{
+\item{rate}{Factor with levels \code{"fixed"} and \code{"adjustable"}.}
+\item{age}{Age of the borrower.}
+\item{school}{Years of schooling for the borrower.}
+\item{networth}{Net worth of the borrower.}
+\item{interest}{Fixed interest rate.}
+\item{points}{Ratio of points paid on adjustable to fixed rate mortgages.}
+\item{maturities}{Ratio of maturities on adjustable to fixed rate mortgages.}
+\item{years}{Years at the present address.}
+\item{married}{Factor. Is the borrower married?}
+\item{first}{Factor. Is the borrower a first-time home buyer?}
+\item{selfemp}{Factor. Is the borrower self-employed?}
+\item{tdiff}{The difference between the 10-year treasury rate less the 1-year treasury rate.}
+\item{margin}{The margin on the adjustable rate mortgage.}
+\item{coborrower}{Factor. Is there a co-borrower?}
+\item{liability}{Short-term liabilities.}
+\item{liquid}{Liquid assets.}
+}
+}
+
+\source{
+The data is from Baltagi (2002).
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed. Berlin, Springer.
+
+Dhillon, U.S., Shilling, J.D. and Sirmans, C.F. (1987). Choosing Between Fixed and
+Adjustable Rate Mortgages. \emph{Journal of Money, Credit and Banking}, \bold{19}, 260--267.
+
+}
+
+\seealso{\code{\link{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)
+}
+
+\keyword{datasets}
diff --git a/man/MotorCycles.Rd b/man/MotorCycles.Rd
new file mode 100644
index 0000000..42b4b51
--- /dev/null
+++ b/man/MotorCycles.Rd
@@ -0,0 +1,32 @@
+\name{MotorCycles}
+\alias{MotorCycles}
+\title{Motor Cycles in The Netherlands}
+\description{
+Time series of stock of motor cycles (two wheels) in The Netherlands
+(in thousands).
+}
+\usage{data("MotorCycles")}
+
+\format{
+An annual univariate time series from 1946 to 1993.
+}
+
+\details{An updated version is available under the name \code{MotorCycles2}. However, the values for the years 1992 and 1993 differ there.}
+
+\source{
+Online complements to Franses (1998).
+}
+
+\references{
+Franses, P.H. (1998). \emph{Time Series Models for Business and Economic Forecasting}.
+Cambridge, UK: Cambridge University Press.
+}
+
+\seealso{\code{\link{Franses1998}}, \code{\link{MotorCycles2}}}
+
+\examples{
+data("MotorCycles")
+plot(MotorCycles)
+}
+
+\keyword{datasets}
diff --git a/man/MotorCycles2.Rd b/man/MotorCycles2.Rd
new file mode 100644
index 0000000..d84a85f
--- /dev/null
+++ b/man/MotorCycles2.Rd
@@ -0,0 +1,37 @@
+\name{MotorCycles2}
+\alias{MotorCycles2}
+\title{Motor Cycles in The Netherlands}
+\description{
+Time series of stock of motor cycles (two wheels) in The Netherlands
+(in thousands).
+}
+\usage{data("MotorCycles2")}
+
+\format{
+An annual univariate time series from 1946 to 2012.
+}
+
+\details{This is an update of the series that was available with Franses (1998). However, the values for the years 1992 and 1993 differ.}
+
+\source{
+Online complements to Franses, van Dijk and Opschoor (2014).
+
+\url{http://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-economics/time-series-models-business-and-economic-forecasting-2nd-edition}
+}
+
+\references{
+Franses, P.H. (1998). \emph{Time Series Models for Business and Economic Forecasting}.
+Cambridge, UK: Cambridge University Press.
+
+Franses, P.H., van Dijk, D. and Opschoor, A. (2014). \emph{Time Series Models for Business and Economic Forecasting}, 2nd ed.
+Cambridge, UK: Cambridge University Press.
+}
+
+\seealso{\code{\link{Franses1998}}, \code{\link{MotorCycles}}}
+
+\examples{
+data("MotorCycles2")
+plot(MotorCycles2)
+}
+
+\keyword{datasets}
diff --git a/man/Municipalities.Rd b/man/Municipalities.Rd
new file mode 100644
index 0000000..7309138
--- /dev/null
+++ b/man/Municipalities.Rd
@@ -0,0 +1,57 @@
+\name{Municipalities}
+\alias{Municipalities}
+
+\title{Municipal Expenditure Data}
+
+\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.
+\describe{
+ \item{municipality}{factor with ID number for municipality.}
+ \item{year}{factor coding year.}
+ \item{expenditures}{total expenditures.}
+ \item{revenues}{total own-source revenues.}
+ \item{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 Municipalities (Kommunernas Finanser).
+}
+
+\source{
+Journal of Applied Econometrics Data Archive.
+
+\url{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 Governments Using GMM Bootstrapping Methods.
+\emph{Journal of Applied Econometrics}, \bold{15}, 401--416.
+
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}}
+
+\examples{
+## Greene (2003), Table 18.2
+data("Municipalities")
+summary(Municipalities)
+}
+
+\keyword{datasets}
diff --git a/man/MurderRates.Rd b/man/MurderRates.Rd
new file mode 100644
index 0000000..9d5cbfb
--- /dev/null
+++ b/man/MurderRates.Rd
@@ -0,0 +1,71 @@
+\name{MurderRates}
+\alias{MurderRates}
+
+\title{Determinants of Murder Rates in the United States}
+
+\description{
+Cross-section data on states in 1950.
+}
+
+\usage{data("MurderRates")}
+
+\format{
+A data frame containing 44 observations on 8 variables.
+\describe{
+ \item{rate}{Murder rate per 100,000 (FBI estimate, 1950).}
+ \item{convictions}{Number of convictions divided by number of murders in 1950.}
+ \item{executions}{Average number of executions during 1946--1950 divided by convictions in 1950.}
+ \item{time}{Median time served (in months) of convicted murderers released in 1951.}
+ \item{income}{Median family income in 1949 (in 1,000 USD).}
+ \item{lfp}{Labor force participation rate in 1950 (in percent).}
+ \item{noncauc}{Proportion of population that is non-Caucasian in 1950.}
+ \item{southern}{Factor indicating region.}
+}
+}
+
+\source{
+Maddala (2001), Table 8.4, p. 330
+}
+
+\references{
+Maddala, G.S. (2001). \emph{Introduction to Econometrics}, 3rd ed. New York: John Wiley.
+
+McManus, W.S. (1985). Estimates of the Deterrent Effect of Capital Punishment:
+The Importance of the Researcher's Prior Beliefs. \emph{Journal of Political Economy},
+\bold{93}, 417--425.
+
+Stokes, H. (2004). On the Advantage of Using Two or More Econometric Software Systems to Solve the Same Problem.
+\emph{Journal of Economic and Social Measurement}, \bold{29}, 307--320.
+}
+
+\examples{
+data("MurderRates")
+
+## Maddala (2001, pp. 331)
+fm_lm <- lm(rate ~ . + I(executions > 0), data = MurderRates)
+summary(fm_lm)
+
+model <- I(executions > 0) ~ time + income + noncauc + lfp + southern
+fm_lpm <- lm(model, data = MurderRates)
+summary(fm_lpm)
+
+## Binomial models. Note: southern coefficient
+fm_logit <- glm(model, data = MurderRates, family = binomial)
+summary(fm_logit)
+
+fm_logit2 <- glm(model, data = MurderRates, family = binomial,
+ control = list(epsilon = 1e-15, maxit = 50, trace = FALSE))
+summary(fm_logit2)
+
+fm_probit <- glm(model, data = MurderRates, family = binomial(link = "probit"))
+summary(fm_probit)
+
+fm_probit2 <- glm(model, data = MurderRates , family = binomial(link = "probit"),
+ control = list(epsilon = 1e-15, maxit = 50, trace = FALSE))
+summary(fm_probit2)
+
+## Explanation: quasi-complete separation
+with(MurderRates, table(executions > 0, southern))
+}
+
+\keyword{datasets}
diff --git a/man/NMES1988.Rd b/man/NMES1988.Rd
new file mode 100644
index 0000000..0d7b590
--- /dev/null
+++ b/man/NMES1988.Rd
@@ -0,0 +1,148 @@
+\name{NMES1988}
+\alias{NMES1988}
+\title{Demand for Medical Care in NMES 1988}
+\description{
+Cross-section data originating from the US National Medical Expenditure Survey (NMES)
+conducted 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")}
+
+\format{
+A data frame containing 4,406 observations on 19 variables.
+\describe{
+ \item{visits}{Number of physician office visits.}
+ \item{nvisits}{Number of non-physician office visits.}
+ \item{ovisits}{Number of physician hospital outpatient visits.}
+ \item{novisits}{Number of non-physician hospital outpatient visits.}
+ \item{emergency}{Emergency room visits.}
+ \item{hospital}{Number of hospital stays.}
+ \item{health}{Factor indicating self-perceived health status, levels are
+ \code{"poor"}, \code{"average"} (reference category), \code{"excellent"}.}
+ \item{chronic}{Number of chronic conditions.}
+ \item{adl}{Factor indicating whether the individual has a condition that
+ limits activities of daily living (\code{"limited"}) or not (\code{"normal"}).}
+ \item{region}{Factor indicating region, levels are \code{northeast},
+ \code{midwest}, \code{west}, \code{other} (reference category).}
+ \item{age}{Age in years (divided by 10).}
+ \item{afam}{Factor. Is the individual African-American?}
+ \item{gender}{Factor indicating gender.}
+ \item{married}{Factor. is the individual married?}
+ \item{school}{Number of years of education.}
+ \item{income}{Family income in USD 10,000.}
+ \item{employed}{Factor. Is the individual employed?}
+ \item{insurance}{Factor. Is the individual covered by private insurance?}
+ \item{medicaid}{Factor. Is the individual covered by Medicaid?}
+}
+}
+
+\source{
+Journal of Applied Econometrics Data Archive for Deb and Trivedi (1997).
+
+\url{http://qed.econ.queensu.ca/jae/1997-v12.3/deb-trivedi/}
+}
+
+\references{
+Cameron, A.C. and Trivedi, P.K. (1998). \emph{Regression Analysis of Count Data}.
+Cambridge: Cambridge University Press.
+
+Deb, P., and Trivedi, P.K. (1997). Demand for Medical Care by the
+Elderly: A Finite Mixture Approach. \emph{Journal of Applied Econometrics},
+\bold{12}, 313--336.
+
+Zeileis, A., Kleiber, C., and Jackman, S. (2008). Regression Models
+for Count Data in R. \emph{Journal of Statistical Software}, \bold{27}(8).
+URL \url{http://www.jstatsoft.org/v27/i08/}.
+}
+
+\seealso{\code{\link{CameronTrivedi1998}}}
+
+\examples{
+## packages
+library("MASS")
+library("pscl")
+
+## select variables for analysis
+data("NMES1988")
+nmes <- NMES1988[, c(1, 7:8, 13, 15, 18)]
+
+## dependent variable
+hist(nmes$visits, breaks = 0:(max(nmes$visits)+1) - 0.5)
+plot(table(nmes$visits))
+
+## convenience transformations for exploratory graphics
+clog <- function(x) log(x + 0.5)
+cfac <- function(x, breaks = NULL) {
+ if(is.null(breaks)) breaks <- unique(quantile(x, 0:10/10))
+ x <- cut(x, breaks, include.lowest = TRUE, right = FALSE)
+ levels(x) <- paste(breaks[-length(breaks)], ifelse(diff(breaks) > 1,
+ c(paste("-", breaks[-c(1, length(breaks))] - 1, sep = ""), "+"), ""), sep = "")
+ return(x)
+}
+
+## 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)
+
+## LM test for overdispersion
+dispersiontest(nmes_pois)
+dispersiontest(nmes_pois, trafo = 2)
+
+## sandwich covariance matrix
+coeftest(nmes_pois, vcov = sandwich)
+
+## 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")
+
+## zero-inflated regression model
+nmes_zinb <- zeroinfl(visits ~ . | chronic + insurance + school + gender,
+ data = nmes, dist = "negbin")
+
+## compare estimated coefficients
+fm <- list("ML-Pois" = nmes_pois, "Quasi-Pois" = nmes_qpois, "NB" = nmes_nb,
+ "Hurdle-NB" = nmes_hurdle, "ZINB" = nmes_zinb)
+round(sapply(fm, function(x) coef(x)[1:7]), digits = 3)
+
+## associated standard errors
+round(cbind("ML-Pois" = sqrt(diag(vcov(nmes_pois))),
+ "Adj-Pois" = sqrt(diag(sandwich(nmes_pois))),
+ sapply(fm[-1], function(x) sqrt(diag(vcov(x)))[1:7])),
+ digits = 3)
+
+## log-likelihoods and number of estimated parameters
+rbind(logLik = sapply(fm, function(x) round(logLik(x), digits = 0)),
+ Df = sapply(fm, function(x) attr(logLik(x), "df")))
+
+## predicted number of zeros
+round(c("Obs" = sum(nmes$visits < 1),
+ "ML-Pois" = sum(dpois(0, fitted(nmes_pois))),
+ "Adj-Pois" = NA,
+ "Quasi-Pois" = NA,
+ "NB" = sum(dnbinom(0, mu = fitted(nmes_nb), size = nmes_nb$theta)),
+ "NB-Hurdle" = sum(predict(nmes_hurdle, type = "prob")[,1]),
+ "ZINB" = sum(predict(nmes_zinb, type = "prob")[,1])))
+
+## coefficients of zero-augmentation models
+t(sapply(fm[4:5], function(x) round(x$coefficients$zero, digits = 3)))
+}
+
+\keyword{datasets}
diff --git a/man/NYSESW.Rd b/man/NYSESW.Rd
new file mode 100644
index 0000000..2fba761
--- /dev/null
+++ b/man/NYSESW.Rd
@@ -0,0 +1,40 @@
+\name{NYSESW}
+\alias{NYSESW}
+
+\title{Daily NYSE Composite Index}
+
+\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
+\code{"zoo"} with \code{"Date"} index).
+}
+
+\source{
+Online complements to Stock and Watson (2007).
+}
+
+\references{
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+## returns
+data("NYSESW")
+ret <- 100 * diff(log(NYSESW))
+plot(ret)
+
+## Stock and Watson (2007), p. 667, GARCH(1,1) model
+library("tseries")
+fm <- garch(coredata(ret))
+summary(fm)
+}
+
+
+\keyword{datasets}
diff --git a/man/NaturalGas.Rd b/man/NaturalGas.Rd
new file mode 100644
index 0000000..2a98c9e
--- /dev/null
+++ b/man/NaturalGas.Rd
@@ -0,0 +1,43 @@
+\name{NaturalGas}
+\alias{NaturalGas}
+
+\title{Natural Gas Data}
+
+\description{
+Panel data originating from 6 US states over the period 1967--1989.
+}
+
+\usage{data("NaturalGas")}
+
+\format{
+A data frame containing 138 observations on 10 variables.
+\describe{
+ \item{state}{factor. State abbreviation.}
+ \item{statecode}{factor. State Code.}
+ \item{year}{factor coding year.}
+ \item{consumption}{Consumption of natural gas by the residential sector.}
+ \item{price}{Price of natural gas}
+ \item{eprice}{Price of electricity.}
+ \item{oprice}{Price of distillate fuel oil.}
+ \item{lprice}{Price of liquefied petroleum gas.}
+ \item{heating}{Heating degree days.}
+ \item{income}{Real per-capita personal income.}
+}
+}
+
+\source{
+The data are from Baltagi (2002).
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed. Berlin, Springer.
+}
+
+\seealso{\code{\link{Baltagi2002}}}
+
+\examples{
+data("NaturalGas")
+summary(NaturalGas)
+}
+
+\keyword{datasets}
diff --git a/man/OECDGas.Rd b/man/OECDGas.Rd
new file mode 100644
index 0000000..537d208
--- /dev/null
+++ b/man/OECDGas.Rd
@@ -0,0 +1,41 @@
+\name{OECDGas}
+\alias{OECDGas}
+\title{Gasoline Consumption Data}
+\description{
+Panel data on gasoline consumption in 18 OECD countries over 19 years, 1960--1978.
+}
+\usage{data("OECDGas")}
+\format{
+A data frame containing 342 observations on 6 variables.
+\describe{
+ \item{country}{Factor indicating country.}
+ \item{year}{Year.}
+ \item{gas}{Logarithm of motor gasoline consumption per car.}
+ \item{income}{Logarithm of real per-capita income.}
+ \item{price}{Logarithm of real motor gasoline price.}
+ \item{cars}{Logarithm of the stock of cars per-capita.}
+}
+}
+
+\source{
+The data is from Baltagi (2002).
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{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. \emph{European Economic Review}, \bold{22}, 117--137.
+}
+
+\seealso{\code{\link{Baltagi2002}}}
+
+\examples{
+data("OECDGas")
+
+library("lattice")
+xyplot(exp(cars) ~ year | country, data = OECDGas, type = "l")
+xyplot(exp(gas) ~ year | country, data = OECDGas, type = "l")
+}
+
+\keyword{datasets}
diff --git a/man/OECDGrowth.Rd b/man/OECDGrowth.Rd
new file mode 100644
index 0000000..49dd45f
--- /dev/null
+++ b/man/OECDGrowth.Rd
@@ -0,0 +1,95 @@
+\name{OECDGrowth}
+\alias{OECDGrowth}
+
+\title{OECD Macroeconomic Data}
+
+\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.
+\describe{
+ \item{gdp85}{real GDP in 1985 (per person of working age, i.e., age 15 to 65),
+ in 1985 international prices.}
+ \item{gdp60}{real GDP in 1960 (per person of working age, i.e., age 15 to 65),
+ in 1985 international prices.}
+ \item{invest}{average of annual ratios of real domestic investment to real GDP (1960--1985).}
+ \item{school}{percentage of the working-age population that is in secondary school.}
+ \item{randd}{average of annual ratios of gross domestic expenditure on research
+ and development to nominal GDP (of available observations during 1960--1985).}
+ \item{popgrowth}{annual population growth 1960--1985, computed as \code{log(pop85/pop60)/25}.}
+}
+}
+
+\source{
+Appendix 1 Nonneman and Vanhoudt (1996), except for one bad misprint:
+The value of \code{school} for Norway is given as 0.01, the correct value is 0.1
+(see Mankiw, Romer and Weil, 1992). \code{OECDGrowth} contains the corrected data.
+}
+
+\references{
+Mankiw, N.G., Romer, D., and Weil, D.N. (1992). A Contribution to the Empirics of Economic Growth.
+\emph{Quarterly Journal of Economics}, \bold{107}, 407--437.
+
+Nonneman, W., and Vanhoudt, P. (1996). A Further Augmentation of the Solow Model
+and the Empirics of Economic Growth. \emph{Quarterly Journal of Economics}, \bold{111}, 943--953.
+
+Zaman, A., Rousseeuw, P.J., and Orhan, M. (2001). Econometric Applications of
+High-Breakdown Robust Regression Techniques. \emph{Economics Letters}, \bold{71}, 1--8.
+}
+
+\seealso{\code{\link{GrowthDJ}}, \code{\link{GrowthSW}}}
+
+\examples{
+data("OECDGrowth")
+
+## Nonneman and Vanhoudt (1996), Table II
+cor(OECDGrowth[, 3:6])
+cor(log(OECDGrowth[, 3:6]))
+
+## textbook Solow model
+## Nonneman and Vanhoudt (1996), Table IV, and
+## Zaman, Rousseeuw and Orhan (2001), Table 2
+so_ols <- lm(log(gdp85/gdp60) ~ log(gdp60) + log(invest) + log(popgrowth+.05),
+ data = OECDGrowth)
+summary(so_ols)
+
+## augmented and extended Solow growth model
+## Nonneman and Vanhoudt (1996), Table IV
+aso_ols <- lm(log(gdp85/gdp60) ~ log(gdp60) + log(invest) +
+ log(school) + log(popgrowth+.05), data = OECDGrowth)
+eso_ols <- lm(log(gdp85/gdp60) ~ log(gdp60) + log(invest) +
+ log(school) + log(randd) + log(popgrowth+.05), data = OECDGrowth)
+
+## determine unusual observations using LTS
+library("MASS")
+so_lts <- lqs(log(gdp85/gdp60) ~ log(gdp60) + log(invest) + log(popgrowth+.05),
+ data = OECDGrowth, psamp = 13, nsamp = "exact")
+
+## 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
+nok <- which(nok1 & nok2)
+nok
+
+## robust results without bad leverage points
+so_rob <- update(so_ols, subset = -nok)
+summary(so_rob)
+## This is similar to Zaman, Rousseeuw and Orhan (2001), Table 2
+## but uses exact computations (and not sub-optimal results
+## for the robust functions lqs and cov.rob)
+}
+
+\keyword{datasets}
diff --git a/man/OlympicTV.Rd b/man/OlympicTV.Rd
new file mode 100644
index 0000000..707d4d4
--- /dev/null
+++ b/man/OlympicTV.Rd
@@ -0,0 +1,33 @@
+\name{OlympicTV}
+\alias{OlympicTV}
+\title{Television Rights for Olympic Games}
+\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.
+\describe{
+ \item{rights}{time series of television rights (in million USD),}
+ \item{network}{factor coding television network.}
+}
+}
+
+\source{
+Online complements to Franses (1998).
+}
+
+\seealso{\code{\link{Franses1998}}}
+
+\references{
+Franses, P.H. (1998). \emph{Time Series Models for Business and Economic Forecasting}.
+Cambridge, UK: Cambridge University Press.
+}
+
+\examples{
+data("OlympicTV")
+plot(OlympicTV$rights)
+}
+
+\keyword{datasets}
diff --git a/man/OrangeCounty.Rd b/man/OrangeCounty.Rd
new file mode 100644
index 0000000..0ea3205
--- /dev/null
+++ b/man/OrangeCounty.Rd
@@ -0,0 +1,36 @@
+\name{OrangeCounty}
+\alias{OrangeCounty}
+
+\title{Orange County Employment}
+
+\description{
+Quarterly time series data on employment in Orange county, 1965--1983.
+}
+
+\usage{data("OrangeCounty")}
+
+\format{
+A quarterly multiple time series from 1965 to 1983 with 2 variables.
+\describe{
+ \item{employment}{Quarterly employment in Orange county.}
+ \item{gnp}{Quarterly real GNP.}
+}
+}
+
+\source{
+The data is from Baltagi (2002).
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed. Berlin, Springer.
+
+}
+
+\seealso{\code{\link{Baltagi2002}}}
+
+\examples{
+data("OrangeCounty")
+plot(OrangeCounty)
+}
+
+\keyword{datasets}
diff --git a/man/PSID1976.Rd b/man/PSID1976.Rd
new file mode 100644
index 0000000..11efd2f
--- /dev/null
+++ b/man/PSID1976.Rd
@@ -0,0 +1,186 @@
+\name{PSID1976}
+\alias{PSID1976}
+
+\title{Labor Force Participation Data}
+
+\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.
+\describe{
+ \item{participation}{Factor. Did the individual participate in the labor force in 1975?
+ (This is essentially \code{wage > 0} or \code{hours > 0}.)}
+ \item{hours}{Wife's hours of work in 1975.}
+ \item{youngkids}{Number of children less than 6 years old in household.}
+ \item{oldkids}{Number of children between ages 6 and 18 in household.}
+ \item{age}{Wife's age in years.}
+ \item{education}{Wife's education in years.}
+ \item{wage}{Wife's average hourly wage, in 1975 dollars.}
+ \item{repwage}{Wife's wage reported at the time of the 1976 interview
+ (not the same as the 1975 estimated wage). To use the subsample with this wage,
+ one needs to select 1975 workers with \code{participation == "yes"}, then select only those
+ women with non-zero wage. Only 325 women work in 1975 and have a non-zero wage in 1976.}
+ \item{hhours}{Husband's hours worked in 1975.}
+ \item{hage}{Husband's age in years.}
+ \item{heducation}{Husband's education in years.}
+ \item{hwage}{Husband's wage, in 1975 dollars.}
+ \item{fincome}{Family income, in 1975 dollars. (This variable is used to construct the
+ property income variable.)}
+ \item{tax}{Marginal tax rate facing the wife, and is taken from published federal
+ tax tables (state and local income taxes are excluded). The taxable income on
+ which this tax rate is calculated includes Social Security, if applicable to wife.}
+ \item{meducation}{Wife's mother's educational attainment, in years.}
+ \item{feducation}{Wife's father's educational attainment, in years.}
+ \item{unemp}{Unemployment rate in county of residence, in percentage points.
+ (This is taken from bracketed ranges.)}
+ \item{city}{Factor. Does the individual live in a large city?}
+ \item{experience}{Actual years of wife's previous labor market experience.}
+ \item{college}{Factor. Did the individual attend college?}
+ \item{hcollege}{Factor. Did the individual's husband attend college?}
+}
+}
+
+\details{
+This data set is also known as the Mroz (1987) data.
+
+Warning: Typical applications using these data employ the variable
+\code{wage} (aka \code{earnings} in previous versions of the data) as the dependent variable.
+The variable \code{repwage} is the reported wage in a 1976 interview, named RPWG by Greene (2003).
+}
+
+\source{
+Online complements to Greene (2003). Table F4.1.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{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.:
+\emph{Numerical Issues in Statistical Computing for the Social Scientist}.
+Hoboken, NJ: John Wiley, Ch. 8, 199--218.
+
+Mroz, T.A. (1987). The Sensitivity of an Empirical Model of Married Women's Hours of Work to
+Economic and Statistical Assumptions. \emph{Econometrica}, \bold{55}, 765--799.
+
+Winkelmann, R., and Boes, S. (2009). \emph{Analysis of Microdata}, 2nd ed. Berlin and Heidelberg: Springer-Verlag.
+
+Wooldridge, J.M. (2002). \emph{Econometric Analysis of Cross-Section and Panel Data}.
+Cambridge, MA: MIT Press.
+}
+
+\seealso{\code{\link{Greene2003}}, \code{\link{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.1, Table 4.2
+## (reproduced in Example 7.1, Table 7.1)
+gr_lm <- lm(log(hours * wage) ~ age + I(age^2) + education + kids,
+ data = PSID1976, subset = participation == "yes")
+summary(gr_lm)
+vcov(gr_lm)
+
+## 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)
+
+## Example 21.4, p. 681, and Tab. 21.3, p. 682
+gr_probit1 <- glm(participation ~ age + I(age^2) + I(fincome/10000) + education + kids,
+ data = PSID1976, family = binomial(link = "probit") )
+gr_probit2 <- glm(participation ~ age + I(age^2) + I(fincome/10000) + education,
+ data = PSID1976, family = binomial(link = "probit"))
+gr_probit3 <- glm(participation ~ kids/(age + I(age^2) + I(fincome/10000) + education),
+ data = PSID1976, family = binomial(link = "probit"))
+## LR test of all coefficients
+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)
+
+## Example 22.8, Table 22.7, p. 786
+library("sampleSelection")
+gr_2step <- selection(participation ~ age + I(age^2) + fincome + education + kids,
+ wage ~ experience + I(experience^2) + education + city,
+ data = PSID1976, method = "2step")
+gr_ml <- selection(participation ~ age + I(age^2) + fincome + education + kids,
+ wage ~ experience + I(experience^2) + education + city,
+ data = PSID1976, method = "ml")
+gr_ols <- lm(wage ~ experience + I(experience^2) + education + city,
+ data = PSID1976, subset = participation == "yes")
+## NOTE: ML estimates agree with Greene, 5e errata.
+## Standard errors are based on the Hessian (here), while Greene has BHHH/OPG.
+
+
+#######################
+## Wooldridge (2002) ##
+#######################
+
+## Table 15.1, p. 468
+wl_lpm <- lm(partnum ~ nwincome + education + experience + I(experience^2) +
+ age + youngkids + oldkids, data = PSID1976)
+wl_logit <- glm(participation ~ nwincome + education + experience + I(experience^2) +
+ age + youngkids + oldkids, family = binomial, data = PSID1976)
+wl_probit <- glm(participation ~ nwincome + education + experience + I(experience^2) +
+ age + youngkids + oldkids, family = binomial(link = "probit"), data = PSID1976)
+## (same as Altman et al.)
+
+## 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)
+
+## Table 16.2, p. 528
+form <- hours ~ nwincome + education + experience + I(experience^2) + age + youngkids + oldkids
+wl_ols <- lm(form, data = PSID1976)
+wl_tobit <- tobit(form, data = PSID1976)
+summary(wl_ols)
+summary(wl_tobit)
+
+
+#######################
+## 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)
+}
+
+\keyword{datasets}
diff --git a/man/PSID1982.Rd b/man/PSID1982.Rd
new file mode 100644
index 0000000..8ed96bc
--- /dev/null
+++ b/man/PSID1982.Rd
@@ -0,0 +1,68 @@
+\name{PSID1982}
+\alias{PSID1982}
+
+\title{PSID Earnings Data 1982}
+
+\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.
+\describe{
+ \item{experience}{Years of full-time work experience.}
+ \item{weeks}{Weeks worked.}
+ \item{occupation}{factor. Is the individual a white-collar (\code{"white"}) or blue-collar (\code{"blue"}) worker?}
+ \item{industry}{factor. Does the individual work in a manufacturing industry?}
+ \item{south}{factor. Does the individual reside in the South?}
+ \item{smsa}{factor. Does the individual reside in a SMSA (standard metropolitan statistical area)?}
+ \item{married}{factor. Is the individual married?}
+ \item{gender}{factor indicating gender.}
+ \item{union}{factor. Is the individual's wage set by a union contract?}
+ \item{education}{Years of education.}
+ \item{ethnicity}{factor indicating ethnicity.
+ Is the individual African-American (\code{"afam"}) or not (\code{"other"})?}
+ \item{wage}{Wage.}
+}
+}
+
+\details{
+\code{PSID1982} is the cross-section for the year 1982 taken from a larger panel data set
+\code{\link{PSID7682}} for the years 1976--1982, originating from Cornwell and Rupert (1988).
+Baltagi (2002) just uses the 1982 cross-section; hence \code{PSID1982} is available as a
+standalone data set because it was included in \pkg{AER} prior to the availability of the
+full \code{PSID7682} panel version.
+}
+
+\source{
+The data is from Baltagi (2002).
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed. Berlin, Springer.
+
+Cornwell, C., and Rupert, P. (1988). Efficient Estimation with Panel Data:
+An Empirical Comparison of Instrumental Variables Estimators.
+\emph{Journal of Applied Econometrics}, \bold{3}, 149--155.
+}
+
+\seealso{\code{\link{PSID7682}}, \code{\link{Baltagi2002}}}
+
+\examples{
+data("PSID1982")
+plot(density(PSID1982$wage, bw = "SJ"))
+
+## Baltagi (2002), Table 4.1
+earn_lm <- lm(log(wage) ~ . + I(experience^2), data = PSID1982)
+summary(earn_lm)
+
+## Baltagi (2002), 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.
+}
+
+\keyword{datasets}
diff --git a/man/PSID7682.Rd b/man/PSID7682.Rd
new file mode 100644
index 0000000..fb27952
--- /dev/null
+++ b/man/PSID7682.Rd
@@ -0,0 +1,113 @@
+\name{PSID7682}
+\alias{PSID7682}
+
+\title{PSID Earnings Panel Data (1976--1982)}
+
+\description{
+Panel data on earnings of 595 individuals for the years 1976--1982,
+originating from the Panel Study of Income Dynamics.
+}
+
+\usage{data("PSID7682")}
+
+\format{
+A data frame containing 7 annual observations on 12 variables for 595 individuals.
+\describe{
+ \item{experience}{Years of full-time work experience.}
+ \item{weeks}{Weeks worked.}
+ \item{occupation}{factor. Is the individual a white-collar (\code{"white"})
+ or blue-collar (\code{"blue"}) worker?}
+ \item{industry}{factor. Does the individual work in a manufacturing industry?}
+ \item{south}{factor. Does the individual reside in the South?}
+ \item{smsa}{factor. Does the individual reside in a SMSA (standard
+ metropolitan statistical area)?}
+ \item{married}{factor. Is the individual married?}
+ \item{gender}{factor indicating gender.}
+ \item{union}{factor. Is the individual's wage set by a union contract?}
+ \item{education}{Years of education.}
+ \item{ethnicity}{factor indicating ethnicity.
+ Is the individual African-American (\code{"afam"}) or not (\code{"other"})?}
+ \item{wage}{Wage.}
+ \item{year}{factor indicating year.}
+ \item{id}{factor indicating individual subject ID.}
+}
+}
+
+\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.
+
+\code{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., \code{subset(PSID7682, year == "1982")}. This is also available as
+a standalone data set \code{\link{PSID1982}} because it was included
+in \pkg{AER} prior to the availability of the full \code{PSID7682} panel
+version.
+}
+
+\source{
+Online complements to Baltagi (2005).
+
+\url{http://www.wiley.com/legacy/wileychi/baltagi3e/data_sets.html}
+
+Also provided in the online complements to Greene (2008), Table F9.1.
+
+\url{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.
+\emph{Journal of Applied Econometrics}, \bold{5}, 401--406.
+
+Baltagi, B.H. (2001). \emph{Econometric Analysis of Panel Data}, 2nd ed. Chichester, UK: John Wiley.
+
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed. Berlin, Springer.
+
+Baltagi, B.H. (2005). \emph{Econometric Analysis of Panel Data}, 3rd ed. Chichester, UK: John Wiley.
+
+Cornwell, C., and Rupert, P. (1988). Efficient Estimation with Panel Data:
+An Empirical Comparison of Instrumental Variables Estimators.
+\emph{Journal of Applied Econometrics}, \bold{3}, 149--155.
+
+Greene, W.H. (2008). \emph{Econometric Analysis}, 6th ed. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{PSID1982}}, \code{\link{Baltagi2002}}}
+
+\examples{
+data("PSID7682")
+
+library("plm")
+psid <- plm.data(PSID7682, c("id", "year"))
+
+## Baltagi & Khanti-Akom, Table I, column "HT"
+## original Cornwell & Rupert choice of exogenous variables
+psid_ht1 <- plm(log(wage) ~ weeks + south + smsa + married +
+ experience + I(experience^2) + occupation + industry + union + gender + ethnicity + education |
+ weeks + south + smsa + married + gender + ethnicity,
+ data = psid, model = "ht")
+
+## Baltagi & Khanti-Akom, Table II, column "HT"
+## alternative choice of exogenous variables
+psid_ht2 <- plm(log(wage) ~ occupation + south + smsa + industry +
+ experience + I(experience^2) + weeks + married + union + gender + ethnicity + education |
+ occupation + south + smsa + industry + gender + ethnicity,
+ data = psid, model = "ht")
+
+## Baltagi & Khanti-Akom, Table III, column "HT"
+## original choice of exogenous variables + time dummies
+## (see also Baltagi, 2001, Table 7.1)
+psid$time <- psid$year
+psid_ht3 <- plm(log(wage) ~ weeks + south + smsa + married + experience + I(experience^2) +
+ occupation + industry + union + gender + ethnicity + education + time |
+ weeks + south + smsa + married + gender + ethnicity + time,
+ data = psid, model = "ht")
+}
+
+\keyword{datasets}
diff --git a/man/Parade2005.Rd b/man/Parade2005.Rd
new file mode 100644
index 0000000..5de2114
--- /dev/null
+++ b/man/Parade2005.Rd
@@ -0,0 +1,61 @@
+\name{Parade2005}
+\alias{Parade2005}
+\title{Parade Magazine 2005 Earnings Data}
+\description{
+US earnings data, as provided in an annual survey of Parade (here from 2005), the
+Sunday newspaper magazine supplementing the Sunday (or Weekend) edition of many
+daily newspapers in the USA.
+}
+\usage{data("Parade2005")}
+
+\format{
+A data frame containing 130 observations on 5 variables.
+\describe{
+\item{earnings}{Annual personal earnings.}
+\item{age}{Age in years.}
+\item{gender}{Factor indicating gender.}
+\item{state}{Factor indicating state.}
+\item{celebrity}{Factor. Is the individual a celebrity?}
+}
+}
+
+\details{
+In addition to the four variables provided by Parade (earnings, age, gender, and state),
+a fifth variable was introduced, the \dQuote{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)")
+
+## celebrity vs. non-celebrity earnings
+noncel <- subset(Parade2005, celebrity == "no")
+cel <- subset(Parade2005, celebrity == "yes")
+
+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)
+}
+
+\keyword{datasets}
diff --git a/man/PepperPrice.Rd b/man/PepperPrice.Rd
new file mode 100644
index 0000000..7146f63
--- /dev/null
+++ b/man/PepperPrice.Rd
@@ -0,0 +1,60 @@
+\name{PepperPrice}
+\alias{PepperPrice}
+\title{Black and White Pepper Prices}
+\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.
+\describe{
+ \item{black}{spot price for black pepper,}
+ \item{white}{spot price for white pepper.}
+}
+}
+
+\source{
+Originally available as an online supplement to Franses (1998). Now available via online complements to Franses, van Dijk and Opschoor (2014).
+
+\url{http://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-economics/time-series-models-business-and-economic-forecasting-2nd-edition}
+}
+
+\references{
+Franses, P.H. (1998). \emph{Time Series Models for Business and Economic Forecasting}.
+Cambridge, UK: Cambridge University Press.
+
+Franses, P.H., van Dijk, D. and Opschoor, A. (2014). \emph{Time Series Models for Business and Economic 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")
+
+## unit root tests
+adf.test(log(PepperPrice[, "white"]))
+adf.test(diff(log(PepperPrice[, "white"])))
+pp.test(log(PepperPrice[, "white"]), type = "Z(t_alpha)")
+pepper_ers <- ur.ers(log(PepperPrice[, "white"]),
+ type = "DF-GLS", model = "const", lag.max = 4)
+summary(pepper_ers)
+
+## 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)
+}
+
+\keyword{datasets}
diff --git a/man/PhDPublications.Rd b/man/PhDPublications.Rd
new file mode 100644
index 0000000..2e164d1
--- /dev/null
+++ b/man/PhDPublications.Rd
@@ -0,0 +1,63 @@
+\name{PhDPublications}
+\alias{PhDPublications}
+\title{Doctoral Publications}
+\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.
+\describe{
+ \item{articles}{Number of articles published during last 3 years of PhD.}
+ \item{gender}{factor indicating gender.}
+ \item{married}{factor. Is the PhD student married?}
+ \item{kids}{Number of children less than 6 years old.}
+ \item{prestige}{Prestige of the graduate program.}
+ \item{mentor}{Number of articles published by student's mentor.}
+}
+}
+
+\source{
+Online complements to Long (1997).
+
+\url{http://www.indiana.edu/~jslsoc/research_rm4cldvs.htm}
+}
+
+\references{
+Long, J.S. (1990).
+\emph{Regression Models for Categorical and Limited Dependent Variables}.
+Thousand Oaks: Sage Publications.
+
+Long, J.S. (1997). The Origin of Sex Differences in Science.
+\emph{Social Forces}, \bold{68}, 1297--1315.
+}
+
+\examples{
+## from Long (1997)
+data("PhDPublications")
+
+## Table 8.1, p. 227
+summary(PhDPublications)
+
+## Figure 8.2, p. 220
+plot(0:10, dpois(0:10, mean(PhDPublications$articles)), type = "b", col = 2,
+ xlab = "Number of articles", ylab = "Probability")
+lines(0:10, prop.table(table(PhDPublications$articles))[1:11], type = "b")
+legend("topright", c("observed", "predicted"), col = 1:2, lty = rep(1, 2), bty = "n")
+
+## Table 8.2, p. 228
+fm_lrm <- lm(log(articles + 0.5) ~ ., data = PhDPublications)
+summary(fm_lrm)
+-2 * logLik(fm_lrm)
+fm_prm <- glm(articles ~ ., data = PhDPublications, family = poisson)
+library("MASS")
+fm_nbrm <- glm.nb(articles ~ ., data = PhDPublications)
+
+## Table 8.3, p. 246
+library("pscl")
+fm_zip <- zeroinfl(articles ~ . | ., data = PhDPublications)
+fm_zinb <- zeroinfl(articles ~ . | ., data = PhDPublications, dist = "negbin")
+}
+
+\keyword{datasets}
diff --git a/man/ProgramEffectiveness.Rd b/man/ProgramEffectiveness.Rd
new file mode 100644
index 0000000..e36525c
--- /dev/null
+++ b/man/ProgramEffectiveness.Rd
@@ -0,0 +1,50 @@
+\name{ProgramEffectiveness}
+\alias{ProgramEffectiveness}
+\title{Program Effectiveness Data}
+
+\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.
+ \describe{
+ \item{grade}{Factor with levels \code{"increase"} and \code{"decrease"}.}
+ \item{average}{Grade-point average.}
+ \item{testscore}{Test score on economics test.}
+ \item{participation}{Factor. Did the individual participate in the program?}
+ }
+}
+
+\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).
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+
+Spector, L. and Mazzeo, M. (1980). Probit Analysis and Economic Education.
+\emph{Journal of Economic Education}, \bold{11}, 37--44.
+}
+
+\seealso{\code{\link{Greene2003}}}
+
+\examples{
+data("ProgramEffectiveness")
+
+## Greene (2003), Table 21.1, col. "Probit"
+fm_probit <- glm(grade ~ average + testscore + participation,
+ data = ProgramEffectiveness, family = binomial(link = "probit"))
+summary(fm_probit)
+}
+
+\keyword{datasets}
diff --git a/man/RecreationDemand.Rd b/man/RecreationDemand.Rd
new file mode 100644
index 0000000..26f39af
--- /dev/null
+++ b/man/RecreationDemand.Rd
@@ -0,0 +1,88 @@
+\name{RecreationDemand}
+\alias{RecreationDemand}
+\title{Recreation Demand Data}
+\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.
+}
+\usage{data("RecreationDemand")}
+
+\format{
+A data frame containing 659 observations on 8 variables.
+\describe{
+ \item{trips}{Number of recreational boating trips.}
+ \item{quality}{Facility's subjective quality ranking on a scale of 1 to 5.}
+ \item{ski}{factor. Was the individual engaged in water-skiing at the lake?}
+ \item{income}{Annual household income of the respondent (in 1,000 USD).}
+ \item{userfee}{factor. Did the individual pay an annual user fee at Lake Somerville?}
+ \item{costC}{Expenditure when visiting Lake Conroe (in USD).}
+ \item{costS}{Expenditure when visiting Lake Somerville (in USD).}
+ \item{costH}{Expenditure when visiting Lake Houston (in USD).}
+}
+}
+
+
+\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.
+
+\verb{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). \emph{Regression Analysis of Count Data}.
+Cambridge: Cambridge University Press.
+
+Gurmu, S. and Trivedi, P.K. (1996). Excess Zeros in Count Models for Recreational Trips.
+\emph{Journal of Business \& Economic Statistics},
+\bold{14}, 469--477.
+
+Ozuna, T. and Gomez, I.A. (1995). Specification and Testing of Count Data Recreation Demand Functions.
+\emph{Empirical Economics}, \bold{20}, 543--550.
+
+Seller, C., Stoll, J.R. and Chavas, J.-P. (1985). Validation of Empirical Measures of Welfare Change: A Comparison of Nonmarket Techniques. \emph{Land Economics}, \bold{61}, 156--175.
+}
+
+\seealso{\code{\link{CameronTrivedi1998}}}
+
+\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")
+
+## Note: quasi-complete separation
+with(RecreationDemand, table(trips > 0, userfee))
+}
+
+\keyword{datasets}
diff --git a/man/ResumeNames.Rd b/man/ResumeNames.Rd
new file mode 100644
index 0000000..f3b4c86
--- /dev/null
+++ b/man/ResumeNames.Rd
@@ -0,0 +1,81 @@
+\name{ResumeNames}
+\alias{ResumeNames}
+
+\title{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")}
+
+\format{
+A data frame containing 4,870 observations on 27 variables.
+\describe{
+ \item{name}{factor indicating applicant's first name.}
+ \item{gender}{factor indicating gender.}
+ \item{ethnicity}{factor indicating ethnicity (i.e., Caucasian-sounding
+ vs. African-American sounding first name).}
+ \item{quality}{factor indicating quality of resume.}
+ \item{call}{factor. Was the applicant called back?}
+ \item{city}{factor indicating city: Boston or Chicago.}
+ \item{jobs}{number of jobs listed on resume.}
+ \item{experience}{number of years of work experience on the resume.}
+ \item{honors}{factor. Did the resume mention some honors?}
+ \item{volunteer}{factor. Did the resume mention some volunteering experience?}
+ \item{military}{factor. Does the applicant have military experience?}
+ \item{holes}{factor. Does the resume have some employment holes?}
+ \item{school}{factor. Does the resume mention some work experience while at school?}
+ \item{email}{factor. Was the e-mail address on the applicant's resume?}
+ \item{computer}{factor. Does the resume mention some computer skills?}
+ \item{special}{factor. Does the resume mention some special skills?}
+ \item{college}{factor. Does the applicant have a college degree or more?}
+ \item{minimum}{factor indicating minimum experience requirement of the employer.}
+ \item{equal}{factor. Is the employer EOE (equal opportunity employment)?}
+ \item{wanted}{factor indicating type of position wanted by employer.}
+ \item{requirements}{factor. Does the ad mention some requirement for the job?}
+ \item{reqexp}{factor. Does the ad mention some experience requirement?}
+ \item{reqcomm}{factor. Does the ad mention some communication skills requirement?}
+ \item{reqeduc}{factor. Does the ad mention some educational requirement?}
+ \item{reqcomp}{factor. Does the ad mention some computer skills requirement?}
+ \item{reqorg}{factor. Does the ad mention some organizational skills requirement?}
+ \item{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 \dQuote{Caucasian sounding names} (such as Emily Walsh or Gregory Baker)
+and \dQuote{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.
+}
+
+\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.
+\emph{American Economic Review}, \bold{94}, 991--1013.
+
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+data("ResumeNames")
+summary(ResumeNames)
+prop.table(xtabs(~ ethnicity + call, data = ResumeNames), 1)
+}
+
+\keyword{datasets}
diff --git a/man/SIC33.Rd b/man/SIC33.Rd
new file mode 100644
index 0000000..5460f2f
--- /dev/null
+++ b/man/SIC33.Rd
@@ -0,0 +1,76 @@
+\name{SIC33}
+\alias{SIC33}
+\title{SIC33 Production Data}
+\description{
+Statewide production data for primary metals industry (SIC 33).
+}
+\usage{data("SIC33")}
+
+\format{
+A data frame containing 27 observations on 3 variables.
+\describe{
+ \item{output}{Value added.}
+ \item{labor}{Labor input.}
+ \item{capital}{Capital stock.}
+}
+}
+
+\source{
+Online complements to Greene (2003). Table F6.1.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}}
+
+\examples{
+data("SIC33")
+
+## Example 6.2 in Greene (2003)
+## 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))
+
+## Table 6.2 in Greene (2003)
+deviance(fm_tl)
+deviance(fm_cb)
+summary(fm_tl)
+summary(fm_cb)
+vcov(fm_tl)
+vcov(fm_cb)
+
+## Cobb-Douglas vs. Translog model
+anova(fm_cb, fm_tl)
+## hypothesis of constant returns
+linearHypothesis(fm_cb, "labor + capital = 1")
+
+## 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
+\donttest{
+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)
+}
+}
+}
+
+\keyword{datasets}
diff --git a/man/STAR.Rd b/man/STAR.Rd
new file mode 100644
index 0000000..dbbceb5
--- /dev/null
+++ b/man/STAR.Rd
@@ -0,0 +1,166 @@
+\name{STAR}
+\alias{STAR}
+
+\title{Project STAR: Student-Teacher Achievement Ratio}
+
+\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.
+\describe{
+ \item{gender}{factor indicating student's gender.}
+ \item{ethnicity}{factor indicating student's ethnicity with levels
+ \code{"cauc"} (Caucasian), \code{"afam"} (African-American), \code{"asian"} (Asian),
+ \code{"hispanic"} (Hispanic), \code{"amindian"} (American-Indian) or \code{"other"}.}
+ \item{birth}{student's birth quarter (of class \code{\link[zoo]{yearqtr}}).}
+ \item{stark}{factor indicating the STAR class type in kindergarten:
+ regular, small, or regular-with-aide. \code{NA} indicates that no STAR class was attended.}
+ \item{star1}{factor indicating the STAR class type in 1st grade:
+ regular, small, or regular-with-aide. \code{NA} indicates that no STAR class was attended.}
+ \item{star2}{factor indicating the STAR class type in 2nd grade:
+ regular, small, or regular-with-aide. \code{NA} indicates that no STAR class was attended.}
+ \item{star3}{factor indicating the STAR class type in 3rd grade:
+ regular, small, or regular-with-aide. \code{NA} indicates that no STAR class was attended.}
+ \item{readk}{total reading scaled score in kindergarten.}
+ \item{read1}{total reading scaled score in 1st grade.}
+ \item{read2}{total reading scaled score in 2nd grade.}
+ \item{read3}{total reading scaled score in 3rd grade.}
+ \item{mathk}{total math scaled score in kindergarten.}
+ \item{math1}{total math scaled score in 1st grade.}
+ \item{math2}{total math scaled score in 2nd grade.}
+ \item{math3}{total math scaled score in 3rd grade.}
+ \item{lunchk}{factor indicating whether the student qualified for free lunch in kindergarten.}
+ \item{lunch1}{factor indicating whether the student qualified for free lunch in 1st grade.}
+ \item{lunch2}{factor indicating whether the student qualified for free lunch in 2nd grade.}
+ \item{lunch3}{factor indicating whether the student qualified for free lunch in 3rd grade.}
+ \item{schoolk}{factor indicating school type in kindergarten:
+ \code{"inner-city"}, \code{"suburban"}, \code{"rural"} or \code{"urban"}.}
+ \item{school1}{factor indicating school type in 1st grade:
+ \code{"inner-city"}, \code{"suburban"}, \code{"rural"} or \code{"urban"}.}
+ \item{school2}{factor indicating school type in 2nd grade:
+ \code{"inner-city"}, \code{"suburban"}, \code{"rural"} or \code{"urban"}.}
+ \item{school3}{factor indicating school type in 3rd grade:
+ \code{"inner-city"}, \code{"suburban"}, \code{"rural"} or \code{"urban"}.}
+ \item{degreek}{factor indicating highest degree of kindergarten teacher:
+ \code{"bachelor"}, \code{"master"}, \code{"specialist"}, or \code{"master+"}.}
+ \item{degree1}{factor indicating highest degree of 1st grade teacher:
+ \code{"bachelor"}, \code{"master"}, \code{"specialist"}, or \code{"phd"}.}
+ \item{degree2}{factor indicating highest degree of 2nd grade teacher:
+ \code{"bachelor"}, \code{"master"}, \code{"specialist"}, or \code{"phd"}.}
+ \item{degree3}{factor indicating highest degree of 3rd grade teacher:
+ \code{"bachelor"}, \code{"master"}, \code{"specialist"}, or \code{"phd"}.}
+ \item{ladderk}{factor indicating teacher's career ladder level in kindergarten: \code{"level1"},
+ \code{"level2"}, \code{"level3"}, \code{"apprentice"}, \code{"probation"} or \code{"pending"}.}
+ \item{ladder1}{factor indicating teacher's career ladder level in 1st grade: \code{"level1"},
+ \code{"level2"}, \code{"level3"}, \code{"apprentice"}, \code{"probation"} or \code{"noladder"}.}
+ \item{ladder2}{factor indicating teacher's career ladder level in 2nd grade: \code{"level1"},
+ \code{"level2"}, \code{"level3"}, \code{"apprentice"}, \code{"probation"} or \code{"noladder"}.}
+ \item{ladder3}{factor indicating teacher's career ladder level in 3rd grade: \code{"level1"},
+ \code{"level2"}, \code{"level3"}, \code{"apprentice"}, \code{"probation"} or \code{"noladder"}.}
+ \item{experiencek}{years of teacher's total teaching experience in kindergarten.}
+ \item{experience1}{years of teacher's total teaching experience in 1st grade.}
+ \item{experience2}{years of teacher's total teaching experience in 2nd grade.}
+ \item{experience3}{years of teacher's total teaching experience in 3rd grade.}
+ \item{tethnicityk}{factor indicating teacher's ethnicity in kindergarten with levels
+ \code{"cauc"} (Caucasian) or \code{"afam"} (African-American).}
+ \item{tethnicity1}{factor indicating teacher's ethnicity in 1st grade with levels
+ \code{"cauc"} (Caucasian) or \code{"afam"} (African-American).}
+ \item{tethnicity2}{factor indicating teacher's ethnicity in 2nd grade with levels
+ \code{"cauc"} (Caucasian) or \code{"afam"} (African-American).}
+ \item{tethnicity3}{factor indicating teacher's ethnicity in 3rd grade with levels
+ \code{"cauc"} (Caucasian), \code{"afam"} (African-American), or \code{"asian"} (Asian).}
+ \item{systemk}{factor indicating school system ID in kindergarten.}
+ \item{system1}{factor indicating school system ID in 1st grade.}
+ \item{system2}{factor indicating school system ID in 2nd grade.}
+ \item{system3}{factor indicating school system ID in 3rd grade.}
+ \item{schoolidk}{factor indicating school ID in kindergarten.}
+ \item{schoolid1}{factor indicating school ID in 1st grade.}
+ \item{schoolid2}{factor indicating school ID in 2nd grade.}
+ \item{schoolid3}{factor indicating school ID in 3rd grade.}
+}
+}
+
+\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 interventions:
+small class (13 to 17 students per teacher), regular class (22 to 25
+students per teacher), and regular-with-aide class (22 to 25 students
+with a full-time teacher's aide). Classroom teachers were also randomly
+assigned to the classes they would teach. The interventions were
+initiated as the students entered school in kindergarten and continued
+through third grade.
+
+The Project STAR public access data set contains data on test scores,
+treatment groups, and student and teacher characteristics for
+the four years of the experiment, from academic year 1985--1986 to
+academic year 1988--1989. The test score data analyzed in this
+chapter are the sum of the scores on the math and reading portion of the
+Stanford Achievement Test.
+
+Stock and Watson (2007) obtained the data set from the
+Project STAR Web site at \url{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 \code{degree}, \code{ladder}
+and \code{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). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+data("STAR")
+
+## Stock and Watson, 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)
+plot(I(read3 + math3) ~ star3, data = STAR)
+
+## Stock and Watson, p. 489
+fmke <- lm(I(readk + mathk) ~ stark + experiencek, data = STAR)
+coeftest(fmke, vcov = sandwich)
+
+## reshape data from wide into long format
+## 1. variables and their levels
+nam <- c("star", "read", "math", "lunch", "school", "degree", "ladder",
+ "experience", "tethnicity", "system", "schoolid")
+lev <- c("k", "1", "2", "3")
+## 2. 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 = "")))
+## 3. 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)
+
+## 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)
+}
+
+\keyword{datasets}
diff --git a/man/ShipAccidents.Rd b/man/ShipAccidents.Rd
new file mode 100644
index 0000000..7a6a246
--- /dev/null
+++ b/man/ShipAccidents.Rd
@@ -0,0 +1,80 @@
+\name{ShipAccidents}
+\alias{ShipAccidents}
+
+\title{Ship Accidents}
+
+\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.
+ \describe{
+ \item{type}{factor with levels \code{"A"} to \code{"E"} for the different ship types,}
+ \item{construction}{factor with levels \code{"1960-64"}, \code{"1965-69"}, \code{"1970-74"},
+ \code{"1975-79"} for the periods of construction,}
+ \item{operation}{factor with levels \code{"1960-74"}, \code{"1975-79"} for the periods of
+ operation,}
+ \item{service}{aggregate months of service,}
+ \item{incidents}{number of damage incidents.}
+ }
+}
+
+\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
+\emph{before} the construction period, hence the variables \code{service} and
+\code{incidents} are necessarily 0. An additional observation (34) has entries
+representing \emph{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 \code{service > 0}.
+}
+
+\source{
+Online complements to Greene (2003).
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+
+McCullagh, P. and Nelder, J.A. (1989). \emph{Generalized Linear Models}, 2nd edition.
+London: Chapman \& Hall.
+}
+
+\seealso{\code{\link{Greene2003}}}
+
+\examples{
+data("ShipAccidents")
+sa <- subset(ShipAccidents, service > 0)
+
+## Greene (2003), Table 21.20
+## (see also McCullagh and Nelder, 1989, Table 6.3)
+sa_full <- glm(incidents ~ type + construction + operation, family = poisson,
+ data = sa, offset = log(service))
+summary(sa_full)
+
+sa_notype <- glm(incidents ~ construction + operation, family = poisson,
+ data = sa, offset = log(service))
+summary(sa_notype)
+
+sa_noperiod <- glm(incidents ~ type + operation, family = poisson,
+ data = sa, offset = log(service))
+summary(sa_noperiod)
+
+## model comparison
+anova(sa_full, sa_notype, test = "Chisq")
+anova(sa_full, sa_noperiod, test = "Chisq")
+
+## test for overdispersion
+dispersiontest(sa_full)
+dispersiontest(sa_full, trafo = 2)
+}
+
+\keyword{datasets}
diff --git a/man/SmokeBan.Rd b/man/SmokeBan.Rd
new file mode 100644
index 0000000..658285e
--- /dev/null
+++ b/man/SmokeBan.Rd
@@ -0,0 +1,58 @@
+\name{SmokeBan}
+\alias{SmokeBan}
+
+\title{Do Workplace Smoking Bans Reduce Smoking?}
+
+\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.
+\describe{
+ \item{smoker}{factor. Is the individual a current smoker?}
+ \item{ban}{factor. Is there a work area smoking ban?}
+ \item{age}{age in years.}
+ \item{education}{factor indicating highest education level attained:
+ high school (hs) drop out, high school graduate, some college,
+ college graduate, master's degree (or higher).}
+ \item{afam}{factor. Is the individual African-American?}
+ \item{hispanic}{factor. Is the individual Hispanic?}
+ \item{gender}{factor indicating gender.}
+}
+}
+
+\details{
+\code{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?
+\emph{American Economic Review}, \bold{89}, 728--747.
+
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+data("SmokeBan")
+
+## proportion of non-smokers increases with education
+plot(smoker ~ education, data = SmokeBan)
+
+## proportion of non-smokers constant over age
+plot(smoker ~ age, data = SmokeBan)
+}
+
+\keyword{datasets}
diff --git a/man/SportsCards.Rd b/man/SportsCards.Rd
new file mode 100644
index 0000000..86d904c
--- /dev/null
+++ b/man/SportsCards.Rd
@@ -0,0 +1,62 @@
+\name{SportsCards}
+\alias{SportsCards}
+
+\title{Endowment Effect for Sports Cards}
+
+\description{
+Trading sports cards: Does ownership increase the value of goods to consumers?
+}
+
+\usage{data("SportsCards")}
+
+\format{
+A data frame containing 148 observations on 9 variables.
+\describe{
+ \item{good}{factor. Was the individual given good A or B (see below)?}
+ \item{dealer}{factor. Was the individual a dealer?}
+ \item{permonth}{number of trades per month reported by the individual.}
+ \item{years}{number of years that the individual has been trading.}
+ \item{income}{factor indicating income group (in 1000 USD).}
+ \item{gender}{factor indicating gender.}
+ \item{education}{factor indicating highest level of education (8th grade or less,
+ high school, 2-year college, other post-high school, 4-year college or graduate school).}
+ \item{age}{age in years.}
+ \item{trade}{factor. Did the individual trade the good he was given for the other good?}
+}
+}
+
+\details{
+\code{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?
+\emph{Quarterly Journal of Economcis}, \bold{118}, 41--71.
+
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+data("SportsCards")
+summary(SportsCards)
+
+plot(trade ~ permonth, data = SportsCards,
+ ylevels = 2:1, breaks = c(0, 5, 10, 20, 30, 70))
+plot(trade ~ years, data = SportsCards,
+ ylevels = 2:1, breaks = c(0, 5, 10, 20, 60))
+}
+
+\keyword{datasets}
diff --git a/man/StockWatson2007.Rd b/man/StockWatson2007.Rd
new file mode 100644
index 0000000..abeac70
--- /dev/null
+++ b/man/StockWatson2007.Rd
@@ -0,0 +1,608 @@
+\name{StockWatson2007}
+\alias{StockWatson2007}
+
+\title{Data and Examples from Stock and Watson (2007)}
+
+\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). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{CartelStability}}, \code{\link{CASchools}}, \code{\link{CigarettesSW}},
+ \code{\link{CollegeDistance}}, \code{\link{CPSSW04}}, \code{\link{CPSSW3}}, \code{\link{CPSSW8}},
+ \code{\link{CPSSW9298}}, \code{\link{CPSSW9204}}, \code{\link{CPSSWEducation}},
+ \code{\link{Fatalities}}, \code{\link{Fertility}}, \code{\link{Fertility2}}, \code{\link{FrozenJuice}},
+ \code{\link{GrowthSW}}, \code{\link{Guns}}, \code{\link{HealthInsurance}}, \code{\link{HMDA}},
+ \code{\link{Journals}}, \code{\link{MASchools}}, \code{\link{NYSESW}}, \code{\link{ResumeNames}},
+ \code{\link{SmokeBan}}, \code{\link{SportsCards}}, \code{\link{STAR}}, \code{\link{TeachingRatings}},
+ \code{\link{USMacroSW}}, \code{\link{USMacroSWM}}, \code{\link{USMacroSWQ}}, \code{\link{USSeatBelts}},
+ \code{\link{USStocksSW}}, \code{\link{WeakInstrument}}}
+
+\examples{
+###############################
+## Current Population Survey ##
+###############################
+
+## 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 ##
+############################
+
+## data and transformations
+data("CASchools", package = "AER")
+CASchools$stratio <- with(CASchools, students/teachers)
+CASchools$score <- with(CASchools, (math + read)/2)
+
+## 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)
+
+## Table 7.1, p. 242 (numbers refer to columns)
+fmc3 <- lm(score ~ stratio + english + lunch, data = CASchools)
+fmc4 <- lm(score ~ stratio + english + calworks, data = CASchools)
+fmc5 <- lm(score ~ stratio + english + lunch + calworks, data = CASchools)
+
+## Equation 8.2, p. 258
+fmquad <- lm(score ~ income + I(income^2), data = CASchools)
+## Equation 8.11, p. 266
+fmcub <- lm(score ~ income + I(income^2) + I(income^3), data = CASchools)
+## Equation 8.23, p. 272
+fmloglog <- lm(log(score) ~ log(income), data = CASchools)
+## Equation 8.24, p. 274
+fmloglin <- lm(log(score) ~ income, data = CASchools)
+## Equation 8.26, p. 275
+fmlinlogcub <- lm(score ~ log(income) + I(log(income)^2) + I(log(income)^3),
+ data = CASchools)
+
+## Table 8.3, p. 292 (numbers refer to columns)
+fmc2 <- lm(score ~ stratio + english + lunch + log(income), data = CASchools)
+fmc7 <- lm(score ~ stratio + I(stratio^2) + I(stratio^3) + english + lunch + log(income),
+ data = CASchools)
+
+
+#####################################
+## Economics journal Subscriptions ##
+#####################################
+
+## data and transformed variables
+data("Journals", package = "AER")
+journals <- Journals[, c("subs", "price")]
+journals$citeprice <- Journals$price/Journals$citations
+journals$age <- 2000 - Journals$foundingyear
+journals$chars <- Journals$charpp*Journals$pages/10^6
+
+## Figure 8.9 (a) and (b)
+plot(subs ~ citeprice, data = journals, pch = 19)
+plot(log(subs) ~ log(citeprice), data = journals, pch = 19)
+fm1 <- lm(log(subs) ~ log(citeprice), data = journals)
+abline(fm1)
+
+## Table 8.2, use HC1 for comparability with Stata
+fm1 <- lm(subs ~ citeprice, data = log(journals))
+fm2 <- lm(subs ~ citeprice + age + chars, data = log(journals))
+fm3 <- lm(subs ~ citeprice + I(citeprice^2) + I(citeprice^3) +
+ age + I(age * citeprice) + chars, data = log(journals))
+fm4 <- lm(subs ~ citeprice + age + I(age * citeprice) + chars, data = log(journals))
+coeftest(fm1, vcov = vcovHC(fm1, type = "HC1"))
+coeftest(fm2, vcov = vcovHC(fm2, type = "HC1"))
+coeftest(fm3, vcov = vcovHC(fm3, type = "HC1"))
+coeftest(fm4, vcov = vcovHC(fm4, type = "HC1"))
+waldtest(fm3, fm4, vcov = vcovHC(fm3, type = "HC1"))
+
+
+###############################
+## Massachusetts test scores ##
+###############################
+
+## compare Massachusetts with California
+data("MASchools", package = "AER")
+data("CASchools", package = "AER")
+CASchools$stratio <- with(CASchools, students/teachers)
+CASchools$score4 <- with(CASchools, (math + read)/2)
+
+## parts of Table 9.1, p. 330
+vars <- c("score4", "stratio", "english", "lunch", "income")
+cbind(
+ CA_mean = sapply(CASchools[, vars], mean),
+ CA_sd = sapply(CASchools[, vars], sd),
+ MA_mean = sapply(MASchools[, vars], mean),
+ MA_sd = sapply(MASchools[, vars], sd))
+
+## Table 9.2, pp. 332--333, numbers refer to columns
+MASchools$higheng <- with(MASchools, english > median(english))
+fm1 <- lm(score4 ~ stratio, data = MASchools)
+fm2 <- lm(score4 ~ stratio + english + lunch + log(income), data = MASchools)
+fm3 <- lm(score4 ~ stratio + english + lunch + income + I(income^2) + I(income^3),
+ data = MASchools)
+fm4 <- lm(score4 ~ stratio + I(stratio^2) + I(stratio^3) + english + lunch +
+ income + I(income^2) + I(income^3), data = MASchools)
+fm5 <- lm(score4 ~ stratio + higheng + I(higheng * stratio) + lunch +
+ income + I(income^2) + I(income^3), data = MASchools)
+fm6 <- lm(score4 ~ stratio + lunch + income + I(income^2) + I(income^3),
+ data = MASchools)
+
+## for comparability with Stata use HC1 below
+coeftest(fm1, vcov = vcovHC(fm1, type = "HC1"))
+coeftest(fm2, vcov = vcovHC(fm2, type = "HC1"))
+coeftest(fm3, vcov = vcovHC(fm3, type = "HC1"))
+coeftest(fm4, vcov = vcovHC(fm4, type = "HC1"))
+coeftest(fm5, vcov = vcovHC(fm5, type = "HC1"))
+coeftest(fm6, vcov = vcovHC(fm6, type = "HC1"))
+
+## Testing exclusion of groups of variables
+fm3r <- update(fm3, . ~ . - I(income^2) - I(income^3))
+waldtest(fm3, fm3r, vcov = vcovHC(fm3, type = "HC1"))
+
+fm4r_str1 <- update(fm4, . ~ . - stratio - I(stratio^2) - I(stratio^3))
+waldtest(fm4, fm4r_str1, vcov = vcovHC(fm4, type = "HC1"))
+fm4r_str2 <- update(fm4, . ~ . - I(stratio^2) - I(stratio^3))
+waldtest(fm4, fm4r_str2, vcov = vcovHC(fm4, type = "HC1"))
+fm4r_inc <- update(fm4, . ~ . - I(income^2) - I(income^3))
+waldtest(fm4, fm4r_inc, vcov = vcovHC(fm4, type = "HC1"))
+
+fm5r_str <- update(fm5, . ~ . - stratio - I(higheng * stratio))
+waldtest(fm5, fm5r_str, vcov = vcovHC(fm5, type = "HC1"))
+fm5r_inc <- update(fm5, . ~ . - I(income^2) - I(income^3))
+waldtest(fm5, fm5r_inc, vcov = vcovHC(fm5, type = "HC1"))
+fm5r_high <- update(fm5, . ~ . - higheng - I(higheng * stratio))
+waldtest(fm5, fm5r_high, vcov = vcovHC(fm5, type = "HC1"))
+
+fm6r_inc <- update(fm6, . ~ . - I(income^2) - I(income^3))
+waldtest(fm6, fm6r_inc, vcov = vcovHC(fm6, type = "HC1"))
+
+
+##################################
+## Home mortgage disclosure act ##
+##################################
+
+## data
+data("HMDA", package = "AER")
+
+## 11.1, 11.3, 11.7, 11.8 and 11.10, pp. 387--395
+fm1 <- lm(I(as.numeric(deny) - 1) ~ pirat, data = HMDA)
+fm2 <- lm(I(as.numeric(deny) - 1) ~ pirat + afam, data = HMDA)
+fm3 <- glm(deny ~ pirat, family = binomial(link = "probit"), data = HMDA)
+fm4 <- glm(deny ~ pirat + afam, family = binomial(link = "probit"), data = HMDA)
+fm5 <- glm(deny ~ pirat + afam, family = binomial(link = "logit"), data = HMDA)
+
+## Table 11.1, p. 401
+mean(HMDA$pirat)
+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))
+
+## Table 11.2, pp. 403--404, numbers refer to columns
+HMDA$lvrat <- factor(ifelse(HMDA$lvrat < 0.8, "low",
+ ifelse(HMDA$lvrat >= 0.8 & HMDA$lvrat <= 0.95, "medium", "high")),
+ levels = c("low", "medium", "high"))
+HMDA$mhist <- as.numeric(HMDA$mhist)
+HMDA$chist <- as.numeric(HMDA$chist)
+
+fm1 <- lm(I(as.numeric(deny) - 1) ~ afam + pirat + hirat + lvrat + chist + mhist +
+ phist + insurance + selfemp, data = HMDA)
+fm2 <- glm(deny ~ afam + pirat + hirat + lvrat + chist + mhist + phist + insurance +
+ selfemp, family = binomial, data = HMDA)
+fm3 <- glm(deny ~ afam + pirat + hirat + lvrat + chist + mhist + phist + insurance +
+ selfemp, family = binomial(link = "probit"), data = HMDA)
+fm4 <- glm(deny ~ afam + pirat + hirat + lvrat + chist + mhist + phist + insurance +
+ selfemp + single + hschool + unemp, family = binomial(link = "probit"), data = HMDA)
+fm5 <- glm(deny ~ afam + pirat + hirat + lvrat + chist + mhist + phist + insurance +
+ selfemp + single + hschool + unemp + condomin +
+ I(mhist==3) + I(mhist==4) + I(chist==3) + I(chist==4) + I(chist==5) + I(chist==6),
+ family = binomial(link = "probit"), data = HMDA)
+fm6 <- glm(deny ~ afam * (pirat + hirat) + lvrat + chist + mhist + phist + insurance +
+ selfemp + single + hschool + unemp, family = binomial(link = "probit"), data = HMDA)
+coeftest(fm1, vcov = sandwich)
+
+fm4r <- update(fm4, . ~ . - single - hschool - unemp)
+waldtest(fm4, fm4r, vcov = sandwich)
+fm5r <- update(fm5, . ~ . - single - hschool - unemp)
+waldtest(fm5, fm5r, vcov = sandwich)
+fm6r <- update(fm6, . ~ . - single - hschool - unemp)
+waldtest(fm6, fm6r, vcov = sandwich)
+
+fm5r2 <- update(fm5, . ~ . - I(mhist==3) - I(mhist==4) - I(chist==3) - I(chist==4) -
+ I(chist==5) - I(chist==6))
+waldtest(fm5, fm5r2, vcov = sandwich)
+
+fm6r2 <- update(fm6, . ~ . - afam * (pirat + hirat) + pirat + hirat)
+waldtest(fm6, fm6r2, vcov = sandwich)
+
+fm6r3 <- update(fm6, . ~ . - afam * (pirat + hirat) + pirat + hirat + afam)
+waldtest(fm6, fm6r3, vcov = sandwich)
+
+
+
+#########################################################
+## Shooting down the "More Guns Less Crime" hypothesis ##
+#########################################################
+
+## data
+data("Guns", package = "AER")
+
+## Empirical Exercise 10.1
+fm1 <- lm(log(violent) ~ law, data = Guns)
+fm2 <- lm(log(violent) ~ law + prisoners + density + income +
+ population + afam + cauc + male, data = Guns)
+fm3 <- lm(log(violent) ~ law + prisoners + density + income +
+ population + afam + cauc + male + state, data = Guns)
+fm4 <- lm(log(violent) ~ law + prisoners + density + income +
+ population + afam + cauc + male + state + year, data = Guns)
+coeftest(fm1, vcov = sandwich)
+coeftest(fm2, vcov = sandwich)
+printCoefmat(coeftest(fm3, vcov = sandwich)[1:9,])
+printCoefmat(coeftest(fm4, vcov = sandwich)[1:9,])
+
+
+###########################
+## US traffic fatalities ##
+###########################
+
+## data from Stock and Watson (2007)
+data("Fatalities")
+## 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")
+
+## for comparability with Stata we use HC1 below
+## p. 351, Eq. (10.2)
+f1982 <- subset(Fatalities, year == "1982")
+fm_1982 <- lm(frate ~ beertax, data = f1982)
+coeftest(fm_1982, vcov = vcovHC(fm_1982, type = "HC1"))
+
+## p. 353, Eq. (10.3)
+f1988 <- subset(Fatalities, year == "1988")
+fm_1988 <- lm(frate ~ beertax, data = f1988)
+coeftest(fm_1988, vcov = vcovHC(fm_1988, type = "HC1"))
+
+## pp. 355, Eq. (10.8)
+fm_diff <- lm(I(f1988$frate - f1982$frate) ~ I(f1988$beertax - f1982$beertax))
+coeftest(fm_diff, vcov = vcovHC(fm_diff, type = "HC1"))
+
+## pp. 360, Eq. (10.15)
+## (1) via formula
+fm_sfe <- lm(frate ~ beertax + state - 1, data = Fatalities)
+## (2) by hand
+fat <- with(Fatalities,
+ data.frame(frates = frate - ave(frate, state),
+ beertaxs = beertax - ave(beertax, state)))
+fm_sfe2 <- lm(frates ~ beertaxs - 1, data = fat)
+## (3) via plm()
+fm_sfe3 <- plm(frate ~ beertax, data = Fatalities,
+ index = c("state", "year"), model = "within")
+
+coeftest(fm_sfe, vcov = vcovHC(fm_sfe, type = "HC1"))[1,]
+
+## uses different df in sd and p-value
+coeftest(fm_sfe2, vcov = vcovHC(fm_sfe2, type = "HC1"))[1,]
+
+## uses different df in p-value
+coeftest(fm_sfe3, vcov = vcovHC(fm_sfe3, type = "HC1", method = "white1"))[1,]
+
+
+## pp. 363, Eq. (10.21)
+## via lm()
+fm_stfe <- lm(frate ~ beertax + state + year - 1, data = Fatalities)
+coeftest(fm_stfe, vcov = vcovHC(fm_stfe, type = "HC1"))[1,]
+## via plm()
+fm_stfe2 <- plm(frate ~ beertax, data = Fatalities,
+ index = c("state", "year"), model = "within", effect = "twoways")
+coeftest(fm_stfe2, vcov = vcovHC) ## different
+
+
+## p. 368, Table 10.1, numbers refer to cols.
+fm1 <- plm(frate ~ beertax, data = Fatalities, index = c("state", "year"),
+ model = "pooling")
+fm2 <- plm(frate ~ beertax, data = Fatalities, index = c("state", "year"),
+ model = "within")
+fm3 <- plm(frate ~ beertax, data = Fatalities, index = c("state", "year"),
+ model = "within", effect = "twoways")
+fm4 <- plm(frate ~ beertax + drinkagec + jail + service + miles + unemp + log(income),
+ data = Fatalities, index = c("state", "year"), model = "within", effect = "twoways")
+fm5 <- plm(frate ~ beertax + drinkagec + jail + service + miles,
+ data = Fatalities, index = c("state", "year"), model = "within", effect = "twoways")
+fm6 <- plm(frate ~ beertax + drinkage + punish + miles + unemp + log(income),
+ data = Fatalities, index = c("state", "year"), model = "within", effect = "twoways")
+fm7 <- plm(frate ~ beertax + drinkagec + jail + service + miles + unemp + log(income),
+ data = Fatalities, index = c("state", "year"), model = "within", effect = "twoways")
+## summaries not too close, s.e.s generally too small
+coeftest(fm1, vcov = vcovHC)
+coeftest(fm2, vcov = vcovHC)
+coeftest(fm3, vcov = vcovHC)
+coeftest(fm4, vcov = vcovHC)
+coeftest(fm5, vcov = vcovHC)
+coeftest(fm6, vcov = vcovHC)
+coeftest(fm7, vcov = vcovHC)
+
+
+######################################
+## Cigarette consumption panel data ##
+######################################
+
+## data and transformations
+data("CigarettesSW", package = "AER")
+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")
+
+## convenience function: HC1 covariances
+hc1 <- function(x) vcovHC(x, type = "HC1")
+
+## 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)
+
+## Table 12.1, p. 448
+ydiff <- log(c1995$packs) - log(c1985$packs)
+pricediff <- log(c1995$price/c1995$cpi) - log(c1985$price/c1985$cpi)
+incdiff <- log(c1995$income/c1995$population/c1995$cpi) -
+ log(c1985$income/c1985$population/c1985$cpi)
+taxsdiff <- (c1995$taxs - c1995$tax)/c1995$cpi - (c1985$taxs - c1985$tax)/c1985$cpi
+taxdiff <- c1995$tax/c1995$cpi - c1985$tax/c1985$cpi
+
+fm_diff1 <- ivreg(ydiff ~ pricediff + incdiff | incdiff + taxsdiff)
+fm_diff2 <- ivreg(ydiff ~ pricediff + incdiff | incdiff + taxdiff)
+fm_diff3 <- ivreg(ydiff ~ pricediff + incdiff | incdiff + taxsdiff + taxdiff)
+coeftest(fm_diff1, vcov = hc1)
+coeftest(fm_diff2, vcov = hc1)
+coeftest(fm_diff3, vcov = hc1)
+
+## checking instrument relevance
+fm_rel1 <- lm(pricediff ~ taxsdiff + incdiff)
+fm_rel2 <- lm(pricediff ~ taxdiff + incdiff)
+fm_rel3 <- lm(pricediff ~ incdiff + taxsdiff + taxdiff)
+linearHypothesis(fm_rel1, "taxsdiff = 0", vcov = hc1)
+linearHypothesis(fm_rel2, "taxdiff = 0", vcov = hc1)
+linearHypothesis(fm_rel3, c("taxsdiff = 0", "taxdiff = 0"), vcov = hc1)
+
+## testing overidentifying restrictions (J test)
+fm_or <- lm(residuals(fm_diff3) ~ incdiff + taxsdiff + taxdiff)
+(fm_or_test <- linearHypothesis(fm_or, c("taxsdiff = 0", "taxdiff = 0"), test = "Chisq"))
+## warning: df (and hence p-value) invalid above.
+## correct df: # instruments - # endogenous variables
+pchisq(fm_or_test[2,5], df.residual(fm_diff3) - df.residual(fm_or), lower.tail = FALSE)
+
+
+#####################################################
+## 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
+fm <- lm(I(read + math) ~ 0 + grade/star, data = star)
+
+
+#################################################
+## 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")
+
+## Equation 14.7, p. 536
+fm_ar1 <- dynlm(d(infl) ~ L(d(infl)),
+ data = usm, start = c(1962,1), end = c(2004,4))
+coeftest(fm_ar1, vcov = sandwich)
+
+## Equation 14.13, p. 538
+fm_ar4 <- dynlm(d(infl) ~ L(d(infl), 1:4),
+ data = usm, start = c(1962,1), end = c(2004,4))
+coeftest(fm_ar4, vcov = sandwich)
+
+## Equation 14.16, p. 542
+fm_adl41 <- dynlm(d(infl) ~ L(d(infl), 1:4) + L(unemp),
+ data = usm, start = c(1962,1), end = c(2004,4))
+coeftest(fm_adl41, vcov = sandwich)
+
+## Equation 14.17, p. 542
+fm_adl44 <- dynlm(d(infl) ~ L(d(infl), 1:4) + L(unemp, 1:4),
+ data = usm, start = c(1962,1), end = c(2004,4))
+coeftest(fm_adl44, vcov = sandwich)
+
+## Granger causality test mentioned on p. 547
+waldtest(fm_ar4, fm_adl44, vcov = sandwich)
+
+## Equation 14.28, p. 559
+fm_sp1 <- dynlm(infl ~ log(gdpjp), start = c(1965,1), end = c(1981,4), data = usm)
+coeftest(fm_sp1, vcov = sandwich)
+
+## Equation 14.29, p. 559
+fm_sp2 <- dynlm(infl ~ log(gdpjp), start = c(1982,1), end = c(2004,4), data = usm)
+coeftest(fm_sp2, vcov = sandwich)
+
+## Equation 14.34, p. 563: ADF by hand
+fm_adf <- dynlm(d(infl) ~ L(infl) + L(d(infl), 1:4),
+ data = usm, start = c(1962,1), end = c(2004,4))
+coeftest(fm_adf)
+
+## Figure 14.5, p. 570
+## SW perform partial break test of unemp coefs
+## here full model is used
+library("strucchange")
+infl <- usm[, "infl"]
+unemp <- usm[, "unemp"]
+usm <- ts.intersect(diff(infl), lag(diff(infl), k = -1), lag(diff(infl), k = -2),
+ lag(diff(infl), k = -3), lag(diff(infl), k = -4), lag(unemp, k = -1),
+ lag(unemp, k = -2), lag(unemp, k = -3), lag(unemp, k = -4))
+colnames(usm) <- c("dinfl", paste("dinfl", 1:4, sep = ""), paste("unemp", 1:4, sep = ""))
+usm <- window(usm, start = c(1962, 1), end = c(2004, 4))
+fs <- Fstats(dinfl ~ ., data = usm)
+sctest(fs, type = "supF")
+plot(fs)
+
+## alternatively: re-use fm_adl44
+mf <- model.frame(fm_adl44)
+mf <- ts(as.matrix(mf), start = c(1962, 1), freq = 4)
+colnames(mf) <- c("y", paste("x", 1:8, sep = ""))
+ff <- as.formula(paste("y", "~", paste("x", 1:8, sep = "", collapse = " + ")))
+fs <- Fstats(ff, data = mf, from = 0.1)
+plot(fs)
+lines(boundary(fs, alpha = 0.01), lty = 2, col = 2)
+lines(boundary(fs, alpha = 0.1), lty = 3, col = 2)
+
+
+##########################################
+## Monthly US stock returns (1931-2002) ##
+##########################################
+
+## package and data
+library("dynlm")
+data("USStocksSW", package = "AER")
+
+## Table 14.3, p. 540
+fm1 <- dynlm(returns ~ L(returns), data = USStocksSW, start = c(1960,1))
+coeftest(fm1, vcov = sandwich)
+fm2 <- dynlm(returns ~ L(returns, 1:2), data = USStocksSW, start = c(1960,1))
+waldtest(fm2, vcov = sandwich)
+fm3 <- dynlm(returns ~ L(returns, 1:4), data = USStocksSW, start = c(1960,1))
+waldtest(fm3, vcov = sandwich)
+
+## Table 14.7, p. 574
+fm4 <- dynlm(returns ~ L(returns) + L(d(dividend)),
+ data = USStocksSW, start = c(1960, 1))
+fm5 <- dynlm(returns ~ L(returns, 1:2) + L(d(dividend), 1:2),
+ data = USStocksSW, start = c(1960, 1))
+fm6 <- dynlm(returns ~ L(returns) + L(dividend),
+ data = USStocksSW, start = c(1960, 1))
+
+
+##################################
+## Price of frozen orange juice ##
+##################################
+
+## load data
+data("FrozenJuice")
+
+## Stock and Watson, p. 594
+library("dynlm")
+fm_dyn <- dynlm(d(100 * log(price/ppi)) ~ fdd, data = FrozenJuice)
+coeftest(fm_dyn, vcov = vcovHC(fm_dyn, type = "HC1"))
+
+## equivalently, returns can be computed 'by hand'
+## (reducing the complexity of the formula notation)
+fj <- ts.union(fdd = FrozenJuice[, "fdd"],
+ ret = 100 * diff(log(FrozenJuice[,"price"]/FrozenJuice[,"ppi"])))
+fm_dyn <- dynlm(ret ~ fdd, data = fj)
+
+## Stock and Watson, p. 595
+fm_dl <- dynlm(ret ~ L(fdd, 0:6), data = fj)
+coeftest(fm_dl, vcov = vcovHC(fm_dl, type = "HC1"))
+
+## Stock and Watson, Table 15.1, p. 620, numbers refer to columns
+## (1) Dynamic Multipliers
+fm1 <- dynlm(ret ~ L(fdd, 0:18), data = fj)
+coeftest(fm1, vcov = NeweyWest(fm1, lag = 7, prewhite = FALSE))
+## (2) Cumulative Multipliers
+fm2 <- dynlm(ret ~ L(d(fdd), 0:17) + L(fdd, 18), data = fj)
+coeftest(fm2, vcov = NeweyWest(fm2, lag = 7, prewhite = FALSE))
+## (3) Cumulative Multipliers, more lags in NW
+coeftest(fm2, vcov = NeweyWest(fm2, lag = 14, prewhite = FALSE))
+## (4) Cumulative Multipliers with monthly indicators
+fm4 <- dynlm(ret ~ L(d(fdd), 0:17) + L(fdd, 18) + season(fdd), data = fj)
+coeftest(fm4, vcov = NeweyWest(fm4, lag = 7, prewhite = FALSE))
+## monthly indicators needed?
+fm4r <- update(fm4, . ~ . - season(fdd))
+waldtest(fm4, fm4r, vcov= NeweyWest(fm4, lag = 7, prewhite = FALSE)) ## close ...
+
+
+#############################################
+## 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))
+}
+
+\keyword{datasets}
diff --git a/man/StrikeDuration.Rd b/man/StrikeDuration.Rd
new file mode 100644
index 0000000..80f469e
--- /dev/null
+++ b/man/StrikeDuration.Rd
@@ -0,0 +1,62 @@
+\name{StrikeDuration}
+\alias{StrikeDuration}
+
+\title{Strike Durations}
+
+\description{
+Data on the duration of strikes in US manufacturing industries, 1968--1976.
+}
+
+\usage{data("StrikeDuration")}
+
+\format{
+A data frame containing 62 observations on 2 variables for the period 1968--1976.
+\describe{
+ \item{duration}{strike duration in days.}
+ \item{uoutput}{unanticipated output (a measure of unanticipated aggregate
+ industrial production net of seasonal and trend components).}
+}
+}
+
+\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 observation 36 is given as 3 by Greene while Kennan has 2. Here we use Greene's version.
+
+\code{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).
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+
+Kennan, J. (1985). The Duration of Contract Strikes in US Manufacturing.
+\emph{Journal of Econometrics}, \bold{28}, 5--28.
+}
+
+\seealso{\code{\link{Greene2003}}}
+
+\examples{
+data("StrikeDuration")
+library("MASS")
+
+## Greene (2003), 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
+
+## Greene (2003), Example 22.10
+library("survival")
+fm_wei <- survreg(Surv(duration) ~ uoutput, dist = "weibull", data = StrikeDuration)
+summary(fm_wei)
+}
+
+\keyword{datasets}
diff --git a/man/SwissLabor.Rd b/man/SwissLabor.Rd
new file mode 100644
index 0000000..2b106be
--- /dev/null
+++ b/man/SwissLabor.Rd
@@ -0,0 +1,49 @@
+\name{SwissLabor}
+\alias{SwissLabor}
+\title{Swiss Labor Market Participation Data}
+\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.
+\describe{
+ \item{participation}{Factor. Did the individual participate in the labor force?}
+ \item{income}{Logarithm of nonlabor income.}
+ \item{age}{Age in decades (years divided by 10).}
+ \item{education}{Years of formal education.}
+ \item{youngkids}{Number of young children (under 7 years of age).}
+ \item{oldkids}{Number of older children (over 7 years of age).}
+ \item{foreign}{Factor. Is the individual a foreigner (i.e., not Swiss)?}
+}
+}
+
+\source{
+Journal of Applied Econometrics Data Archive.
+
+\url{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. \emph{Journal of Applied Econometrics},
+\bold{11}, 321--339.
+}
+
+\examples{
+data("SwissLabor")
+
+### Gerfin (1996), Table I.
+fm_probit <- glm(participation ~ . + I(age^2), data = SwissLabor,
+ family = binomial(link = "probit"))
+summary(fm_probit)
+
+### alternatively
+fm_logit <- glm(participation ~ . + I(age^2), data = SwissLabor,
+ family = binomial)
+summary(fm_logit)
+}
+
+\keyword{datasets}
diff --git a/man/TeachingRatings.Rd b/man/TeachingRatings.Rd
new file mode 100644
index 0000000..8c84669
--- /dev/null
+++ b/man/TeachingRatings.Rd
@@ -0,0 +1,75 @@
+\name{TeachingRatings}
+\alias{TeachingRatings}
+
+\title{Impact of Beauty on Instructor's Teaching Ratings}
+
+\description{
+Data on course evaluations, course characteristics, and professor
+characteristics for 463 courses for the academic years 2000--2002 at the
+University of Texas at Austin.
+}
+\usage{data("TeachingRatings")}
+
+\format{
+A data frame containing 463 observations on 13 variables.
+\describe{
+ \item{minority}{factor. Does the instructor belong to a minority (non-Caucasian)?}
+ \item{age}{the professor's age.}
+ \item{gender}{factor indicating instructor's gender.}
+ \item{credits}{factor. Is the course a single-credit elective (e.g., yoga, aerobics, dance)?}
+ \item{beauty}{rating of the instructor's physical appearance by a panel of six students,
+ averaged across the six panelists, shifted to have a mean of zero.}
+ \item{eval}{course overall teaching evaluation score, on
+ a scale of 1 (very unsatisfactory) to 5 (excellent).}
+ \item{division}{factor. Is the course an upper or lower division course? (Lower division
+ courses are mainly large freshman and sophomore courses)?}
+ \item{native}{factor. Is the instructor a native English speaker?}
+ \item{tenure}{factor. Is the instructor on tenure track?}
+ \item{students}{number of students that participated in the evaluation.}
+ \item{allstudents}{number of students enrolled in the course.}
+ \item{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.
+ \emph{Economics of Education Review}, \bold{24}, 369--376.
+
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+data("TeachingRatings")
+
+## evaluation score vs. beauty
+plot(eval ~ beauty, data = TeachingRatings)
+fm <- lm(eval ~ beauty, data = TeachingRatings)
+abline(fm)
+summary(fm)
+
+## prediction of Stock & Watson's evaluation score
+sw <- with(TeachingRatings, mean(beauty) + c(0, 1) * sd(beauty))
+names(sw) <- c("Watson", "Stock")
+predict(fm, newdata = data.frame(beauty = sw))
+
+## Hamermesh and Parker, 2005, Table 3
+fmw <- lm(eval ~ beauty + gender + minority + native + tenure + division + credits,
+ weights = students, data = TeachingRatings)
+coeftest(fmw, vcov = sandwich)
+## (same coefficients but with different covariances)
+}
+
+\keyword{datasets}
diff --git a/man/TechChange.Rd b/man/TechChange.Rd
new file mode 100644
index 0000000..d6c8852
--- /dev/null
+++ b/man/TechChange.Rd
@@ -0,0 +1,52 @@
+\name{TechChange}
+\alias{TechChange}
+\title{Technological Change Data}
+
+\description{
+US time series data, 1909--1949.
+}
+
+\usage{data("TechChange")}
+
+\format{
+An annual multiple time series from 1909 to 1949 with 3 variables.
+\describe{
+ \item{output}{Output.}
+ \item{clr}{Capital/labor ratio.}
+ \item{technology}{Index of technology.}
+}
+}
+
+\source{
+Online complements to Greene (2003), Table F7.2.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+
+Solow, R. (1957). Technical Change and the Aggregate Production Function.
+\emph{Review of Economics and Statistics}, \bold{39}, 312--320.
+}
+
+\seealso{\code{\link{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)
+
+## Exercise 7.2 (a) and (c)
+plot(I(output/technology) ~ clr, data = TechChange)
+
+library("strucchange")
+sctest(I(output/technology) ~ log(clr), data = TechChange, type = "Chow", point = c(1942, 1))
+}
+
+\keyword{datasets}
diff --git a/man/TradeCredit.Rd b/man/TradeCredit.Rd
new file mode 100644
index 0000000..c938f6f
--- /dev/null
+++ b/man/TradeCredit.Rd
@@ -0,0 +1,43 @@
+\name{TradeCredit}
+\alias{TradeCredit}
+\title{Trade Credit and the Money Market}
+
+\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.
+\describe{
+\item{trade}{Nominal total trade money.}
+\item{reserve}{Nominal effective reserve money.}
+\item{gnp}{GNP in current dollars.}
+\item{utilization}{Degree of market utilization.}
+\item{interest}{Short-term rate of interest.}
+\item{size}{Mean real size of the representative economic unit (1939 = 100).}
+\item{price}{GNP price deflator (1958 = 100).}
+}
+}
+
+\source{
+The data are from Baltagi (2002).
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed. Berlin, Springer.
+
+Laffer, A.B. (1970). Trade Credit and the Money Market. \emph{Journal of Political Economy},
+\bold{78}, 239--267.
+
+}
+
+\seealso{\code{\link{Baltagi2002}}}
+
+\examples{
+data("TradeCredit")
+plot(TradeCredit)
+}
+
+\keyword{datasets}
diff --git a/man/TravelMode.Rd b/man/TravelMode.Rd
new file mode 100644
index 0000000..17eecb6
--- /dev/null
+++ b/man/TravelMode.Rd
@@ -0,0 +1,58 @@
+\name{TravelMode}
+\alias{TravelMode}
+\title{Travel Mode Choice Data}
+
+\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.
+ \describe{
+ \item{individual}{Factor indicating individual with levels \code{1} to \code{200}.}
+ \item{mode}{Factor indicating travel mode with levels
+ \code{"car"}, \code{"air"}, \code{"train"}, or \code{"bus"}.}
+ \item{choice}{Factor indicating choice with levels \code{"no"} and \code{"yes"}.}
+ \item{wait}{Terminal waiting time, 0 for car.}
+ \item{vcost}{Vehicle cost component.}
+ \item{travel}{Travel time in the vehicle.}
+ \item{gcost}{Generalized cost measure.}
+ \item{income}{Household income.}
+ \item{size}{Party size.}
+ }
+}
+
+\source{
+Online complements to Greene (2003).
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}}
+
+\examples{
+data("TravelMode")
+
+## overall proportions for chosen mode
+with(TravelMode, prop.table(table(mode[choice == "yes"])))
+
+## travel vs. waiting time for different travel modes
+library("lattice")
+xyplot(travel ~ wait | mode, data = TravelMode)
+
+## Greene (2003), Table 21.11, conditional logit model
+if(require("mlogit")) {
+TravelMode$incair <- with(TravelMode, income * (mode == "air"))
+tm_cl <- mlogit(choice ~ gcost + wait + incair, data = TravelMode,
+ shape = "long", alt.var = "mode", reflevel = "car")
+summary(tm_cl)
+}
+}
+
+\keyword{datasets}
diff --git a/man/UKInflation.Rd b/man/UKInflation.Rd
new file mode 100644
index 0000000..9cce7f0
--- /dev/null
+++ b/man/UKInflation.Rd
@@ -0,0 +1,36 @@
+\name{UKInflation}
+\alias{UKInflation}
+\title{UK Manufacturing Inflation Data}
+\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.
+\describe{
+\item{actual}{Actual inflation.}
+\item{expected}{Expected inflation.}
+}
+}
+
+\source{
+Online complements to Greene (2003), Table F8.1.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{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. \emph{Economics Letters}, \bold{27}, 341--348.
+}
+
+\seealso{\code{\link{Greene2003}}}
+
+\examples{
+data("UKInflation")
+plot(UKInflation)
+}
+
+\keyword{datasets}
diff --git a/man/UKNonDurables.Rd b/man/UKNonDurables.Rd
new file mode 100644
index 0000000..c32573c
--- /dev/null
+++ b/man/UKNonDurables.Rd
@@ -0,0 +1,53 @@
+\name{UKNonDurables}
+\alias{UKNonDurables}
+\title{Consumption of Non-Durables in the UK}
+\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.
+\emph{International Journal of Forecasting}, \bold{6}, 327--336.
+
+Franses, P.H. (1998). \emph{Time Series Models for Business and Economic Forecasting}.
+Cambridge, UK: Cambridge University Press.
+}
+
+\seealso{\code{\link{Franses1998}}}
+
+\examples{
+data("UKNonDurables")
+plot(UKNonDurables)
+
+## EACF tables (Franses 1998, p. 99)
+ctrafo <- function(x) residuals(lm(x ~ factor(cycle(x))))
+ddiff <- function(x) diff(diff(x, frequency(x)), 1)
+eacf <- function(y, lag = 12) {
+ stopifnot(all(lag > 0))
+ if(length(lag) < 2) lag <- 1:lag
+ rval <- sapply(
+ list(y = y, dy = diff(y), cdy = ctrafo(diff(y)),
+ Dy = diff(y, frequency(y)), dDy = ddiff(y)),
+ function(x) acf(x, plot = FALSE, lag.max = max(lag))$acf[lag + 1])
+ rownames(rval) <- lag
+ return(rval)
+}
+
+## Franses (1998), Table 5.2
+round(eacf(log(UKNonDurables)), digits = 3)
+
+## Franses (1998), Equation 5.51
+## (Franses: sma1 = -0.632 (0.069))
+arima(log(UKNonDurables), c(0, 1, 0), c(0, 1, 1))
+}
+
+\keyword{datasets}
diff --git a/man/USAirlines.Rd b/man/USAirlines.Rd
new file mode 100644
index 0000000..79d67a9
--- /dev/null
+++ b/man/USAirlines.Rd
@@ -0,0 +1,72 @@
+\name{USAirlines}
+\alias{USAirlines}
+
+\title{Cost Data for US Airlines}
+
+\description{
+Cost data for six US airlines in 1970--1984.
+}
+
+\usage{data("USAirlines")}
+
+\format{
+A data frame containing 90 observations on 6 variables.
+\describe{
+ \item{firm}{factor indicating airline firm.}
+ \item{year}{factor indicating year.}
+ \item{output}{output revenue passenger miles index number.}
+ \item{cost}{total cost (in USD 1000).}
+ \item{price}{fuel price.}
+ \item{load}{average capacity utilization of the fleet.}
+}
+}
+
+\source{
+Online complements to Greene (2003). Table F7.1.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}}
+
+\examples{
+data("USAirlines")
+
+## Example 7.2 in Greene (2003)
+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)
+
+## alternatively, use plm()
+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)
+
+## More examples can be found in:
+## help("Greene2003")
+}
+
+\keyword{datasets}
diff --git a/man/USConsump1950.Rd b/man/USConsump1950.Rd
new file mode 100644
index 0000000..9df1089
--- /dev/null
+++ b/man/USConsump1950.Rd
@@ -0,0 +1,65 @@
+\name{USConsump1950}
+\alias{USConsump1950}
+\title{US Consumption Data (1940--1950)}
+
+\description{
+Time series data on US income and consumption expenditure, 1940--1950.
+}
+
+\usage{data("USConsump1950")}
+
+\format{
+An annual multiple time series from 1940 to 1950 with 3 variables.
+ \describe{
+ \item{income}{Disposable income.}
+ \item{expenditure}{Consumption expenditure.}
+ \item{war}{Indicator variable: Was the year a year of war?}
+ }
+}
+
+\source{
+Online complements to Greene (2003). Table F2.1.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}, \code{\link{USConsump1979}}, \code{\link{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)
+
+## different intercepts for war yes/no
+fm2 <- lm(expenditure ~ income + war, data = usc)
+summary(fm2)
+
+## 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
+}
+
+\keyword{datasets}
diff --git a/man/USConsump1979.Rd b/man/USConsump1979.Rd
new file mode 100644
index 0000000..243a143
--- /dev/null
+++ b/man/USConsump1979.Rd
@@ -0,0 +1,39 @@
+\name{USConsump1979}
+\alias{USConsump1979}
+\title{US Consumption Data (1970--1979)}
+\description{
+Time series data on US income and consumption expenditure, 1970--1979.
+}
+\usage{data("USConsump1979")}
+\format{
+An annual multiple time series from 1970 to 1979 with 2 variables.
+\describe{
+ \item{income}{Disposable income.}
+ \item{expenditure}{Consumption expenditure.}
+}
+}
+
+\source{
+Online complements to Greene (2003). Table F1.1.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}, \code{\link{USConsump1950}}, \code{\link{USConsump1993}}}
+
+\examples{
+data("USConsump1979")
+plot(USConsump1979)
+
+## Example 1.1 in Greene (2003)
+plot(expenditure ~ income, data = as.data.frame(USConsump1979), pch = 19)
+fm <- lm(expenditure ~ income, data = as.data.frame(USConsump1979))
+summary(fm)
+abline(fm)
+}
+
+\keyword{datasets}
diff --git a/man/USConsump1993.Rd b/man/USConsump1993.Rd
new file mode 100644
index 0000000..1658503
--- /dev/null
+++ b/man/USConsump1993.Rd
@@ -0,0 +1,81 @@
+\name{USConsump1993}
+\alias{USConsump1993}
+\title{US Consumption Data (1950--1993)}
+\description{
+Time series data on US income and consumption expenditure, 1950--1993.
+}
+\usage{data("USConsump1993")}
+
+\format{
+An annual multiple time series from 1950 to 1993 with 2 variables.
+\describe{
+ \item{income}{Disposable personal income (in 1987 USD).}
+ \item{expenditure}{Personal consumption expenditures (in 1987 USD).}
+}
+}
+
+\source{
+The data is from Baltagi (2002).
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed. Berlin, Springer.
+}
+
+\seealso{\code{\link{Baltagi2002}}, \code{\link{USConsump1950}}, \code{\link{USConsump1979}}}
+
+\examples{
+## data from Baltagi (2002)
+data("USConsump1993", package = "AER")
+plot(USConsump1993, plot.type = "single", col = 1:2)
+
+## Chapter 5 (p. 122-125)
+fm <- lm(expenditure ~ income, data = USConsump1993)
+summary(fm)
+## Durbin-Watson test (p. 122)
+dwtest(fm)
+## Breusch-Godfrey test (Table 5.4, p. 124)
+bgtest(fm)
+## Newey-West standard errors (Table 5.5, p. 125)
+coeftest(fm, vcov = NeweyWest(fm, lag = 3, prewhite = FALSE, adjust = TRUE))
+
+## 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)
+
+## J test for non-nested models
+library("dynlm")
+fm1 <- dynlm(expenditure ~ income + L(income), data = USConsump1993)
+fm2 <- dynlm(expenditure ~ income + L(expenditure), data = USConsump1993)
+jtest(fm1, fm2)
+
+## Chapter 14
+## ACF and PACF for expenditures and first differences
+exps <- USConsump1993[, "expenditure"]
+(acf(exps))
+(pacf(exps))
+(acf(diff(exps)))
+(pacf(diff(exps)))
+
+## dynamic regressions, eq. (14.8)
+fm <- dynlm(d(exps) ~ I(time(exps) - 1949) + L(exps))
+summary(fm)
+}
+
+\keyword{datasets}
diff --git a/man/USCrudes.Rd b/man/USCrudes.Rd
new file mode 100644
index 0000000..9188653
--- /dev/null
+++ b/man/USCrudes.Rd
@@ -0,0 +1,44 @@
+\name{USCrudes}
+\alias{USCrudes}
+\title{US Crudes Data}
+
+\description{
+Cross-section data originating from 99 US oil field postings.
+}
+
+\usage{data("USCrudes")}
+
+\format{
+A data frame containing 99 observations on 3 variables.
+\describe{
+ \item{price}{Crude prices (USD/barrel).}
+ \item{gravity}{Gravity (degree API).}
+ \item{sulphur}{Sulphur (in \%).}
+}
+}
+
+\source{
+The data is from Baltagi (2002).
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed. Berlin, Springer.
+
+}
+
+\seealso{\code{\link{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)
+}
+}
+
+\keyword{datasets}
diff --git a/man/USGasB.Rd b/man/USGasB.Rd
new file mode 100644
index 0000000..b27fc21
--- /dev/null
+++ b/man/USGasB.Rd
@@ -0,0 +1,36 @@
+\name{USGasB}
+\alias{USGasB}
+\title{US Gasoline Market Data (1950--1987, Baltagi)}
+\description{
+Time series data on the US gasoline market.
+}
+\usage{data("USGasB")}
+\format{
+An annual multiple time series from 1950 to 1987 with 6 variables.
+\describe{
+ \item{cars}{Stock of cars.}
+ \item{gas}{Consumption of motor gasoline (in 1000 gallons).}
+ \item{price}{Retail price of motor gasoline.}
+ \item{population}{Population.}
+ \item{gnp}{Real gross national product (in 1982 dollars).}
+ \item{deflator}{GNP deflator (1982 = 100).}
+}
+}
+
+\source{
+The data are from Baltagi (2002).
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed. Berlin, Springer.
+
+}
+
+\seealso{\code{\link{Baltagi2002}}, \code{\link{USGasG}}}
+
+\examples{
+data("USGasB")
+plot(USGasB)
+}
+
+\keyword{datasets}
diff --git a/man/USGasG.Rd b/man/USGasG.Rd
new file mode 100644
index 0000000..bacdbca
--- /dev/null
+++ b/man/USGasG.Rd
@@ -0,0 +1,92 @@
+\name{USGasG}
+\alias{USGasG}
+\title{US Gasoline Market Data (1960--1995, Greene)}
+\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.
+ \describe{
+ \item{gas}{Total US gasoline consumption (computed as
+ total expenditure divided by price index).}
+ \item{price}{Price index for gasoline.}
+ \item{income}{Per capita disposable income.}
+ \item{newcar}{Price index for new cars.}
+ \item{usedcar}{Price index for used cars.}
+ \item{transport}{Price index for public transportation.}
+ \item{durable}{Aggregate price index for consumer durables.}
+ \item{nondurable}{Aggregate price index for consumer nondurables.}
+ \item{service}{Aggregate price index for consumer services.}
+ \item{population}{US total population in millions.}
+ }
+}
+
+\source{
+Online complements to Greene (2003). Table F2.2.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}, \code{\link{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)
+## 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.
+
+## More examples can be found in:
+## help("Greene2003")
+}
+
+\keyword{datasets}
diff --git a/man/USInvest.Rd b/man/USInvest.Rd
new file mode 100644
index 0000000..3a9f431
--- /dev/null
+++ b/man/USInvest.Rd
@@ -0,0 +1,64 @@
+\name{USInvest}
+\alias{USInvest}
+\title{US Investment Data}
+
+\description{
+Time series data on investments in the US, 1968--1982.
+}
+
+\usage{data("USInvest")}
+
+\format{
+An annual multiple time series from 1968 to 1982 with 4 variables.
+ \describe{
+ \item{gnp}{Nominal gross national product,}
+ \item{invest}{Nominal investment,}
+ \item{price}{Consumer price index,}
+ \item{interest}{Interest rate (average yearly discount rate at the New York Federal Reserve Bank).}
+ }
+}
+
+\source{
+Online complements to Greene (2003). Table F3.1.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}}
+
+\examples{
+data("USInvest")
+
+## Chapter 3 in Greene (2003)
+## transform (and round) data to match Table 3.1
+us <- as.data.frame(USInvest)
+us$invest <- round(0.1 * us$invest/us$price, digits = 3)
+us$gnp <- round(0.1 * us$gnp/us$price, digits = 3)
+us$inflation <- c(4.4, round(100 * diff(us$price)/us$price[-15], digits = 2))
+us$trend <- 1:15
+us <- us[, c(2, 6, 1, 4, 5)]
+
+## p. 22-24
+coef(lm(invest ~ trend + gnp, data = us))
+coef(lm(invest ~ gnp, data = us))
+
+## Example 3.1, Table 3.2
+cor(us)[1,-1]
+pcor <- solve(cor(us))
+dcor <- 1/sqrt(diag(pcor))
+pcor <- (-pcor * (dcor \%o\% dcor))[1,-1]
+
+## Table 3.4
+fm <- lm(invest ~ trend + gnp + interest + inflation, data = us)
+fm1 <- lm(invest ~ 1, data = us)
+anova(fm1, fm)
+
+## More examples can be found in:
+## help("Greene2003")
+}
+
+\keyword{datasets}
diff --git a/man/USMacroB.Rd b/man/USMacroB.Rd
new file mode 100644
index 0000000..ff858b7
--- /dev/null
+++ b/man/USMacroB.Rd
@@ -0,0 +1,38 @@
+\name{USMacroB}
+\alias{USMacroB}
+\title{US Macroeconomic Data (1959--1995, Baltagi)}
+
+\description{
+Time series data on 3 US macroeconomic variables for 1959--1995,
+extracted from the Citibank data base.
+}
+
+\usage{data("USMacroB")}
+
+\format{
+A quarterly multiple time series from 1959(1) to 1995(2) with 3 variables.
+\describe{
+ \item{gnp}{Gross national product.}
+ \item{mbase}{Average of the seasonally adjusted monetary base.}
+ \item{tbill}{Average of 3 month treasury-bill rate (per annum).}
+}
+}
+
+\source{
+The data is from Baltagi (2002).
+}
+
+\references{
+Baltagi, B.H. (2002). \emph{Econometrics}, 3rd ed. Berlin, Springer.
+
+}
+
+\seealso{\code{\link{Baltagi2002}}, \code{\link{USMacroSW}}, \code{\link{USMacroSWQ}},
+ \code{\link{USMacroSWM}}, \code{\link{USMacroG}}}
+
+\examples{
+data("USMacroB")
+plot(USMacroB)
+}
+
+\keyword{datasets}
diff --git a/man/USMacroG.Rd b/man/USMacroG.Rd
new file mode 100644
index 0000000..1fb4e5f
--- /dev/null
+++ b/man/USMacroG.Rd
@@ -0,0 +1,86 @@
+\name{USMacroG}
+\alias{USMacroG}
+\title{US Macroeconomic Data (1950--2000, Greene)}
+
+\description{
+Time series data on 12 US macroeconomic variables for 1950--2000.
+}
+
+\usage{data("USMacroG")}
+
+\format{
+A quarterly multiple time series from 1950(1) to 2000(4) with 12 variables.
+ \describe{
+ \item{gdp}{Real gross domestic product (in billion USD),}
+ \item{consumption}{Real consumption expenditures,}
+ \item{invest}{Real investment by private sector,}
+ \item{government}{Real government expenditures,}
+ \item{dpi}{Real disposable personal income,}
+ \item{cpi}{Consumer price index,}
+ \item{m1}{Nominal money stock,}
+ \item{tbill}{Quarterly average of month end 90 day treasury bill rate,}
+ \item{unemp}{Unemployment rate,}
+ \item{population}{Population (in million), interpolation of year end figures
+ using constant growth rate per quarter,}
+ \item{inflation}{Inflation rate,}
+ \item{interest}{Ex post real interest rate (essentially, \code{tbill - inflation}).}
+ }
+}
+
+\source{
+Online complements to Greene (2003). Table F5.1.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}, \code{\link{USMacroSW}}, \code{\link{USMacroSWQ}},
+ \code{\link{USMacroSWM}}, \code{\link{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)
+
+## Cox test in both directions:
+coxtest(fm1, fm2)
+## ...and do the same for jtest() and encomptest().
+## Notice that in this particular case two of them are coincident.
+jtest(fm1, fm2)
+encomptest(fm1, fm2)
+## encomptest could also be performed `by hand' via
+fmE <- dynlm(consumption ~ dpi + L(dpi) + L(consumption), data = USMacroG)
+waldtest(fm1, fmE, fm2)
+
+## More examples can be found in:
+## help("Greene2003")
+}
+
+\keyword{datasets}
diff --git a/man/USMacroSW.Rd b/man/USMacroSW.Rd
new file mode 100644
index 0000000..4d354d7
--- /dev/null
+++ b/man/USMacroSW.Rd
@@ -0,0 +1,88 @@
+\name{USMacroSW}
+\alias{USMacroSW}
+\title{US Macroeconomic Data (1957--2005, Stock \& Watson)}
+
+\description{
+Time series data on 7 (mostly) US macroeconomic variables for 1957--2005.
+}
+
+\usage{data("USMacroSW")
+}
+
+\format{
+A quarterly multiple time series from 1957(1) to 2005(1) with 7 variables.
+ \describe{
+ \item{unemp}{Unemployment rate.}
+ \item{cpi}{Consumer price index.}
+ \item{ffrate}{Federal funds interest rate.}
+ \item{tbill}{3-month treasury bill interest rate.}
+ \item{tbond}{1-year treasury bond interest rate.}
+ \item{gbpusd}{GBP/USD exchange rate (US dollar in cents per British pound).}
+ \item{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 BLS's Current Population. The quarterly data
+used here were computed by averaging the monthly values. The interest data are the
+monthly average of daily rates as reported by the Federal Reserve and the dollar-pound
+exchange rate data are the monthly average of daily rates; both are for the final month in
+the quarter. Japanese real GDP data were obtained from the OECD.
+}
+
+
+\source{
+Online complements to Stock and Watson (2007).
+}
+
+\references{
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}, \code{\link{USMacroSWM}}, \code{\link{USMacroSWQ}},
+ \code{\link{USMacroB}}, \code{\link{USMacroG}}}
+
+\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")
+
+## Equations 14.7, 14.13, 14.16, 14.17, pp. 536
+fm_ar1 <- dynlm(d(infl) ~ L(d(infl)),
+ data = usm, start = c(1962,1), end = c(2004,4))
+fm_ar4 <- dynlm(d(infl) ~ L(d(infl), 1:4),
+ data = usm, start = c(1962,1), end = c(2004,4))
+fm_adl41 <- dynlm(d(infl) ~ L(d(infl), 1:4) + L(unemp),
+ data = usm, start = c(1962,1), end = c(2004,4))
+fm_adl44 <- dynlm(d(infl) ~ L(d(infl), 1:4) + L(unemp, 1:4),
+ data = usm, start = c(1962,1), end = c(2004,4))
+coeftest(fm_ar1, vcov = sandwich)
+coeftest(fm_ar4, vcov = sandwich)
+coeftest(fm_adl41, vcov = sandwich)
+coeftest(fm_adl44, vcov = sandwich)
+
+## Granger causality test mentioned on p. 547
+waldtest(fm_ar4, fm_adl44, vcov = sandwich)
+
+## Figure 14.5, p. 570
+## SW perform partial break test of unemp coefs
+## here full model is used
+mf <- model.frame(fm_adl44) ## re-use fm_adl44
+mf <- ts(as.matrix(mf), start = c(1962, 1), freq = 4)
+colnames(mf) <- c("y", paste("x", 1:8, sep = ""))
+ff <- as.formula(paste("y", "~", paste("x", 1:8, sep = "", collapse = " + ")))
+fs <- Fstats(ff, data = mf, from = 0.1)
+plot(fs)
+lines(boundary(fs, alpha = 0.01), lty = 2, col = 2)
+lines(boundary(fs, alpha = 0.1), lty = 3, col = 2)
+
+## More examples can be found in:
+## help("StockWatson2007")
+}
+
+\keyword{datasets}
diff --git a/man/USMacroSWM.Rd b/man/USMacroSWM.Rd
new file mode 100644
index 0000000..4b5cd22
--- /dev/null
+++ b/man/USMacroSWM.Rd
@@ -0,0 +1,37 @@
+\name{USMacroSWM}
+\alias{USMacroSWM}
+
+\title{Monthly US Macroeconomic Data (1947--2004, Stock \& Watson)}
+
+\description{
+Time series data on 4 US macroeconomic variables for 1947--2004.
+}
+\usage{data("USMacroSWM")}
+
+\format{
+A monthly multiple time series from 1947(1) to 2004(4) with 4 variables.
+\describe{
+ \item{production}{index of industrial production.}
+ \item{oil}{oil price shocks, starting 1948(1).}
+ \item{cpi}{all-items consumer price index.}
+ \item{expenditure}{personal consumption expenditures price deflator, starting 1959(1).}
+ }
+}
+
+\source{
+Online complements to Stock and Watson (2007).
+}
+
+\references{
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}, \code{\link{USMacroSW}}, \code{\link{USMacroSWQ}},
+ \code{\link{USMacroB}}, \code{\link{USMacroG}}}
+
+\examples{
+data("USMacroSWM")
+plot(USMacroSWM)
+}
+
+\keyword{datasets}
diff --git a/man/USMacroSWQ.Rd b/man/USMacroSWQ.Rd
new file mode 100644
index 0000000..33f6433
--- /dev/null
+++ b/man/USMacroSWQ.Rd
@@ -0,0 +1,37 @@
+\name{USMacroSWQ}
+\alias{USMacroSWQ}
+
+\title{Quarterly US Macroeconomic Data (1947--2004, Stock \& Watson)}
+
+\description{
+Time series data on 2 US macroeconomic variables for 1947--2004.
+}
+\usage{data("USMacroSWQ")}
+
+\format{
+A quarterly multiple time series from 1947(1) to 2004(4) with 2 variables.
+\describe{
+ \item{gdp}{real GDP for the United States in billions of chained (2000) dollars
+ seasonally adjusted, annual rate.}
+ \item{tbill}{3-month treasury bill rate. Quarterly averages of daily dates
+ in percentage points at an annual rate.}
+ }
+}
+
+\source{
+Online complements to Stock and Watson (2007).
+}
+
+\references{
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}, \code{\link{USMacroSW}}, \code{\link{USMacroSWM}},
+ \code{\link{USMacroB}}, \code{\link{USMacroG}}}
+
+\examples{
+data("USMacroSWQ")
+plot(USMacroSWQ)
+}
+
+\keyword{datasets}
diff --git a/man/USMoney.Rd b/man/USMoney.Rd
new file mode 100644
index 0000000..9678c8b
--- /dev/null
+++ b/man/USMoney.Rd
@@ -0,0 +1,38 @@
+\name{USMoney}
+\alias{USMoney}
+
+\title{USMoney}
+
+\description{
+Money, output and price deflator time series data, 1950--1983.
+}
+
+\usage{data("USMoney")}
+
+\format{
+A quarterly multiple time series from 1950 to 1983 with 3 variables.
+\describe{
+ \item{gnp}{nominal GNP.}
+ \item{m1}{M1 measure of money stock.}
+ \item{deflator}{implicit price deflator for GNP.}
+}
+}
+
+\source{
+Online complements to Greene (2003), Table F20.2.
+
+\url{http://pages.stern.nyu.edu/~wgreene/Text/tables/tablelist5.htm}
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+}
+
+\seealso{\code{\link{Greene2003}}}
+
+\examples{
+data("USMoney")
+plot(USMoney)
+}
+
+\keyword{datasets}
diff --git a/man/USProdIndex.Rd b/man/USProdIndex.Rd
new file mode 100644
index 0000000..b9ae052
--- /dev/null
+++ b/man/USProdIndex.Rd
@@ -0,0 +1,54 @@
+\name{USProdIndex}
+\alias{USProdIndex}
+\title{Index of US Industrial Production}
+\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.
+\describe{
+ \item{unadjusted}{raw index of industrial production,}
+ \item{adjusted}{seasonally adjusted index.}
+}
+}
+
+\source{
+Online complements to Franses (1998).
+}
+
+\references{
+Franses, P.H. (1998). \emph{Time Series Models for Business and Economic Forecasting}.
+Cambridge, UK: Cambridge University Press.
+}
+
+\seealso{\code{\link{Franses1998}}}
+
+\examples{
+data("USProdIndex")
+plot(USProdIndex, plot.type = "single", col = 1:2)
+
+## EACF tables (Franses 1998, p. 99)
+ctrafo <- function(x) residuals(lm(x ~ factor(cycle(x))))
+ddiff <- function(x) diff(diff(x, frequency(x)), 1)
+eacf <- function(y, lag = 12) {
+ stopifnot(all(lag > 0))
+ if(length(lag) < 2) lag <- 1:lag
+ rval <- sapply(
+ list(y = y, dy = diff(y), cdy = ctrafo(diff(y)),
+ Dy = diff(y, frequency(y)), dDy = ddiff(y)),
+ function(x) acf(x, plot = FALSE, lag.max = max(lag))$acf[lag + 1])
+ rownames(rval) <- lag
+ return(rval)
+}
+
+## Franses (1998), Table 5.1
+round(eacf(log(USProdIndex[,1])), digits = 3)
+
+## Franses (1998), Equation 5.6: Unrestricted airline model
+## (Franses: ma1 = 0.388 (0.063), ma4 = -0.739 (0.060), ma5 = -0.452 (0.069))
+arima(log(USProdIndex[,1]), c(0, 1, 5), c(0, 1, 0), fixed = c(NA, 0, 0, NA, NA))
+}
+
+\keyword{datasets}
diff --git a/man/USSeatBelts.Rd b/man/USSeatBelts.Rd
new file mode 100644
index 0000000..0883297
--- /dev/null
+++ b/man/USSeatBelts.Rd
@@ -0,0 +1,59 @@
+\name{USSeatBelts}
+\alias{USSeatBelts}
+
+\title{Effects of Mandatory Seat Belt Laws in the US}
+
+\description{
+Balanced panel data for the years 1983--1997 from 50 US States, plus the District of Columbia,
+for assessing traffic fatalities and seat belt usage.
+}
+
+\usage{data("USSeatBelts")}
+
+\format{
+A data frame containing 765 observations on 12 variables.
+\describe{
+ \item{state}{factor indicating US state (abbreviation).}
+ \item{year}{factor indicating year.}
+ \item{miles}{millions of traffic miles per year.}
+ \item{fatalities}{number of fatalities per million of traffic miles
+ (absolute frequencies of fatalities = \code{fatalities} times \code{miles}).}
+ \item{seatbelt}{seat belt usage rate, as self-reported by state population surveyed.}
+ \item{speed65}{factor. Is there a 65 mile per hour speed limit?}
+ \item{speed70}{factor. Is there a 70 (or higher) mile per hour speed limit?}
+ \item{drinkage}{factor. Is there a minimum drinking age of 21 years?}
+ \item{alcohol}{factor. Is there a maximum of 0.08 blood alcohol content?}
+ \item{income}{median per capita income (in current US dollar).}
+ \item{age}{mean age.}
+ \item{enforce}{factor indicating seat belt law enforcement
+ (\code{"no"}, \code{"primary"}, \code{"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).
+}
+
+\references{
+Cohen, A., and Einav, L. (2003). The Effects of Mandatory Seat Belt Laws on Driving
+Behavior and Traffic Fatalities.
+\emph{The Review of Economics and Statistics}, \bold{85}, 828--843
+
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+data("USSeatBelts")
+summary(USSeatBelts)
+
+library("lattice")
+xyplot(fatalities ~ as.numeric(as.character(year)) | state, data = USSeatBelts, type = "l")
+}
+
+\keyword{datasets}
diff --git a/man/USStocksSW.Rd b/man/USStocksSW.Rd
new file mode 100644
index 0000000..aa2f2de
--- /dev/null
+++ b/man/USStocksSW.Rd
@@ -0,0 +1,59 @@
+\name{USStocksSW}
+\alias{USStocksSW}
+
+\title{Monthly US Stock Returns (1931--2002, Stock \& Watson)}
+
+\description{
+Monthly data from 1931--2002 for US stock prices, measured by the
+broad-based (NYSE and AMEX) value-weighted index of stock prices as
+constructed by the Center for Research in Security Prices (CRSP).
+}
+
+\usage{data("USStocksSW")}
+
+\format{
+A monthly multiple time series from 1931(1) to 2002(12) with 2 variables.
+\describe{
+ \item{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.}
+ \item{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).
+}
+
+\references{
+Campbell, J.Y., and Yogo, M. (2006). Efficient Tests of Stock Return Predictability
+\emph{Journal of Financial Economics}, \bold{81}, 27--60.
+
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+data("USStocksSW")
+plot(USStocksSW)
+
+## Stock and Watson, p. 540, Table 14.3
+library("dynlm")
+fm1 <- dynlm(returns ~ L(returns), data = USStocksSW, start = c(1960,1))
+coeftest(fm1, vcov = sandwich)
+fm2 <- dynlm(returns ~ L(returns, 1:2), data = USStocksSW, start = c(1960,1))
+waldtest(fm2, vcov = sandwich)
+fm3 <- dynlm(returns ~ L(returns, 1:4), data = USStocksSW, start = c(1960,1))
+waldtest(fm3, vcov = sandwich)
+
+## Stock and Watson, p. 574, Table 14.7
+fm4 <- dynlm(returns ~ L(returns) + L(d(dividend)), data = USStocksSW, start = c(1960, 1))
+fm5 <- dynlm(returns ~ L(returns, 1:2) + L(d(dividend), 1:2), data = USStocksSW, start = c(1960,1))
+fm6 <- dynlm(returns ~ L(returns) + L(dividend), data = USStocksSW, start = c(1960,1))
+}
+
+\keyword{datasets}
diff --git a/man/WeakInstrument.Rd b/man/WeakInstrument.Rd
new file mode 100644
index 0000000..ed5fdb4
--- /dev/null
+++ b/man/WeakInstrument.Rd
@@ -0,0 +1,37 @@
+\name{WeakInstrument}
+\alias{WeakInstrument}
+
+\title{Artificial Weak Instrument Data}
+
+\description{
+Artificial data set to illustrate the problem of weak instruments.
+}
+
+\usage{data("WeakInstrument")}
+
+\format{
+A data frame containing 200 observations on 3 variables.
+\describe{
+ \item{y}{dependent variable.}
+ \item{x}{regressor variable.}
+ \item{z}{instrument variable.}
+}
+}
+
+\source{
+Online complements to Stock and Watson (2007).
+}
+
+\references{
+Stock, J.H. and Watson, M.W. (2007). \emph{Introduction to Econometrics}, 2nd ed. Boston: Addison Wesley.
+}
+
+\seealso{\code{\link{StockWatson2007}}}
+
+\examples{
+data("WeakInstrument")
+fm <- ivreg(y ~ x | z, data = WeakInstrument)
+summary(fm)
+}
+
+\keyword{datasets}
diff --git a/man/WinkelmannBoes2009.Rd b/man/WinkelmannBoes2009.Rd
new file mode 100644
index 0000000..a342b62
--- /dev/null
+++ b/man/WinkelmannBoes2009.Rd
@@ -0,0 +1,366 @@
+\name{WinkelmannBoes2009}
+\alias{WinkelmannBoes2009}
+
+\title{Data and Examples from Winkelmann and Boes (2009)}
+
+\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). \emph{Analysis of Microdata}, 2nd ed. Berlin and Heidelberg: Springer-Verlag.
+}
+
+\seealso{\code{\link{GSS7402}}, \code{\link{GSOEP9402}}, \code{\link{PSID1976}}}
+
+\examples{
+#########################################
+## US General Social Survey 1974--2002 ##
+#########################################
+
+## data
+data("GSS7402", package = "AER")
+
+## completed fertility subset
+gss40 <- subset(GSS7402, age >= 40)
+
+
+## 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)
+
+
+## Chapter 3, Example 3.14
+## Table 3.1
+gss40$nokids <- factor(gss40$kids <= 0,
+ levels = c(FALSE, TRUE), labels = c("no", "yes"))
+nokids_p1 <- glm(nokids ~ 1, data = gss40, family = binomial(link = "probit"))
+nokids_p2 <- glm(nokids ~ trend, data = gss40, family = binomial(link = "probit"))
+nokids_p3 <- glm(nokids ~ trend + education + ethnicity + siblings,
+ data = gss40, family = binomial(link = "probit"))
+
+## p. 87
+lrtest(nokids_p1, nokids_p2, nokids_p3)
+
+## Chapter 4, Example 4.1
+gss40$nokids01 <- as.numeric(gss40$nokids) - 1
+nokids_lm3 <- lm(nokids01 ~ trend + education + ethnicity + siblings, data = gss40)
+coeftest(nokids_lm3, vcov = sandwich)
+
+## Example 4.3
+## Table 4.1
+nokids_l1 <- glm(nokids ~ 1, data = gss40, family = binomial(link = "logit"))
+nokids_l3 <- glm(nokids ~ trend + education + ethnicity + siblings,
+ data = gss40, family = binomial(link = "logit"))
+lrtest(nokids_p3)
+lrtest(nokids_l3)
+
+## Table 4.2
+nokids_xbar <- colMeans(model.matrix(nokids_l3))
+sum(coef(nokids_p3) * nokids_xbar)
+sum(coef(nokids_l3) * nokids_xbar)
+dnorm(sum(coef(nokids_p3) * nokids_xbar))
+dlogis(sum(coef(nokids_l3) * nokids_xbar))
+dnorm(sum(coef(nokids_p3) * nokids_xbar)) * coef(nokids_p3)[3]
+dlogis(sum(coef(nokids_l3) * nokids_xbar)) * coef(nokids_l3)[3]
+exp(coef(nokids_l3)[3])
+
+## Figure 4.4
+## everything by hand (for ethnicity = "cauc" group)
+nokids_xbar <- as.vector(nokids_xbar)
+nokids_nd <- data.frame(education = seq(0, 20, by = 0.5), trend = nokids_xbar[2],
+ ethnicity = "cauc", siblings = nokids_xbar[4])
+nokids_p3_fit <- predict(nokids_p3, newdata = nokids_nd,
+ type = "response", se.fit = TRUE)
+plot(nokids_nd$education, nokids_p3_fit$fit, type = "l",
+ xlab = "education", ylab = "predicted probability", ylim = c(0, 0.3))
+polygon(c(nokids_nd$education, rev(nokids_nd$education)),
+ c(nokids_p3_fit$fit + 1.96 * nokids_p3_fit$se.fit,
+ rev(nokids_p3_fit$fit - 1.96 * nokids_p3_fit$se.fit)),
+ col = "lightgray", border = "lightgray")
+lines(nokids_nd$education, nokids_p3_fit$fit)
+
+## using "effects" package (for average "ethnicity" variable)
+library("effects")
+nokids_p3_ef <- effect("education", nokids_p3, xlevels = list(education = 0:20))
+plot(nokids_p3_ef, rescale.axis = FALSE, ylim = c(0, 0.3))
+
+## using "effects" plus modification by hand
+nokids_p3_ef1 <- as.data.frame(nokids_p3_ef)
+plot(pnorm(fit) ~ education, data = nokids_p3_ef1, type = "n", ylim = c(0, 0.3))
+polygon(c(0:20, 20:0), pnorm(c(nokids_p3_ef1$upper, rev(nokids_p3_ef1$lower))),
+ col = "lightgray", border = "lightgray")
+lines(pnorm(fit) ~ education, data = nokids_p3_ef1)
+
+## Table 4.6
+## McFadden's R^2
+1 - as.numeric( logLik(nokids_p3) / logLik(nokids_p1) )
+1 - as.numeric( logLik(nokids_l3) / logLik(nokids_l1) )
+## McKelvey and Zavoina R^2
+r2mz <- function(obj) {
+ ystar <- predict(obj)
+ sse <- sum((ystar - mean(ystar))^2)
+ s2 <- switch(obj$family$link, "probit" = 1, "logit" = pi^2/3, NA)
+ n <- length(residuals(obj))
+ sse / (n * s2 + sse)
+}
+r2mz(nokids_p3)
+r2mz(nokids_l3)
+## AUC
+library("ROCR")
+nokids_p3_pred <- prediction(fitted(nokids_p3), gss40$nokids)
+nokids_l3_pred <- prediction(fitted(nokids_l3), gss40$nokids)
+plot(performance(nokids_p3_pred, "tpr", "fpr"))
+abline(0, 1, lty = 2)
+performance(nokids_p3_pred, "auc")
+plot(performance(nokids_l3_pred, "tpr", "fpr"))
+abline(0, 1, lty = 2)
+performance(nokids_l3_pred, "auc")@y.values
+
+## Chapter 7
+## Table 7.3
+## subset selection
+gss02 <- subset(GSS7402, year == 2002 & (age < 40 | !is.na(agefirstbirth)))
+#Z# This selection conforms with top of page 229. However, there
+#Z# are too many observations: 1374. Furthermore, there are six
+#Z# observations with agefirstbirth <= 14 which will cause problems in
+#Z# taking logs!
+
+## computing time to first birth
+gss02$tfb <- with(gss02, ifelse(is.na(agefirstbirth), age - 14, agefirstbirth - 14))
+#Z# currently this is still needed before taking logs
+gss02$tfb <- pmax(gss02$tfb, 1)
+
+tfb_tobit <- tobit(log(tfb) ~ education + ethnicity + siblings + city16 + immigrant,
+ data = gss02, left = -Inf, right = log(gss02$age - 14))
+tfb_ols <- lm(log(tfb) ~ education + ethnicity + siblings + city16 + immigrant,
+ data = gss02, subset = !is.na(agefirstbirth))
+
+## 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,
+ data = gss2002, dist = "lognormal")
+
+## Example 8.11
+kids_pois <- glm(kids ~ education + trend + ethnicity + immigrant + lowincome16 + city16,
+ data = gss40, family = poisson)
+library("MASS")
+kids_nb <- glm.nb(kids ~ education + trend + ethnicity + immigrant + lowincome16 + city16,
+ data = gss40)
+lrtest(kids_pois, kids_nb)
+
+
+############################################
+## German Socio-Economic Panel 1994--2002 ##
+############################################
+
+## data
+data("GSOEP9402", package = "AER")
+
+## some convenience data transformations
+gsoep <- GSOEP9402
+gsoep$meducation2 <- cut(gsoep$meducation, breaks = c(6, 10.25, 12.25, 18),
+ labels = c("7-10", "10.5-12", "12.5-18"))
+gsoep$year2 <- factor(gsoep$year)
+
+## 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
+plot(gsoep_eff, confint = FALSE)
+
+## Table 5.3, odds
+exp(coef(gsoep_mnl)[, "meducation"])
+
+## 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")
+
+plot(jitter(hours, 200) ~ jitter(wage, 50), data = PSID1976,
+ xlab = "Wife's average hourly wage (jittered)",
+ ylab = "Hours of work in 1975 (jittered)")
+
+## 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")
+
+## Example 7.10, Table 7.4
+wage_ols <- lm(log(wage) ~ education + experience + I(experience^2),
+ 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)
+
+## Table 5.6 (model 3 probably not fully converged in W&B)
+crack$price <- crack$price/100
+crack_mlogit1 <- mlogit(choice ~ price | 0, data = crack, reflevel = "private")
+crack_mlogit2 <- mlogit(choice ~ price | 1, data = crack, reflevel = "private")
+crack_mlogit3 <- mlogit(choice ~ price + feat + disp | 1, data = crack,
+ reflevel = "private")
+lrtest(crack_mlogit1, crack_mlogit2, crack_mlogit3)
+
+## 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)
+}
+}
+
+\keyword{datasets}
diff --git a/man/dispersiontest.Rd b/man/dispersiontest.Rd
new file mode 100644
index 0000000..b309ef6
--- /dev/null
+++ b/man/dispersiontest.Rd
@@ -0,0 +1,84 @@
+\name{dispersiontest}
+\alias{dispersiontest}
+\title{Dispersion Test}
+\description{
+ Tests the null hypothesis of equidispersion in Poisson GLMs against
+ the alternative of overdispersion and/or underdispersion.
+}
+\usage{
+dispersiontest(object, trafo = NULL, alternative = c("greater", "two.sided", "less"))
+}
+\arguments{
+ \item{object}{a fitted Poisson GLM of class \code{"glm"} as fitted
+ by \code{\link{glm}} with family \code{\link{poisson}}.}
+ \item{trafo}{a specification of the alternative (see also details),
+ can be numeric or a (positive) function or \code{NULL} (the default).}
+ \item{alternative}{a character string specifying the alternative hypothesis:
+ \code{"greater"} corresponds to overdispersion, \code{"less"} to
+ underdispersion and \code{"two.sided"} to either one.}
+}
+\details{
+The standard Poisson GLM models the (conditional) mean
+\eqn{\mathsf{E}[y] = \mu}{E[y] = mu} which is assumed to be equal to the
+variance \eqn{\mathsf{VAR}[y] = \mu}{VAR[y] = mu}. \code{dispersiontest}
+assesses the hypothesis that this assumption holds (equidispersion) against
+the alternative that the variance is of the form:
+ \deqn{\mathsf{VAR}[y] \quad = \quad \mu \; + \; \alpha \cdot \mathrm{trafo}(\mu).}{VAR[y] = mu + alpha * trafo(mu).}
+Overdispersion corresponds to \eqn{\alpha > 0}{alpha > 0} and underdispersion to
+\eqn{\alpha < 0}{alpha < 0}. The coefficient \eqn{\alpha}{alpha} can be estimated
+by an auxiliary OLS regression and tested with the corresponding t (or z) statistic
+which is asymptotically standard normal under the null hypothesis.
+
+Common specifications of the transformation function \eqn{\mathrm{trafo}}{trafo} are
+\eqn{\mathrm{trafo}(\mu) = \mu^2}{trafo(mu) = mu^2} or \eqn{\mathrm{trafo}(\mu) = \mu}{trafo(mu) = mu}.
+The former corresponds to a negative binomial (NB) model with quadratic variance function
+(called NB2 by Cameron and Trivedi, 2005), the latter to a NB model with linear variance
+function (called NB1 by Cameron and Trivedi, 2005) or quasi-Poisson model with dispersion
+parameter, i.e.,
+ \deqn{\mathsf{VAR}[y] \quad = \quad (1 + \alpha) \cdot \mu = \mathrm{dispersion} \cdot \mu.}{VAR[y] = (1 + alpha) * mu = dispersion * mu.}
+By default, for \code{trafo = NULL}, the latter dispersion formulation is used in
+\code{dispersiontest}. Otherwise, if \code{trafo} is specified, the test is formulated
+in terms of the parameter \eqn{\alpha}{alpha}. The transformation \code{trafo} can either
+be specified as a function or an integer corresponding to the function \code{function(x) x^trafo},
+such that \code{trafo = 1} and \code{trafo = 2} yield the linear and quadratic formulations
+respectively.
+}
+
+\value{An object of class \code{"htest"}.}
+
+\references{
+Cameron, A.C. and Trivedi, P.K. (1990). Regression-based Tests for Overdispersion in the Poisson Model.
+\emph{Journal of Econometrics}, \bold{46}, 347--364.
+
+Cameron, A.C. and Trivedi, P.K. (1998). \emph{Regression Analysis of Count Data}.
+Cambridge: Cambridge University Press.
+
+Cameron, A.C. and Trivedi, P.K. (2005). \emph{Microeconometrics: Methods and Applications}.
+Cambridge: Cambridge University Press.
+}
+
+\seealso{\code{\link{glm}}, \code{\link{poisson}}, \code{\link[MASS]{glm.nb}}}
+
+\examples{
+data("RecreationDemand")
+rd <- glm(trips ~ ., data = RecreationDemand, family = poisson)
+
+## linear specification (in terms of dispersion)
+dispersiontest(rd)
+## linear specification (in terms of alpha)
+dispersiontest(rd, trafo = 1)
+## quadratic specification (in terms of alpha)
+dispersiontest(rd, trafo = 2)
+dispersiontest(rd, trafo = function(x) x^2)
+
+## 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)
+}
+\keyword{htest}
diff --git a/man/ivreg.Rd b/man/ivreg.Rd
new file mode 100644
index 0000000..8ffa08c
--- /dev/null
+++ b/man/ivreg.Rd
@@ -0,0 +1,109 @@
+\name{ivreg}
+\alias{ivreg}
+\alias{print.ivreg}
+
+\title{Instrumental-Variable Regression}
+\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, \dots)
+}
+
+\arguments{
+ \item{formula, instruments}{formula specification(s) of the regression
+ relationship and the instruments. Either \code{instruments} is missing and
+ \code{formula} has three parts as in \code{y ~ x1 + x2 | z1 + z2 + z3}
+ (recommended) or \code{formula} is \code{y ~ x1 + x2} and \code{instruments}
+ is a one-sided formula \code{~ z1 + z2 + z3} (only for backward compatibility).}
+ \item{data}{an optional data frame containing the variables in the model.
+ By default the variables are taken from the environment of the \code{formula}.}
+ \item{subset}{an optional vector specifying a subset of observations to be used in
+ fitting the model.}
+ \item{na.action}{a function that indicates what should happen when the
+ data contain \code{NA}s. The default is set by the \code{na.action} option.}
+ \item{weights}{an optional vector of weights to be used in the fitting process.}
+ \item{offset}{an optional offset that can be used to specify an a priori known
+ component to be included during fitting.}
+ \item{contrasts}{an optional list. See the \code{contrasts.arg} of
+ \code{\link[stats:model.matrix]{model.matrix.default}}.}
+ \item{model, x, y}{logicals. If \code{TRUE} the corresponding components of
+ the fit (the model frame, the model matrices , the response) are returned.}
+ \item{\dots}{further arguments passed to \code{\link{ivreg.fit}}.}
+}
+
+\details{
+\code{ivreg} is the high-level interface to the work-horse function \code{\link{ivreg.fit}},
+a set of standard methods (including \code{print}, \code{summary}, \code{vcov}, \code{anova},
+\code{hatvalues}, \code{predict}, \code{terms}, \code{model.matrix}, \code{bread},
+\code{estfun}) is available and described on \code{\link{summary.ivreg}}.
+
+Regressors and instruments for \code{ivreg} are most easily specified in a formula
+with two parts on the right-hand side, e.g., \code{y ~ x1 + x2 | z1 + z2 + z3},
+where \code{x1} and \code{x2} are the regressors and \code{z1},
+\code{z2}, and \code{z3} are the instruments. Note that exogenous
+regressors have to be included as instruments for themselves. For
+example, if there is one exogenous regressor \code{ex} and one endogenous
+regressor \code{en} with instrument \code{in}, the appropriate formula
+would be \code{y ~ ex + en | ex + in}. Equivalently, this can be specified as
+\code{y ~ ex + en | . - en + in}, i.e., by providing an update formula with a
+\code{.} in the second part of the formula. The latter is typically more convenient,
+if there is a large number of exogenous regressors.
+}
+
+\value{
+ \code{ivreg} returns an object of class \code{"ivreg"}, with the following components:
+ \item{coefficients}{parameter estimates.}
+ \item{residuals}{a vector of residuals.}
+ \item{fitted.values}{a vector of predicted means.}
+ \item{weights}{either the vector of weights used (if any) or \code{NULL} (if none).}
+ \item{offset}{either the offset used (if any) or \code{NULL} (if none).}
+ \item{n}{number of observations.}
+ \item{nobs}{number of observations with non-zero weights.}
+ \item{rank}{the numeric rank of the fitted linear model.}
+ \item{df.residual}{residual degrees of freedom for fitted model.}
+ \item{cov.unscaled}{unscaled covariance matrix for the coefficients.}
+ \item{sigma}{residual standard error.}
+ \item{call}{the original function call.}
+ \item{formula}{the model formula.}
+ \item{terms}{a list with elements \code{"regressors"} and \code{"instruments"}
+ containing the terms objects for the respective components.}
+ \item{levels}{levels of the categorical regressors.}
+ \item{contrasts}{the contrasts used for categorical regressors.}
+ \item{model}{the full model frame (if \code{model = TRUE}).}
+ \item{y}{the response vector (if \code{y = TRUE}).}
+ \item{x}{a list with elements \code{"regressors"}, \code{"instruments"}, \code{"projected"},
+ containing the model matrices from the respective components
+ (if \code{x = TRUE}). \code{"projected"} is the matrix of regressors projected
+ on the image of the instruments.}
+}
+
+\references{
+ Greene, W. H. (1993)
+ \emph{Econometric Analysis}, 2nd ed., Macmillan.
+}
+
+\seealso{\code{\link{ivreg.fit}}, \code{\link[stats]{lm}}, \code{\link[stats:lmfit]{lm.fit}}}
+
+\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)
+}
+
+\keyword{regression}
diff --git a/man/ivreg.fit.Rd b/man/ivreg.fit.Rd
new file mode 100644
index 0000000..c2887d3
--- /dev/null
+++ b/man/ivreg.fit.Rd
@@ -0,0 +1,72 @@
+\name{ivreg.fit}
+\alias{ivreg.fit}
+
+\title{Fitting Instrumental-Variable Regressions}
+\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, \dots)
+}
+
+\arguments{
+ \item{x}{regressor matrix.}
+ \item{y}{vector with dependent variable.}
+ \item{z}{instruments matrix.}
+ \item{weights}{an optional vector of weights to be used in the fitting process.}
+ \item{offset}{an optional offset that can be used to specify an a priori known
+ component to be included during fitting.}
+ \item{\dots}{further arguments passed to \code{\link[stats:lmfit]{lm.fit}} or
+ \code{link[stats]{lm.wfit}}, respectively.}
+}
+
+\details{
+\code{\link{ivreg}} is the high-level interface to the work-horse function \code{ivreg.fit},
+a set of standard methods (including \code{summary}, \code{vcov}, \code{anova},
+\code{hatvalues}, \code{predict}, \code{terms}, \code{model.matrix}, \code{bread},
+\code{estfun}) is available and described on \code{\link{summary.ivreg}}.
+
+\code{ivreg.fit} is a convenience interface to \code{\link{lm.fit}} (or \code{\link{lm.wfit}})
+for first projecting \code{x} onto the image of \code{z} and the running
+a regression of \code{y} onto the projected \code{x}.
+}
+
+\value{
+ \code{ivreg.fit} returns an unclassed list with the following components:
+ \item{coefficients}{parameter estimates.}
+ \item{residuals}{a vector of residuals.}
+ \item{fitted.values}{a vector of predicted means.}
+ \item{weights}{either the vector of weights used (if any) or \code{NULL} (if none).}
+ \item{offset}{either the offset used (if any) or \code{NULL} (if none).}
+ \item{estfun}{a matrix containing the empirical estimating functions.}
+ \item{n}{number of observations.}
+ \item{nobs}{number of observations with non-zero weights.}
+ \item{rank}{the numeric rank of the fitted linear model.}
+ \item{df.residual}{residual degrees of freedom for fitted model.}
+ \item{cov.unscaled}{unscaled covariance matrix for the coefficients.}
+ \item{sigma}{residual standard error.}
+}
+
+\seealso{\code{\link{ivreg}}, \code{\link[stats:lmfit]{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
+}
+
+\keyword{regression}
diff --git a/man/summary.ivreg.Rd b/man/summary.ivreg.Rd
new file mode 100644
index 0000000..c1a4618
--- /dev/null
+++ b/man/summary.ivreg.Rd
@@ -0,0 +1,80 @@
+\name{summary.ivreg}
+\alias{summary.ivreg}
+\alias{print.summary.ivreg}
+\alias{vcov.ivreg}
+\alias{bread.ivreg}
+\alias{estfun.ivreg}
+\alias{anova.ivreg}
+\alias{hatvalues.ivreg}
+\alias{predict.ivreg}
+\alias{terms.ivreg}
+\alias{model.matrix.ivreg}
+
+
+\title{Methods for Instrumental-Variable Regression}
+\description{
+ Methods to standard generics for instrumental-variable regressions
+ fitted by \code{\link{ivreg}}.
+}
+
+\usage{
+\method{summary}{ivreg}(object, vcov. = NULL, df = NULL, diagnostics = FALSE, \dots)
+\method{anova}{ivreg}(object, object2, test = "F", vcov = NULL, \dots)
+
+\method{terms}{ivreg}(x, component = c("regressors", "instruments"), \dots)
+\method{model.matrix}{ivreg}(object, component = c("projected", "regressors", "instruments"), \dots)
+}
+
+\arguments{
+ \item{object, object2, x}{an object of class \code{"ivreg"} as fitted by
+ \code{\link{ivreg}}.}
+ \item{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 \code{diagnostics = TRUE} in the \code{summary()} method).}
+ \item{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 \code{Inf} (or equivalently \code{0}) for which a z or Chi-squared
+ test is computed.}
+ \item{diagnostics}{logical. Should diagnostic tests for the instrumental-variable
+ regression be carried out? These encompass an F test of the first stage regression
+ for weak instruments, a Wu-Hausman test for endogeneity, and a Sargan
+ test of overidentifying restrictions (only if there are more instruments than
+ regressors).}
+ \item{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).}
+ \item{component}{character specifying for which component of the
+ terms or model matrix should be extracted. \code{"projected"} gives the matrix of
+ regressors projected on the image of the instruments.}
+ \item{\dots}{currently not used.}
+}
+
+\details{
+\code{\link{ivreg}} is the high-level interface to the work-horse function \code{\link{ivreg.fit}},
+a set of standard methods (including \code{summary}, \code{vcov}, \code{anova},
+\code{hatvalues}, \code{predict}, \code{terms}, \code{model.matrix}, \code{bread},
+\code{estfun}) is available.
+}
+
+\seealso{\code{\link{ivreg}}, \code{\link[stats:lmfit]{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")
+}
+
+\keyword{regression}
diff --git a/man/tobit.Rd b/man/tobit.Rd
new file mode 100644
index 0000000..b2113e0
--- /dev/null
+++ b/man/tobit.Rd
@@ -0,0 +1,84 @@
+\name{tobit}
+\alias{tobit}
+\alias{print.tobit}
+\alias{summary.tobit}
+\alias{print.summary.tobit}
+\alias{formula.tobit}
+\alias{model.frame.tobit}
+\alias{update.tobit}
+\alias{waldtest.tobit}
+\alias{lrtest.tobit}
+\alias{linearHypothesis.tobit}
+\alias{deviance.survreg}
+\alias{fitted.survreg}
+\alias{nobs.survreg}
+\alias{weights.survreg}
+
+\title{Tobit Regression}
+
+\description{
+Fitting and testing tobit regression models for censored data.
+}
+
+\usage{
+ tobit(formula, left = 0, right = Inf, dist = "gaussian",
+ subset = NULL, data = list(), \dots)
+}
+
+\arguments{
+ \item{formula}{a symbolic description of a regression model of type
+ \code{y ~ x1 + x2 + \dots}.}
+ \item{left}{left limit for the censored dependent variable \code{y}.
+ If set to \code{-Inf}, \code{y} is assumed not to be left-censored.}
+ \item{right}{right limit for the censored dependent variable \code{y}.
+ If set to \code{Inf}, the default, \code{y} is assumed not to be right-censored.}
+ \item{dist}{assumed distribution for the dependent variable \code{y}.
+ This is passed to \code{\link[survival]{survreg}}, see the respective man page for
+ more details.}
+ \item{subset}{a specification of the rows to be used.}
+ \item{data}{a data frame containing the variables in the model.}
+ \item{\dots}{further arguments passed to \code{\link[survival]{survreg}}.}
+}
+
+\details{
+ The function \code{tobit} is a convenience interface to \code{\link[survival]{survreg}}
+ (for survival regression, including censored regression) setting different
+ defaults and providing a more convenient interface for specification
+ 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 \code{y ~ x1 + x2 + \dots} passed to \code{tobit}
+ is simply transformed into a formula suitable for \code{\link[survival]{survreg}}: This means
+ the dependent variable is first censored and then wrapped into a \code{\link[survival]{Surv}}
+ object containing the censoring information which is subsequently passed to
+ \code{\link[survival]{survreg}}, e.g., \code{Surv(ifelse(y <= 0, 0, y), y > 0, type = "left") ~ x1 + x2 + \dots}
+ for the default settings.
+}
+
+\references{
+Greene, W.H. (2003). \emph{Econometric Analysis}, 5th edition. Upper Saddle River, NJ: Prentice Hall.
+
+Tobin, J. (1958). Estimation of Relationships for Limited Dependent Variables.
+ \emph{Econometrica}, \bold{26}, 24--36.
+}
+
+\value{
+ An object of class \code{"tobit"} inheriting from class \code{"survreg"}.
+}
+
+\examples{
+data("Affairs")
+
+## from Table 22.4 in Greene (2003)
+fm.tobit <- tobit(affairs ~ age + yearsmarried + religiousness + occupation + rating,
+ data = Affairs)
+fm.tobit2 <- tobit(affairs ~ age + yearsmarried + religiousness + occupation + rating,
+ right = 4, data = Affairs)
+
+summary(fm.tobit)
+summary(fm.tobit2)
+}
+
+\keyword{regression}
diff --git a/tests/Ch-Basics.R b/tests/Ch-Basics.R
new file mode 100644
index 0000000..bab6162
--- /dev/null
+++ b/tests/Ch-Basics.R
@@ -0,0 +1,794 @@
+###################################################
+### chunk number 1: setup
+###################################################
+options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+
+options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
+
+library("AER")
+
+set.seed(1071)
+
+
+###################################################
+### chunk number 2: calc1
+###################################################
+1 + 1
+2^3
+
+
+###################################################
+### chunk number 3: calc2
+###################################################
+log(exp(sin(pi/4)^2) * exp(cos(pi/4)^2))
+
+
+###################################################
+### chunk number 4: vec1
+###################################################
+x <- c(1.8, 3.14, 4, 88.169, 13)
+
+
+###################################################
+### chunk number 5: length
+###################################################
+length(x)
+
+
+###################################################
+### chunk number 6: vec2
+###################################################
+2 * x + 3
+5:1 * x + 1:5
+
+
+###################################################
+### chunk number 7: vec3
+###################################################
+log(x)
+
+
+###################################################
+### chunk number 8: subset1
+###################################################
+x[c(1, 4)]
+
+
+###################################################
+### chunk number 9: subset2
+###################################################
+x[-c(2, 3, 5)]
+
+
+###################################################
+### chunk number 10: pattern1
+###################################################
+ones <- rep(1, 10)
+even <- seq(from = 2, to = 20, by = 2)
+trend <- 1981:2005
+
+
+###################################################
+### chunk number 11: pattern2
+###################################################
+c(ones, even)
+
+
+###################################################
+### chunk number 12: matrix1
+###################################################
+A <- matrix(1:6, nrow = 2)
+
+
+###################################################
+### chunk number 13: matrix2
+###################################################
+t(A)
+
+
+###################################################
+### chunk number 14: matrix3
+###################################################
+dim(A)
+nrow(A)
+ncol(A)
+
+
+###################################################
+### chunk number 15: matrix-subset
+###################################################
+A1 <- A[1:2, c(1, 3)]
+
+
+###################################################
+### chunk number 16: matrix4
+###################################################
+solve(A1)
+
+
+###################################################
+### chunk number 17: matrix-solve
+###################################################
+A1 %*% solve(A1)
+
+
+###################################################
+### chunk number 18: diag
+###################################################
+diag(4)
+
+
+###################################################
+### chunk number 19: matrix-combine1
+###################################################
+cbind(1, A1)
+
+
+###################################################
+### chunk number 20: matrix-combine2
+###################################################
+rbind(A1, diag(4, 2))
+
+
+###################################################
+### chunk number 21: vector-mode
+###################################################
+x <- c(1.8, 3.14, 4, 88.169, 13)
+
+
+###################################################
+### chunk number 22: logical
+###################################################
+x > 3.5
+
+
+###################################################
+### chunk number 23: names
+###################################################
+names(x) <- c("a", "b", "c", "d", "e")
+x
+
+
+###################################################
+### chunk number 24: subset-more
+###################################################
+x[3:5]
+x[c("c", "d", "e")]
+x[x > 3.5]
+
+
+###################################################
+### chunk number 25: list1
+###################################################
+mylist <- list(sample = rnorm(5),
+ family = "normal distribution",
+ parameters = list(mean = 0, sd = 1))
+mylist
+
+
+###################################################
+### chunk number 26: list2
+###################################################
+mylist[[1]]
+mylist[["sample"]]
+mylist$sample
+
+
+###################################################
+### chunk number 27: list3
+###################################################
+mylist[[3]]$sd
+
+
+###################################################
+### chunk number 28: logical2
+###################################################
+x <- c(1.8, 3.14, 4, 88.169, 13)
+x > 3 & x <= 4
+
+
+###################################################
+### chunk number 29: logical3
+###################################################
+which(x > 3 & x <= 4)
+
+
+###################################################
+### chunk number 30: logical4
+###################################################
+all(x > 3)
+any(x > 3)
+
+
+###################################################
+### chunk number 31: logical5
+###################################################
+(1.5 - 0.5) == 1
+(1.9 - 0.9) == 1
+
+
+###################################################
+### chunk number 32: logical6
+###################################################
+all.equal(1.9 - 0.9, 1)
+
+
+###################################################
+### chunk number 33: logical7
+###################################################
+7 + TRUE
+
+
+###################################################
+### chunk number 34: coercion1
+###################################################
+is.numeric(x)
+is.character(x)
+as.character(x)
+
+
+###################################################
+### chunk number 35: coercion2
+###################################################
+c(1, "a")
+
+
+###################################################
+### chunk number 36: rng1
+###################################################
+set.seed(123)
+rnorm(2)
+rnorm(2)
+set.seed(123)
+rnorm(2)
+
+
+###################################################
+### chunk number 37: rng2
+###################################################
+sample(1:5)
+sample(c("male", "female"), size = 5, replace = TRUE,
+ prob = c(0.2, 0.8))
+
+
+###################################################
+### chunk number 38: flow1
+###################################################
+x <- c(1.8, 3.14, 4, 88.169, 13)
+if(rnorm(1) > 0) sum(x) else mean(x)
+
+
+###################################################
+### chunk number 39: flow2
+###################################################
+ifelse(x > 4, sqrt(x), x^2)
+
+
+###################################################
+### chunk number 40: flow3
+###################################################
+for(i in 2:5) {
+ x[i] <- x[i] - x[i-1]
+}
+x[-1]
+
+
+###################################################
+### chunk number 41: flow4
+###################################################
+while(sum(x) < 100) {
+ x <- 2 * x
+}
+x
+
+
+###################################################
+### chunk number 42: cmeans
+###################################################
+cmeans <- function(X) {
+ rval <- rep(0, ncol(X))
+ for(j in 1:ncol(X)) {
+ mysum <- 0
+ for(i in 1:nrow(X)) mysum <- mysum + X[i,j]
+ rval[j] <- mysum/nrow(X)
+ }
+ return(rval)
+}
+
+
+###################################################
+### chunk number 43: colmeans1
+###################################################
+X <- matrix(1:20, ncol = 2)
+cmeans(X)
+
+
+###################################################
+### chunk number 44: colmeans2
+###################################################
+colMeans(X)
+
+
+###################################################
+### chunk number 45: colmeans3 eval=FALSE
+###################################################
+## X <- matrix(rnorm(2*10^6), ncol = 2)
+## system.time(colMeans(X))
+## system.time(cmeans(X))
+
+
+###################################################
+### chunk number 46: colmeans4
+###################################################
+cmeans2 <- function(X) {
+ rval <- rep(0, ncol(X))
+ for(j in 1:ncol(X)) rval[j] <- mean(X[,j])
+ return(rval)
+}
+
+
+###################################################
+### chunk number 47: colmeans5 eval=FALSE
+###################################################
+## system.time(cmeans2(X))
+
+
+###################################################
+### chunk number 48: colmeans6 eval=FALSE
+###################################################
+## apply(X, 2, mean)
+
+
+###################################################
+### chunk number 49: colmeans7 eval=FALSE
+###################################################
+## system.time(apply(X, 2, mean))
+
+
+###################################################
+### chunk number 50: formula1
+###################################################
+f <- y ~ x
+class(f)
+
+
+###################################################
+### chunk number 51: formula2
+###################################################
+x <- seq(from = 0, to = 10, by = 0.5)
+y <- 2 + 3 * x + rnorm(21)
+
+
+###################################################
+### chunk number 52: formula3 eval=FALSE
+###################################################
+## plot(y ~ x)
+## lm(y ~ x)
+
+
+###################################################
+### chunk number 53: formula3a
+###################################################
+print(lm(y ~ x))
+
+
+###################################################
+### chunk number 54: formula3b
+###################################################
+plot(y ~ x)
+
+
+###################################################
+### chunk number 55: formula3c
+###################################################
+fm <- lm(y ~ x)
+
+
+###################################################
+### chunk number 56: mydata1
+###################################################
+mydata <- data.frame(one = 1:10, two = 11:20, three = 21:30)
+
+
+###################################################
+### chunk number 57: mydata1a
+###################################################
+mydata <- as.data.frame(matrix(1:30, ncol = 3))
+names(mydata) <- c("one", "two", "three")
+
+
+###################################################
+### chunk number 58: mydata2
+###################################################
+mydata$two
+mydata[, "two"]
+mydata[, 2]
+
+
+###################################################
+### chunk number 59: attach
+###################################################
+attach(mydata)
+mean(two)
+detach(mydata)
+
+
+###################################################
+### chunk number 60: with
+###################################################
+with(mydata, mean(two))
+
+
+###################################################
+### chunk number 61: mydata-subset
+###################################################
+mydata.sub <- subset(mydata, two <= 16, select = -two)
+
+
+###################################################
+### chunk number 62: write-table
+###################################################
+write.table(mydata, file = "mydata.txt", col.names = TRUE)
+
+
+###################################################
+### chunk number 63: read-table
+###################################################
+newdata <- read.table("mydata.txt", header = TRUE)
+
+
+###################################################
+### chunk number 64: save
+###################################################
+save(mydata, file = "mydata.rda")
+
+
+###################################################
+### chunk number 65: load
+###################################################
+load("mydata.rda")
+
+
+###################################################
+### chunk number 66: file-remove
+###################################################
+file.remove("mydata.rda")
+
+
+###################################################
+### chunk number 67: data
+###################################################
+data("Journals", package = "AER")
+
+
+###################################################
+### chunk number 68: foreign
+###################################################
+library("foreign")
+write.dta(mydata, file = "mydata.dta")
+
+
+###################################################
+### chunk number 69: read-dta
+###################################################
+mydata <- read.dta("mydata.dta")
+
+
+###################################################
+### chunk number 70: cleanup
+###################################################
+file.remove("mydata.dta")
+
+
+###################################################
+### chunk number 71: factor
+###################################################
+g <- rep(0:1, c(2, 4))
+g <- factor(g, levels = 0:1, labels = c("male", "female"))
+g
+
+
+###################################################
+### chunk number 72: na1
+###################################################
+newdata <- read.table("mydata.txt", na.strings = "-999")
+
+
+###################################################
+### chunk number 73: na2
+###################################################
+file.remove("mydata.txt")
+
+
+###################################################
+### chunk number 74: oop1
+###################################################
+x <- c(1.8, 3.14, 4, 88.169, 13)
+g <- factor(rep(c(0, 1), c(2, 4)), levels = c(0, 1),
+ labels = c("male", "female"))
+
+
+###################################################
+### chunk number 75: oop2
+###################################################
+summary(x)
+summary(g)
+
+
+###################################################
+### chunk number 76: oop3
+###################################################
+class(x)
+class(g)
+
+
+###################################################
+### chunk number 77: oop4
+###################################################
+summary
+
+
+###################################################
+### chunk number 78: oop5
+###################################################
+normsample <- function(n, ...) {
+ rval <- rnorm(n, ...)
+ class(rval) <- "normsample"
+ return(rval)
+}
+
+
+###################################################
+### chunk number 79: oop6
+###################################################
+set.seed(123)
+x <- normsample(10, mean = 5)
+class(x)
+
+
+###################################################
+### chunk number 80: oop7
+###################################################
+summary.normsample <- function(object, ...) {
+ rval <- c(length(object), mean(object), sd(object))
+ names(rval) <- c("sample size","mean","standard deviation")
+ return(rval)
+}
+
+
+###################################################
+### chunk number 81: oop8
+###################################################
+summary(x)
+
+
+###################################################
+### chunk number 82: journals-data eval=FALSE
+###################################################
+## data("Journals")
+## Journals$citeprice <- Journals$price/Journals$citations
+## attach(Journals)
+## plot(log(subs), log(citeprice))
+## rug(log(subs))
+## rug(log(citeprice), side = 2)
+## detach(Journals)
+
+
+###################################################
+### chunk number 83: journals-data1
+###################################################
+data("Journals")
+Journals$citeprice <- Journals$price/Journals$citations
+attach(Journals)
+plot(log(subs), log(citeprice))
+rug(log(subs))
+rug(log(citeprice), side = 2)
+detach(Journals)
+
+
+###################################################
+### chunk number 84: plot-formula
+###################################################
+plot(log(subs) ~ log(citeprice), data = Journals)
+
+
+###################################################
+### chunk number 85: graphics1
+###################################################
+plot(log(subs) ~ log(citeprice), data = Journals, pch = 20,
+ col = "blue", ylim = c(0, 8), xlim = c(-7, 4),
+ main = "Library subscriptions")
+
+
+###################################################
+### chunk number 86: graphics2
+###################################################
+pdf("myfile.pdf", height = 5, width = 6)
+plot(1:20, pch = 1:20, col = 1:20, cex = 2)
+dev.off()
+
+
+###################################################
+### chunk number 87: dnorm-annotate eval=FALSE
+###################################################
+## curve(dnorm, from = -5, to = 5, col = "slategray", lwd = 3,
+## main = "Density of the standard normal distribution")
+## text(-5, 0.3, expression(f(x) == frac(1, sigma ~~
+## sqrt(2*pi)) ~~ e^{-frac((x - mu)^2, 2*sigma^2)}), adj = 0)
+
+
+###################################################
+### chunk number 88: dnorm-annotate1
+###################################################
+curve(dnorm, from = -5, to = 5, col = "slategray", lwd = 3,
+ main = "Density of the standard normal distribution")
+text(-5, 0.3, expression(f(x) == frac(1, sigma ~~
+ sqrt(2*pi)) ~~ e^{-frac((x - mu)^2, 2*sigma^2)}), adj = 0)
+
+
+###################################################
+### chunk number 89: eda1
+###################################################
+data("CPS1985")
+str(CPS1985)
+
+
+###################################################
+### chunk number 90: eda2
+###################################################
+head(CPS1985)
+
+
+###################################################
+### chunk number 91: eda3
+###################################################
+levels(CPS1985$occupation)[c(2, 6)] <- c("techn", "mgmt")
+attach(CPS1985)
+
+
+###################################################
+### chunk number 92: eda4
+###################################################
+summary(wage)
+
+
+###################################################
+### chunk number 93: eda5
+###################################################
+mean(wage)
+median(wage)
+
+
+###################################################
+### chunk number 94: eda6
+###################################################
+var(wage)
+sd(wage)
+
+
+###################################################
+### chunk number 95: wage-hist
+###################################################
+hist(wage, freq = FALSE)
+hist(log(wage), freq = FALSE)
+lines(density(log(wage)), col = 4)
+
+
+###################################################
+### chunk number 96: wage-hist1
+###################################################
+hist(wage, freq = FALSE)
+hist(log(wage), freq = FALSE)
+lines(density(log(wage)), col = 4)
+
+
+###################################################
+### chunk number 97: occ-table
+###################################################
+summary(occupation)
+
+
+###################################################
+### chunk number 98: occ-table
+###################################################
+tab <- table(occupation)
+prop.table(tab)
+
+
+###################################################
+### chunk number 99: occ-barpie
+###################################################
+barplot(tab)
+pie(tab)
+
+
+###################################################
+### chunk number 100: occ-barpie
+###################################################
+par(mar = c(4, 3, 1, 1))
+barplot(tab, las = 3)
+par(mar = c(2, 3, 1, 3))
+pie(tab, radius = 1)
+
+
+###################################################
+### chunk number 101: xtabs
+###################################################
+xtabs(~ gender + occupation, data = CPS1985)
+
+
+###################################################
+### chunk number 102: spine eval=FALSE
+###################################################
+## plot(gender ~ occupation, data = CPS1985)
+
+
+###################################################
+### chunk number 103: spine1
+###################################################
+plot(gender ~ occupation, data = CPS1985)
+
+
+###################################################
+### chunk number 104: wageeduc-cor
+###################################################
+cor(log(wage), education)
+cor(log(wage), education, method = "spearman")
+
+
+###################################################
+### chunk number 105: wageeduc-scatter eval=FALSE
+###################################################
+## plot(log(wage) ~ education)
+
+
+###################################################
+### chunk number 106: wageeduc-scatter1
+###################################################
+plot(log(wage) ~ education)
+
+
+###################################################
+### chunk number 107: tapply
+###################################################
+tapply(log(wage), gender, mean)
+
+
+###################################################
+### chunk number 108: boxqq1 eval=FALSE
+###################################################
+## plot(log(wage) ~ gender)
+
+
+###################################################
+### chunk number 109: boxqq2 eval=FALSE
+###################################################
+## mwage <- subset(CPS1985, gender == "male")$wage
+## fwage <- subset(CPS1985, gender == "female")$wage
+## qqplot(mwage, fwage, xlim = range(wage), ylim = range(wage),
+## xaxs = "i", yaxs = "i", xlab = "male", ylab = "female")
+## abline(0, 1)
+
+
+###################################################
+### chunk number 110: qq
+###################################################
+plot(log(wage) ~ gender)
+mwage <- subset(CPS1985, gender == "male")$wage
+fwage <- subset(CPS1985, gender == "female")$wage
+qqplot(mwage, fwage, xlim = range(wage), ylim = range(wage),
+ xaxs = "i", yaxs = "i", xlab = "male", ylab = "female")
+abline(0, 1)
+
+
+###################################################
+### chunk number 111: detach
+###################################################
+detach(CPS1985)
+
+
diff --git a/tests/Ch-Basics.Rout.save b/tests/Ch-Basics.Rout.save
new file mode 100644
index 0000000..c945946
--- /dev/null
+++ b/tests/Ch-Basics.Rout.save
@@ -0,0 +1,992 @@
+
+R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
+Copyright (C) 2016 The R Foundation for Statistical Computing
+Platform: x86_64-pc-linux-gnu (64-bit)
+
+R is free software and comes with ABSOLUTELY NO WARRANTY.
+You are welcome to redistribute it under certain conditions.
+Type 'license()' or 'licence()' for distribution details.
+
+R is a collaborative project with many contributors.
+Type 'contributors()' for more information and
+'citation()' on how to cite R or R packages in publications.
+
+Type 'demo()' for some demos, 'help()' for on-line help, or
+'help.start()' for an HTML browser interface to help.
+Type 'q()' to quit R.
+
+> ###################################################
+> ### chunk number 1: setup
+> ###################################################
+> options(prompt = "R> ", continue = "+ ", width = 64,
++ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+R>
+R> options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
++ twofig = function() {par(mfrow = c(1,2))},
++ threefig = function() {par(mfrow = c(1,3))},
++ fourfig = function() {par(mfrow = c(2,2))},
++ sixfig = function() {par(mfrow = c(3,2))}))
+R>
+R> library("AER")
+Loading required package: car
+Loading required package: lmtest
+Loading required package: zoo
+
+Attaching package: 'zoo'
+
+The following objects are masked from 'package:base':
+
+ as.Date, as.Date.numeric
+
+Loading required package: sandwich
+Loading required package: survival
+R>
+R> set.seed(1071)
+R>
+R>
+R> ###################################################
+R> ### chunk number 2: calc1
+R> ###################################################
+R> 1 + 1
+[1] 2
+R> 2^3
+[1] 8
+R>
+R>
+R> ###################################################
+R> ### chunk number 3: calc2
+R> ###################################################
+R> log(exp(sin(pi/4)^2) * exp(cos(pi/4)^2))
+[1] 1
+R>
+R>
+R> ###################################################
+R> ### chunk number 4: vec1
+R> ###################################################
+R> x <- c(1.8, 3.14, 4, 88.169, 13)
+R>
+R>
+R> ###################################################
+R> ### chunk number 5: length
+R> ###################################################
+R> length(x)
+[1] 5
+R>
+R>
+R> ###################################################
+R> ### chunk number 6: vec2
+R> ###################################################
+R> 2 * x + 3
+[1] 6.60 9.28 11.00 179.34 29.00
+R> 5:1 * x + 1:5
+[1] 10.00 14.56 15.00 180.34 18.00
+R>
+R>
+R> ###################################################
+R> ### chunk number 7: vec3
+R> ###################################################
+R> log(x)
+[1] 0.5878 1.1442 1.3863 4.4793 2.5649
+R>
+R>
+R> ###################################################
+R> ### chunk number 8: subset1
+R> ###################################################
+R> x[c(1, 4)]
+[1] 1.80 88.17
+R>
+R>
+R> ###################################################
+R> ### chunk number 9: subset2
+R> ###################################################
+R> x[-c(2, 3, 5)]
+[1] 1.80 88.17
+R>
+R>
+R> ###################################################
+R> ### chunk number 10: pattern1
+R> ###################################################
+R> ones <- rep(1, 10)
+R> even <- seq(from = 2, to = 20, by = 2)
+R> trend <- 1981:2005
+R>
+R>
+R> ###################################################
+R> ### chunk number 11: pattern2
+R> ###################################################
+R> c(ones, even)
+ [1] 1 1 1 1 1 1 1 1 1 1 2 4 6 8 10 12 14 16 18 20
+R>
+R>
+R> ###################################################
+R> ### chunk number 12: matrix1
+R> ###################################################
+R> A <- matrix(1:6, nrow = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 13: matrix2
+R> ###################################################
+R> t(A)
+ [,1] [,2]
+[1,] 1 2
+[2,] 3 4
+[3,] 5 6
+R>
+R>
+R> ###################################################
+R> ### chunk number 14: matrix3
+R> ###################################################
+R> dim(A)
+[1] 2 3
+R> nrow(A)
+[1] 2
+R> ncol(A)
+[1] 3
+R>
+R>
+R> ###################################################
+R> ### chunk number 15: matrix-subset
+R> ###################################################
+R> A1 <- A[1:2, c(1, 3)]
+R>
+R>
+R> ###################################################
+R> ### chunk number 16: matrix4
+R> ###################################################
+R> solve(A1)
+ [,1] [,2]
+[1,] -1.5 1.25
+[2,] 0.5 -0.25
+R>
+R>
+R> ###################################################
+R> ### chunk number 17: matrix-solve
+R> ###################################################
+R> A1 %*% solve(A1)
+ [,1] [,2]
+[1,] 1 0
+[2,] 0 1
+R>
+R>
+R> ###################################################
+R> ### chunk number 18: diag
+R> ###################################################
+R> diag(4)
+ [,1] [,2] [,3] [,4]
+[1,] 1 0 0 0
+[2,] 0 1 0 0
+[3,] 0 0 1 0
+[4,] 0 0 0 1
+R>
+R>
+R> ###################################################
+R> ### chunk number 19: matrix-combine1
+R> ###################################################
+R> cbind(1, A1)
+ [,1] [,2] [,3]
+[1,] 1 1 5
+[2,] 1 2 6
+R>
+R>
+R> ###################################################
+R> ### chunk number 20: matrix-combine2
+R> ###################################################
+R> rbind(A1, diag(4, 2))
+ [,1] [,2]
+[1,] 1 5
+[2,] 2 6
+[3,] 4 0
+[4,] 0 4
+R>
+R>
+R> ###################################################
+R> ### chunk number 21: vector-mode
+R> ###################################################
+R> x <- c(1.8, 3.14, 4, 88.169, 13)
+R>
+R>
+R> ###################################################
+R> ### chunk number 22: logical
+R> ###################################################
+R> x > 3.5
+[1] FALSE FALSE TRUE TRUE TRUE
+R>
+R>
+R> ###################################################
+R> ### chunk number 23: names
+R> ###################################################
+R> names(x) <- c("a", "b", "c", "d", "e")
+R> x
+ a b c d e
+ 1.80 3.14 4.00 88.17 13.00
+R>
+R>
+R> ###################################################
+R> ### chunk number 24: subset-more
+R> ###################################################
+R> x[3:5]
+ c d e
+ 4.00 88.17 13.00
+R> x[c("c", "d", "e")]
+ c d e
+ 4.00 88.17 13.00
+R> x[x > 3.5]
+ c d e
+ 4.00 88.17 13.00
+R>
+R>
+R> ###################################################
+R> ### chunk number 25: list1
+R> ###################################################
+R> mylist <- list(sample = rnorm(5),
++ family = "normal distribution",
++ parameters = list(mean = 0, sd = 1))
+R> mylist
+$sample
+[1] 0.3771 -0.9346 2.4302 1.3195 0.4503
+
+$family
+[1] "normal distribution"
+
+$parameters
+$parameters$mean
+[1] 0
+
+$parameters$sd
+[1] 1
+
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 26: list2
+R> ###################################################
+R> mylist[[1]]
+[1] 0.3771 -0.9346 2.4302 1.3195 0.4503
+R> mylist[["sample"]]
+[1] 0.3771 -0.9346 2.4302 1.3195 0.4503
+R> mylist$sample
+[1] 0.3771 -0.9346 2.4302 1.3195 0.4503
+R>
+R>
+R> ###################################################
+R> ### chunk number 27: list3
+R> ###################################################
+R> mylist[[3]]$sd
+[1] 1
+R>
+R>
+R> ###################################################
+R> ### chunk number 28: logical2
+R> ###################################################
+R> x <- c(1.8, 3.14, 4, 88.169, 13)
+R> x > 3 & x <= 4
+[1] FALSE TRUE TRUE FALSE FALSE
+R>
+R>
+R> ###################################################
+R> ### chunk number 29: logical3
+R> ###################################################
+R> which(x > 3 & x <= 4)
+[1] 2 3
+R>
+R>
+R> ###################################################
+R> ### chunk number 30: logical4
+R> ###################################################
+R> all(x > 3)
+[1] FALSE
+R> any(x > 3)
+[1] TRUE
+R>
+R>
+R> ###################################################
+R> ### chunk number 31: logical5
+R> ###################################################
+R> (1.5 - 0.5) == 1
+[1] TRUE
+R> (1.9 - 0.9) == 1
+[1] FALSE
+R>
+R>
+R> ###################################################
+R> ### chunk number 32: logical6
+R> ###################################################
+R> all.equal(1.9 - 0.9, 1)
+[1] TRUE
+R>
+R>
+R> ###################################################
+R> ### chunk number 33: logical7
+R> ###################################################
+R> 7 + TRUE
+[1] 8
+R>
+R>
+R> ###################################################
+R> ### chunk number 34: coercion1
+R> ###################################################
+R> is.numeric(x)
+[1] TRUE
+R> is.character(x)
+[1] FALSE
+R> as.character(x)
+[1] "1.8" "3.14" "4" "88.169" "13"
+R>
+R>
+R> ###################################################
+R> ### chunk number 35: coercion2
+R> ###################################################
+R> c(1, "a")
+[1] "1" "a"
+R>
+R>
+R> ###################################################
+R> ### chunk number 36: rng1
+R> ###################################################
+R> set.seed(123)
+R> rnorm(2)
+[1] -0.5605 -0.2302
+R> rnorm(2)
+[1] 1.55871 0.07051
+R> set.seed(123)
+R> rnorm(2)
+[1] -0.5605 -0.2302
+R>
+R>
+R> ###################################################
+R> ### chunk number 37: rng2
+R> ###################################################
+R> sample(1:5)
+[1] 5 1 2 3 4
+R> sample(c("male", "female"), size = 5, replace = TRUE,
++ prob = c(0.2, 0.8))
+[1] "female" "male" "female" "female" "female"
+R>
+R>
+R> ###################################################
+R> ### chunk number 38: flow1
+R> ###################################################
+R> x <- c(1.8, 3.14, 4, 88.169, 13)
+R> if(rnorm(1) > 0) sum(x) else mean(x)
+[1] 22.02
+R>
+R>
+R> ###################################################
+R> ### chunk number 39: flow2
+R> ###################################################
+R> ifelse(x > 4, sqrt(x), x^2)
+[1] 3.240 9.860 16.000 9.390 3.606
+R>
+R>
+R> ###################################################
+R> ### chunk number 40: flow3
+R> ###################################################
+R> for(i in 2:5) {
++ x[i] <- x[i] - x[i-1]
++ }
+R> x[-1]
+[1] 1.34 2.66 85.51 -72.51
+R>
+R>
+R> ###################################################
+R> ### chunk number 41: flow4
+R> ###################################################
+R> while(sum(x) < 100) {
++ x <- 2 * x
++ }
+R> x
+[1] 14.40 10.72 21.28 684.07 -580.07
+R>
+R>
+R> ###################################################
+R> ### chunk number 42: cmeans
+R> ###################################################
+R> cmeans <- function(X) {
++ rval <- rep(0, ncol(X))
++ for(j in 1:ncol(X)) {
++ mysum <- 0
++ for(i in 1:nrow(X)) mysum <- mysum + X[i,j]
++ rval[j] <- mysum/nrow(X)
++ }
++ return(rval)
++ }
+R>
+R>
+R> ###################################################
+R> ### chunk number 43: colmeans1
+R> ###################################################
+R> X <- matrix(1:20, ncol = 2)
+R> cmeans(X)
+[1] 5.5 15.5
+R>
+R>
+R> ###################################################
+R> ### chunk number 44: colmeans2
+R> ###################################################
+R> colMeans(X)
+[1] 5.5 15.5
+R>
+R>
+R> ###################################################
+R> ### chunk number 45: colmeans3 eval=FALSE
+R> ###################################################
+R> ## X <- matrix(rnorm(2*10^6), ncol = 2)
+R> ## system.time(colMeans(X))
+R> ## system.time(cmeans(X))
+R>
+R>
+R> ###################################################
+R> ### chunk number 46: colmeans4
+R> ###################################################
+R> cmeans2 <- function(X) {
++ rval <- rep(0, ncol(X))
++ for(j in 1:ncol(X)) rval[j] <- mean(X[,j])
++ return(rval)
++ }
+R>
+R>
+R> ###################################################
+R> ### chunk number 47: colmeans5 eval=FALSE
+R> ###################################################
+R> ## system.time(cmeans2(X))
+R>
+R>
+R> ###################################################
+R> ### chunk number 48: colmeans6 eval=FALSE
+R> ###################################################
+R> ## apply(X, 2, mean)
+R>
+R>
+R> ###################################################
+R> ### chunk number 49: colmeans7 eval=FALSE
+R> ###################################################
+R> ## system.time(apply(X, 2, mean))
+R>
+R>
+R> ###################################################
+R> ### chunk number 50: formula1
+R> ###################################################
+R> f <- y ~ x
+R> class(f)
+[1] "formula"
+R>
+R>
+R> ###################################################
+R> ### chunk number 51: formula2
+R> ###################################################
+R> x <- seq(from = 0, to = 10, by = 0.5)
+R> y <- 2 + 3 * x + rnorm(21)
+R>
+R>
+R> ###################################################
+R> ### chunk number 52: formula3 eval=FALSE
+R> ###################################################
+R> ## plot(y ~ x)
+R> ## lm(y ~ x)
+R>
+R>
+R> ###################################################
+R> ### chunk number 53: formula3a
+R> ###################################################
+R> print(lm(y ~ x))
+
+Call:
+lm(formula = y ~ x)
+
+Coefficients:
+(Intercept) x
+ 2.26 2.91
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 54: formula3b
+R> ###################################################
+R> plot(y ~ x)
+R>
+R>
+R> ###################################################
+R> ### chunk number 55: formula3c
+R> ###################################################
+R> fm <- lm(y ~ x)
+R>
+R>
+R> ###################################################
+R> ### chunk number 56: mydata1
+R> ###################################################
+R> mydata <- data.frame(one = 1:10, two = 11:20, three = 21:30)
+R>
+R>
+R> ###################################################
+R> ### chunk number 57: mydata1a
+R> ###################################################
+R> mydata <- as.data.frame(matrix(1:30, ncol = 3))
+R> names(mydata) <- c("one", "two", "three")
+R>
+R>
+R> ###################################################
+R> ### chunk number 58: mydata2
+R> ###################################################
+R> mydata$two
+ [1] 11 12 13 14 15 16 17 18 19 20
+R> mydata[, "two"]
+ [1] 11 12 13 14 15 16 17 18 19 20
+R> mydata[, 2]
+ [1] 11 12 13 14 15 16 17 18 19 20
+R>
+R>
+R> ###################################################
+R> ### chunk number 59: attach
+R> ###################################################
+R> attach(mydata)
+R> mean(two)
+[1] 15.5
+R> detach(mydata)
+R>
+R>
+R> ###################################################
+R> ### chunk number 60: with
+R> ###################################################
+R> with(mydata, mean(two))
+[1] 15.5
+R>
+R>
+R> ###################################################
+R> ### chunk number 61: mydata-subset
+R> ###################################################
+R> mydata.sub <- subset(mydata, two <= 16, select = -two)
+R>
+R>
+R> ###################################################
+R> ### chunk number 62: write-table
+R> ###################################################
+R> write.table(mydata, file = "mydata.txt", col.names = TRUE)
+R>
+R>
+R> ###################################################
+R> ### chunk number 63: read-table
+R> ###################################################
+R> newdata <- read.table("mydata.txt", header = TRUE)
+R>
+R>
+R> ###################################################
+R> ### chunk number 64: save
+R> ###################################################
+R> save(mydata, file = "mydata.rda")
+R>
+R>
+R> ###################################################
+R> ### chunk number 65: load
+R> ###################################################
+R> load("mydata.rda")
+R>
+R>
+R> ###################################################
+R> ### chunk number 66: file-remove
+R> ###################################################
+R> file.remove("mydata.rda")
+[1] TRUE
+R>
+R>
+R> ###################################################
+R> ### chunk number 67: data
+R> ###################################################
+R> data("Journals", package = "AER")
+R>
+R>
+R> ###################################################
+R> ### chunk number 68: foreign
+R> ###################################################
+R> library("foreign")
+R> write.dta(mydata, file = "mydata.dta")
+R>
+R>
+R> ###################################################
+R> ### chunk number 69: read-dta
+R> ###################################################
+R> mydata <- read.dta("mydata.dta")
+R>
+R>
+R> ###################################################
+R> ### chunk number 70: cleanup
+R> ###################################################
+R> file.remove("mydata.dta")
+[1] TRUE
+R>
+R>
+R> ###################################################
+R> ### chunk number 71: factor
+R> ###################################################
+R> g <- rep(0:1, c(2, 4))
+R> g <- factor(g, levels = 0:1, labels = c("male", "female"))
+R> g
+[1] male male female female female female
+Levels: male female
+R>
+R>
+R> ###################################################
+R> ### chunk number 72: na1
+R> ###################################################
+R> newdata <- read.table("mydata.txt", na.strings = "-999")
+R>
+R>
+R> ###################################################
+R> ### chunk number 73: na2
+R> ###################################################
+R> file.remove("mydata.txt")
+[1] TRUE
+R>
+R>
+R> ###################################################
+R> ### chunk number 74: oop1
+R> ###################################################
+R> x <- c(1.8, 3.14, 4, 88.169, 13)
+R> g <- factor(rep(c(0, 1), c(2, 4)), levels = c(0, 1),
++ labels = c("male", "female"))
+R>
+R>
+R> ###################################################
+R> ### chunk number 75: oop2
+R> ###################################################
+R> summary(x)
+ Min. 1st Qu. Median Mean 3rd Qu. Max.
+ 1.80 3.14 4.00 22.00 13.00 88.20
+R> summary(g)
+ male female
+ 2 4
+R>
+R>
+R> ###################################################
+R> ### chunk number 76: oop3
+R> ###################################################
+R> class(x)
+[1] "numeric"
+R> class(g)
+[1] "factor"
+R>
+R>
+R> ###################################################
+R> ### chunk number 77: oop4
+R> ###################################################
+R> summary
+function (object, ...)
+UseMethod("summary")
+<bytecode: 0x55d041640c08>
+<environment: namespace:base>
+R>
+R>
+R> ###################################################
+R> ### chunk number 78: oop5
+R> ###################################################
+R> normsample <- function(n, ...) {
++ rval <- rnorm(n, ...)
++ class(rval) <- "normsample"
++ return(rval)
++ }
+R>
+R>
+R> ###################################################
+R> ### chunk number 79: oop6
+R> ###################################################
+R> set.seed(123)
+R> x <- normsample(10, mean = 5)
+R> class(x)
+[1] "normsample"
+R>
+R>
+R> ###################################################
+R> ### chunk number 80: oop7
+R> ###################################################
+R> summary.normsample <- function(object, ...) {
++ rval <- c(length(object), mean(object), sd(object))
++ names(rval) <- c("sample size","mean","standard deviation")
++ return(rval)
++ }
+R>
+R>
+R> ###################################################
+R> ### chunk number 81: oop8
+R> ###################################################
+R> summary(x)
+ sample size mean standard deviation
+ 10.0000 5.0746 0.9538
+R>
+R>
+R> ###################################################
+R> ### chunk number 82: journals-data eval=FALSE
+R> ###################################################
+R> ## data("Journals")
+R> ## Journals$citeprice <- Journals$price/Journals$citations
+R> ## attach(Journals)
+R> ## plot(log(subs), log(citeprice))
+R> ## rug(log(subs))
+R> ## rug(log(citeprice), side = 2)
+R> ## detach(Journals)
+R>
+R>
+R> ###################################################
+R> ### chunk number 83: journals-data1
+R> ###################################################
+R> data("Journals")
+R> Journals$citeprice <- Journals$price/Journals$citations
+R> attach(Journals)
+R> plot(log(subs), log(citeprice))
+R> rug(log(subs))
+R> rug(log(citeprice), side = 2)
+R> detach(Journals)
+R>
+R>
+R> ###################################################
+R> ### chunk number 84: plot-formula
+R> ###################################################
+R> plot(log(subs) ~ log(citeprice), data = Journals)
+R>
+R>
+R> ###################################################
+R> ### chunk number 85: graphics1
+R> ###################################################
+R> plot(log(subs) ~ log(citeprice), data = Journals, pch = 20,
++ col = "blue", ylim = c(0, 8), xlim = c(-7, 4),
++ main = "Library subscriptions")
+R>
+R>
+R> ###################################################
+R> ### chunk number 86: graphics2
+R> ###################################################
+R> pdf("myfile.pdf", height = 5, width = 6)
+R> plot(1:20, pch = 1:20, col = 1:20, cex = 2)
+R> dev.off()
+pdf
+ 2
+R>
+R>
+R> ###################################################
+R> ### chunk number 87: dnorm-annotate eval=FALSE
+R> ###################################################
+R> ## curve(dnorm, from = -5, to = 5, col = "slategray", lwd = 3,
+R> ## main = "Density of the standard normal distribution")
+R> ## text(-5, 0.3, expression(f(x) == frac(1, sigma ~~
+R> ## sqrt(2*pi)) ~~ e^{-frac((x - mu)^2, 2*sigma^2)}), adj = 0)
+R>
+R>
+R> ###################################################
+R> ### chunk number 88: dnorm-annotate1
+R> ###################################################
+R> curve(dnorm, from = -5, to = 5, col = "slategray", lwd = 3,
++ main = "Density of the standard normal distribution")
+R> text(-5, 0.3, expression(f(x) == frac(1, sigma ~~
++ sqrt(2*pi)) ~~ e^{-frac((x - mu)^2, 2*sigma^2)}), adj = 0)
+R>
+R>
+R> ###################################################
+R> ### chunk number 89: eda1
+R> ###################################################
+R> data("CPS1985")
+R> str(CPS1985)
+'data.frame': 534 obs. of 11 variables:
+ $ wage : num 5.1 4.95 6.67 4 7.5 ...
+ $ education : num 8 9 12 12 12 13 10 12 16 12 ...
+ $ experience: num 21 42 1 4 17 9 27 9 11 9 ...
+ $ age : num 35 57 19 22 35 28 43 27 33 27 ...
+ $ ethnicity : Factor w/ 3 levels "cauc","hispanic",..: 2 1 1 1 1 1 1 1 1 1 ...
+ $ region : Factor w/ 2 levels "south","other": 2 2 2 2 2 2 1 2 2 2 ...
+ $ gender : Factor w/ 2 levels "male","female": 2 2 1 1 1 1 1 1 1 1 ...
+ $ occupation: Factor w/ 6 levels "worker","technical",..: 1 1 1 1 1 1 1 1 1 1 ...
+ $ sector : Factor w/ 3 levels "manufacturing",..: 1 1 1 3 3 3 3 3 1 3 ...
+ $ union : Factor w/ 2 levels "no","yes": 1 1 1 1 1 2 1 1 1 1 ...
+ $ married : Factor w/ 2 levels "no","yes": 2 2 1 1 2 1 1 1 2 1 ...
+R>
+R>
+R> ###################################################
+R> ### chunk number 90: eda2
+R> ###################################################
+R> head(CPS1985)
+ wage education experience age ethnicity region gender
+1 5.10 8 21 35 hispanic other female
+1100 4.95 9 42 57 cauc other female
+2 6.67 12 1 19 cauc other male
+3 4.00 12 4 22 cauc other male
+4 7.50 12 17 35 cauc other male
+5 13.07 13 9 28 cauc other male
+ occupation sector union married
+1 worker manufacturing no yes
+1100 worker manufacturing no yes
+2 worker manufacturing no no
+3 worker other no no
+4 worker other no yes
+5 worker other yes no
+R>
+R>
+R> ###################################################
+R> ### chunk number 91: eda3
+R> ###################################################
+R> levels(CPS1985$occupation)[c(2, 6)] <- c("techn", "mgmt")
+R> attach(CPS1985)
+R>
+R>
+R> ###################################################
+R> ### chunk number 92: eda4
+R> ###################################################
+R> summary(wage)
+ Min. 1st Qu. Median Mean 3rd Qu. Max.
+ 1.00 5.25 7.78 9.02 11.20 44.50
+R>
+R>
+R> ###################################################
+R> ### chunk number 93: eda5
+R> ###################################################
+R> mean(wage)
+[1] 9.024
+R> median(wage)
+[1] 7.78
+R>
+R>
+R> ###################################################
+R> ### chunk number 94: eda6
+R> ###################################################
+R> var(wage)
+[1] 26.41
+R> sd(wage)
+[1] 5.139
+R>
+R>
+R> ###################################################
+R> ### chunk number 95: wage-hist
+R> ###################################################
+R> hist(wage, freq = FALSE)
+R> hist(log(wage), freq = FALSE)
+R> lines(density(log(wage)), col = 4)
+R>
+R>
+R> ###################################################
+R> ### chunk number 96: wage-hist1
+R> ###################################################
+R> hist(wage, freq = FALSE)
+R> hist(log(wage), freq = FALSE)
+R> lines(density(log(wage)), col = 4)
+R>
+R>
+R> ###################################################
+R> ### chunk number 97: occ-table
+R> ###################################################
+R> summary(occupation)
+ worker techn services office sales mgmt
+ 156 105 83 97 38 55
+R>
+R>
+R> ###################################################
+R> ### chunk number 98: occ-table
+R> ###################################################
+R> tab <- table(occupation)
+R> prop.table(tab)
+occupation
+ worker techn services office sales mgmt
+ 0.29213 0.19663 0.15543 0.18165 0.07116 0.10300
+R>
+R>
+R> ###################################################
+R> ### chunk number 99: occ-barpie
+R> ###################################################
+R> barplot(tab)
+R> pie(tab)
+R>
+R>
+R> ###################################################
+R> ### chunk number 100: occ-barpie
+R> ###################################################
+R> par(mar = c(4, 3, 1, 1))
+R> barplot(tab, las = 3)
+R> par(mar = c(2, 3, 1, 3))
+R> pie(tab, radius = 1)
+R>
+R>
+R> ###################################################
+R> ### chunk number 101: xtabs
+R> ###################################################
+R> xtabs(~ gender + occupation, data = CPS1985)
+ occupation
+gender worker techn services office sales mgmt
+ male 126 53 34 21 21 34
+ female 30 52 49 76 17 21
+R>
+R>
+R> ###################################################
+R> ### chunk number 102: spine eval=FALSE
+R> ###################################################
+R> ## plot(gender ~ occupation, data = CPS1985)
+R>
+R>
+R> ###################################################
+R> ### chunk number 103: spine1
+R> ###################################################
+R> plot(gender ~ occupation, data = CPS1985)
+R>
+R>
+R> ###################################################
+R> ### chunk number 104: wageeduc-cor
+R> ###################################################
+R> cor(log(wage), education)
+[1] 0.3804
+R> cor(log(wage), education, method = "spearman")
+[1] 0.3813
+R>
+R>
+R> ###################################################
+R> ### chunk number 105: wageeduc-scatter eval=FALSE
+R> ###################################################
+R> ## plot(log(wage) ~ education)
+R>
+R>
+R> ###################################################
+R> ### chunk number 106: wageeduc-scatter1
+R> ###################################################
+R> plot(log(wage) ~ education)
+R>
+R>
+R> ###################################################
+R> ### chunk number 107: tapply
+R> ###################################################
+R> tapply(log(wage), gender, mean)
+ male female
+ 2.165 1.934
+R>
+R>
+R> ###################################################
+R> ### chunk number 108: boxqq1 eval=FALSE
+R> ###################################################
+R> ## plot(log(wage) ~ gender)
+R>
+R>
+R> ###################################################
+R> ### chunk number 109: boxqq2 eval=FALSE
+R> ###################################################
+R> ## mwage <- subset(CPS1985, gender == "male")$wage
+R> ## fwage <- subset(CPS1985, gender == "female")$wage
+R> ## qqplot(mwage, fwage, xlim = range(wage), ylim = range(wage),
+R> ## xaxs = "i", yaxs = "i", xlab = "male", ylab = "female")
+R> ## abline(0, 1)
+R>
+R>
+R> ###################################################
+R> ### chunk number 110: qq
+R> ###################################################
+R> plot(log(wage) ~ gender)
+R> mwage <- subset(CPS1985, gender == "male")$wage
+R> fwage <- subset(CPS1985, gender == "female")$wage
+R> qqplot(mwage, fwage, xlim = range(wage), ylim = range(wage),
++ xaxs = "i", yaxs = "i", xlab = "male", ylab = "female")
+R> abline(0, 1)
+R>
+R>
+R> ###################################################
+R> ### chunk number 111: detach
+R> ###################################################
+R> detach(CPS1985)
+R>
+R>
+R>
+> proc.time()
+ user system elapsed
+ 1.336 0.040 1.389
diff --git a/tests/Ch-Intro.R b/tests/Ch-Intro.R
new file mode 100644
index 0000000..62ca72c
--- /dev/null
+++ b/tests/Ch-Intro.R
@@ -0,0 +1,211 @@
+###################################################
+### chunk number 1: setup
+###################################################
+options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+
+options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
+
+library("AER")
+
+set.seed(1071)
+
+
+###################################################
+### chunk number 2: journals-data
+###################################################
+data("Journals", package = "AER")
+
+
+###################################################
+### chunk number 3: journals-dim
+###################################################
+dim(Journals)
+names(Journals)
+
+
+###################################################
+### chunk number 4: journals-plot eval=FALSE
+###################################################
+## plot(log(subs) ~ log(price/citations), data = Journals)
+
+
+###################################################
+### chunk number 5: journals-lm eval=FALSE
+###################################################
+## j_lm <- lm(log(subs) ~ log(price/citations), data = Journals)
+## abline(j_lm)
+
+
+###################################################
+### chunk number 6: journals-lmplot
+###################################################
+plot(log(subs) ~ log(price/citations), data = Journals)
+j_lm <- lm(log(subs) ~ log(price/citations), data = Journals)
+abline(j_lm)
+
+
+###################################################
+### chunk number 7: journals-lm-summary
+###################################################
+summary(j_lm)
+
+
+###################################################
+### chunk number 8: cps-data
+###################################################
+data("CPS1985", package = "AER")
+cps <- CPS1985
+
+
+###################################################
+### chunk number 9: cps-data1 eval=FALSE
+###################################################
+## data("CPS1985", package = "AER")
+## cps <- CPS1985
+
+
+###################################################
+### chunk number 10: cps-reg
+###################################################
+library("quantreg")
+cps_lm <- lm(log(wage) ~ experience + I(experience^2) +
+ education, data = cps)
+cps_rq <- rq(log(wage) ~ experience + I(experience^2) +
+ education, data = cps, tau = seq(0.2, 0.8, by = 0.15))
+
+
+###################################################
+### chunk number 11: cps-predict
+###################################################
+cps2 <- data.frame(education = mean(cps$education),
+ experience = min(cps$experience):max(cps$experience))
+cps2 <- cbind(cps2, predict(cps_lm, newdata = cps2,
+ interval = "prediction"))
+cps2 <- cbind(cps2,
+ predict(cps_rq, newdata = cps2, type = ""))
+
+
+###################################################
+### chunk number 12: rq-plot eval=FALSE
+###################################################
+## plot(log(wage) ~ experience, data = cps)
+## for(i in 6:10) lines(cps2[,i] ~ experience,
+## data = cps2, col = "red")
+
+
+###################################################
+### chunk number 13: rq-plot1
+###################################################
+plot(log(wage) ~ experience, data = cps)
+for(i in 6:10) lines(cps2[,i] ~ experience,
+ data = cps2, col = "red")
+
+
+###################################################
+### chunk number 14: srq-plot eval=FALSE
+###################################################
+## plot(summary(cps_rq))
+
+
+###################################################
+### chunk number 15: srq-plot1
+###################################################
+plot(summary(cps_rq))
+
+
+###################################################
+### chunk number 16: bkde-fit
+###################################################
+library("KernSmooth")
+cps_bkde <- bkde2D(cbind(cps$experience, log(cps$wage)),
+ bandwidth = c(3.5, 0.5), gridsize = c(200, 200))
+
+
+###################################################
+### chunk number 17: bkde-plot eval=FALSE
+###################################################
+## image(cps_bkde$x1, cps_bkde$x2, cps_bkde$fhat,
+## col = rev(gray.colors(10, gamma = 1)),
+## xlab = "experience", ylab = "log(wage)")
+## box()
+## lines(fit ~ experience, data = cps2)
+## lines(lwr ~ experience, data = cps2, lty = 2)
+## lines(upr ~ experience, data = cps2, lty = 2)
+
+
+###################################################
+### chunk number 18: bkde-plot1
+###################################################
+image(cps_bkde$x1, cps_bkde$x2, cps_bkde$fhat,
+ col = rev(gray.colors(10, gamma = 1)),
+ xlab = "experience", ylab = "log(wage)")
+box()
+lines(fit ~ experience, data = cps2)
+lines(lwr ~ experience, data = cps2, lty = 2)
+lines(upr ~ experience, data = cps2, lty = 2)
+
+
+###################################################
+### chunk number 19: install eval=FALSE
+###################################################
+## install.packages("AER")
+
+
+###################################################
+### chunk number 20: library
+###################################################
+library("AER")
+
+
+###################################################
+### chunk number 21: objects
+###################################################
+objects()
+
+
+###################################################
+### chunk number 22: search
+###################################################
+search()
+
+
+###################################################
+### chunk number 23: assignment
+###################################################
+x <- 2
+objects()
+
+
+###################################################
+### chunk number 24: remove
+###################################################
+remove(x)
+objects()
+
+
+###################################################
+### chunk number 25: log eval=FALSE
+###################################################
+## log(16, 2)
+## log(x = 16, 2)
+## log(16, base = 2)
+## log(base = 2, x = 16)
+
+
+###################################################
+### chunk number 26: q eval=FALSE
+###################################################
+## q()
+
+
+###################################################
+### chunk number 27: apropos
+###################################################
+apropos("help")
+
+
diff --git a/tests/Ch-Intro.Rout.save b/tests/Ch-Intro.Rout.save
new file mode 100644
index 0000000..b85b222
--- /dev/null
+++ b/tests/Ch-Intro.Rout.save
@@ -0,0 +1,303 @@
+
+R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
+Copyright (C) 2016 The R Foundation for Statistical Computing
+Platform: x86_64-pc-linux-gnu (64-bit)
+
+R is free software and comes with ABSOLUTELY NO WARRANTY.
+You are welcome to redistribute it under certain conditions.
+Type 'license()' or 'licence()' for distribution details.
+
+R is a collaborative project with many contributors.
+Type 'contributors()' for more information and
+'citation()' on how to cite R or R packages in publications.
+
+Type 'demo()' for some demos, 'help()' for on-line help, or
+'help.start()' for an HTML browser interface to help.
+Type 'q()' to quit R.
+
+> ###################################################
+> ### chunk number 1: setup
+> ###################################################
+> options(prompt = "R> ", continue = "+ ", width = 64,
++ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+R>
+R> options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
++ twofig = function() {par(mfrow = c(1,2))},
++ threefig = function() {par(mfrow = c(1,3))},
++ fourfig = function() {par(mfrow = c(2,2))},
++ sixfig = function() {par(mfrow = c(3,2))}))
+R>
+R> library("AER")
+Loading required package: car
+Loading required package: lmtest
+Loading required package: zoo
+
+Attaching package: 'zoo'
+
+The following objects are masked from 'package:base':
+
+ as.Date, as.Date.numeric
+
+Loading required package: sandwich
+Loading required package: survival
+R>
+R> set.seed(1071)
+R>
+R>
+R> ###################################################
+R> ### chunk number 2: journals-data
+R> ###################################################
+R> data("Journals", package = "AER")
+R>
+R>
+R> ###################################################
+R> ### chunk number 3: journals-dim
+R> ###################################################
+R> dim(Journals)
+[1] 180 10
+R> names(Journals)
+ [1] "title" "publisher" "society" "price"
+ [5] "pages" "charpp" "citations" "foundingyear"
+ [9] "subs" "field"
+R>
+R>
+R> ###################################################
+R> ### chunk number 4: journals-plot eval=FALSE
+R> ###################################################
+R> ## plot(log(subs) ~ log(price/citations), data = Journals)
+R>
+R>
+R> ###################################################
+R> ### chunk number 5: journals-lm eval=FALSE
+R> ###################################################
+R> ## j_lm <- lm(log(subs) ~ log(price/citations), data = Journals)
+R> ## abline(j_lm)
+R>
+R>
+R> ###################################################
+R> ### chunk number 6: journals-lmplot
+R> ###################################################
+R> plot(log(subs) ~ log(price/citations), data = Journals)
+R> j_lm <- lm(log(subs) ~ log(price/citations), data = Journals)
+R> abline(j_lm)
+R>
+R>
+R> ###################################################
+R> ### chunk number 7: journals-lm-summary
+R> ###################################################
+R> summary(j_lm)
+
+Call:
+lm(formula = log(subs) ~ log(price/citations), data = Journals)
+
+Residuals:
+ Min 1Q Median 3Q Max
+-2.7248 -0.5361 0.0372 0.4662 1.8481
+
+Coefficients:
+ Estimate Std. Error t value Pr(>|t|)
+(Intercept) 4.7662 0.0559 85.2 <2e-16
+log(price/citations) -0.5331 0.0356 -15.0 <2e-16
+
+Residual standard error: 0.75 on 178 degrees of freedom
+Multiple R-squared: 0.557, Adjusted R-squared: 0.555
+F-statistic: 224 on 1 and 178 DF, p-value: <2e-16
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 8: cps-data
+R> ###################################################
+R> data("CPS1985", package = "AER")
+R> cps <- CPS1985
+R>
+R>
+R> ###################################################
+R> ### chunk number 9: cps-data1 eval=FALSE
+R> ###################################################
+R> ## data("CPS1985", package = "AER")
+R> ## cps <- CPS1985
+R>
+R>
+R> ###################################################
+R> ### chunk number 10: cps-reg
+R> ###################################################
+R> library("quantreg")
+Loading required package: SparseM
+
+Attaching package: 'SparseM'
+
+The following object is masked from 'package:base':
+
+ backsolve
+
+
+Attaching package: 'quantreg'
+
+The following object is masked from 'package:survival':
+
+ untangle.specials
+
+R> cps_lm <- lm(log(wage) ~ experience + I(experience^2) +
++ education, data = cps)
+R> cps_rq <- rq(log(wage) ~ experience + I(experience^2) +
++ education, data = cps, tau = seq(0.2, 0.8, by = 0.15))
+R>
+R>
+R> ###################################################
+R> ### chunk number 11: cps-predict
+R> ###################################################
+R> cps2 <- data.frame(education = mean(cps$education),
++ experience = min(cps$experience):max(cps$experience))
+R> cps2 <- cbind(cps2, predict(cps_lm, newdata = cps2,
++ interval = "prediction"))
+R> cps2 <- cbind(cps2,
++ predict(cps_rq, newdata = cps2, type = ""))
+R>
+R>
+R> ###################################################
+R> ### chunk number 12: rq-plot eval=FALSE
+R> ###################################################
+R> ## plot(log(wage) ~ experience, data = cps)
+R> ## for(i in 6:10) lines(cps2[,i] ~ experience,
+R> ## data = cps2, col = "red")
+R>
+R>
+R> ###################################################
+R> ### chunk number 13: rq-plot1
+R> ###################################################
+R> plot(log(wage) ~ experience, data = cps)
+R> for(i in 6:10) lines(cps2[,i] ~ experience,
++ data = cps2, col = "red")
+R>
+R>
+R> ###################################################
+R> ### chunk number 14: srq-plot eval=FALSE
+R> ###################################################
+R> ## plot(summary(cps_rq))
+R>
+R>
+R> ###################################################
+R> ### chunk number 15: srq-plot1
+R> ###################################################
+R> plot(summary(cps_rq))
+Warning messages:
+1: In rq.fit.br(x, y, tau = tau, ci = TRUE, ...) :
+ Solution may be nonunique
+2: In rq.fit.br(x, y, tau = tau, ci = TRUE, ...) :
+ Solution may be nonunique
+R>
+R>
+R> ###################################################
+R> ### chunk number 16: bkde-fit
+R> ###################################################
+R> library("KernSmooth")
+KernSmooth 2.23 loaded
+Copyright M. P. Wand 1997-2009
+R> cps_bkde <- bkde2D(cbind(cps$experience, log(cps$wage)),
++ bandwidth = c(3.5, 0.5), gridsize = c(200, 200))
+R>
+R>
+R> ###################################################
+R> ### chunk number 17: bkde-plot eval=FALSE
+R> ###################################################
+R> ## image(cps_bkde$x1, cps_bkde$x2, cps_bkde$fhat,
+R> ## col = rev(gray.colors(10, gamma = 1)),
+R> ## xlab = "experience", ylab = "log(wage)")
+R> ## box()
+R> ## lines(fit ~ experience, data = cps2)
+R> ## lines(lwr ~ experience, data = cps2, lty = 2)
+R> ## lines(upr ~ experience, data = cps2, lty = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 18: bkde-plot1
+R> ###################################################
+R> image(cps_bkde$x1, cps_bkde$x2, cps_bkde$fhat,
++ col = rev(gray.colors(10, gamma = 1)),
++ xlab = "experience", ylab = "log(wage)")
+R> box()
+R> lines(fit ~ experience, data = cps2)
+R> lines(lwr ~ experience, data = cps2, lty = 2)
+R> lines(upr ~ experience, data = cps2, lty = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 19: install eval=FALSE
+R> ###################################################
+R> ## install.packages("AER")
+R>
+R>
+R> ###################################################
+R> ### chunk number 20: library
+R> ###################################################
+R> library("AER")
+R>
+R>
+R> ###################################################
+R> ### chunk number 21: objects
+R> ###################################################
+R> objects()
+[1] "CPS1985" "Journals" "cps" "cps2" "cps_bkde"
+[6] "cps_lm" "cps_rq" "i" "j_lm"
+R>
+R>
+R> ###################################################
+R> ### chunk number 22: search
+R> ###################################################
+R> search()
+ [1] ".GlobalEnv" "package:KernSmooth"
+ [3] "package:quantreg" "package:SparseM"
+ [5] "package:AER" "package:survival"
+ [7] "package:sandwich" "package:lmtest"
+ [9] "package:zoo" "package:car"
+[11] "package:stats" "package:graphics"
+[13] "package:grDevices" "package:utils"
+[15] "package:datasets" "package:methods"
+[17] "Autoloads" "package:base"
+R>
+R>
+R> ###################################################
+R> ### chunk number 23: assignment
+R> ###################################################
+R> x <- 2
+R> objects()
+ [1] "CPS1985" "Journals" "cps" "cps2" "cps_bkde"
+ [6] "cps_lm" "cps_rq" "i" "j_lm" "x"
+R>
+R>
+R> ###################################################
+R> ### chunk number 24: remove
+R> ###################################################
+R> remove(x)
+R> objects()
+[1] "CPS1985" "Journals" "cps" "cps2" "cps_bkde"
+[6] "cps_lm" "cps_rq" "i" "j_lm"
+R>
+R>
+R> ###################################################
+R> ### chunk number 25: log eval=FALSE
+R> ###################################################
+R> ## log(16, 2)
+R> ## log(x = 16, 2)
+R> ## log(16, base = 2)
+R> ## log(base = 2, x = 16)
+R>
+R>
+R> ###################################################
+R> ### chunk number 26: q eval=FALSE
+R> ###################################################
+R> ## q()
+R>
+R>
+R> ###################################################
+R> ### chunk number 27: apropos
+R> ###################################################
+R> apropos("help")
+[1] "help" "help.request" "help.search" "help.start"
+R>
+R>
+R>
+> proc.time()
+ user system elapsed
+ 1.508 0.048 1.557
diff --git a/tests/Ch-LinearRegression.R b/tests/Ch-LinearRegression.R
new file mode 100644
index 0000000..ebad197
--- /dev/null
+++ b/tests/Ch-LinearRegression.R
@@ -0,0 +1,600 @@
+###################################################
+### chunk number 1: setup
+###################################################
+options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+
+options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
+
+library("AER")
+
+set.seed(1071)
+
+
+###################################################
+### chunk number 2: data-journals
+###################################################
+data("Journals")
+journals <- Journals[, c("subs", "price")]
+journals$citeprice <- Journals$price/Journals$citations
+summary(journals)
+
+
+###################################################
+### chunk number 3: linreg-plot eval=FALSE
+###################################################
+## plot(log(subs) ~ log(citeprice), data = journals)
+## jour_lm <- lm(log(subs) ~ log(citeprice), data = journals)
+## abline(jour_lm)
+
+
+###################################################
+### chunk number 4: linreg-plot1
+###################################################
+plot(log(subs) ~ log(citeprice), data = journals)
+jour_lm <- lm(log(subs) ~ log(citeprice), data = journals)
+abline(jour_lm)
+
+
+###################################################
+### chunk number 5: linreg-class
+###################################################
+class(jour_lm)
+
+
+###################################################
+### chunk number 6: linreg-names
+###################################################
+names(jour_lm)
+
+
+###################################################
+### chunk number 7: linreg-summary
+###################################################
+summary(jour_lm)
+
+
+###################################################
+### chunk number 8: linreg-summary
+###################################################
+jour_slm <- summary(jour_lm)
+class(jour_slm)
+names(jour_slm)
+
+
+###################################################
+### chunk number 9: linreg-coef
+###################################################
+jour_slm$coefficients
+
+
+###################################################
+### chunk number 10: linreg-anova
+###################################################
+anova(jour_lm)
+
+
+###################################################
+### chunk number 11: journals-coef
+###################################################
+coef(jour_lm)
+
+
+###################################################
+### chunk number 12: journals-confint
+###################################################
+confint(jour_lm, level = 0.95)
+
+
+###################################################
+### chunk number 13: journals-predict
+###################################################
+predict(jour_lm, newdata = data.frame(citeprice = 2.11),
+ interval = "confidence")
+predict(jour_lm, newdata = data.frame(citeprice = 2.11),
+ interval = "prediction")
+
+
+###################################################
+### chunk number 14: predict-plot eval=FALSE
+###################################################
+## lciteprice <- seq(from = -6, to = 4, by = 0.25)
+## jour_pred <- predict(jour_lm, interval = "prediction",
+## newdata = data.frame(citeprice = exp(lciteprice)))
+## plot(log(subs) ~ log(citeprice), data = journals)
+## lines(jour_pred[, 1] ~ lciteprice, col = 1)
+## lines(jour_pred[, 2] ~ lciteprice, col = 1, lty = 2)
+## lines(jour_pred[, 3] ~ lciteprice, col = 1, lty = 2)
+
+
+###################################################
+### chunk number 15: predict-plot1
+###################################################
+lciteprice <- seq(from = -6, to = 4, by = 0.25)
+jour_pred <- predict(jour_lm, interval = "prediction",
+ newdata = data.frame(citeprice = exp(lciteprice)))
+plot(log(subs) ~ log(citeprice), data = journals)
+lines(jour_pred[, 1] ~ lciteprice, col = 1)
+lines(jour_pred[, 2] ~ lciteprice, col = 1, lty = 2)
+lines(jour_pred[, 3] ~ lciteprice, col = 1, lty = 2)
+
+
+###################################################
+### chunk number 16: journals-plot eval=FALSE
+###################################################
+## par(mfrow = c(2, 2))
+## plot(jour_lm)
+## par(mfrow = c(1, 1))
+
+
+###################################################
+### chunk number 17: journals-plot1
+###################################################
+par(mfrow = c(2, 2))
+plot(jour_lm)
+par(mfrow = c(1, 1))
+
+
+###################################################
+### chunk number 18: journal-lht
+###################################################
+linearHypothesis(jour_lm, "log(citeprice) = -0.5")
+
+
+###################################################
+### chunk number 19: CPS-data
+###################################################
+data("CPS1988")
+summary(CPS1988)
+
+
+###################################################
+### chunk number 20: CPS-base
+###################################################
+cps_lm <- lm(log(wage) ~ experience + I(experience^2) +
+ education + ethnicity, data = CPS1988)
+
+
+###################################################
+### chunk number 21: CPS-visualization-unused eval=FALSE
+###################################################
+## ex <- 0:56
+## ed <- with(CPS1988, tapply(education,
+## list(ethnicity, experience), mean))[, as.character(ex)]
+## fm <- cps_lm
+## wago <- predict(fm, newdata = data.frame(experience = ex,
+## ethnicity = "cauc", education = as.numeric(ed["cauc",])))
+## wagb <- predict(fm, newdata = data.frame(experience = ex,
+## ethnicity = "afam", education = as.numeric(ed["afam",])))
+## plot(log(wage) ~ experience, data = CPS1988, pch = ".",
+## col = as.numeric(ethnicity))
+## lines(ex, wago)
+## lines(ex, wagb, col = 2)
+
+
+###################################################
+### chunk number 22: CPS-summary
+###################################################
+summary(cps_lm)
+
+
+###################################################
+### chunk number 23: CPS-noeth
+###################################################
+cps_noeth <- lm(log(wage) ~ experience + I(experience^2) +
+ education, data = CPS1988)
+anova(cps_noeth, cps_lm)
+
+
+###################################################
+### chunk number 24: CPS-anova
+###################################################
+anova(cps_lm)
+
+
+###################################################
+### chunk number 25: CPS-noeth2 eval=FALSE
+###################################################
+## cps_noeth <- update(cps_lm, formula = . ~ . - ethnicity)
+
+
+###################################################
+### chunk number 26: CPS-waldtest
+###################################################
+waldtest(cps_lm, . ~ . - ethnicity)
+
+
+###################################################
+### chunk number 27: CPS-spline
+###################################################
+library("splines")
+cps_plm <- lm(log(wage) ~ bs(experience, df = 5) +
+ education + ethnicity, data = CPS1988)
+
+
+###################################################
+### chunk number 28: CPS-spline-summary eval=FALSE
+###################################################
+## summary(cps_plm)
+
+
+###################################################
+### chunk number 29: CPS-BIC
+###################################################
+cps_bs <- lapply(3:10, function(i) lm(log(wage) ~
+ bs(experience, df = i) + education + ethnicity,
+ data = CPS1988))
+structure(sapply(cps_bs, AIC, k = log(nrow(CPS1988))),
+ .Names = 3:10)
+
+
+###################################################
+### chunk number 30: plm-plot eval=FALSE
+###################################################
+## cps <- data.frame(experience = -2:60, education =
+## with(CPS1988, mean(education[ethnicity == "cauc"])),
+## ethnicity = "cauc")
+## cps$yhat1 <- predict(cps_lm, newdata = cps)
+## cps$yhat2 <- predict(cps_plm, newdata = cps)
+##
+## plot(log(wage) ~ jitter(experience, factor = 3), pch = 19,
+## col = rgb(0.5, 0.5, 0.5, alpha = 0.02), data = CPS1988)
+## lines(yhat1 ~ experience, data = cps, lty = 2)
+## lines(yhat2 ~ experience, data = cps)
+## legend("topleft", c("quadratic", "spline"), lty = c(2,1),
+## bty = "n")
+
+
+###################################################
+### chunk number 31: plm-plot1
+###################################################
+cps <- data.frame(experience = -2:60, education =
+ with(CPS1988, mean(education[ethnicity == "cauc"])),
+ ethnicity = "cauc")
+cps$yhat1 <- predict(cps_lm, newdata = cps)
+cps$yhat2 <- predict(cps_plm, newdata = cps)
+
+plot(log(wage) ~ jitter(experience, factor = 3), pch = 19,
+ col = rgb(0.5, 0.5, 0.5, alpha = 0.02), data = CPS1988)
+lines(yhat1 ~ experience, data = cps, lty = 2)
+lines(yhat2 ~ experience, data = cps)
+legend("topleft", c("quadratic", "spline"), lty = c(2,1),
+ bty = "n")
+
+
+###################################################
+### chunk number 32: CPS-int
+###################################################
+cps_int <- lm(log(wage) ~ experience + I(experience^2) +
+ education * ethnicity, data = CPS1988)
+coeftest(cps_int)
+
+
+###################################################
+### chunk number 33: CPS-int2 eval=FALSE
+###################################################
+## cps_int <- lm(log(wage) ~ experience + I(experience^2) +
+## education + ethnicity + education:ethnicity,
+## data = CPS1988)
+
+
+###################################################
+### chunk number 34: CPS-sep
+###################################################
+cps_sep <- lm(log(wage) ~ ethnicity /
+ (experience + I(experience^2) + education) - 1,
+ data = CPS1988)
+
+
+###################################################
+### chunk number 35: CPS-sep-coef
+###################################################
+cps_sep_cf <- matrix(coef(cps_sep), nrow = 2)
+rownames(cps_sep_cf) <- levels(CPS1988$ethnicity)
+colnames(cps_sep_cf) <- names(coef(cps_lm))[1:4]
+cps_sep_cf
+
+
+###################################################
+### chunk number 36: CPS-sep-anova
+###################################################
+anova(cps_sep, cps_lm)
+
+
+###################################################
+### chunk number 37: CPS-sep-visualization-unused eval=FALSE
+###################################################
+## ex <- 0:56
+## ed <- with(CPS1988, tapply(education, list(ethnicity,
+## experience), mean))[, as.character(ex)]
+## fm <- cps_lm
+## wago <- predict(fm, newdata = data.frame(experience = ex,
+## ethnicity = "cauc", education = as.numeric(ed["cauc",])))
+## wagb <- predict(fm, newdata = data.frame(experience = ex,
+## ethnicity = "afam", education = as.numeric(ed["afam",])))
+## plot(log(wage) ~ jitter(experience, factor = 2),
+## data = CPS1988, pch = ".", col = as.numeric(ethnicity))
+##
+##
+## plot(log(wage) ~ as.factor(experience), data = CPS1988,
+## pch = ".")
+## lines(ex, wago, lwd = 2)
+## lines(ex, wagb, col = 2, lwd = 2)
+## fm <- cps_sep
+## wago <- predict(fm, newdata = data.frame(experience = ex,
+## ethnicity = "cauc", education = as.numeric(ed["cauc",])))
+## wagb <- predict(fm, newdata = data.frame(experience = ex,
+## ethnicity = "afam", education = as.numeric(ed["afam",])))
+## lines(ex, wago, lty = 2, lwd = 2)
+## lines(ex, wagb, col = 2, lty = 2, lwd = 2)
+
+
+###################################################
+### chunk number 38: CPS-region
+###################################################
+CPS1988$region <- relevel(CPS1988$region, ref = "south")
+cps_region <- lm(log(wage) ~ ethnicity + education +
+ experience + I(experience^2) + region, data = CPS1988)
+coef(cps_region)
+
+
+###################################################
+### chunk number 39: wls1
+###################################################
+jour_wls1 <- lm(log(subs) ~ log(citeprice), data = journals,
+ weights = 1/citeprice^2)
+
+
+###################################################
+### chunk number 40: wls2
+###################################################
+jour_wls2 <- lm(log(subs) ~ log(citeprice), data = journals,
+ weights = 1/citeprice)
+
+
+###################################################
+### chunk number 41: journals-wls1 eval=FALSE
+###################################################
+## plot(log(subs) ~ log(citeprice), data = journals)
+## abline(jour_lm)
+## abline(jour_wls1, lwd = 2, lty = 2)
+## abline(jour_wls2, lwd = 2, lty = 3)
+## legend("bottomleft", c("OLS", "WLS1", "WLS2"),
+## lty = 1:3, lwd = 2, bty = "n")
+
+
+###################################################
+### chunk number 42: journals-wls11
+###################################################
+plot(log(subs) ~ log(citeprice), data = journals)
+abline(jour_lm)
+abline(jour_wls1, lwd = 2, lty = 2)
+abline(jour_wls2, lwd = 2, lty = 3)
+legend("bottomleft", c("OLS", "WLS1", "WLS2"),
+ lty = 1:3, lwd = 2, bty = "n")
+
+
+###################################################
+### chunk number 43: fgls1
+###################################################
+auxreg <- lm(log(residuals(jour_lm)^2) ~ log(citeprice),
+ data = journals)
+jour_fgls1 <- lm(log(subs) ~ log(citeprice),
+ weights = 1/exp(fitted(auxreg)), data = journals)
+
+
+###################################################
+### chunk number 44: fgls2
+###################################################
+gamma2i <- coef(auxreg)[2]
+gamma2 <- 0
+while(abs((gamma2i - gamma2)/gamma2) > 1e-7) {
+ gamma2 <- gamma2i
+ fglsi <- lm(log(subs) ~ log(citeprice), data = journals,
+ weights = 1/citeprice^gamma2)
+ gamma2i <- coef(lm(log(residuals(fglsi)^2) ~
+ log(citeprice), data = journals))[2]
+}
+jour_fgls2 <- lm(log(subs) ~ log(citeprice), data = journals,
+ weights = 1/citeprice^gamma2)
+
+
+###################################################
+### chunk number 45: fgls2-coef
+###################################################
+coef(jour_fgls2)
+
+
+###################################################
+### chunk number 46: journals-fgls
+###################################################
+plot(log(subs) ~ log(citeprice), data = journals)
+abline(jour_lm)
+abline(jour_fgls2, lty = 2, lwd = 2)
+
+
+###################################################
+### chunk number 47: usmacro-plot eval=FALSE
+###################################################
+## data("USMacroG")
+## plot(USMacroG[, c("dpi", "consumption")], lty = c(3, 1),
+## plot.type = "single", ylab = "")
+## legend("topleft", legend = c("income", "consumption"),
+## lty = c(3, 1), bty = "n")
+
+
+###################################################
+### chunk number 48: usmacro-plot1
+###################################################
+data("USMacroG")
+plot(USMacroG[, c("dpi", "consumption")], lty = c(3, 1),
+ plot.type = "single", ylab = "")
+legend("topleft", legend = c("income", "consumption"),
+ lty = c(3, 1), bty = "n")
+
+
+###################################################
+### chunk number 49: usmacro-fit
+###################################################
+library("dynlm")
+cons_lm1 <- dynlm(consumption ~ dpi + L(dpi), data = USMacroG)
+cons_lm2 <- dynlm(consumption ~ dpi + L(consumption),
+ data = USMacroG)
+
+
+###################################################
+### chunk number 50: usmacro-summary1
+###################################################
+summary(cons_lm1)
+
+
+###################################################
+### chunk number 51: usmacro-summary2
+###################################################
+summary(cons_lm2)
+
+
+###################################################
+### chunk number 52: dynlm-plot eval=FALSE
+###################################################
+## plot(merge(as.zoo(USMacroG[,"consumption"]), fitted(cons_lm1),
+## fitted(cons_lm2), 0, residuals(cons_lm1),
+## residuals(cons_lm2)), screens = rep(1:2, c(3, 3)),
+## lty = rep(1:3, 2), ylab = c("Fitted values", "Residuals"),
+## xlab = "Time", main = "")
+## legend(0.05, 0.95, c("observed", "cons_lm1", "cons_lm2"),
+## lty = 1:3, bty = "n")
+
+
+###################################################
+### chunk number 53: dynlm-plot1
+###################################################
+plot(merge(as.zoo(USMacroG[,"consumption"]), fitted(cons_lm1),
+ fitted(cons_lm2), 0, residuals(cons_lm1),
+ residuals(cons_lm2)), screens = rep(1:2, c(3, 3)),
+ lty = rep(1:3, 2), ylab = c("Fitted values", "Residuals"),
+ xlab = "Time", main = "")
+legend(0.05, 0.95, c("observed", "cons_lm1", "cons_lm2"),
+ lty = 1:3, bty = "n")
+
+
+###################################################
+### chunk number 54: encompassing1
+###################################################
+cons_lmE <- dynlm(consumption ~ dpi + L(dpi) +
+ L(consumption), data = USMacroG)
+
+
+###################################################
+### chunk number 55: encompassing2
+###################################################
+anova(cons_lm1, cons_lmE, cons_lm2)
+
+
+###################################################
+### chunk number 56: encompassing3
+###################################################
+encomptest(cons_lm1, cons_lm2)
+
+
+###################################################
+### chunk number 57: plm-data
+###################################################
+data("Grunfeld", package = "AER")
+library("plm")
+gr <- subset(Grunfeld, firm %in% c("General Electric",
+ "General Motors", "IBM"))
+pgr <- plm.data(gr, index = c("firm", "year"))
+
+
+###################################################
+### chunk number 58: plm-pool
+###################################################
+gr_pool <- plm(invest ~ value + capital, data = pgr,
+ model = "pooling")
+
+
+###################################################
+### chunk number 59: plm-FE
+###################################################
+gr_fe <- plm(invest ~ value + capital, data = pgr,
+ model = "within")
+summary(gr_fe)
+
+
+###################################################
+### chunk number 60: plm-pFtest
+###################################################
+pFtest(gr_fe, gr_pool)
+
+
+###################################################
+### chunk number 61: plm-RE
+###################################################
+gr_re <- plm(invest ~ value + capital, data = pgr,
+ model = "random", random.method = "walhus")
+summary(gr_re)
+
+
+###################################################
+### chunk number 62: plm-plmtest
+###################################################
+plmtest(gr_pool)
+
+
+###################################################
+### chunk number 63: plm-phtest
+###################################################
+phtest(gr_re, gr_fe)
+
+
+###################################################
+### chunk number 64: EmplUK-data
+###################################################
+data("EmplUK", package = "plm")
+form <- log(emp) ~ log(wage) + log(capital) + log(output)
+
+
+###################################################
+### chunk number 65: plm-AB
+###################################################
+empl_ab <- pgmm(dynformula(form, list(2, 1, 0, 1)),
+ data = EmplUK, index = c("firm", "year"),
+ effect = "twoways", model = "twosteps",
+ gmm.inst = ~ log(emp), lag.gmm = list(c(2, 99)))
+
+
+###################################################
+### chunk number 66: plm-AB-summary
+###################################################
+summary(empl_ab, robust = FALSE)
+
+
+###################################################
+### chunk number 67: systemfit
+###################################################
+library("systemfit")
+gr2 <- subset(Grunfeld, firm %in% c("Chrysler", "IBM"))
+pgr2 <- plm.data(gr2, c("firm", "year"))
+
+
+###################################################
+### chunk number 68: SUR
+###################################################
+gr_sur <- systemfit(invest ~ value + capital,
+ method = "SUR", data = pgr2)
+summary(gr_sur, residCov = FALSE, equations = FALSE)
+
+
+###################################################
+### chunk number 69: nlme eval=FALSE
+###################################################
+## library("nlme")
+## g1 <- subset(Grunfeld, firm == "Westinghouse")
+## gls(invest ~ value + capital, data = g1, correlation = corAR1())
+
+
diff --git a/tests/Ch-LinearRegression.Rout.save b/tests/Ch-LinearRegression.Rout.save
new file mode 100644
index 0000000..a8bb489
--- /dev/null
+++ b/tests/Ch-LinearRegression.Rout.save
@@ -0,0 +1,967 @@
+
+R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
+Copyright (C) 2016 The R Foundation for Statistical Computing
+Platform: x86_64-pc-linux-gnu (64-bit)
+
+R is free software and comes with ABSOLUTELY NO WARRANTY.
+You are welcome to redistribute it under certain conditions.
+Type 'license()' or 'licence()' for distribution details.
+
+R is a collaborative project with many contributors.
+Type 'contributors()' for more information and
+'citation()' on how to cite R or R packages in publications.
+
+Type 'demo()' for some demos, 'help()' for on-line help, or
+'help.start()' for an HTML browser interface to help.
+Type 'q()' to quit R.
+
+> ###################################################
+> ### chunk number 1: setup
+> ###################################################
+> options(prompt = "R> ", continue = "+ ", width = 64,
++ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+R>
+R> options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
++ twofig = function() {par(mfrow = c(1,2))},
++ threefig = function() {par(mfrow = c(1,3))},
++ fourfig = function() {par(mfrow = c(2,2))},
++ sixfig = function() {par(mfrow = c(3,2))}))
+R>
+R> library("AER")
+Loading required package: car
+Loading required package: lmtest
+Loading required package: zoo
+
+Attaching package: 'zoo'
+
+The following objects are masked from 'package:base':
+
+ as.Date, as.Date.numeric
+
+Loading required package: sandwich
+Loading required package: survival
+R>
+R> set.seed(1071)
+R>
+R>
+R> ###################################################
+R> ### chunk number 2: data-journals
+R> ###################################################
+R> data("Journals")
+R> journals <- Journals[, c("subs", "price")]
+R> journals$citeprice <- Journals$price/Journals$citations
+R> summary(journals)
+ subs price citeprice
+ Min. : 2 Min. : 20 Min. : 0.005
+ 1st Qu.: 52 1st Qu.: 134 1st Qu.: 0.464
+ Median : 122 Median : 282 Median : 1.321
+ Mean : 197 Mean : 418 Mean : 2.548
+ 3rd Qu.: 268 3rd Qu.: 541 3rd Qu.: 3.440
+ Max. :1098 Max. :2120 Max. :24.459
+R>
+R>
+R> ###################################################
+R> ### chunk number 3: linreg-plot eval=FALSE
+R> ###################################################
+R> ## plot(log(subs) ~ log(citeprice), data = journals)
+R> ## jour_lm <- lm(log(subs) ~ log(citeprice), data = journals)
+R> ## abline(jour_lm)
+R>
+R>
+R> ###################################################
+R> ### chunk number 4: linreg-plot1
+R> ###################################################
+R> plot(log(subs) ~ log(citeprice), data = journals)
+R> jour_lm <- lm(log(subs) ~ log(citeprice), data = journals)
+R> abline(jour_lm)
+R>
+R>
+R> ###################################################
+R> ### chunk number 5: linreg-class
+R> ###################################################
+R> class(jour_lm)
+[1] "lm"
+R>
+R>
+R> ###################################################
+R> ### chunk number 6: linreg-names
+R> ###################################################
+R> names(jour_lm)
+ [1] "coefficients" "residuals" "effects"
+ [4] "rank" "fitted.values" "assign"
+ [7] "qr" "df.residual" "xlevels"
+[10] "call" "terms" "model"
+R>
+R>
+R> ###################################################
+R> ### chunk number 7: linreg-summary
+R> ###################################################
+R> summary(jour_lm)
+
+Call:
+lm(formula = log(subs) ~ log(citeprice), data = journals)
+
+Residuals:
+ Min 1Q Median 3Q Max
+-2.7248 -0.5361 0.0372 0.4662 1.8481
+
+Coefficients:
+ Estimate Std. Error t value Pr(>|t|)
+(Intercept) 4.7662 0.0559 85.2 <2e-16
+log(citeprice) -0.5331 0.0356 -15.0 <2e-16
+
+Residual standard error: 0.75 on 178 degrees of freedom
+Multiple R-squared: 0.557, Adjusted R-squared: 0.555
+F-statistic: 224 on 1 and 178 DF, p-value: <2e-16
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 8: linreg-summary
+R> ###################################################
+R> jour_slm <- summary(jour_lm)
+R> class(jour_slm)
+[1] "summary.lm"
+R> names(jour_slm)
+ [1] "call" "terms" "residuals"
+ [4] "coefficients" "aliased" "sigma"
+ [7] "df" "r.squared" "adj.r.squared"
+[10] "fstatistic" "cov.unscaled"
+R>
+R>
+R> ###################################################
+R> ### chunk number 9: linreg-coef
+R> ###################################################
+R> jour_slm$coefficients
+ Estimate Std. Error t value Pr(>|t|)
+(Intercept) 4.7662 0.05591 85.25 2.954e-146
+log(citeprice) -0.5331 0.03561 -14.97 2.564e-33
+R>
+R>
+R> ###################################################
+R> ### chunk number 10: linreg-anova
+R> ###################################################
+R> anova(jour_lm)
+Analysis of Variance Table
+
+Response: log(subs)
+ Df Sum Sq Mean Sq F value Pr(>F)
+log(citeprice) 1 126 125.9 224 <2e-16
+Residuals 178 100 0.6
+R>
+R>
+R> ###################################################
+R> ### chunk number 11: journals-coef
+R> ###################################################
+R> coef(jour_lm)
+ (Intercept) log(citeprice)
+ 4.7662 -0.5331
+R>
+R>
+R> ###################################################
+R> ### chunk number 12: journals-confint
+R> ###################################################
+R> confint(jour_lm, level = 0.95)
+ 2.5 % 97.5 %
+(Intercept) 4.6559 4.8765
+log(citeprice) -0.6033 -0.4628
+R>
+R>
+R> ###################################################
+R> ### chunk number 13: journals-predict
+R> ###################################################
+R> predict(jour_lm, newdata = data.frame(citeprice = 2.11),
++ interval = "confidence")
+ fit lwr upr
+1 4.368 4.247 4.489
+R> predict(jour_lm, newdata = data.frame(citeprice = 2.11),
++ interval = "prediction")
+ fit lwr upr
+1 4.368 2.884 5.853
+R>
+R>
+R> ###################################################
+R> ### chunk number 14: predict-plot eval=FALSE
+R> ###################################################
+R> ## lciteprice <- seq(from = -6, to = 4, by = 0.25)
+R> ## jour_pred <- predict(jour_lm, interval = "prediction",
+R> ## newdata = data.frame(citeprice = exp(lciteprice)))
+R> ## plot(log(subs) ~ log(citeprice), data = journals)
+R> ## lines(jour_pred[, 1] ~ lciteprice, col = 1)
+R> ## lines(jour_pred[, 2] ~ lciteprice, col = 1, lty = 2)
+R> ## lines(jour_pred[, 3] ~ lciteprice, col = 1, lty = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 15: predict-plot1
+R> ###################################################
+R> lciteprice <- seq(from = -6, to = 4, by = 0.25)
+R> jour_pred <- predict(jour_lm, interval = "prediction",
++ newdata = data.frame(citeprice = exp(lciteprice)))
+R> plot(log(subs) ~ log(citeprice), data = journals)
+R> lines(jour_pred[, 1] ~ lciteprice, col = 1)
+R> lines(jour_pred[, 2] ~ lciteprice, col = 1, lty = 2)
+R> lines(jour_pred[, 3] ~ lciteprice, col = 1, lty = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 16: journals-plot eval=FALSE
+R> ###################################################
+R> ## par(mfrow = c(2, 2))
+R> ## plot(jour_lm)
+R> ## par(mfrow = c(1, 1))
+R>
+R>
+R> ###################################################
+R> ### chunk number 17: journals-plot1
+R> ###################################################
+R> par(mfrow = c(2, 2))
+R> plot(jour_lm)
+R> par(mfrow = c(1, 1))
+R>
+R>
+R> ###################################################
+R> ### chunk number 18: journal-lht
+R> ###################################################
+R> linearHypothesis(jour_lm, "log(citeprice) = -0.5")
+Linear hypothesis test
+
+Hypothesis:
+log(citeprice) = - 0.5
+
+Model 1: restricted model
+Model 2: log(subs) ~ log(citeprice)
+
+ Res.Df RSS Df Sum of Sq F Pr(>F)
+1 179 100
+2 178 100 1 0.484 0.86 0.35
+R>
+R>
+R> ###################################################
+R> ### chunk number 19: CPS-data
+R> ###################################################
+R> data("CPS1988")
+R> summary(CPS1988)
+ wage education experience ethnicity
+ Min. : 50 Min. : 0.0 Min. :-4.0 cauc:25923
+ 1st Qu.: 309 1st Qu.:12.0 1st Qu.: 8.0 afam: 2232
+ Median : 522 Median :12.0 Median :16.0
+ Mean : 604 Mean :13.1 Mean :18.2
+ 3rd Qu.: 783 3rd Qu.:15.0 3rd Qu.:27.0
+ Max. :18777 Max. :18.0 Max. :63.0
+ smsa region parttime
+ no : 7223 northeast:6441 no :25631
+ yes:20932 midwest :6863 yes: 2524
+ south :8760
+ west :6091
+
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 20: CPS-base
+R> ###################################################
+R> cps_lm <- lm(log(wage) ~ experience + I(experience^2) +
++ education + ethnicity, data = CPS1988)
+R>
+R>
+R> ###################################################
+R> ### chunk number 21: CPS-visualization-unused eval=FALSE
+R> ###################################################
+R> ## ex <- 0:56
+R> ## ed <- with(CPS1988, tapply(education,
+R> ## list(ethnicity, experience), mean))[, as.character(ex)]
+R> ## fm <- cps_lm
+R> ## wago <- predict(fm, newdata = data.frame(experience = ex,
+R> ## ethnicity = "cauc", education = as.numeric(ed["cauc",])))
+R> ## wagb <- predict(fm, newdata = data.frame(experience = ex,
+R> ## ethnicity = "afam", education = as.numeric(ed["afam",])))
+R> ## plot(log(wage) ~ experience, data = CPS1988, pch = ".",
+R> ## col = as.numeric(ethnicity))
+R> ## lines(ex, wago)
+R> ## lines(ex, wagb, col = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 22: CPS-summary
+R> ###################################################
+R> summary(cps_lm)
+
+Call:
+lm(formula = log(wage) ~ experience + I(experience^2) + education +
+ ethnicity, data = CPS1988)
+
+Residuals:
+ Min 1Q Median 3Q Max
+-2.943 -0.316 0.058 0.376 4.383
+
+Coefficients:
+ Estimate Std. Error t value Pr(>|t|)
+(Intercept) 4.321395 0.019174 225.4 <2e-16
+experience 0.077473 0.000880 88.0 <2e-16
+I(experience^2) -0.001316 0.000019 -69.3 <2e-16
+education 0.085673 0.001272 67.3 <2e-16
+ethnicityafam -0.243364 0.012918 -18.8 <2e-16
+
+Residual standard error: 0.584 on 28150 degrees of freedom
+Multiple R-squared: 0.335, Adjusted R-squared: 0.335
+F-statistic: 3.54e+03 on 4 and 28150 DF, p-value: <2e-16
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 23: CPS-noeth
+R> ###################################################
+R> cps_noeth <- lm(log(wage) ~ experience + I(experience^2) +
++ education, data = CPS1988)
+R> anova(cps_noeth, cps_lm)
+Analysis of Variance Table
+
+Model 1: log(wage) ~ experience + I(experience^2) + education
+Model 2: log(wage) ~ experience + I(experience^2) + education + ethnicity
+ Res.Df RSS Df Sum of Sq F Pr(>F)
+1 28151 9720
+2 28150 9599 1 121 355 <2e-16
+R>
+R>
+R> ###################################################
+R> ### chunk number 24: CPS-anova
+R> ###################################################
+R> anova(cps_lm)
+Analysis of Variance Table
+
+Response: log(wage)
+ Df Sum Sq Mean Sq F value Pr(>F)
+experience 1 840 840 2462 <2e-16
+I(experience^2) 1 2249 2249 6597 <2e-16
+education 1 1620 1620 4750 <2e-16
+ethnicity 1 121 121 355 <2e-16
+Residuals 28150 9599 0
+R>
+R>
+R> ###################################################
+R> ### chunk number 25: CPS-noeth2 eval=FALSE
+R> ###################################################
+R> ## cps_noeth <- update(cps_lm, formula = . ~ . - ethnicity)
+R>
+R>
+R> ###################################################
+R> ### chunk number 26: CPS-waldtest
+R> ###################################################
+R> waldtest(cps_lm, . ~ . - ethnicity)
+Wald test
+
+Model 1: log(wage) ~ experience + I(experience^2) + education + ethnicity
+Model 2: log(wage) ~ experience + I(experience^2) + education
+ Res.Df Df F Pr(>F)
+1 28150
+2 28151 -1 355 <2e-16
+R>
+R>
+R> ###################################################
+R> ### chunk number 27: CPS-spline
+R> ###################################################
+R> library("splines")
+R> cps_plm <- lm(log(wage) ~ bs(experience, df = 5) +
++ education + ethnicity, data = CPS1988)
+R>
+R>
+R> ###################################################
+R> ### chunk number 28: CPS-spline-summary eval=FALSE
+R> ###################################################
+R> ## summary(cps_plm)
+R>
+R>
+R> ###################################################
+R> ### chunk number 29: CPS-BIC
+R> ###################################################
+R> cps_bs <- lapply(3:10, function(i) lm(log(wage) ~
++ bs(experience, df = i) + education + ethnicity,
++ data = CPS1988))
+R> structure(sapply(cps_bs, AIC, k = log(nrow(CPS1988))),
++ .Names = 3:10)
+ 3 4 5 6 7 8 9 10
+49205 48836 48794 48795 48801 48797 48799 48802
+R>
+R>
+R> ###################################################
+R> ### chunk number 30: plm-plot eval=FALSE
+R> ###################################################
+R> ## cps <- data.frame(experience = -2:60, education =
+R> ## with(CPS1988, mean(education[ethnicity == "cauc"])),
+R> ## ethnicity = "cauc")
+R> ## cps$yhat1 <- predict(cps_lm, newdata = cps)
+R> ## cps$yhat2 <- predict(cps_plm, newdata = cps)
+R> ##
+R> ## plot(log(wage) ~ jitter(experience, factor = 3), pch = 19,
+R> ## col = rgb(0.5, 0.5, 0.5, alpha = 0.02), data = CPS1988)
+R> ## lines(yhat1 ~ experience, data = cps, lty = 2)
+R> ## lines(yhat2 ~ experience, data = cps)
+R> ## legend("topleft", c("quadratic", "spline"), lty = c(2,1),
+R> ## bty = "n")
+R>
+R>
+R> ###################################################
+R> ### chunk number 31: plm-plot1
+R> ###################################################
+R> cps <- data.frame(experience = -2:60, education =
++ with(CPS1988, mean(education[ethnicity == "cauc"])),
++ ethnicity = "cauc")
+R> cps$yhat1 <- predict(cps_lm, newdata = cps)
+R> cps$yhat2 <- predict(cps_plm, newdata = cps)
+R>
+R> plot(log(wage) ~ jitter(experience, factor = 3), pch = 19,
++ col = rgb(0.5, 0.5, 0.5, alpha = 0.02), data = CPS1988)
+R> lines(yhat1 ~ experience, data = cps, lty = 2)
+R> lines(yhat2 ~ experience, data = cps)
+R> legend("topleft", c("quadratic", "spline"), lty = c(2,1),
++ bty = "n")
+R>
+R>
+R> ###################################################
+R> ### chunk number 32: CPS-int
+R> ###################################################
+R> cps_int <- lm(log(wage) ~ experience + I(experience^2) +
++ education * ethnicity, data = CPS1988)
+R> coeftest(cps_int)
+
+t test of coefficients:
+
+ Estimate Std. Error t value Pr(>|t|)
+(Intercept) 4.313059 0.019590 220.17 <2e-16
+experience 0.077520 0.000880 88.06 <2e-16
+I(experience^2) -0.001318 0.000019 -69.34 <2e-16
+education 0.086312 0.001309 65.94 <2e-16
+ethnicityafam -0.123887 0.059026 -2.10 0.036
+education:ethnicityafam -0.009648 0.004651 -2.07 0.038
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 33: CPS-int2 eval=FALSE
+R> ###################################################
+R> ## cps_int <- lm(log(wage) ~ experience + I(experience^2) +
+R> ## education + ethnicity + education:ethnicity,
+R> ## data = CPS1988)
+R>
+R>
+R> ###################################################
+R> ### chunk number 34: CPS-sep
+R> ###################################################
+R> cps_sep <- lm(log(wage) ~ ethnicity /
++ (experience + I(experience^2) + education) - 1,
++ data = CPS1988)
+R>
+R>
+R> ###################################################
+R> ### chunk number 35: CPS-sep-coef
+R> ###################################################
+R> cps_sep_cf <- matrix(coef(cps_sep), nrow = 2)
+R> rownames(cps_sep_cf) <- levels(CPS1988$ethnicity)
+R> colnames(cps_sep_cf) <- names(coef(cps_lm))[1:4]
+R> cps_sep_cf
+ (Intercept) experience I(experience^2) education
+cauc 4.310 0.07923 -0.0013597 0.08575
+afam 4.159 0.06190 -0.0009415 0.08654
+R>
+R>
+R> ###################################################
+R> ### chunk number 36: CPS-sep-anova
+R> ###################################################
+R> anova(cps_sep, cps_lm)
+Analysis of Variance Table
+
+Model 1: log(wage) ~ ethnicity/(experience + I(experience^2) + education) -
+ 1
+Model 2: log(wage) ~ experience + I(experience^2) + education + ethnicity
+ Res.Df RSS Df Sum of Sq F Pr(>F)
+1 28147 9582
+2 28150 9599 -3 -16.8 16.5 1.1e-10
+R>
+R>
+R> ###################################################
+R> ### chunk number 37: CPS-sep-visualization-unused eval=FALSE
+R> ###################################################
+R> ## ex <- 0:56
+R> ## ed <- with(CPS1988, tapply(education, list(ethnicity,
+R> ## experience), mean))[, as.character(ex)]
+R> ## fm <- cps_lm
+R> ## wago <- predict(fm, newdata = data.frame(experience = ex,
+R> ## ethnicity = "cauc", education = as.numeric(ed["cauc",])))
+R> ## wagb <- predict(fm, newdata = data.frame(experience = ex,
+R> ## ethnicity = "afam", education = as.numeric(ed["afam",])))
+R> ## plot(log(wage) ~ jitter(experience, factor = 2),
+R> ## data = CPS1988, pch = ".", col = as.numeric(ethnicity))
+R> ##
+R> ##
+R> ## plot(log(wage) ~ as.factor(experience), data = CPS1988,
+R> ## pch = ".")
+R> ## lines(ex, wago, lwd = 2)
+R> ## lines(ex, wagb, col = 2, lwd = 2)
+R> ## fm <- cps_sep
+R> ## wago <- predict(fm, newdata = data.frame(experience = ex,
+R> ## ethnicity = "cauc", education = as.numeric(ed["cauc",])))
+R> ## wagb <- predict(fm, newdata = data.frame(experience = ex,
+R> ## ethnicity = "afam", education = as.numeric(ed["afam",])))
+R> ## lines(ex, wago, lty = 2, lwd = 2)
+R> ## lines(ex, wagb, col = 2, lty = 2, lwd = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 38: CPS-region
+R> ###################################################
+R> CPS1988$region <- relevel(CPS1988$region, ref = "south")
+R> cps_region <- lm(log(wage) ~ ethnicity + education +
++ experience + I(experience^2) + region, data = CPS1988)
+R> coef(cps_region)
+ (Intercept) ethnicityafam education experience
+ 4.283606 -0.225679 0.084672 0.077656
+I(experience^2) regionnortheast regionmidwest regionwest
+ -0.001323 0.131920 0.043789 0.040327
+R>
+R>
+R> ###################################################
+R> ### chunk number 39: wls1
+R> ###################################################
+R> jour_wls1 <- lm(log(subs) ~ log(citeprice), data = journals,
++ weights = 1/citeprice^2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 40: wls2
+R> ###################################################
+R> jour_wls2 <- lm(log(subs) ~ log(citeprice), data = journals,
++ weights = 1/citeprice)
+R>
+R>
+R> ###################################################
+R> ### chunk number 41: journals-wls1 eval=FALSE
+R> ###################################################
+R> ## plot(log(subs) ~ log(citeprice), data = journals)
+R> ## abline(jour_lm)
+R> ## abline(jour_wls1, lwd = 2, lty = 2)
+R> ## abline(jour_wls2, lwd = 2, lty = 3)
+R> ## legend("bottomleft", c("OLS", "WLS1", "WLS2"),
+R> ## lty = 1:3, lwd = 2, bty = "n")
+R>
+R>
+R> ###################################################
+R> ### chunk number 42: journals-wls11
+R> ###################################################
+R> plot(log(subs) ~ log(citeprice), data = journals)
+R> abline(jour_lm)
+R> abline(jour_wls1, lwd = 2, lty = 2)
+R> abline(jour_wls2, lwd = 2, lty = 3)
+R> legend("bottomleft", c("OLS", "WLS1", "WLS2"),
++ lty = 1:3, lwd = 2, bty = "n")
+R>
+R>
+R> ###################################################
+R> ### chunk number 43: fgls1
+R> ###################################################
+R> auxreg <- lm(log(residuals(jour_lm)^2) ~ log(citeprice),
++ data = journals)
+R> jour_fgls1 <- lm(log(subs) ~ log(citeprice),
++ weights = 1/exp(fitted(auxreg)), data = journals)
+R>
+R>
+R> ###################################################
+R> ### chunk number 44: fgls2
+R> ###################################################
+R> gamma2i <- coef(auxreg)[2]
+R> gamma2 <- 0
+R> while(abs((gamma2i - gamma2)/gamma2) > 1e-7) {
++ gamma2 <- gamma2i
++ fglsi <- lm(log(subs) ~ log(citeprice), data = journals,
++ weights = 1/citeprice^gamma2)
++ gamma2i <- coef(lm(log(residuals(fglsi)^2) ~
++ log(citeprice), data = journals))[2]
++ }
+R> jour_fgls2 <- lm(log(subs) ~ log(citeprice), data = journals,
++ weights = 1/citeprice^gamma2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 45: fgls2-coef
+R> ###################################################
+R> coef(jour_fgls2)
+ (Intercept) log(citeprice)
+ 4.7758 -0.5008
+R>
+R>
+R> ###################################################
+R> ### chunk number 46: journals-fgls
+R> ###################################################
+R> plot(log(subs) ~ log(citeprice), data = journals)
+R> abline(jour_lm)
+R> abline(jour_fgls2, lty = 2, lwd = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 47: usmacro-plot eval=FALSE
+R> ###################################################
+R> ## data("USMacroG")
+R> ## plot(USMacroG[, c("dpi", "consumption")], lty = c(3, 1),
+R> ## plot.type = "single", ylab = "")
+R> ## legend("topleft", legend = c("income", "consumption"),
+R> ## lty = c(3, 1), bty = "n")
+R>
+R>
+R> ###################################################
+R> ### chunk number 48: usmacro-plot1
+R> ###################################################
+R> data("USMacroG")
+R> plot(USMacroG[, c("dpi", "consumption")], lty = c(3, 1),
++ plot.type = "single", ylab = "")
+R> legend("topleft", legend = c("income", "consumption"),
++ lty = c(3, 1), bty = "n")
+R>
+R>
+R> ###################################################
+R> ### chunk number 49: usmacro-fit
+R> ###################################################
+R> library("dynlm")
+R> cons_lm1 <- dynlm(consumption ~ dpi + L(dpi), data = USMacroG)
+R> cons_lm2 <- dynlm(consumption ~ dpi + L(consumption),
++ data = USMacroG)
+R>
+R>
+R> ###################################################
+R> ### chunk number 50: usmacro-summary1
+R> ###################################################
+R> summary(cons_lm1)
+
+Time series regression with "ts" data:
+Start = 1950(2), End = 2000(4)
+
+Call:
+dynlm(formula = consumption ~ dpi + L(dpi), data = USMacroG)
+
+Residuals:
+ Min 1Q Median 3Q Max
+-190.0 -56.7 1.6 49.9 323.9
+
+Coefficients:
+ Estimate Std. Error t value Pr(>|t|)
+(Intercept) -81.0796 14.5081 -5.59 7.4e-08
+dpi 0.8912 0.2063 4.32 2.4e-05
+L(dpi) 0.0309 0.2075 0.15 0.88
+
+Residual standard error: 87.6 on 200 degrees of freedom
+Multiple R-squared: 0.996, Adjusted R-squared: 0.996
+F-statistic: 2.79e+04 on 2 and 200 DF, p-value: <2e-16
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 51: usmacro-summary2
+R> ###################################################
+R> summary(cons_lm2)
+
+Time series regression with "ts" data:
+Start = 1950(2), End = 2000(4)
+
+Call:
+dynlm(formula = consumption ~ dpi + L(consumption), data = USMacroG)
+
+Residuals:
+ Min 1Q Median 3Q Max
+-101.30 -9.67 1.14 12.69 45.32
+
+Coefficients:
+ Estimate Std. Error t value Pr(>|t|)
+(Intercept) 0.53522 3.84517 0.14 0.89
+dpi -0.00406 0.01663 -0.24 0.81
+L(consumption) 1.01311 0.01816 55.79 <2e-16
+
+Residual standard error: 21.5 on 200 degrees of freedom
+Multiple R-squared: 1, Adjusted R-squared: 1
+F-statistic: 4.63e+05 on 2 and 200 DF, p-value: <2e-16
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 52: dynlm-plot eval=FALSE
+R> ###################################################
+R> ## plot(merge(as.zoo(USMacroG[,"consumption"]), fitted(cons_lm1),
+R> ## fitted(cons_lm2), 0, residuals(cons_lm1),
+R> ## residuals(cons_lm2)), screens = rep(1:2, c(3, 3)),
+R> ## lty = rep(1:3, 2), ylab = c("Fitted values", "Residuals"),
+R> ## xlab = "Time", main = "")
+R> ## legend(0.05, 0.95, c("observed", "cons_lm1", "cons_lm2"),
+R> ## lty = 1:3, bty = "n")
+R>
+R>
+R> ###################################################
+R> ### chunk number 53: dynlm-plot1
+R> ###################################################
+R> plot(merge(as.zoo(USMacroG[,"consumption"]), fitted(cons_lm1),
++ fitted(cons_lm2), 0, residuals(cons_lm1),
++ residuals(cons_lm2)), screens = rep(1:2, c(3, 3)),
++ lty = rep(1:3, 2), ylab = c("Fitted values", "Residuals"),
++ xlab = "Time", main = "")
+R> legend(0.05, 0.95, c("observed", "cons_lm1", "cons_lm2"),
++ lty = 1:3, bty = "n")
+R>
+R>
+R> ###################################################
+R> ### chunk number 54: encompassing1
+R> ###################################################
+R> cons_lmE <- dynlm(consumption ~ dpi + L(dpi) +
++ L(consumption), data = USMacroG)
+R>
+R>
+R> ###################################################
+R> ### chunk number 55: encompassing2
+R> ###################################################
+R> anova(cons_lm1, cons_lmE, cons_lm2)
+Analysis of Variance Table
+
+Model 1: consumption ~ dpi + L(dpi)
+Model 2: consumption ~ dpi + L(dpi) + L(consumption)
+Model 3: consumption ~ dpi + L(consumption)
+ Res.Df RSS Df Sum of Sq F Pr(>F)
+1 200 1534001
+2 199 73550 1 1460451 3951.4 < 2e-16
+3 200 92644 -1 -19094 51.7 1.3e-11
+R>
+R>
+R> ###################################################
+R> ### chunk number 56: encompassing3
+R> ###################################################
+R> encomptest(cons_lm1, cons_lm2)
+Encompassing test
+
+Model 1: consumption ~ dpi + L(dpi)
+Model 2: consumption ~ dpi + L(consumption)
+Model E: consumption ~ dpi + L(dpi) + L(consumption)
+ Res.Df Df F Pr(>F)
+M1 vs. ME 199 -1 3951.4 < 2e-16
+M2 vs. ME 199 -1 51.7 1.3e-11
+R>
+R>
+R> ###################################################
+R> ### chunk number 57: plm-data
+R> ###################################################
+R> data("Grunfeld", package = "AER")
+R> library("plm")
+Loading required package: Formula
+R> gr <- subset(Grunfeld, firm %in% c("General Electric",
++ "General Motors", "IBM"))
+R> pgr <- plm.data(gr, index = c("firm", "year"))
+R>
+R>
+R> ###################################################
+R> ### chunk number 58: plm-pool
+R> ###################################################
+R> gr_pool <- plm(invest ~ value + capital, data = pgr,
++ model = "pooling")
+R>
+R>
+R> ###################################################
+R> ### chunk number 59: plm-FE
+R> ###################################################
+R> gr_fe <- plm(invest ~ value + capital, data = pgr,
++ model = "within")
+R> summary(gr_fe)
+Oneway (individual) effect Within Model
+
+Call:
+plm(formula = invest ~ value + capital, data = pgr, model = "within")
+
+Balanced Panel: n=3, T=20, N=60
+
+Residuals :
+ Min. 1st Qu. Median 3rd Qu. Max.
+-167.00 -26.10 2.09 26.80 202.00
+
+Coefficients :
+ Estimate Std. Error t-value Pr(>|t|)
+value 0.1049 0.0163 6.42 3.3e-08
+capital 0.3453 0.0244 14.16 < 2e-16
+
+Total Sum of Squares: 1890000
+Residual Sum of Squares: 244000
+R-Squared: 0.871
+Adj. R-Squared: 0.861
+F-statistic: 185.407 on 2 and 55 DF, p-value: <2e-16
+R>
+R>
+R> ###################################################
+R> ### chunk number 60: plm-pFtest
+R> ###################################################
+R> pFtest(gr_fe, gr_pool)
+
+ F test for individual effects
+
+data: invest ~ value + capital
+F = 57, df1 = 2, df2 = 55, p-value = 4e-14
+alternative hypothesis: significant effects
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 61: plm-RE
+R> ###################################################
+R> gr_re <- plm(invest ~ value + capital, data = pgr,
++ model = "random", random.method = "walhus")
+R> summary(gr_re)
+Oneway (individual) effect Random Effect Model
+ (Wallace-Hussain's transformation)
+
+Call:
+plm(formula = invest ~ value + capital, data = pgr, model = "random",
+ random.method = "walhus")
+
+Balanced Panel: n=3, T=20, N=60
+
+Effects:
+ var std.dev share
+idiosyncratic 4389.3 66.3 0.35
+individual 8079.7 89.9 0.65
+theta: 0.837
+
+Residuals :
+ Min. 1st Qu. Median 3rd Qu. Max.
+-187.00 -32.90 6.96 31.40 210.00
+
+Coefficients :
+ Estimate Std. Error t-value Pr(>|t|)
+(Intercept) -109.9766 61.7014 -1.78 0.08
+value 0.1043 0.0150 6.95 3.8e-09
+capital 0.3448 0.0245 14.06 < 2e-16
+
+Total Sum of Squares: 1990000
+Residual Sum of Squares: 258000
+R-Squared: 0.87
+Adj. R-Squared: 0.866
+F-statistic: 191.545 on 2 and 57 DF, p-value: <2e-16
+R>
+R>
+R> ###################################################
+R> ### chunk number 62: plm-plmtest
+R> ###################################################
+R> plmtest(gr_pool)
+
+ Lagrange Multiplier Test - (Honda) for balanced panels
+
+data: invest ~ value + capital
+normal = 15, p-value <2e-16
+alternative hypothesis: significant effects
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 63: plm-phtest
+R> ###################################################
+R> phtest(gr_re, gr_fe)
+
+ Hausman Test
+
+data: invest ~ value + capital
+chisq = 0.04, df = 2, p-value = 1
+alternative hypothesis: one model is inconsistent
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 64: EmplUK-data
+R> ###################################################
+R> data("EmplUK", package = "plm")
+R> form <- log(emp) ~ log(wage) + log(capital) + log(output)
+R>
+R>
+R> ###################################################
+R> ### chunk number 65: plm-AB
+R> ###################################################
+R> empl_ab <- pgmm(dynformula(form, list(2, 1, 0, 1)),
++ data = EmplUK, index = c("firm", "year"),
++ effect = "twoways", model = "twosteps",
++ gmm.inst = ~ log(emp), lag.gmm = list(c(2, 99)))
+R>
+R>
+R> ###################################################
+R> ### chunk number 66: plm-AB-summary
+R> ###################################################
+R> summary(empl_ab, robust = FALSE)
+Twoways effects Two steps model
+
+Call:
+pgmm(formula = dynformula(form, list(2, 1, 0, 1)), data = EmplUK,
+ effect = "twoways", model = "twosteps", index = c("firm",
+ "year"), gmm.inst = ~log(emp), lag.gmm = list(c(2, 99)))
+
+Unbalanced Panel: n=140, T=7-9, N=1031
+
+Number of Observations Used: 611
+
+Residuals
+ Min. 1st Qu. Median Mean 3rd Qu. Max.
+-0.6190 -0.0256 0.0000 -0.0001 0.0332 0.6410
+
+Coefficients
+ Estimate Std. Error z-value Pr(>|z|)
+lag(log(emp), c(1, 2))1 0.4742 0.0853 5.56 2.7e-08
+lag(log(emp), c(1, 2))2 -0.0530 0.0273 -1.94 0.05222
+log(wage) -0.5132 0.0493 -10.40 < 2e-16
+lag(log(wage), 1) 0.2246 0.0801 2.81 0.00502
+log(capital) 0.2927 0.0395 7.42 1.2e-13
+log(output) 0.6098 0.1085 5.62 1.9e-08
+lag(log(output), 1) -0.4464 0.1248 -3.58 0.00035
+
+Sargan Test: chisq(25) = 30.11 (p.value=0.22)
+Autocorrelation test (1): normal = -2.428 (p.value=0.0152)
+Autocorrelation test (2): normal = -0.3325 (p.value=0.739)
+Wald test for coefficients: chisq(7) = 372 (p.value=<2e-16)
+Wald test for time dummies: chisq(6) = 26.9 (p.value=0.000151)
+R>
+R>
+R> ###################################################
+R> ### chunk number 67: systemfit
+R> ###################################################
+R> library("systemfit")
+Loading required package: Matrix
+R> gr2 <- subset(Grunfeld, firm %in% c("Chrysler", "IBM"))
+R> pgr2 <- plm.data(gr2, c("firm", "year"))
+R>
+R>
+R> ###################################################
+R> ### chunk number 68: SUR
+R> ###################################################
+R> gr_sur <- systemfit(invest ~ value + capital,
++ method = "SUR", data = pgr2)
+R> summary(gr_sur, residCov = FALSE, equations = FALSE)
+
+systemfit results
+method: SUR
+
+ N DF SSR detRCov OLS-R2 McElroy-R2
+system 40 34 4114 11022 0.929 0.927
+
+ N DF SSR MSE RMSE R2 Adj R2
+Chrysler 20 17 3002 176.6 13.29 0.913 0.903
+IBM 20 17 1112 65.4 8.09 0.952 0.946
+
+
+Coefficients:
+ Estimate Std. Error t value Pr(>|t|)
+Chrysler_(Intercept) -5.7031 13.2774 -0.43 0.67293
+Chrysler_value 0.0780 0.0196 3.98 0.00096
+Chrysler_capital 0.3115 0.0287 10.85 4.6e-09
+IBM_(Intercept) -8.0908 4.5216 -1.79 0.09139
+IBM_value 0.1272 0.0306 4.16 0.00066
+IBM_capital 0.0966 0.0983 0.98 0.33951
+R>
+R>
+R> ###################################################
+R> ### chunk number 69: nlme eval=FALSE
+R> ###################################################
+R> ## library("nlme")
+R> ## g1 <- subset(Grunfeld, firm == "Westinghouse")
+R> ## gls(invest ~ value + capital, data = g1, correlation = corAR1())
+R>
+R>
+R>
+> proc.time()
+ user system elapsed
+ 3.772 0.072 3.846
diff --git a/tests/Ch-Microeconometrics.R b/tests/Ch-Microeconometrics.R
new file mode 100644
index 0000000..7da424c
--- /dev/null
+++ b/tests/Ch-Microeconometrics.R
@@ -0,0 +1,390 @@
+###################################################
+### chunk number 1: setup
+###################################################
+options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+
+options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
+
+library("AER")
+
+set.seed(1071)
+
+
+###################################################
+### chunk number 2: swisslabor-data
+###################################################
+data("SwissLabor")
+swiss_probit <- glm(participation ~ . + I(age^2),
+ data = SwissLabor, family = binomial(link = "probit"))
+summary(swiss_probit)
+
+
+###################################################
+### chunk number 3: swisslabor-plot eval=FALSE
+###################################################
+## plot(participation ~ age, data = SwissLabor, ylevels = 2:1)
+
+
+###################################################
+### chunk number 4: swisslabor-plot-refined
+###################################################
+plot(participation ~ education, data = SwissLabor, ylevels = 2:1)
+fm <- glm(participation ~ education + I(education^2), data = SwissLabor, family = binomial)
+edu <- sort(unique(SwissLabor$education))
+prop <- sapply(edu, function(x) mean(SwissLabor$education <= x))
+lines(predict(fm, newdata = data.frame(education = edu), type = "response") ~ prop, col = 2)
+
+plot(participation ~ age, data = SwissLabor, ylevels = 2:1)
+fm <- glm(participation ~ age + I(age^2), data = SwissLabor, family = binomial)
+ag <- sort(unique(SwissLabor$age))
+prop <- sapply(ag, function(x) mean(SwissLabor$age <= x))
+lines(predict(fm, newdata = data.frame(age = ag), type = "response") ~ prop, col = 2)
+
+
+###################################################
+### chunk number 5: effects1
+###################################################
+fav <- mean(dnorm(predict(swiss_probit, type = "link")))
+fav * coef(swiss_probit)
+
+
+###################################################
+### chunk number 6: effects2
+###################################################
+av <- colMeans(SwissLabor[, -c(1, 7)])
+av <- data.frame(rbind(swiss = av, foreign = av),
+ foreign = factor(c("no", "yes")))
+av <- predict(swiss_probit, newdata = av, type = "link")
+av <- dnorm(av)
+av["swiss"] * coef(swiss_probit)[-7]
+
+
+###################################################
+### chunk number 7: effects3
+###################################################
+av["foreign"] * coef(swiss_probit)[-7]
+
+
+###################################################
+### chunk number 8: mcfadden
+###################################################
+swiss_probit0 <- update(swiss_probit, formula = . ~ 1)
+1 - as.vector(logLik(swiss_probit)/logLik(swiss_probit0))
+
+
+###################################################
+### chunk number 9: confusion-matrix
+###################################################
+table(true = SwissLabor$participation,
+ pred = round(fitted(swiss_probit)))
+
+
+###################################################
+### chunk number 10: confusion-matrix1
+###################################################
+tab <- table(true = SwissLabor$participation,
+ pred = round(fitted(swiss_probit)))
+tabp <- round(100 * c(tab[1,1] + tab[2,2], tab[2,1] + tab[1,2])/sum(tab), digits = 2)
+
+
+###################################################
+### chunk number 11: roc-plot eval=FALSE
+###################################################
+## library("ROCR")
+## pred <- prediction(fitted(swiss_probit),
+## SwissLabor$participation)
+## plot(performance(pred, "acc"))
+## plot(performance(pred, "tpr", "fpr"))
+## abline(0, 1, lty = 2)
+
+
+###################################################
+### chunk number 12: roc-plot1
+###################################################
+library("ROCR")
+pred <- prediction(fitted(swiss_probit),
+ SwissLabor$participation)
+plot(performance(pred, "acc"))
+plot(performance(pred, "tpr", "fpr"))
+abline(0, 1, lty = 2)
+
+
+###################################################
+### chunk number 13: rss
+###################################################
+deviance(swiss_probit)
+sum(residuals(swiss_probit, type = "deviance")^2)
+sum(residuals(swiss_probit, type = "pearson")^2)
+
+
+###################################################
+### chunk number 14: coeftest eval=FALSE
+###################################################
+## coeftest(swiss_probit, vcov = sandwich)
+
+
+###################################################
+### chunk number 15: murder
+###################################################
+data("MurderRates")
+murder_logit <- glm(I(executions > 0) ~ time + income +
+ noncauc + lfp + southern, data = MurderRates,
+ family = binomial)
+
+
+###################################################
+### chunk number 16: murder-coeftest
+###################################################
+coeftest(murder_logit)
+
+
+###################################################
+### chunk number 17: murder2
+###################################################
+murder_logit2 <- glm(I(executions > 0) ~ time + income +
+ noncauc + lfp + southern, data = MurderRates,
+ family = binomial, control = list(epsilon = 1e-15,
+ maxit = 50, trace = FALSE))
+
+
+###################################################
+### chunk number 18: murder2-coeftest
+###################################################
+coeftest(murder_logit2)
+
+
+###################################################
+### chunk number 19: separation
+###################################################
+table(I(MurderRates$executions > 0), MurderRates$southern)
+
+
+###################################################
+### chunk number 20: countreg-pois
+###################################################
+data("RecreationDemand")
+rd_pois <- glm(trips ~ ., data = RecreationDemand,
+ family = poisson)
+
+
+###################################################
+### chunk number 21: countreg-pois-coeftest
+###################################################
+coeftest(rd_pois)
+
+
+###################################################
+### chunk number 22: countreg-pois-logLik
+###################################################
+logLik(rd_pois)
+
+
+###################################################
+### chunk number 23: countreg-odtest1
+###################################################
+dispersiontest(rd_pois)
+
+
+###################################################
+### chunk number 24: countreg-odtest2
+###################################################
+dispersiontest(rd_pois, trafo = 2)
+
+
+###################################################
+### chunk number 25: countreg-nbin
+###################################################
+library("MASS")
+rd_nb <- glm.nb(trips ~ ., data = RecreationDemand)
+coeftest(rd_nb)
+logLik(rd_nb)
+
+
+###################################################
+### chunk number 26: countreg-se
+###################################################
+round(sqrt(rbind(diag(vcov(rd_pois)),
+ diag(sandwich(rd_pois)))), digits = 3)
+
+
+###################################################
+### chunk number 27: countreg-sandwich
+###################################################
+coeftest(rd_pois, vcov = sandwich)
+
+
+###################################################
+### chunk number 28: countreg-OPG
+###################################################
+round(sqrt(diag(vcovOPG(rd_pois))), 3)
+
+
+###################################################
+### chunk number 29: countreg-plot
+###################################################
+plot(table(RecreationDemand$trips), ylab = "")
+
+
+###################################################
+### chunk number 30: countreg-zeros
+###################################################
+rbind(obs = table(RecreationDemand$trips)[1:10], exp = round(
+ sapply(0:9, function(x) sum(dpois(x, fitted(rd_pois))))))
+
+
+###################################################
+### chunk number 31: countreg-pscl
+###################################################
+library("pscl")
+
+
+###################################################
+### chunk number 32: countreg-zinb
+###################################################
+rd_zinb <- zeroinfl(trips ~ . | quality + income,
+ data = RecreationDemand, dist = "negbin")
+
+
+###################################################
+### chunk number 33: countreg-zinb-summary
+###################################################
+summary(rd_zinb)
+
+
+###################################################
+### chunk number 34: countreg-zinb-expected
+###################################################
+round(colSums(predict(rd_zinb, type = "prob")[,1:10]))
+
+
+###################################################
+### chunk number 35: countreg-hurdle
+###################################################
+rd_hurdle <- hurdle(trips ~ . | quality + income,
+ data = RecreationDemand, dist = "negbin")
+summary(rd_hurdle)
+
+
+###################################################
+### chunk number 36: countreg-hurdle-expected
+###################################################
+round(colSums(predict(rd_hurdle, type = "prob")[,1:10]))
+
+
+###################################################
+### chunk number 37: tobit1
+###################################################
+data("Affairs")
+aff_tob <- tobit(affairs ~ age + yearsmarried +
+ religiousness + occupation + rating, data = Affairs)
+summary(aff_tob)
+
+
+###################################################
+### chunk number 38: tobit2
+###################################################
+aff_tob2 <- update(aff_tob, right = 4)
+summary(aff_tob2)
+
+
+###################################################
+### chunk number 39: tobit3
+###################################################
+linearHypothesis(aff_tob, c("age = 0", "occupation = 0"),
+ vcov = sandwich)
+
+
+###################################################
+### chunk number 40: numeric-response
+###################################################
+SwissLabor$partnum <- as.numeric(SwissLabor$participation) - 1
+
+
+###################################################
+### chunk number 41: kleinspady eval=FALSE
+###################################################
+## library("np")
+## swiss_bw <- npindexbw(partnum ~ income + age + education +
+## youngkids + oldkids + foreign + I(age^2), data = SwissLabor,
+## method = "kleinspady", nmulti = 5)
+
+
+###################################################
+### chunk number 42: kleinspady-bw eval=FALSE
+###################################################
+## summary(swiss_bw)
+
+
+###################################################
+### chunk number 43: kleinspady-summary eval=FALSE
+###################################################
+## swiss_ks <- npindex(bws = swiss_bw, gradients = TRUE)
+## summary(swiss_ks)
+
+
+###################################################
+### chunk number 44: probit-confusion
+###################################################
+table(Actual = SwissLabor$participation, Predicted =
+ round(predict(swiss_probit, type = "response")))
+
+
+###################################################
+### chunk number 45: bw-tab
+###################################################
+data("BankWages")
+edcat <- factor(BankWages$education)
+levels(edcat)[3:10] <- rep(c("14-15", "16-18", "19-21"),
+ c(2, 3, 3))
+tab <- xtabs(~ edcat + job, data = BankWages)
+prop.table(tab, 1)
+
+
+###################################################
+### chunk number 46: bw-plot eval=FALSE
+###################################################
+## plot(job ~ edcat, data = BankWages, off = 0)
+
+
+###################################################
+### chunk number 47: bw-plot1
+###################################################
+plot(job ~ edcat, data = BankWages, off = 0)
+box()
+
+
+###################################################
+### chunk number 48: bw-multinom
+###################################################
+library("nnet")
+bank_mnl <- multinom(job ~ education + minority,
+ data = BankWages, subset = gender == "male", trace = FALSE)
+
+
+###################################################
+### chunk number 49: bw-multinom-coeftest
+###################################################
+coeftest(bank_mnl)
+
+
+###################################################
+### chunk number 50: bw-polr
+###################################################
+library("MASS")
+bank_polr <- polr(job ~ education + minority,
+ data = BankWages, subset = gender == "male", Hess = TRUE)
+coeftest(bank_polr)
+
+
+###################################################
+### chunk number 51: bw-AIC
+###################################################
+AIC(bank_mnl)
+AIC(bank_polr)
+
+
diff --git a/tests/Ch-Microeconometrics.Rout.save b/tests/Ch-Microeconometrics.Rout.save
new file mode 100644
index 0000000..82e9165
--- /dev/null
+++ b/tests/Ch-Microeconometrics.Rout.save
@@ -0,0 +1,758 @@
+
+R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
+Copyright (C) 2016 The R Foundation for Statistical Computing
+Platform: x86_64-pc-linux-gnu (64-bit)
+
+R is free software and comes with ABSOLUTELY NO WARRANTY.
+You are welcome to redistribute it under certain conditions.
+Type 'license()' or 'licence()' for distribution details.
+
+R is a collaborative project with many contributors.
+Type 'contributors()' for more information and
+'citation()' on how to cite R or R packages in publications.
+
+Type 'demo()' for some demos, 'help()' for on-line help, or
+'help.start()' for an HTML browser interface to help.
+Type 'q()' to quit R.
+
+> ###################################################
+> ### chunk number 1: setup
+> ###################################################
+> options(prompt = "R> ", continue = "+ ", width = 64,
++ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+R>
+R> options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
++ twofig = function() {par(mfrow = c(1,2))},
++ threefig = function() {par(mfrow = c(1,3))},
++ fourfig = function() {par(mfrow = c(2,2))},
++ sixfig = function() {par(mfrow = c(3,2))}))
+R>
+R> library("AER")
+Loading required package: car
+Loading required package: lmtest
+Loading required package: zoo
+
+Attaching package: 'zoo'
+
+The following objects are masked from 'package:base':
+
+ as.Date, as.Date.numeric
+
+Loading required package: sandwich
+Loading required package: survival
+R>
+R> set.seed(1071)
+R>
+R>
+R> ###################################################
+R> ### chunk number 2: swisslabor-data
+R> ###################################################
+R> data("SwissLabor")
+R> swiss_probit <- glm(participation ~ . + I(age^2),
++ data = SwissLabor, family = binomial(link = "probit"))
+R> summary(swiss_probit)
+
+Call:
+glm(formula = participation ~ . + I(age^2), family = binomial(link = "probit"),
+ data = SwissLabor)
+
+Deviance Residuals:
+ Min 1Q Median 3Q Max
+-1.919 -0.970 -0.479 1.021 2.480
+
+Coefficients:
+ Estimate Std. Error z value Pr(>|z|)
+(Intercept) 3.7491 1.4069 2.66 0.0077
+income -0.6669 0.1320 -5.05 4.3e-07
+age 2.0753 0.4054 5.12 3.1e-07
+education 0.0192 0.0179 1.07 0.2843
+youngkids -0.7145 0.1004 -7.12 1.1e-12
+oldkids -0.1470 0.0509 -2.89 0.0039
+foreignyes 0.7144 0.1213 5.89 3.9e-09
+I(age^2) -0.2943 0.0499 -5.89 3.8e-09
+
+(Dispersion parameter for binomial family taken to be 1)
+
+ Null deviance: 1203.2 on 871 degrees of freedom
+Residual deviance: 1017.2 on 864 degrees of freedom
+AIC: 1033
+
+Number of Fisher Scoring iterations: 4
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 3: swisslabor-plot eval=FALSE
+R> ###################################################
+R> ## plot(participation ~ age, data = SwissLabor, ylevels = 2:1)
+R>
+R>
+R> ###################################################
+R> ### chunk number 4: swisslabor-plot-refined
+R> ###################################################
+R> plot(participation ~ education, data = SwissLabor, ylevels = 2:1)
+R> fm <- glm(participation ~ education + I(education^2), data = SwissLabor, family = binomial)
+R> edu <- sort(unique(SwissLabor$education))
+R> prop <- sapply(edu, function(x) mean(SwissLabor$education <= x))
+R> lines(predict(fm, newdata = data.frame(education = edu), type = "response") ~ prop, col = 2)
+R>
+R> plot(participation ~ age, data = SwissLabor, ylevels = 2:1)
+R> fm <- glm(participation ~ age + I(age^2), data = SwissLabor, family = binomial)
+R> ag <- sort(unique(SwissLabor$age))
+R> prop <- sapply(ag, function(x) mean(SwissLabor$age <= x))
+R> lines(predict(fm, newdata = data.frame(age = ag), type = "response") ~ prop, col = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 5: effects1
+R> ###################################################
+R> fav <- mean(dnorm(predict(swiss_probit, type = "link")))
+R> fav * coef(swiss_probit)
+(Intercept) income age education youngkids
+ 1.241930 -0.220932 0.687466 0.006359 -0.236682
+ oldkids foreignyes I(age^2)
+ -0.048690 0.236644 -0.097505
+R>
+R>
+R> ###################################################
+R> ### chunk number 6: effects2
+R> ###################################################
+R> av <- colMeans(SwissLabor[, -c(1, 7)])
+R> av <- data.frame(rbind(swiss = av, foreign = av),
++ foreign = factor(c("no", "yes")))
+R> av <- predict(swiss_probit, newdata = av, type = "link")
+R> av <- dnorm(av)
+R> av["swiss"] * coef(swiss_probit)[-7]
+(Intercept) income age education youngkids
+ 1.495137 -0.265976 0.827628 0.007655 -0.284938
+ oldkids I(age^2)
+ -0.058617 -0.117384
+R>
+R>
+R> ###################################################
+R> ### chunk number 7: effects3
+R> ###################################################
+R> av["foreign"] * coef(swiss_probit)[-7]
+(Intercept) income age education youngkids
+ 1.136517 -0.202180 0.629115 0.005819 -0.216593
+ oldkids I(age^2)
+ -0.044557 -0.089229
+R>
+R>
+R> ###################################################
+R> ### chunk number 8: mcfadden
+R> ###################################################
+R> swiss_probit0 <- update(swiss_probit, formula = . ~ 1)
+R> 1 - as.vector(logLik(swiss_probit)/logLik(swiss_probit0))
+[1] 0.1546
+R>
+R>
+R> ###################################################
+R> ### chunk number 9: confusion-matrix
+R> ###################################################
+R> table(true = SwissLabor$participation,
++ pred = round(fitted(swiss_probit)))
+ pred
+true 0 1
+ no 337 134
+ yes 146 255
+R>
+R>
+R> ###################################################
+R> ### chunk number 10: confusion-matrix1
+R> ###################################################
+R> tab <- table(true = SwissLabor$participation,
++ pred = round(fitted(swiss_probit)))
+R> tabp <- round(100 * c(tab[1,1] + tab[2,2], tab[2,1] + tab[1,2])/sum(tab), digits = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 11: roc-plot eval=FALSE
+R> ###################################################
+R> ## library("ROCR")
+R> ## pred <- prediction(fitted(swiss_probit),
+R> ## SwissLabor$participation)
+R> ## plot(performance(pred, "acc"))
+R> ## plot(performance(pred, "tpr", "fpr"))
+R> ## abline(0, 1, lty = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 12: roc-plot1
+R> ###################################################
+R> library("ROCR")
+Loading required package: gplots
+
+Attaching package: 'gplots'
+
+The following object is masked from 'package:stats':
+
+ lowess
+
+R> pred <- prediction(fitted(swiss_probit),
++ SwissLabor$participation)
+R> plot(performance(pred, "acc"))
+R> plot(performance(pred, "tpr", "fpr"))
+R> abline(0, 1, lty = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 13: rss
+R> ###################################################
+R> deviance(swiss_probit)
+[1] 1017
+R> sum(residuals(swiss_probit, type = "deviance")^2)
+[1] 1017
+R> sum(residuals(swiss_probit, type = "pearson")^2)
+[1] 866.5
+R>
+R>
+R> ###################################################
+R> ### chunk number 14: coeftest eval=FALSE
+R> ###################################################
+R> ## coeftest(swiss_probit, vcov = sandwich)
+R>
+R>
+R> ###################################################
+R> ### chunk number 15: murder
+R> ###################################################
+R> data("MurderRates")
+R> murder_logit <- glm(I(executions > 0) ~ time + income +
++ noncauc + lfp + southern, data = MurderRates,
++ family = binomial)
+Warning message:
+glm.fit: fitted probabilities numerically 0 or 1 occurred
+R>
+R>
+R> ###################################################
+R> ### chunk number 16: murder-coeftest
+R> ###################################################
+R> coeftest(murder_logit)
+
+z test of coefficients:
+
+ Estimate Std. Error z value Pr(>|z|)
+(Intercept) 10.9933 20.7734 0.53 0.597
+time 0.0194 0.0104 1.87 0.062
+income 10.6101 5.6541 1.88 0.061
+noncauc 70.9879 36.4118 1.95 0.051
+lfp -0.6676 0.4767 -1.40 0.161
+southernyes 17.3313 2872.1707 0.01 0.995
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 17: murder2
+R> ###################################################
+R> murder_logit2 <- glm(I(executions > 0) ~ time + income +
++ noncauc + lfp + southern, data = MurderRates,
++ family = binomial, control = list(epsilon = 1e-15,
++ maxit = 50, trace = FALSE))
+Warning message:
+glm.fit: fitted probabilities numerically 0 or 1 occurred
+R>
+R>
+R> ###################################################
+R> ### chunk number 18: murder2-coeftest
+R> ###################################################
+R> coeftest(murder_logit2)
+
+z test of coefficients:
+
+ Estimate Std. Error z value Pr(>|z|)
+(Intercept) 1.10e+01 2.08e+01 0.53 0.597
+time 1.94e-02 1.04e-02 1.87 0.062
+income 1.06e+01 5.65e+00 1.88 0.061
+noncauc 7.10e+01 3.64e+01 1.95 0.051
+lfp -6.68e-01 4.77e-01 -1.40 0.161
+southernyes 3.13e+01 1.73e+07 0.00 1.000
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 19: separation
+R> ###################################################
+R> table(I(MurderRates$executions > 0), MurderRates$southern)
+
+ no yes
+ FALSE 9 0
+ TRUE 20 15
+R>
+R>
+R> ###################################################
+R> ### chunk number 20: countreg-pois
+R> ###################################################
+R> data("RecreationDemand")
+R> rd_pois <- glm(trips ~ ., data = RecreationDemand,
++ family = poisson)
+R>
+R>
+R> ###################################################
+R> ### chunk number 21: countreg-pois-coeftest
+R> ###################################################
+R> coeftest(rd_pois)
+
+z test of coefficients:
+
+ Estimate Std. Error z value Pr(>|z|)
+(Intercept) 0.26499 0.09372 2.83 0.0047
+quality 0.47173 0.01709 27.60 < 2e-16
+skiyes 0.41821 0.05719 7.31 2.6e-13
+income -0.11132 0.01959 -5.68 1.3e-08
+userfeeyes 0.89817 0.07899 11.37 < 2e-16
+costC -0.00343 0.00312 -1.10 0.2713
+costS -0.04254 0.00167 -25.47 < 2e-16
+costH 0.03613 0.00271 13.34 < 2e-16
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 22: countreg-pois-logLik
+R> ###################################################
+R> logLik(rd_pois)
+'log Lik.' -1529 (df=8)
+R>
+R>
+R> ###################################################
+R> ### chunk number 23: countreg-odtest1
+R> ###################################################
+R> dispersiontest(rd_pois)
+
+ Overdispersion test
+
+data: rd_pois
+z = 2.4, p-value = 0.008
+alternative hypothesis: true dispersion is greater than 1
+sample estimates:
+dispersion
+ 6.566
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 24: countreg-odtest2
+R> ###################################################
+R> dispersiontest(rd_pois, trafo = 2)
+
+ Overdispersion test
+
+data: rd_pois
+z = 2.9, p-value = 0.002
+alternative hypothesis: true alpha is greater than 0
+sample estimates:
+alpha
+1.316
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 25: countreg-nbin
+R> ###################################################
+R> library("MASS")
+R> rd_nb <- glm.nb(trips ~ ., data = RecreationDemand)
+R> coeftest(rd_nb)
+
+z test of coefficients:
+
+ Estimate Std. Error z value Pr(>|z|)
+(Intercept) -1.12194 0.21430 -5.24 1.6e-07
+quality 0.72200 0.04012 18.00 < 2e-16
+skiyes 0.61214 0.15030 4.07 4.6e-05
+income -0.02606 0.04245 -0.61 0.539
+userfeeyes 0.66917 0.35302 1.90 0.058
+costC 0.04801 0.00918 5.23 1.7e-07
+costS -0.09269 0.00665 -13.93 < 2e-16
+costH 0.03884 0.00775 5.01 5.4e-07
+
+R> logLik(rd_nb)
+'log Lik.' -825.6 (df=9)
+R>
+R>
+R> ###################################################
+R> ### chunk number 26: countreg-se
+R> ###################################################
+R> round(sqrt(rbind(diag(vcov(rd_pois)),
++ diag(sandwich(rd_pois)))), digits = 3)
+ (Intercept) quality skiyes income userfeeyes costC costS
+[1,] 0.094 0.017 0.057 0.02 0.079 0.003 0.002
+[2,] 0.432 0.049 0.194 0.05 0.247 0.015 0.012
+ costH
+[1,] 0.003
+[2,] 0.009
+R>
+R>
+R> ###################################################
+R> ### chunk number 27: countreg-sandwich
+R> ###################################################
+R> coeftest(rd_pois, vcov = sandwich)
+
+z test of coefficients:
+
+ Estimate Std. Error z value Pr(>|z|)
+(Intercept) 0.26499 0.43248 0.61 0.54006
+quality 0.47173 0.04885 9.66 < 2e-16
+skiyes 0.41821 0.19387 2.16 0.03099
+income -0.11132 0.05031 -2.21 0.02691
+userfeeyes 0.89817 0.24691 3.64 0.00028
+costC -0.00343 0.01470 -0.23 0.81549
+costS -0.04254 0.01173 -3.62 0.00029
+costH 0.03613 0.00939 3.85 0.00012
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 28: countreg-OPG
+R> ###################################################
+R> round(sqrt(diag(vcovOPG(rd_pois))), 3)
+(Intercept) quality skiyes income userfeeyes
+ 0.025 0.007 0.020 0.010 0.033
+ costC costS costH
+ 0.001 0.000 0.001
+R>
+R>
+R> ###################################################
+R> ### chunk number 29: countreg-plot
+R> ###################################################
+R> plot(table(RecreationDemand$trips), ylab = "")
+R>
+R>
+R> ###################################################
+R> ### chunk number 30: countreg-zeros
+R> ###################################################
+R> rbind(obs = table(RecreationDemand$trips)[1:10], exp = round(
++ sapply(0:9, function(x) sum(dpois(x, fitted(rd_pois))))))
+ 0 1 2 3 4 5 6 7 8 9
+obs 417 68 38 34 17 13 11 2 8 1
+exp 277 146 68 41 30 23 17 13 10 7
+R>
+R>
+R> ###################################################
+R> ### chunk number 31: countreg-pscl
+R> ###################################################
+R> library("pscl")
+Loading required package: lattice
+Classes and Methods for R developed in the
+
+Political Science Computational Laboratory
+
+Department of Political Science
+
+Stanford University
+
+Simon Jackman
+
+hurdle and zeroinfl functions by Achim Zeileis
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 32: countreg-zinb
+R> ###################################################
+R> rd_zinb <- zeroinfl(trips ~ . | quality + income,
++ data = RecreationDemand, dist = "negbin")
+R>
+R>
+R> ###################################################
+R> ### chunk number 33: countreg-zinb-summary
+R> ###################################################
+R> summary(rd_zinb)
+
+Call:
+zeroinfl(formula = trips ~ . | quality + income, data = RecreationDemand,
+ dist = "negbin")
+
+Pearson residuals:
+ Min 1Q Median 3Q Max
+-1.0889 -0.2004 -0.0570 -0.0451 40.0139
+
+Count model coefficients (negbin with log link):
+ Estimate Std. Error z value Pr(>|z|)
+(Intercept) 1.09663 0.25668 4.27 1.9e-05
+quality 0.16891 0.05303 3.19 0.0014
+skiyes 0.50069 0.13449 3.72 0.0002
+income -0.06927 0.04380 -1.58 0.1138
+userfeeyes 0.54279 0.28280 1.92 0.0549
+costC 0.04044 0.01452 2.79 0.0053
+costS -0.06621 0.00775 -8.55 < 2e-16
+costH 0.02060 0.01023 2.01 0.0441
+Log(theta) 0.19017 0.11299 1.68 0.0924
+
+Zero-inflation model coefficients (binomial with logit link):
+ Estimate Std. Error z value Pr(>|z|)
+(Intercept) 5.743 1.556 3.69 0.00022
+quality -8.307 3.682 -2.26 0.02404
+income -0.258 0.282 -0.92 0.35950
+
+Theta = 1.209
+Number of iterations in BFGS optimization: 26
+Log-likelihood: -722 on 12 Df
+R>
+R>
+R> ###################################################
+R> ### chunk number 34: countreg-zinb-expected
+R> ###################################################
+R> round(colSums(predict(rd_zinb, type = "prob")[,1:10]))
+ 0 1 2 3 4 5 6 7 8 9
+433 47 35 27 20 16 12 10 8 7
+R>
+R>
+R> ###################################################
+R> ### chunk number 35: countreg-hurdle
+R> ###################################################
+R> rd_hurdle <- hurdle(trips ~ . | quality + income,
++ data = RecreationDemand, dist = "negbin")
+R> summary(rd_hurdle)
+
+Call:
+hurdle(formula = trips ~ . | quality + income, data = RecreationDemand,
+ dist = "negbin")
+
+Pearson residuals:
+ Min 1Q Median 3Q Max
+-1.610 -0.207 -0.185 -0.164 12.111
+
+Count model coefficients (truncated negbin with log link):
+ Estimate Std. Error z value Pr(>|z|)
+(Intercept) 0.8419 0.3828 2.20 0.0278
+quality 0.1717 0.0723 2.37 0.0176
+skiyes 0.6224 0.1901 3.27 0.0011
+income -0.0571 0.0645 -0.88 0.3763
+userfeeyes 0.5763 0.3851 1.50 0.1345
+costC 0.0571 0.0217 2.63 0.0085
+costS -0.0775 0.0115 -6.71 1.9e-11
+costH 0.0124 0.0149 0.83 0.4064
+Log(theta) -0.5303 0.2611 -2.03 0.0423
+Zero hurdle model coefficients (binomial with logit link):
+ Estimate Std. Error z value Pr(>|z|)
+(Intercept) -2.7663 0.3623 -7.64 2.3e-14
+quality 1.5029 0.1003 14.98 < 2e-16
+income -0.0447 0.0785 -0.57 0.57
+
+Theta: count = 0.588
+Number of iterations in BFGS optimization: 18
+Log-likelihood: -765 on 12 Df
+R>
+R>
+R> ###################################################
+R> ### chunk number 36: countreg-hurdle-expected
+R> ###################################################
+R> round(colSums(predict(rd_hurdle, type = "prob")[,1:10]))
+ 0 1 2 3 4 5 6 7 8 9
+417 74 42 27 19 14 10 8 6 5
+R>
+R>
+R> ###################################################
+R> ### chunk number 37: tobit1
+R> ###################################################
+R> data("Affairs")
+R> aff_tob <- tobit(affairs ~ age + yearsmarried +
++ religiousness + occupation + rating, data = Affairs)
+R> summary(aff_tob)
+
+Call:
+tobit(formula = affairs ~ age + yearsmarried + religiousness +
+ occupation + rating, data = Affairs)
+
+Observations:
+ Total Left-censored Uncensored Right-censored
+ 601 451 150 0
+
+Coefficients:
+ Estimate Std. Error z value Pr(>|z|)
+(Intercept) 8.1742 2.7414 2.98 0.0029
+age -0.1793 0.0791 -2.27 0.0234
+yearsmarried 0.5541 0.1345 4.12 3.8e-05
+religiousness -1.6862 0.4038 -4.18 3.0e-05
+occupation 0.3261 0.2544 1.28 0.2000
+rating -2.2850 0.4078 -5.60 2.1e-08
+Log(scale) 2.1099 0.0671 31.44 < 2e-16
+
+Scale: 8.25
+
+Gaussian distribution
+Number of Newton-Raphson Iterations: 4
+Log-likelihood: -706 on 7 Df
+Wald-statistic: 67.7 on 5 Df, p-value: 3.1e-13
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 38: tobit2
+R> ###################################################
+R> aff_tob2 <- update(aff_tob, right = 4)
+R> summary(aff_tob2)
+
+Call:
+tobit(formula = affairs ~ age + yearsmarried + religiousness +
+ occupation + rating, right = 4, data = Affairs)
+
+Observations:
+ Total Left-censored Uncensored Right-censored
+ 601 451 70 80
+
+Coefficients:
+ Estimate Std. Error z value Pr(>|z|)
+(Intercept) 7.9010 2.8039 2.82 0.00483
+age -0.1776 0.0799 -2.22 0.02624
+yearsmarried 0.5323 0.1412 3.77 0.00016
+religiousness -1.6163 0.4244 -3.81 0.00014
+occupation 0.3242 0.2539 1.28 0.20162
+rating -2.2070 0.4498 -4.91 9.3e-07
+Log(scale) 2.0723 0.1104 18.77 < 2e-16
+
+Scale: 7.94
+
+Gaussian distribution
+Number of Newton-Raphson Iterations: 4
+Log-likelihood: -500 on 7 Df
+Wald-statistic: 42.6 on 5 Df, p-value: 4.5e-08
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 39: tobit3
+R> ###################################################
+R> linearHypothesis(aff_tob, c("age = 0", "occupation = 0"),
++ vcov = sandwich)
+Linear hypothesis test
+
+Hypothesis:
+age = 0
+occupation = 0
+
+Model 1: restricted model
+Model 2: affairs ~ age + yearsmarried + religiousness + occupation + rating
+
+Note: Coefficient covariance matrix supplied.
+
+ Res.Df Df Chisq Pr(>Chisq)
+1 596
+2 594 2 4.91 0.086
+R>
+R>
+R> ###################################################
+R> ### chunk number 40: numeric-response
+R> ###################################################
+R> SwissLabor$partnum <- as.numeric(SwissLabor$participation) - 1
+R>
+R>
+R> ###################################################
+R> ### chunk number 41: kleinspady eval=FALSE
+R> ###################################################
+R> ## library("np")
+R> ## swiss_bw <- npindexbw(partnum ~ income + age + education +
+R> ## youngkids + oldkids + foreign + I(age^2), data = SwissLabor,
+R> ## method = "kleinspady", nmulti = 5)
+R>
+R>
+R> ###################################################
+R> ### chunk number 42: kleinspady-bw eval=FALSE
+R> ###################################################
+R> ## summary(swiss_bw)
+R>
+R>
+R> ###################################################
+R> ### chunk number 43: kleinspady-summary eval=FALSE
+R> ###################################################
+R> ## swiss_ks <- npindex(bws = swiss_bw, gradients = TRUE)
+R> ## summary(swiss_ks)
+R>
+R>
+R> ###################################################
+R> ### chunk number 44: probit-confusion
+R> ###################################################
+R> table(Actual = SwissLabor$participation, Predicted =
++ round(predict(swiss_probit, type = "response")))
+ Predicted
+Actual 0 1
+ no 337 134
+ yes 146 255
+R>
+R>
+R> ###################################################
+R> ### chunk number 45: bw-tab
+R> ###################################################
+R> data("BankWages")
+R> edcat <- factor(BankWages$education)
+R> levels(edcat)[3:10] <- rep(c("14-15", "16-18", "19-21"),
++ c(2, 3, 3))
+R> tab <- xtabs(~ edcat + job, data = BankWages)
+R> prop.table(tab, 1)
+ job
+edcat custodial admin manage
+ 8 0.245283 0.754717 0.000000
+ 12 0.068421 0.926316 0.005263
+ 14-15 0.008197 0.959016 0.032787
+ 16-18 0.000000 0.367089 0.632911
+ 19-21 0.000000 0.033333 0.966667
+R>
+R>
+R> ###################################################
+R> ### chunk number 46: bw-plot eval=FALSE
+R> ###################################################
+R> ## plot(job ~ edcat, data = BankWages, off = 0)
+R>
+R>
+R> ###################################################
+R> ### chunk number 47: bw-plot1
+R> ###################################################
+R> plot(job ~ edcat, data = BankWages, off = 0)
+R> box()
+R>
+R>
+R> ###################################################
+R> ### chunk number 48: bw-multinom
+R> ###################################################
+R> library("nnet")
+R> bank_mnl <- multinom(job ~ education + minority,
++ data = BankWages, subset = gender == "male", trace = FALSE)
+R>
+R>
+R> ###################################################
+R> ### chunk number 49: bw-multinom-coeftest
+R> ###################################################
+R> coeftest(bank_mnl)
+
+z test of coefficients:
+
+ Estimate Std. Error z value Pr(>|z|)
+admin:(Intercept) -4.761 1.173 -4.06 4.9e-05
+admin:education 0.553 0.099 5.59 2.3e-08
+admin:minorityyes -0.427 0.503 -0.85 0.3957
+manage:(Intercept) -30.775 4.479 -6.87 6.4e-12
+manage:education 2.187 0.295 7.42 1.2e-13
+manage:minorityyes -2.536 0.934 -2.71 0.0066
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 50: bw-polr
+R> ###################################################
+R> library("MASS")
+R> bank_polr <- polr(job ~ education + minority,
++ data = BankWages, subset = gender == "male", Hess = TRUE)
+R> coeftest(bank_polr)
+
+z test of coefficients:
+
+ Estimate Std. Error z value Pr(>|z|)
+education 0.8700 0.0931 9.35 < 2e-16
+minorityyes -1.0564 0.4120 -2.56 0.01
+custodial|admin 7.9514 1.0769 7.38 1.5e-13
+admin|manage 14.1721 1.4744 9.61 < 2e-16
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 51: bw-AIC
+R> ###################################################
+R> AIC(bank_mnl)
+[1] 249.5
+R> AIC(bank_polr)
+[1] 268.6
+R>
+R>
+R>
+> proc.time()
+ user system elapsed
+ 1.904 0.048 1.951
diff --git a/tests/Ch-Programming.R b/tests/Ch-Programming.R
new file mode 100644
index 0000000..b6f7dd3
--- /dev/null
+++ b/tests/Ch-Programming.R
@@ -0,0 +1,245 @@
+###################################################
+### chunk number 1: setup
+###################################################
+options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+
+options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
+
+library("AER")
+
+set.seed(1071)
+
+
+###################################################
+### chunk number 2: DGP
+###################################################
+dgp <- function(nobs = 15, model = c("trend", "dynamic"),
+ corr = 0, coef = c(0.25, -0.75), sd = 1)
+{
+ model <- match.arg(model)
+ coef <- rep(coef, length.out = 2)
+
+ err <- as.vector(filter(rnorm(nobs, sd = sd), corr,
+ method = "recursive"))
+ if(model == "trend") {
+ x <- 1:nobs
+ y <- coef[1] + coef[2] * x + err
+ } else {
+ y <- rep(NA, nobs)
+ y[1] <- coef[1] + err[1]
+ for(i in 2:nobs)
+ y[i] <- coef[1] + coef[2] * y[i-1] + err[i]
+ x <- c(0, y[1:(nobs-1)])
+ }
+ return(data.frame(y = y, x = x))
+}
+
+
+###################################################
+### chunk number 3: simpower
+###################################################
+simpower <- function(nrep = 100, size = 0.05, ...)
+{
+ pval <- matrix(rep(NA, 2 * nrep), ncol = 2)
+ colnames(pval) <- c("dwtest", "bgtest")
+ for(i in 1:nrep) {
+ dat <- dgp(...)
+ pval[i,1] <- dwtest(y ~ x, data = dat,
+ alternative = "two.sided")$p.value
+ pval[i,2] <- bgtest(y ~ x, data = dat)$p.value
+ }
+ return(colMeans(pval < size))
+}
+
+
+###################################################
+### chunk number 4: simulation-function
+###################################################
+simulation <- function(corr = c(0, 0.2, 0.4, 0.6, 0.8,
+ 0.9, 0.95, 0.99), nobs = c(15, 30, 50),
+ model = c("trend", "dynamic"), ...)
+{
+ prs <- expand.grid(corr = corr, nobs = nobs, model = model)
+ nprs <- nrow(prs)
+
+ pow <- matrix(rep(NA, 2 * nprs), ncol = 2)
+ for(i in 1:nprs) pow[i,] <- simpower(corr = prs[i,1],
+ nobs = prs[i,2], model = as.character(prs[i,3]), ...)
+
+ rval <- rbind(prs, prs)
+ rval$test <- factor(rep(1:2, c(nprs, nprs)),
+ labels = c("dwtest", "bgtest"))
+ rval$power <- c(pow[,1], pow[,2])
+ rval$nobs <- factor(rval$nobs)
+ return(rval)
+}
+
+
+###################################################
+### chunk number 5: simulation
+###################################################
+set.seed(123)
+psim <- simulation()
+
+
+###################################################
+### chunk number 6: simulation-table
+###################################################
+tab <- xtabs(power ~ corr + test + model + nobs, data = psim)
+ftable(tab, row.vars = c("model", "nobs", "test"),
+ col.vars = "corr")
+
+
+###################################################
+### chunk number 7: simulation-visualization
+###################################################
+library("lattice")
+xyplot(power ~ corr | model + nobs, groups = ~ test,
+ data = psim, type = "b")
+
+
+###################################################
+### chunk number 8: simulation-visualization1
+###################################################
+library("lattice")
+trellis.par.set(theme = canonical.theme(color = FALSE))
+print(xyplot(power ~ corr | model + nobs, groups = ~ test, data = psim, type = "b"))
+
+
+###################################################
+### chunk number 9: journals-lm
+###################################################
+data("Journals")
+journals <- Journals[, c("subs", "price")]
+journals$citeprice <- Journals$price/Journals$citations
+jour_lm <- lm(log(subs) ~ log(citeprice), data = journals)
+
+
+###################################################
+### chunk number 10: journals-residuals-based-resampling-unused eval=FALSE
+###################################################
+## refit <- function(data, i) {
+## d <- data
+## d$subs <- exp(d$fitted + d$res[i])
+## coef(lm(log(subs) ~ log(citeprice), data = d))
+## }
+
+
+###################################################
+### chunk number 11: journals-case-based-resampling
+###################################################
+refit <- function(data, i)
+ coef(lm(log(subs) ~ log(citeprice), data = data[i,]))
+
+
+###################################################
+### chunk number 12: journals-boot
+###################################################
+library("boot")
+set.seed(123)
+jour_boot <- boot(journals, refit, R = 999)
+
+
+###################################################
+### chunk number 13: journals-boot-print
+###################################################
+jour_boot
+
+
+###################################################
+### chunk number 14: journals-lm-coeftest
+###################################################
+coeftest(jour_lm)
+
+
+###################################################
+### chunk number 15: journals-boot-ci
+###################################################
+boot.ci(jour_boot, index = 2, type = "basic")
+
+
+###################################################
+### chunk number 16: journals-lm-ci
+###################################################
+confint(jour_lm, parm = 2)
+
+
+###################################################
+### chunk number 17: ml-loglik
+###################################################
+data("Equipment", package = "AER")
+
+nlogL <- function(par) {
+ beta <- par[1:3]
+ theta <- par[4]
+ sigma2 <- par[5]
+
+ Y <- with(Equipment, valueadded/firms)
+ K <- with(Equipment, capital/firms)
+ L <- with(Equipment, labor/firms)
+
+ rhs <- beta[1] + beta[2] * log(K) + beta[3] * log(L)
+ lhs <- log(Y) + theta * Y
+
+ rval <- sum(log(1 + theta * Y) - log(Y) +
+ dnorm(lhs, mean = rhs, sd = sqrt(sigma2), log = TRUE))
+ return(-rval)
+}
+
+
+###################################################
+### chunk number 18: ml-0
+###################################################
+fm0 <- lm(log(valueadded/firms) ~ log(capital/firms) +
+ log(labor/firms), data = Equipment)
+
+
+###################################################
+### chunk number 19: ml-0-coef
+###################################################
+par0 <- as.vector(c(coef(fm0), 0, mean(residuals(fm0)^2)))
+
+
+###################################################
+### chunk number 20: ml-optim
+###################################################
+opt <- optim(par0, nlogL, hessian = TRUE)
+
+
+###################################################
+### chunk number 21: ml-optim-output
+###################################################
+opt$par
+sqrt(diag(solve(opt$hessian)))[1:4]
+-opt$value
+
+
+###################################################
+### chunk number 22: Sweave eval=FALSE
+###################################################
+## Sweave("Sweave-journals.Rnw")
+
+
+###################################################
+### chunk number 23: Stangle eval=FALSE
+###################################################
+## Stangle("Sweave-journals.Rnw")
+
+
+###################################################
+### chunk number 24: texi2dvi eval=FALSE
+###################################################
+## texi2dvi("Sweave-journals.tex", pdf = TRUE)
+
+
+###################################################
+### chunk number 25: vignette eval=FALSE
+###################################################
+## vignette("Sweave-journals", package = "AER")
+
+
diff --git a/tests/Ch-Programming.Rout.save b/tests/Ch-Programming.Rout.save
new file mode 100644
index 0000000..174789a
--- /dev/null
+++ b/tests/Ch-Programming.Rout.save
@@ -0,0 +1,344 @@
+
+R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
+Copyright (C) 2016 The R Foundation for Statistical Computing
+Platform: x86_64-pc-linux-gnu (64-bit)
+
+R is free software and comes with ABSOLUTELY NO WARRANTY.
+You are welcome to redistribute it under certain conditions.
+Type 'license()' or 'licence()' for distribution details.
+
+R is a collaborative project with many contributors.
+Type 'contributors()' for more information and
+'citation()' on how to cite R or R packages in publications.
+
+Type 'demo()' for some demos, 'help()' for on-line help, or
+'help.start()' for an HTML browser interface to help.
+Type 'q()' to quit R.
+
+> ###################################################
+> ### chunk number 1: setup
+> ###################################################
+> options(prompt = "R> ", continue = "+ ", width = 64,
++ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+R>
+R> options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
++ twofig = function() {par(mfrow = c(1,2))},
++ threefig = function() {par(mfrow = c(1,3))},
++ fourfig = function() {par(mfrow = c(2,2))},
++ sixfig = function() {par(mfrow = c(3,2))}))
+R>
+R> library("AER")
+Loading required package: car
+Loading required package: lmtest
+Loading required package: zoo
+
+Attaching package: 'zoo'
+
+The following objects are masked from 'package:base':
+
+ as.Date, as.Date.numeric
+
+Loading required package: sandwich
+Loading required package: survival
+R>
+R> set.seed(1071)
+R>
+R>
+R> ###################################################
+R> ### chunk number 2: DGP
+R> ###################################################
+R> dgp <- function(nobs = 15, model = c("trend", "dynamic"),
++ corr = 0, coef = c(0.25, -0.75), sd = 1)
++ {
++ model <- match.arg(model)
++ coef <- rep(coef, length.out = 2)
++
++ err <- as.vector(filter(rnorm(nobs, sd = sd), corr,
++ method = "recursive"))
++ if(model == "trend") {
++ x <- 1:nobs
++ y <- coef[1] + coef[2] * x + err
++ } else {
++ y <- rep(NA, nobs)
++ y[1] <- coef[1] + err[1]
++ for(i in 2:nobs)
++ y[i] <- coef[1] + coef[2] * y[i-1] + err[i]
++ x <- c(0, y[1:(nobs-1)])
++ }
++ return(data.frame(y = y, x = x))
++ }
+R>
+R>
+R> ###################################################
+R> ### chunk number 3: simpower
+R> ###################################################
+R> simpower <- function(nrep = 100, size = 0.05, ...)
++ {
++ pval <- matrix(rep(NA, 2 * nrep), ncol = 2)
++ colnames(pval) <- c("dwtest", "bgtest")
++ for(i in 1:nrep) {
++ dat <- dgp(...)
++ pval[i,1] <- dwtest(y ~ x, data = dat,
++ alternative = "two.sided")$p.value
++ pval[i,2] <- bgtest(y ~ x, data = dat)$p.value
++ }
++ return(colMeans(pval < size))
++ }
+R>
+R>
+R> ###################################################
+R> ### chunk number 4: simulation-function
+R> ###################################################
+R> simulation <- function(corr = c(0, 0.2, 0.4, 0.6, 0.8,
++ 0.9, 0.95, 0.99), nobs = c(15, 30, 50),
++ model = c("trend", "dynamic"), ...)
++ {
++ prs <- expand.grid(corr = corr, nobs = nobs, model = model)
++ nprs <- nrow(prs)
++
++ pow <- matrix(rep(NA, 2 * nprs), ncol = 2)
++ for(i in 1:nprs) pow[i,] <- simpower(corr = prs[i,1],
++ nobs = prs[i,2], model = as.character(prs[i,3]), ...)
++
++ rval <- rbind(prs, prs)
++ rval$test <- factor(rep(1:2, c(nprs, nprs)),
++ labels = c("dwtest", "bgtest"))
++ rval$power <- c(pow[,1], pow[,2])
++ rval$nobs <- factor(rval$nobs)
++ return(rval)
++ }
+R>
+R>
+R> ###################################################
+R> ### chunk number 5: simulation
+R> ###################################################
+R> set.seed(123)
+R> psim <- simulation()
+R>
+R>
+R> ###################################################
+R> ### chunk number 6: simulation-table
+R> ###################################################
+R> tab <- xtabs(power ~ corr + test + model + nobs, data = psim)
+R> ftable(tab, row.vars = c("model", "nobs", "test"),
++ col.vars = "corr")
+ corr 0 0.2 0.4 0.6 0.8 0.9 0.95 0.99
+model nobs test
+trend 15 dwtest 0.05 0.10 0.21 0.36 0.55 0.65 0.66 0.62
+ bgtest 0.07 0.05 0.05 0.10 0.30 0.40 0.41 0.31
+ 30 dwtest 0.09 0.20 0.57 0.80 0.96 1.00 0.96 0.98
+ bgtest 0.09 0.09 0.37 0.69 0.93 0.99 0.94 0.93
+ 50 dwtest 0.03 0.31 0.76 0.99 1.00 1.00 1.00 1.00
+ bgtest 0.05 0.23 0.63 0.95 1.00 1.00 1.00 1.00
+dynamic 15 dwtest 0.02 0.01 0.00 0.00 0.01 0.03 0.01 0.00
+ bgtest 0.07 0.04 0.01 0.09 0.14 0.21 0.17 0.26
+ 30 dwtest 0.00 0.01 0.01 0.06 0.00 0.03 0.03 0.19
+ bgtest 0.05 0.05 0.18 0.39 0.52 0.63 0.64 0.74
+ 50 dwtest 0.02 0.02 0.01 0.03 0.03 0.15 0.39 0.56
+ bgtest 0.05 0.10 0.36 0.72 0.91 0.90 0.93 0.91
+R>
+R>
+R> ###################################################
+R> ### chunk number 7: simulation-visualization
+R> ###################################################
+R> library("lattice")
+R> xyplot(power ~ corr | model + nobs, groups = ~ test,
++ data = psim, type = "b")
+R>
+R>
+R> ###################################################
+R> ### chunk number 8: simulation-visualization1
+R> ###################################################
+R> library("lattice")
+R> trellis.par.set(theme = canonical.theme(color = FALSE))
+R> print(xyplot(power ~ corr | model + nobs, groups = ~ test, data = psim, type = "b"))
+R>
+R>
+R> ###################################################
+R> ### chunk number 9: journals-lm
+R> ###################################################
+R> data("Journals")
+R> journals <- Journals[, c("subs", "price")]
+R> journals$citeprice <- Journals$price/Journals$citations
+R> jour_lm <- lm(log(subs) ~ log(citeprice), data = journals)
+R>
+R>
+R> ###################################################
+R> ### chunk number 10: journals-residuals-based-resampling-unused eval=FALSE
+R> ###################################################
+R> ## refit <- function(data, i) {
+R> ## d <- data
+R> ## d$subs <- exp(d$fitted + d$res[i])
+R> ## coef(lm(log(subs) ~ log(citeprice), data = d))
+R> ## }
+R>
+R>
+R> ###################################################
+R> ### chunk number 11: journals-case-based-resampling
+R> ###################################################
+R> refit <- function(data, i)
++ coef(lm(log(subs) ~ log(citeprice), data = data[i,]))
+R>
+R>
+R> ###################################################
+R> ### chunk number 12: journals-boot
+R> ###################################################
+R> library("boot")
+
+Attaching package: 'boot'
+
+The following object is masked from 'package:lattice':
+
+ melanoma
+
+The following object is masked from 'package:survival':
+
+ aml
+
+The following object is masked from 'package:car':
+
+ logit
+
+R> set.seed(123)
+R> jour_boot <- boot(journals, refit, R = 999)
+R>
+R>
+R> ###################################################
+R> ### chunk number 13: journals-boot-print
+R> ###################################################
+R> jour_boot
+
+ORDINARY NONPARAMETRIC BOOTSTRAP
+
+
+Call:
+boot(data = journals, statistic = refit, R = 999)
+
+
+Bootstrap Statistics :
+ original bias std. error
+t1* 4.7662 -0.0010560 0.05545
+t2* -0.5331 -0.0001606 0.03304
+R>
+R>
+R> ###################################################
+R> ### chunk number 14: journals-lm-coeftest
+R> ###################################################
+R> coeftest(jour_lm)
+
+t test of coefficients:
+
+ Estimate Std. Error t value Pr(>|t|)
+(Intercept) 4.7662 0.0559 85.2 <2e-16
+log(citeprice) -0.5331 0.0356 -15.0 <2e-16
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 15: journals-boot-ci
+R> ###################################################
+R> boot.ci(jour_boot, index = 2, type = "basic")
+BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
+Based on 999 bootstrap replicates
+
+CALL :
+boot.ci(boot.out = jour_boot, type = "basic", index = 2)
+
+Intervals :
+Level Basic
+95% (-0.5952, -0.4665 )
+Calculations and Intervals on Original Scale
+R>
+R>
+R> ###################################################
+R> ### chunk number 16: journals-lm-ci
+R> ###################################################
+R> confint(jour_lm, parm = 2)
+ 2.5 % 97.5 %
+log(citeprice) -0.6033 -0.4628
+R>
+R>
+R> ###################################################
+R> ### chunk number 17: ml-loglik
+R> ###################################################
+R> data("Equipment", package = "AER")
+R>
+R> nlogL <- function(par) {
++ beta <- par[1:3]
++ theta <- par[4]
++ sigma2 <- par[5]
++
++ Y <- with(Equipment, valueadded/firms)
++ K <- with(Equipment, capital/firms)
++ L <- with(Equipment, labor/firms)
++
++ rhs <- beta[1] + beta[2] * log(K) + beta[3] * log(L)
++ lhs <- log(Y) + theta * Y
++
++ rval <- sum(log(1 + theta * Y) - log(Y) +
++ dnorm(lhs, mean = rhs, sd = sqrt(sigma2), log = TRUE))
++ return(-rval)
++ }
+R>
+R>
+R> ###################################################
+R> ### chunk number 18: ml-0
+R> ###################################################
+R> fm0 <- lm(log(valueadded/firms) ~ log(capital/firms) +
++ log(labor/firms), data = Equipment)
+R>
+R>
+R> ###################################################
+R> ### chunk number 19: ml-0-coef
+R> ###################################################
+R> par0 <- as.vector(c(coef(fm0), 0, mean(residuals(fm0)^2)))
+R>
+R>
+R> ###################################################
+R> ### chunk number 20: ml-optim
+R> ###################################################
+R> opt <- optim(par0, nlogL, hessian = TRUE)
+Warning messages:
+1: In log(1 + theta * Y) : NaNs produced
+2: In sqrt(sigma2) : NaNs produced
+R>
+R>
+R> ###################################################
+R> ### chunk number 21: ml-optim-output
+R> ###################################################
+R> opt$par
+[1] 2.91469 0.34998 1.09232 0.10666 0.04275
+R> sqrt(diag(solve(opt$hessian)))[1:4]
+[1] 0.36055 0.09671 0.14079 0.05850
+R> -opt$value
+[1] -8.939
+R>
+R>
+R> ###################################################
+R> ### chunk number 22: Sweave eval=FALSE
+R> ###################################################
+R> ## Sweave("Sweave-journals.Rnw")
+R>
+R>
+R> ###################################################
+R> ### chunk number 23: Stangle eval=FALSE
+R> ###################################################
+R> ## Stangle("Sweave-journals.Rnw")
+R>
+R>
+R> ###################################################
+R> ### chunk number 24: texi2dvi eval=FALSE
+R> ###################################################
+R> ## texi2dvi("Sweave-journals.tex", pdf = TRUE)
+R>
+R>
+R> ###################################################
+R> ### chunk number 25: vignette eval=FALSE
+R> ###################################################
+R> ## vignette("Sweave-journals", package = "AER")
+R>
+R>
+R>
+> proc.time()
+ user system elapsed
+ 15.940 0.044 15.985
diff --git a/tests/Ch-TimeSeries.R b/tests/Ch-TimeSeries.R
new file mode 100644
index 0000000..a5e6ea3
--- /dev/null
+++ b/tests/Ch-TimeSeries.R
@@ -0,0 +1,446 @@
+###################################################
+### chunk number 1: setup
+###################################################
+options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+
+options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
+
+library("AER")
+
+set.seed(1071)
+
+
+###################################################
+### chunk number 2: options
+###################################################
+options(digits = 6)
+
+
+###################################################
+### chunk number 3: ts-plot eval=FALSE
+###################################################
+## data("UKNonDurables")
+## plot(UKNonDurables)
+
+
+###################################################
+### chunk number 4: UKNonDurables-data
+###################################################
+data("UKNonDurables")
+
+
+###################################################
+### chunk number 5: tsp
+###################################################
+tsp(UKNonDurables)
+
+
+###################################################
+### chunk number 6: window
+###################################################
+window(UKNonDurables, end = c(1956, 4))
+
+
+###################################################
+### chunk number 7: filter eval=FALSE
+###################################################
+## data("UKDriverDeaths")
+## plot(UKDriverDeaths)
+## lines(filter(UKDriverDeaths, c(1/2, rep(1, 11), 1/2)/12),
+## col = 2)
+
+
+###################################################
+### chunk number 8: ts-plot1
+###################################################
+data("UKNonDurables")
+plot(UKNonDurables)
+data("UKDriverDeaths")
+plot(UKDriverDeaths)
+lines(filter(UKDriverDeaths, c(1/2, rep(1, 11), 1/2)/12),
+ col = 2)
+
+
+###################################################
+### chunk number 9: filter1 eval=FALSE
+###################################################
+## data("UKDriverDeaths")
+## plot(UKDriverDeaths)
+## lines(filter(UKDriverDeaths, c(1/2, rep(1, 11), 1/2)/12),
+## col = 2)
+
+
+###################################################
+### chunk number 10: rollapply
+###################################################
+plot(rollapply(UKDriverDeaths, 12, sd))
+
+
+###################################################
+### chunk number 11: ar-sim
+###################################################
+set.seed(1234)
+x <- filter(rnorm(100), 0.9, method = "recursive")
+
+
+###################################################
+### chunk number 12: decompose
+###################################################
+dd_dec <- decompose(log(UKDriverDeaths))
+dd_stl <- stl(log(UKDriverDeaths), s.window = 13)
+
+
+###################################################
+### chunk number 13: decompose-components
+###################################################
+plot(dd_dec$trend, ylab = "trend")
+lines(dd_stl$time.series[,"trend"], lty = 2, lwd = 2)
+
+
+###################################################
+### chunk number 14: seat-mean-sd
+###################################################
+plot(dd_dec$trend, ylab = "trend")
+lines(dd_stl$time.series[,"trend"], lty = 2, lwd = 2)
+plot(rollapply(UKDriverDeaths, 12, sd))
+
+
+###################################################
+### chunk number 15: stl
+###################################################
+plot(dd_stl)
+
+
+###################################################
+### chunk number 16: Holt-Winters
+###################################################
+dd_past <- window(UKDriverDeaths, end = c(1982, 12))
+dd_hw <- try(HoltWinters(dd_past))
+if(!inherits(dd_hw, "try-error")) {
+dd_pred <- predict(dd_hw, n.ahead = 24)
+
+
+###################################################
+### chunk number 17: Holt-Winters-plot
+###################################################
+plot(dd_hw, dd_pred, ylim = range(UKDriverDeaths))
+lines(UKDriverDeaths)
+
+
+###################################################
+### chunk number 18: Holt-Winters-plot1
+###################################################
+plot(dd_hw, dd_pred, ylim = range(UKDriverDeaths))
+lines(UKDriverDeaths)
+}
+
+###################################################
+### chunk number 19: acf eval=FALSE
+###################################################
+## acf(x)
+## pacf(x)
+
+
+###################################################
+### chunk number 20: acf1
+###################################################
+acf(x, ylim = c(-0.2, 1))
+pacf(x, ylim = c(-0.2, 1))
+
+
+###################################################
+### chunk number 21: ar
+###################################################
+ar(x)
+
+
+###################################################
+### chunk number 22: window-non-durab
+###################################################
+nd <- window(log(UKNonDurables), end = c(1970, 4))
+
+
+###################################################
+### chunk number 23: non-durab-acf
+###################################################
+acf(diff(nd), ylim = c(-1, 1))
+pacf(diff(nd), ylim = c(-1, 1))
+acf(diff(diff(nd, 4)), ylim = c(-1, 1))
+pacf(diff(diff(nd, 4)), ylim = c(-1, 1))
+
+
+###################################################
+### chunk number 24: non-durab-acf1
+###################################################
+acf(diff(nd), ylim = c(-1, 1))
+pacf(diff(nd), ylim = c(-1, 1))
+acf(diff(diff(nd, 4)), ylim = c(-1, 1))
+pacf(diff(diff(nd, 4)), ylim = c(-1, 1))
+
+
+###################################################
+### chunk number 25: arima-setup
+###################################################
+nd_pars <- expand.grid(ar = 0:2, diff = 1, ma = 0:2,
+ sar = 0:1, sdiff = 1, sma = 0:1)
+nd_aic <- rep(0, nrow(nd_pars))
+for(i in seq(along = nd_aic)) nd_aic[i] <- AIC(arima(nd,
+ unlist(nd_pars[i, 1:3]), unlist(nd_pars[i, 4:6])),
+ k = log(length(nd)))
+nd_pars[which.min(nd_aic),]
+
+
+###################################################
+### chunk number 26: arima
+###################################################
+nd_arima <- arima(nd, order = c(0,1,1), seasonal = c(0,1,1))
+nd_arima
+
+
+###################################################
+### chunk number 27: tsdiag
+###################################################
+tsdiag(nd_arima)
+
+
+###################################################
+### chunk number 28: tsdiag1
+###################################################
+tsdiag(nd_arima)
+
+
+###################################################
+### chunk number 29: arima-predict
+###################################################
+nd_pred <- predict(nd_arima, n.ahead = 18 * 4)
+
+
+###################################################
+### chunk number 30: arima-compare
+###################################################
+plot(log(UKNonDurables))
+lines(nd_pred$pred, col = 2)
+
+
+###################################################
+### chunk number 31: arima-compare1
+###################################################
+plot(log(UKNonDurables))
+lines(nd_pred$pred, col = 2)
+
+
+###################################################
+### chunk number 32: pepper
+###################################################
+data("PepperPrice")
+plot(PepperPrice, plot.type = "single", col = 1:2)
+legend("topleft", c("black", "white"), bty = "n",
+col = 1:2, lty = rep(1,2))
+
+
+###################################################
+### chunk number 33: pepper1
+###################################################
+data("PepperPrice")
+plot(PepperPrice, plot.type = "single", col = 1:2)
+legend("topleft", c("black", "white"), bty = "n",
+col = 1:2, lty = rep(1,2))
+
+
+###################################################
+### chunk number 34: adf1
+###################################################
+library("tseries")
+adf.test(log(PepperPrice[, "white"]))
+
+
+###################################################
+### chunk number 35: adf1
+###################################################
+adf.test(diff(log(PepperPrice[, "white"])))
+
+
+###################################################
+### chunk number 36: pp
+###################################################
+pp.test(log(PepperPrice[, "white"]), type = "Z(t_alpha)")
+
+
+###################################################
+### chunk number 37: urca eval=FALSE
+###################################################
+## library("urca")
+## pepper_ers <- ur.ers(log(PepperPrice[, "white"]),
+## type = "DF-GLS", model = "const", lag.max = 4)
+## summary(pepper_ers)
+
+
+###################################################
+### chunk number 38: kpss
+###################################################
+kpss.test(log(PepperPrice[, "white"]))
+
+
+###################################################
+### chunk number 39: po
+###################################################
+po.test(log(PepperPrice))
+
+
+###################################################
+### chunk number 40: joh-trace
+###################################################
+library("urca")
+pepper_jo <- ca.jo(log(PepperPrice), ecdet = "const",
+ type = "trace")
+summary(pepper_jo)
+
+
+###################################################
+### chunk number 41: joh-lmax eval=FALSE
+###################################################
+## pepper_jo2 <- ca.jo(log(PepperPrice), ecdet = "const", type = "eigen")
+## summary(pepper_jo2)
+
+
+###################################################
+### chunk number 42: dynlm-by-hand
+###################################################
+dd <- log(UKDriverDeaths)
+dd_dat <- ts.intersect(dd, dd1 = lag(dd, k = -1),
+ dd12 = lag(dd, k = -12))
+lm(dd ~ dd1 + dd12, data = dd_dat)
+
+
+###################################################
+### chunk number 43: dynlm
+###################################################
+library("dynlm")
+dynlm(dd ~ L(dd) + L(dd, 12))
+
+
+###################################################
+### chunk number 44: efp
+###################################################
+library("strucchange")
+dd_ocus <- efp(dd ~ dd1 + dd12, data = dd_dat,
+ type = "OLS-CUSUM")
+
+
+###################################################
+### chunk number 45: efp-test
+###################################################
+sctest(dd_ocus)
+
+
+###################################################
+### chunk number 46: efp-plot eval=FALSE
+###################################################
+## plot(dd_ocus)
+
+
+###################################################
+### chunk number 47: Fstats
+###################################################
+dd_fs <- Fstats(dd ~ dd1 + dd12, data = dd_dat, from = 0.1)
+plot(dd_fs)
+sctest(dd_fs)
+
+
+###################################################
+### chunk number 48: ocus-supF
+###################################################
+plot(dd_ocus)
+plot(dd_fs, main = "supF test")
+
+
+###################################################
+### chunk number 49: GermanM1
+###################################################
+data("GermanM1")
+LTW <- dm ~ dy2 + dR + dR1 + dp + m1 + y1 + R1 + season
+
+
+###################################################
+### chunk number 50: re eval=FALSE
+###################################################
+## m1_re <- efp(LTW, data = GermanM1, type = "RE")
+## plot(m1_re)
+
+
+###################################################
+### chunk number 51: re1
+###################################################
+m1_re <- efp(LTW, data = GermanM1, type = "RE")
+plot(m1_re)
+
+
+###################################################
+### chunk number 52: dating
+###################################################
+dd_bp <- breakpoints(dd ~ dd1 + dd12, data = dd_dat, h = 0.1)
+
+
+###################################################
+### chunk number 53: dating-coef
+###################################################
+coef(dd_bp, breaks = 2)
+
+
+###################################################
+### chunk number 54: dating-plot eval=FALSE
+###################################################
+## plot(dd)
+## lines(fitted(dd_bp, breaks = 2), col = 4)
+## lines(confint(dd_bp, breaks = 2))
+
+
+###################################################
+### chunk number 55: dating-plot1
+###################################################
+plot(dd_bp, legend = FALSE, main = "")
+plot(dd)
+lines(fitted(dd_bp, breaks = 2), col = 4)
+lines(confint(dd_bp, breaks = 2))
+
+
+###################################################
+### chunk number 56: StructTS
+###################################################
+dd_struct <- StructTS(log(UKDriverDeaths))
+
+
+###################################################
+### chunk number 57: StructTS-plot eval=FALSE
+###################################################
+## plot(cbind(fitted(dd_struct), residuals(dd_struct)))
+
+
+###################################################
+### chunk number 58: StructTS-plot1
+###################################################
+dd_struct_plot <- cbind(fitted(dd_struct), residuals = residuals(dd_struct))
+colnames(dd_struct_plot) <- c("level", "slope", "season", "residuals")
+plot(dd_struct_plot, main = "")
+
+
+###################################################
+### chunk number 59: garch-plot
+###################################################
+data("MarkPound")
+plot(MarkPound, main = "")
+
+
+###################################################
+### chunk number 60: garch
+###################################################
+data("MarkPound")
+mp <- garch(MarkPound, grad = "numerical", trace = FALSE)
+summary(mp)
+
+
diff --git a/tests/Ch-TimeSeries.Rout.save b/tests/Ch-TimeSeries.Rout.save
new file mode 100644
index 0000000..f283ddf
--- /dev/null
+++ b/tests/Ch-TimeSeries.Rout.save
@@ -0,0 +1,641 @@
+
+R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
+Copyright (C) 2016 The R Foundation for Statistical Computing
+Platform: x86_64-pc-linux-gnu (64-bit)
+
+R is free software and comes with ABSOLUTELY NO WARRANTY.
+You are welcome to redistribute it under certain conditions.
+Type 'license()' or 'licence()' for distribution details.
+
+R is a collaborative project with many contributors.
+Type 'contributors()' for more information and
+'citation()' on how to cite R or R packages in publications.
+
+Type 'demo()' for some demos, 'help()' for on-line help, or
+'help.start()' for an HTML browser interface to help.
+Type 'q()' to quit R.
+
+> ###################################################
+> ### chunk number 1: setup
+> ###################################################
+> options(prompt = "R> ", continue = "+ ", width = 64,
++ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+R>
+R> options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
++ twofig = function() {par(mfrow = c(1,2))},
++ threefig = function() {par(mfrow = c(1,3))},
++ fourfig = function() {par(mfrow = c(2,2))},
++ sixfig = function() {par(mfrow = c(3,2))}))
+R>
+R> library("AER")
+Loading required package: car
+Loading required package: lmtest
+Loading required package: zoo
+
+Attaching package: 'zoo'
+
+The following objects are masked from 'package:base':
+
+ as.Date, as.Date.numeric
+
+Loading required package: sandwich
+Loading required package: survival
+R>
+R> set.seed(1071)
+R>
+R>
+R> ###################################################
+R> ### chunk number 2: options
+R> ###################################################
+R> options(digits = 6)
+R>
+R>
+R> ###################################################
+R> ### chunk number 3: ts-plot eval=FALSE
+R> ###################################################
+R> ## data("UKNonDurables")
+R> ## plot(UKNonDurables)
+R>
+R>
+R> ###################################################
+R> ### chunk number 4: UKNonDurables-data
+R> ###################################################
+R> data("UKNonDurables")
+R>
+R>
+R> ###################################################
+R> ### chunk number 5: tsp
+R> ###################################################
+R> tsp(UKNonDurables)
+[1] 1955.00 1988.75 4.00
+R>
+R>
+R> ###################################################
+R> ### chunk number 6: window
+R> ###################################################
+R> window(UKNonDurables, end = c(1956, 4))
+ Qtr1 Qtr2 Qtr3 Qtr4
+1955 24030 25620 26209 27167
+1956 24620 25972 26285 27659
+R>
+R>
+R> ###################################################
+R> ### chunk number 7: filter eval=FALSE
+R> ###################################################
+R> ## data("UKDriverDeaths")
+R> ## plot(UKDriverDeaths)
+R> ## lines(filter(UKDriverDeaths, c(1/2, rep(1, 11), 1/2)/12),
+R> ## col = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 8: ts-plot1
+R> ###################################################
+R> data("UKNonDurables")
+R> plot(UKNonDurables)
+R> data("UKDriverDeaths")
+R> plot(UKDriverDeaths)
+R> lines(filter(UKDriverDeaths, c(1/2, rep(1, 11), 1/2)/12),
++ col = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 9: filter1 eval=FALSE
+R> ###################################################
+R> ## data("UKDriverDeaths")
+R> ## plot(UKDriverDeaths)
+R> ## lines(filter(UKDriverDeaths, c(1/2, rep(1, 11), 1/2)/12),
+R> ## col = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 10: rollapply
+R> ###################################################
+R> plot(rollapply(UKDriverDeaths, 12, sd))
+R>
+R>
+R> ###################################################
+R> ### chunk number 11: ar-sim
+R> ###################################################
+R> set.seed(1234)
+R> x <- filter(rnorm(100), 0.9, method = "recursive")
+R>
+R>
+R> ###################################################
+R> ### chunk number 12: decompose
+R> ###################################################
+R> dd_dec <- decompose(log(UKDriverDeaths))
+R> dd_stl <- stl(log(UKDriverDeaths), s.window = 13)
+R>
+R>
+R> ###################################################
+R> ### chunk number 13: decompose-components
+R> ###################################################
+R> plot(dd_dec$trend, ylab = "trend")
+R> lines(dd_stl$time.series[,"trend"], lty = 2, lwd = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 14: seat-mean-sd
+R> ###################################################
+R> plot(dd_dec$trend, ylab = "trend")
+R> lines(dd_stl$time.series[,"trend"], lty = 2, lwd = 2)
+R> plot(rollapply(UKDriverDeaths, 12, sd))
+R>
+R>
+R> ###################################################
+R> ### chunk number 15: stl
+R> ###################################################
+R> plot(dd_stl)
+R>
+R>
+R> ###################################################
+R> ### chunk number 16: Holt-Winters
+R> ###################################################
+R> dd_past <- window(UKDriverDeaths, end = c(1982, 12))
+R> dd_hw <- try(HoltWinters(dd_past))
+R> if(!inherits(dd_hw, "try-error")) {
++ dd_pred <- predict(dd_hw, n.ahead = 24)
++
++
++ ###################################################
++ ### chunk number 17: Holt-Winters-plot
++ ###################################################
++ plot(dd_hw, dd_pred, ylim = range(UKDriverDeaths))
++ lines(UKDriverDeaths)
++
++
++ ###################################################
++ ### chunk number 18: Holt-Winters-plot1
++ ###################################################
++ plot(dd_hw, dd_pred, ylim = range(UKDriverDeaths))
++ lines(UKDriverDeaths)
++ }
+R>
+R> ###################################################
+R> ### chunk number 19: acf eval=FALSE
+R> ###################################################
+R> ## acf(x)
+R> ## pacf(x)
+R>
+R>
+R> ###################################################
+R> ### chunk number 20: acf1
+R> ###################################################
+R> acf(x, ylim = c(-0.2, 1))
+R> pacf(x, ylim = c(-0.2, 1))
+R>
+R>
+R> ###################################################
+R> ### chunk number 21: ar
+R> ###################################################
+R> ar(x)
+
+Call:
+ar(x = x)
+
+Coefficients:
+ 1
+0.928
+
+Order selected 1 sigma^2 estimated as 1.29
+R>
+R>
+R> ###################################################
+R> ### chunk number 22: window-non-durab
+R> ###################################################
+R> nd <- window(log(UKNonDurables), end = c(1970, 4))
+R>
+R>
+R> ###################################################
+R> ### chunk number 23: non-durab-acf
+R> ###################################################
+R> acf(diff(nd), ylim = c(-1, 1))
+R> pacf(diff(nd), ylim = c(-1, 1))
+R> acf(diff(diff(nd, 4)), ylim = c(-1, 1))
+R> pacf(diff(diff(nd, 4)), ylim = c(-1, 1))
+R>
+R>
+R> ###################################################
+R> ### chunk number 24: non-durab-acf1
+R> ###################################################
+R> acf(diff(nd), ylim = c(-1, 1))
+R> pacf(diff(nd), ylim = c(-1, 1))
+R> acf(diff(diff(nd, 4)), ylim = c(-1, 1))
+R> pacf(diff(diff(nd, 4)), ylim = c(-1, 1))
+R>
+R>
+R> ###################################################
+R> ### chunk number 25: arima-setup
+R> ###################################################
+R> nd_pars <- expand.grid(ar = 0:2, diff = 1, ma = 0:2,
++ sar = 0:1, sdiff = 1, sma = 0:1)
+R> nd_aic <- rep(0, nrow(nd_pars))
+R> for(i in seq(along = nd_aic)) nd_aic[i] <- AIC(arima(nd,
++ unlist(nd_pars[i, 1:3]), unlist(nd_pars[i, 4:6])),
++ k = log(length(nd)))
+R> nd_pars[which.min(nd_aic),]
+ ar diff ma sar sdiff sma
+22 0 1 1 0 1 1
+R>
+R>
+R> ###################################################
+R> ### chunk number 26: arima
+R> ###################################################
+R> nd_arima <- arima(nd, order = c(0,1,1), seasonal = c(0,1,1))
+R> nd_arima
+
+Call:
+arima(x = nd, order = c(0, 1, 1), seasonal = c(0, 1, 1))
+
+Coefficients:
+ ma1 sma1
+ -0.353 -0.583
+s.e. 0.143 0.138
+
+sigma^2 estimated as 9.65e-05: log likelihood = 188.14, aic = -370.27
+R>
+R>
+R> ###################################################
+R> ### chunk number 27: tsdiag
+R> ###################################################
+R> tsdiag(nd_arima)
+R>
+R>
+R> ###################################################
+R> ### chunk number 28: tsdiag1
+R> ###################################################
+R> tsdiag(nd_arima)
+R>
+R>
+R> ###################################################
+R> ### chunk number 29: arima-predict
+R> ###################################################
+R> nd_pred <- predict(nd_arima, n.ahead = 18 * 4)
+R>
+R>
+R> ###################################################
+R> ### chunk number 30: arima-compare
+R> ###################################################
+R> plot(log(UKNonDurables))
+R> lines(nd_pred$pred, col = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 31: arima-compare1
+R> ###################################################
+R> plot(log(UKNonDurables))
+R> lines(nd_pred$pred, col = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 32: pepper
+R> ###################################################
+R> data("PepperPrice")
+R> plot(PepperPrice, plot.type = "single", col = 1:2)
+R> legend("topleft", c("black", "white"), bty = "n",
++ col = 1:2, lty = rep(1,2))
+R>
+R>
+R> ###################################################
+R> ### chunk number 33: pepper1
+R> ###################################################
+R> data("PepperPrice")
+R> plot(PepperPrice, plot.type = "single", col = 1:2)
+R> legend("topleft", c("black", "white"), bty = "n",
++ col = 1:2, lty = rep(1,2))
+R>
+R>
+R> ###################################################
+R> ### chunk number 34: adf1
+R> ###################################################
+R> library("tseries")
+R> adf.test(log(PepperPrice[, "white"]))
+
+ Augmented Dickey-Fuller Test
+
+data: log(PepperPrice[, "white"])
+Dickey-Fuller = -1.744, Lag order = 6, p-value = 0.684
+alternative hypothesis: stationary
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 35: adf1
+R> ###################################################
+R> adf.test(diff(log(PepperPrice[, "white"])))
+
+ Augmented Dickey-Fuller Test
+
+data: diff(log(PepperPrice[, "white"]))
+Dickey-Fuller = -5.336, Lag order = 6, p-value = 0.01
+alternative hypothesis: stationary
+
+Warning message:
+In adf.test(diff(log(PepperPrice[, "white"]))) :
+ p-value smaller than printed p-value
+R>
+R>
+R> ###################################################
+R> ### chunk number 36: pp
+R> ###################################################
+R> pp.test(log(PepperPrice[, "white"]), type = "Z(t_alpha)")
+
+ Phillips-Perron Unit Root Test
+
+data: log(PepperPrice[, "white"])
+Dickey-Fuller Z(t_alpha) = -1.644, Truncation lag
+parameter = 5, p-value = 0.726
+alternative hypothesis: stationary
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 37: urca eval=FALSE
+R> ###################################################
+R> ## library("urca")
+R> ## pepper_ers <- ur.ers(log(PepperPrice[, "white"]),
+R> ## type = "DF-GLS", model = "const", lag.max = 4)
+R> ## summary(pepper_ers)
+R>
+R>
+R> ###################################################
+R> ### chunk number 38: kpss
+R> ###################################################
+R> kpss.test(log(PepperPrice[, "white"]))
+
+ KPSS Test for Level Stationarity
+
+data: log(PepperPrice[, "white"])
+KPSS Level = 0.9129, Truncation lag parameter = 3,
+p-value = 0.01
+
+Warning message:
+In kpss.test(log(PepperPrice[, "white"])) :
+ p-value smaller than printed p-value
+R>
+R>
+R> ###################################################
+R> ### chunk number 39: po
+R> ###################################################
+R> po.test(log(PepperPrice))
+
+ Phillips-Ouliaris Cointegration Test
+
+data: log(PepperPrice)
+Phillips-Ouliaris demeaned = -24.1, Truncation lag
+parameter = 2, p-value = 0.024
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 40: joh-trace
+R> ###################################################
+R> library("urca")
+R> pepper_jo <- ca.jo(log(PepperPrice), ecdet = "const",
++ type = "trace")
+R> summary(pepper_jo)
+
+######################
+# Johansen-Procedure #
+######################
+
+Test type: trace statistic , without linear trend and constant in cointegration
+
+Eigenvalues (lambda):
+[1] 4.93195e-02 1.35081e-02 2.08167e-17
+
+Values of teststatistic and critical values of test:
+
+ test 10pct 5pct 1pct
+r <= 1 | 3.66 7.52 9.24 12.97
+r = 0 | 17.26 17.85 19.96 24.60
+
+Eigenvectors, normalised to first column:
+(These are the cointegration relations)
+
+ black.l2 white.l2 constant
+black.l2 1.000000 1.00000 1.00000
+white.l2 -0.889231 -5.09942 2.28091
+constant -0.556994 33.02742 -20.03244
+
+Weights W:
+(This is the loading matrix)
+
+ black.l2 white.l2 constant
+black.d -0.0747230 0.00245321 -4.95816e-18
+white.d 0.0201561 0.00353701 8.85035e-18
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 41: joh-lmax eval=FALSE
+R> ###################################################
+R> ## pepper_jo2 <- ca.jo(log(PepperPrice), ecdet = "const", type = "eigen")
+R> ## summary(pepper_jo2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 42: dynlm-by-hand
+R> ###################################################
+R> dd <- log(UKDriverDeaths)
+R> dd_dat <- ts.intersect(dd, dd1 = lag(dd, k = -1),
++ dd12 = lag(dd, k = -12))
+R> lm(dd ~ dd1 + dd12, data = dd_dat)
+
+Call:
+lm(formula = dd ~ dd1 + dd12, data = dd_dat)
+
+Coefficients:
+(Intercept) dd1 dd12
+ 0.421 0.431 0.511
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 43: dynlm
+R> ###################################################
+R> library("dynlm")
+R> dynlm(dd ~ L(dd) + L(dd, 12))
+
+Time series regression with "ts" data:
+Start = 1970(1), End = 1984(12)
+
+Call:
+dynlm(formula = dd ~ L(dd) + L(dd, 12))
+
+Coefficients:
+(Intercept) L(dd) L(dd, 12)
+ 0.421 0.431 0.511
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 44: efp
+R> ###################################################
+R> library("strucchange")
+R> dd_ocus <- efp(dd ~ dd1 + dd12, data = dd_dat,
++ type = "OLS-CUSUM")
+R>
+R>
+R> ###################################################
+R> ### chunk number 45: efp-test
+R> ###################################################
+R> sctest(dd_ocus)
+
+ OLS-based CUSUM test
+
+data: dd_ocus
+S0 = 1.487, p-value = 0.0241
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 46: efp-plot eval=FALSE
+R> ###################################################
+R> ## plot(dd_ocus)
+R>
+R>
+R> ###################################################
+R> ### chunk number 47: Fstats
+R> ###################################################
+R> dd_fs <- Fstats(dd ~ dd1 + dd12, data = dd_dat, from = 0.1)
+R> plot(dd_fs)
+R> sctest(dd_fs)
+
+ supF test
+
+data: dd_fs
+sup.F = 19.33, p-value = 0.00672
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 48: ocus-supF
+R> ###################################################
+R> plot(dd_ocus)
+R> plot(dd_fs, main = "supF test")
+R>
+R>
+R> ###################################################
+R> ### chunk number 49: GermanM1
+R> ###################################################
+R> data("GermanM1")
+R> LTW <- dm ~ dy2 + dR + dR1 + dp + m1 + y1 + R1 + season
+R>
+R>
+R> ###################################################
+R> ### chunk number 50: re eval=FALSE
+R> ###################################################
+R> ## m1_re <- efp(LTW, data = GermanM1, type = "RE")
+R> ## plot(m1_re)
+R>
+R>
+R> ###################################################
+R> ### chunk number 51: re1
+R> ###################################################
+R> m1_re <- efp(LTW, data = GermanM1, type = "RE")
+R> plot(m1_re)
+R>
+R>
+R> ###################################################
+R> ### chunk number 52: dating
+R> ###################################################
+R> dd_bp <- breakpoints(dd ~ dd1 + dd12, data = dd_dat, h = 0.1)
+R>
+R>
+R> ###################################################
+R> ### chunk number 53: dating-coef
+R> ###################################################
+R> coef(dd_bp, breaks = 2)
+ (Intercept) dd1 dd12
+1970(1) - 1973(10) 1.45776 0.117323 0.694480
+1973(11) - 1983(1) 1.53421 0.218214 0.572330
+1983(2) - 1984(12) 1.68690 0.548609 0.214166
+R>
+R>
+R> ###################################################
+R> ### chunk number 54: dating-plot eval=FALSE
+R> ###################################################
+R> ## plot(dd)
+R> ## lines(fitted(dd_bp, breaks = 2), col = 4)
+R> ## lines(confint(dd_bp, breaks = 2))
+R>
+R>
+R> ###################################################
+R> ### chunk number 55: dating-plot1
+R> ###################################################
+R> plot(dd_bp, legend = FALSE, main = "")
+R> plot(dd)
+R> lines(fitted(dd_bp, breaks = 2), col = 4)
+R> lines(confint(dd_bp, breaks = 2))
+R>
+R>
+R> ###################################################
+R> ### chunk number 56: StructTS
+R> ###################################################
+R> dd_struct <- StructTS(log(UKDriverDeaths))
+R>
+R>
+R> ###################################################
+R> ### chunk number 57: StructTS-plot eval=FALSE
+R> ###################################################
+R> ## plot(cbind(fitted(dd_struct), residuals(dd_struct)))
+R>
+R>
+R> ###################################################
+R> ### chunk number 58: StructTS-plot1
+R> ###################################################
+R> dd_struct_plot <- cbind(fitted(dd_struct), residuals = residuals(dd_struct))
+R> colnames(dd_struct_plot) <- c("level", "slope", "season", "residuals")
+R> plot(dd_struct_plot, main = "")
+R>
+R>
+R> ###################################################
+R> ### chunk number 59: garch-plot
+R> ###################################################
+R> data("MarkPound")
+R> plot(MarkPound, main = "")
+R>
+R>
+R> ###################################################
+R> ### chunk number 60: garch
+R> ###################################################
+R> data("MarkPound")
+R> mp <- garch(MarkPound, grad = "numerical", trace = FALSE)
+R> summary(mp)
+
+Call:
+garch(x = MarkPound, grad = "numerical", trace = FALSE)
+
+Model:
+GARCH(1,1)
+
+Residuals:
+ Min 1Q Median 3Q Max
+-6.79739 -0.53703 -0.00264 0.55233 5.24867
+
+Coefficient(s):
+ Estimate Std. Error t value Pr(>|t|)
+a0 0.0109 0.0013 8.38 <2e-16
+a1 0.1546 0.0139 11.14 <2e-16
+b1 0.8044 0.0160 50.13 <2e-16
+
+Diagnostic Tests:
+ Jarque Bera Test
+
+data: Residuals
+X-squared = 1060, df = 2, p-value <2e-16
+
+
+ Box-Ljung test
+
+data: Squared.Residuals
+X-squared = 2.478, df = 1, p-value = 0.115
+
+R>
+R>
+R>
+> proc.time()
+ user system elapsed
+ 2.756 0.052 2.807
diff --git a/tests/Ch-Validation.R b/tests/Ch-Validation.R
new file mode 100644
index 0000000..922efa1
--- /dev/null
+++ b/tests/Ch-Validation.R
@@ -0,0 +1,362 @@
+###################################################
+### chunk number 1: setup
+###################################################
+options(prompt = "R> ", continue = "+ ", width = 64,
+ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+
+options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
+ twofig = function() {par(mfrow = c(1,2))},
+ threefig = function() {par(mfrow = c(1,3))},
+ fourfig = function() {par(mfrow = c(2,2))},
+ sixfig = function() {par(mfrow = c(3,2))}))
+
+library("AER")
+
+set.seed(1071)
+
+
+###################################################
+### chunk number 2: ps-summary
+###################################################
+data("PublicSchools")
+summary(PublicSchools)
+
+
+###################################################
+### chunk number 3: ps-plot eval=FALSE
+###################################################
+## ps <- na.omit(PublicSchools)
+## ps$Income <- ps$Income / 10000
+## plot(Expenditure ~ Income, data = ps, ylim = c(230, 830))
+## ps_lm <- lm(Expenditure ~ Income, data = ps)
+## abline(ps_lm)
+## id <- c(2, 24, 48)
+## text(ps[id, 2:1], rownames(ps)[id], pos = 1, xpd = TRUE)
+
+
+###################################################
+### chunk number 4: ps-plot1
+###################################################
+ps <- na.omit(PublicSchools)
+ps$Income <- ps$Income / 10000
+plot(Expenditure ~ Income, data = ps, ylim = c(230, 830))
+ps_lm <- lm(Expenditure ~ Income, data = ps)
+abline(ps_lm)
+id <- c(2, 24, 48)
+text(ps[id, 2:1], rownames(ps)[id], pos = 1, xpd = TRUE)
+
+
+###################################################
+### chunk number 5: ps-lmplot eval=FALSE
+###################################################
+## plot(ps_lm, which = 1:6)
+
+
+###################################################
+### chunk number 6: ps-lmplot1
+###################################################
+plot(ps_lm, which = 1:6)
+
+
+###################################################
+### chunk number 7: ps-hatvalues eval=FALSE
+###################################################
+## ps_hat <- hatvalues(ps_lm)
+## plot(ps_hat)
+## abline(h = c(1, 3) * mean(ps_hat), col = 2)
+## id <- which(ps_hat > 3 * mean(ps_hat))
+## text(id, ps_hat[id], rownames(ps)[id], pos = 1, xpd = TRUE)
+
+
+###################################################
+### chunk number 8: ps-hatvalues1
+###################################################
+ps_hat <- hatvalues(ps_lm)
+plot(ps_hat)
+abline(h = c(1, 3) * mean(ps_hat), col = 2)
+id <- which(ps_hat > 3 * mean(ps_hat))
+text(id, ps_hat[id], rownames(ps)[id], pos = 1, xpd = TRUE)
+
+
+###################################################
+### chunk number 9: influence-measures1 eval=FALSE
+###################################################
+## influence.measures(ps_lm)
+
+
+###################################################
+### chunk number 10: which-hatvalues
+###################################################
+which(ps_hat > 3 * mean(ps_hat))
+
+
+###################################################
+### chunk number 11: influence-measures2
+###################################################
+summary(influence.measures(ps_lm))
+
+
+###################################################
+### chunk number 12: ps-noinf eval=FALSE
+###################################################
+## plot(Expenditure ~ Income, data = ps, ylim = c(230, 830))
+## abline(ps_lm)
+## id <- which(apply(influence.measures(ps_lm)$is.inf, 1, any))
+## text(ps[id, 2:1], rownames(ps)[id], pos = 1, xpd = TRUE)
+## ps_noinf <- lm(Expenditure ~ Income, data = ps[-id,])
+## abline(ps_noinf, lty = 2)
+
+
+###################################################
+### chunk number 13: ps-noinf1
+###################################################
+plot(Expenditure ~ Income, data = ps, ylim = c(230, 830))
+abline(ps_lm)
+id <- which(apply(influence.measures(ps_lm)$is.inf, 1, any))
+text(ps[id, 2:1], rownames(ps)[id], pos = 1, xpd = TRUE)
+ps_noinf <- lm(Expenditure ~ Income, data = ps[-id,])
+abline(ps_noinf, lty = 2)
+
+
+###################################################
+### chunk number 14: journals-age
+###################################################
+data("Journals")
+journals <- Journals[, c("subs", "price")]
+journals$citeprice <- Journals$price/Journals$citations
+journals$age <- 2000 - Journals$foundingyear
+
+
+###################################################
+### chunk number 15: journals-lm
+###################################################
+jour_lm <- lm(log(subs) ~ log(citeprice), data = journals)
+
+
+###################################################
+### chunk number 16: bptest1
+###################################################
+bptest(jour_lm)
+
+
+###################################################
+### chunk number 17: bptest2
+###################################################
+bptest(jour_lm, ~ log(citeprice) + I(log(citeprice)^2),
+ data = journals)
+
+
+###################################################
+### chunk number 18: gqtest
+###################################################
+gqtest(jour_lm, order.by = ~ citeprice, data = journals)
+
+
+###################################################
+### chunk number 19: resettest
+###################################################
+resettest(jour_lm)
+
+
+###################################################
+### chunk number 20: raintest
+###################################################
+raintest(jour_lm, order.by = ~ age, data = journals)
+
+
+###################################################
+### chunk number 21: harvtest
+###################################################
+harvtest(jour_lm, order.by = ~ age, data = journals)
+
+
+###################################################
+### chunk number 22:
+###################################################
+library("dynlm")
+
+
+###################################################
+### chunk number 23: usmacro-dynlm
+###################################################
+data("USMacroG")
+consump1 <- dynlm(consumption ~ dpi + L(dpi),
+ data = USMacroG)
+
+
+###################################################
+### chunk number 24: dwtest
+###################################################
+dwtest(consump1)
+
+
+###################################################
+### chunk number 25: Box-test
+###################################################
+Box.test(residuals(consump1), type = "Ljung-Box")
+
+
+###################################################
+### chunk number 26: bgtest
+###################################################
+bgtest(consump1)
+
+
+###################################################
+### chunk number 27: vcov
+###################################################
+vcov(jour_lm)
+vcovHC(jour_lm)
+
+
+###################################################
+### chunk number 28: coeftest
+###################################################
+coeftest(jour_lm, vcov = vcovHC)
+
+
+###################################################
+### chunk number 29: sandwiches
+###################################################
+t(sapply(c("const", "HC0", "HC1", "HC2", "HC3", "HC4"),
+ function(x) sqrt(diag(vcovHC(jour_lm, type = x)))))
+
+
+###################################################
+### chunk number 30: ps-anova
+###################################################
+ps_lm <- lm(Expenditure ~ Income, data = ps)
+ps_lm2 <- lm(Expenditure ~ Income + I(Income^2), data = ps)
+anova(ps_lm, ps_lm2)
+
+
+###################################################
+### chunk number 31: ps-waldtest
+###################################################
+waldtest(ps_lm, ps_lm2, vcov = vcovHC(ps_lm2, type = "HC4"))
+
+
+###################################################
+### chunk number 32: vcovHAC
+###################################################
+rbind(SE = sqrt(diag(vcov(consump1))),
+ QS = sqrt(diag(kernHAC(consump1))),
+ NW = sqrt(diag(NeweyWest(consump1))))
+
+
+###################################################
+### chunk number 33: solow-lm
+###################################################
+data("OECDGrowth")
+solow_lm <- lm(log(gdp85/gdp60) ~ log(gdp60) +
+ log(invest) + log(popgrowth + .05), data = OECDGrowth)
+summary(solow_lm)
+
+
+###################################################
+### chunk number 34: solow-plot eval=FALSE
+###################################################
+## plot(solow_lm)
+
+
+###################################################
+### chunk number 35: solow-lts
+###################################################
+library("MASS")
+solow_lts <- lqs(log(gdp85/gdp60) ~ log(gdp60) +
+ log(invest) + log(popgrowth + .05), data = OECDGrowth,
+ psamp = 13, nsamp = "exact")
+
+
+###################################################
+### chunk number 36: solow-smallresid
+###################################################
+smallresid <- which(
+ abs(residuals(solow_lts)/solow_lts$scale[2]) <= 2.5)
+
+
+###################################################
+### chunk number 37: solow-nohighlev
+###################################################
+X <- model.matrix(solow_lm)[,-1]
+Xcv <- cov.rob(X, nsamp = "exact")
+nohighlev <- which(
+ sqrt(mahalanobis(X, Xcv$center, Xcv$cov)) <= 2.5)
+
+
+###################################################
+### chunk number 38: solow-goodobs
+###################################################
+goodobs <- unique(c(smallresid, nohighlev))
+
+
+###################################################
+### chunk number 39: solow-badobs
+###################################################
+rownames(OECDGrowth)[-goodobs]
+
+
+###################################################
+### chunk number 40: solow-rob
+###################################################
+solow_rob <- update(solow_lm, subset = goodobs)
+summary(solow_rob)
+
+
+###################################################
+### chunk number 41: quantreg
+###################################################
+library("quantreg")
+
+
+###################################################
+### chunk number 42: cps-lad
+###################################################
+library("quantreg")
+data("CPS1988")
+cps_f <- log(wage) ~ experience + I(experience^2) + education
+cps_lad <- rq(cps_f, data = CPS1988)
+summary(cps_lad)
+
+
+###################################################
+### chunk number 43: cps-rq
+###################################################
+cps_rq <- rq(cps_f, tau = c(0.25, 0.75), data = CPS1988)
+summary(cps_rq)
+
+
+###################################################
+### chunk number 44: cps-rqs
+###################################################
+cps_rq25 <- rq(cps_f, tau = 0.25, data = CPS1988)
+cps_rq75 <- rq(cps_f, tau = 0.75, data = CPS1988)
+anova(cps_rq25, cps_rq75)
+
+
+###################################################
+### chunk number 45: cps-rq-anova
+###################################################
+anova(cps_rq25, cps_rq75, joint = FALSE)
+
+
+###################################################
+### chunk number 46: rqbig
+###################################################
+cps_rqbig <- rq(cps_f, tau = seq(0.05, 0.95, by = 0.05),
+ data = CPS1988)
+cps_rqbigs <- summary(cps_rqbig)
+
+
+###################################################
+### chunk number 47: rqbig-plot eval=FALSE
+###################################################
+## plot(cps_rqbigs)
+
+
+###################################################
+### chunk number 48: rqbig-plot1
+###################################################
+plot(cps_rqbigs)
+
+
diff --git a/tests/Ch-Validation.Rout.save b/tests/Ch-Validation.Rout.save
new file mode 100644
index 0000000..16bf189
--- /dev/null
+++ b/tests/Ch-Validation.Rout.save
@@ -0,0 +1,613 @@
+
+R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
+Copyright (C) 2016 The R Foundation for Statistical Computing
+Platform: x86_64-pc-linux-gnu (64-bit)
+
+R is free software and comes with ABSOLUTELY NO WARRANTY.
+You are welcome to redistribute it under certain conditions.
+Type 'license()' or 'licence()' for distribution details.
+
+R is a collaborative project with many contributors.
+Type 'contributors()' for more information and
+'citation()' on how to cite R or R packages in publications.
+
+Type 'demo()' for some demos, 'help()' for on-line help, or
+'help.start()' for an HTML browser interface to help.
+Type 'q()' to quit R.
+
+> ###################################################
+> ### chunk number 1: setup
+> ###################################################
+> options(prompt = "R> ", continue = "+ ", width = 64,
++ digits = 4, show.signif.stars = FALSE, useFancyQuotes = FALSE)
+R>
+R> options(SweaveHooks = list(onefig = function() {par(mfrow = c(1,1))},
++ twofig = function() {par(mfrow = c(1,2))},
++ threefig = function() {par(mfrow = c(1,3))},
++ fourfig = function() {par(mfrow = c(2,2))},
++ sixfig = function() {par(mfrow = c(3,2))}))
+R>
+R> library("AER")
+Loading required package: car
+Loading required package: lmtest
+Loading required package: zoo
+
+Attaching package: 'zoo'
+
+The following objects are masked from 'package:base':
+
+ as.Date, as.Date.numeric
+
+Loading required package: sandwich
+Loading required package: survival
+R>
+R> set.seed(1071)
+R>
+R>
+R> ###################################################
+R> ### chunk number 2: ps-summary
+R> ###################################################
+R> data("PublicSchools")
+R> summary(PublicSchools)
+ Expenditure Income
+ Min. :259 Min. : 5736
+ 1st Qu.:315 1st Qu.: 6670
+ Median :354 Median : 7597
+ Mean :373 Mean : 7608
+ 3rd Qu.:426 3rd Qu.: 8286
+ Max. :821 Max. :10851
+ NA's :1
+R>
+R>
+R> ###################################################
+R> ### chunk number 3: ps-plot eval=FALSE
+R> ###################################################
+R> ## ps <- na.omit(PublicSchools)
+R> ## ps$Income <- ps$Income / 10000
+R> ## plot(Expenditure ~ Income, data = ps, ylim = c(230, 830))
+R> ## ps_lm <- lm(Expenditure ~ Income, data = ps)
+R> ## abline(ps_lm)
+R> ## id <- c(2, 24, 48)
+R> ## text(ps[id, 2:1], rownames(ps)[id], pos = 1, xpd = TRUE)
+R>
+R>
+R> ###################################################
+R> ### chunk number 4: ps-plot1
+R> ###################################################
+R> ps <- na.omit(PublicSchools)
+R> ps$Income <- ps$Income / 10000
+R> plot(Expenditure ~ Income, data = ps, ylim = c(230, 830))
+R> ps_lm <- lm(Expenditure ~ Income, data = ps)
+R> abline(ps_lm)
+R> id <- c(2, 24, 48)
+R> text(ps[id, 2:1], rownames(ps)[id], pos = 1, xpd = TRUE)
+R>
+R>
+R> ###################################################
+R> ### chunk number 5: ps-lmplot eval=FALSE
+R> ###################################################
+R> ## plot(ps_lm, which = 1:6)
+R>
+R>
+R> ###################################################
+R> ### chunk number 6: ps-lmplot1
+R> ###################################################
+R> plot(ps_lm, which = 1:6)
+R>
+R>
+R> ###################################################
+R> ### chunk number 7: ps-hatvalues eval=FALSE
+R> ###################################################
+R> ## ps_hat <- hatvalues(ps_lm)
+R> ## plot(ps_hat)
+R> ## abline(h = c(1, 3) * mean(ps_hat), col = 2)
+R> ## id <- which(ps_hat > 3 * mean(ps_hat))
+R> ## text(id, ps_hat[id], rownames(ps)[id], pos = 1, xpd = TRUE)
+R>
+R>
+R> ###################################################
+R> ### chunk number 8: ps-hatvalues1
+R> ###################################################
+R> ps_hat <- hatvalues(ps_lm)
+R> plot(ps_hat)
+R> abline(h = c(1, 3) * mean(ps_hat), col = 2)
+R> id <- which(ps_hat > 3 * mean(ps_hat))
+R> text(id, ps_hat[id], rownames(ps)[id], pos = 1, xpd = TRUE)
+R>
+R>
+R> ###################################################
+R> ### chunk number 9: influence-measures1 eval=FALSE
+R> ###################################################
+R> ## influence.measures(ps_lm)
+R>
+R>
+R> ###################################################
+R> ### chunk number 10: which-hatvalues
+R> ###################################################
+R> which(ps_hat > 3 * mean(ps_hat))
+ Alaska Washington DC
+ 2 48
+R>
+R>
+R> ###################################################
+R> ### chunk number 11: influence-measures2
+R> ###################################################
+R> summary(influence.measures(ps_lm))
+Potentially influential observations of
+ lm(formula = Expenditure ~ Income, data = ps) :
+
+ dfb.1_ dfb.Incm dffit cov.r cook.d hat
+Alaska -2.39_* 2.52_* 2.65_* 0.55_* 2.31_* 0.21_*
+Mississippi 0.07 -0.07 0.08 1.14_* 0.00 0.08
+Washington DC 0.66 -0.71 -0.77_* 1.01 0.28 0.13_*
+R>
+R>
+R> ###################################################
+R> ### chunk number 12: ps-noinf eval=FALSE
+R> ###################################################
+R> ## plot(Expenditure ~ Income, data = ps, ylim = c(230, 830))
+R> ## abline(ps_lm)
+R> ## id <- which(apply(influence.measures(ps_lm)$is.inf, 1, any))
+R> ## text(ps[id, 2:1], rownames(ps)[id], pos = 1, xpd = TRUE)
+R> ## ps_noinf <- lm(Expenditure ~ Income, data = ps[-id,])
+R> ## abline(ps_noinf, lty = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 13: ps-noinf1
+R> ###################################################
+R> plot(Expenditure ~ Income, data = ps, ylim = c(230, 830))
+R> abline(ps_lm)
+R> id <- which(apply(influence.measures(ps_lm)$is.inf, 1, any))
+R> text(ps[id, 2:1], rownames(ps)[id], pos = 1, xpd = TRUE)
+R> ps_noinf <- lm(Expenditure ~ Income, data = ps[-id,])
+R> abline(ps_noinf, lty = 2)
+R>
+R>
+R> ###################################################
+R> ### chunk number 14: journals-age
+R> ###################################################
+R> data("Journals")
+R> journals <- Journals[, c("subs", "price")]
+R> journals$citeprice <- Journals$price/Journals$citations
+R> journals$age <- 2000 - Journals$foundingyear
+R>
+R>
+R> ###################################################
+R> ### chunk number 15: journals-lm
+R> ###################################################
+R> jour_lm <- lm(log(subs) ~ log(citeprice), data = journals)
+R>
+R>
+R> ###################################################
+R> ### chunk number 16: bptest1
+R> ###################################################
+R> bptest(jour_lm)
+
+ studentized Breusch-Pagan test
+
+data: jour_lm
+BP = 9.8, df = 1, p-value = 0.002
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 17: bptest2
+R> ###################################################
+R> bptest(jour_lm, ~ log(citeprice) + I(log(citeprice)^2),
++ data = journals)
+
+ studentized Breusch-Pagan test
+
+data: jour_lm
+BP = 11, df = 2, p-value = 0.004
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 18: gqtest
+R> ###################################################
+R> gqtest(jour_lm, order.by = ~ citeprice, data = journals)
+
+ Goldfeld-Quandt test
+
+data: jour_lm
+GQ = 1.7, df1 = 88, df2 = 88, p-value = 0.007
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 19: resettest
+R> ###################################################
+R> resettest(jour_lm)
+
+ RESET test
+
+data: jour_lm
+RESET = 1.4, df1 = 2, df2 = 180, p-value = 0.2
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 20: raintest
+R> ###################################################
+R> raintest(jour_lm, order.by = ~ age, data = journals)
+
+ Rainbow test
+
+data: jour_lm
+Rain = 1.8, df1 = 90, df2 = 88, p-value = 0.004
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 21: harvtest
+R> ###################################################
+R> harvtest(jour_lm, order.by = ~ age, data = journals)
+
+ Harvey-Collier test
+
+data: jour_lm
+HC = 5.1, df = 180, p-value = 9e-07
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 22:
+R> ###################################################
+R> library("dynlm")
+R>
+R>
+R> ###################################################
+R> ### chunk number 23: usmacro-dynlm
+R> ###################################################
+R> data("USMacroG")
+R> consump1 <- dynlm(consumption ~ dpi + L(dpi),
++ data = USMacroG)
+R>
+R>
+R> ###################################################
+R> ### chunk number 24: dwtest
+R> ###################################################
+R> dwtest(consump1)
+
+ Durbin-Watson test
+
+data: consump1
+DW = 0.087, p-value <2e-16
+alternative hypothesis: true autocorrelation is greater than 0
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 25: Box-test
+R> ###################################################
+R> Box.test(residuals(consump1), type = "Ljung-Box")
+
+ Box-Ljung test
+
+data: residuals(consump1)
+X-squared = 180, df = 1, p-value <2e-16
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 26: bgtest
+R> ###################################################
+R> bgtest(consump1)
+
+ Breusch-Godfrey test for serial correlation of order up
+ to 1
+
+data: consump1
+LM test = 190, df = 1, p-value <2e-16
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 27: vcov
+R> ###################################################
+R> vcov(jour_lm)
+ (Intercept) log(citeprice)
+(Intercept) 3.126e-03 -6.144e-05
+log(citeprice) -6.144e-05 1.268e-03
+R> vcovHC(jour_lm)
+ (Intercept) log(citeprice)
+(Intercept) 0.003085 0.000693
+log(citeprice) 0.000693 0.001188
+R>
+R>
+R> ###################################################
+R> ### chunk number 28: coeftest
+R> ###################################################
+R> coeftest(jour_lm, vcov = vcovHC)
+
+t test of coefficients:
+
+ Estimate Std. Error t value Pr(>|t|)
+(Intercept) 4.7662 0.0555 85.8 <2e-16
+log(citeprice) -0.5331 0.0345 -15.5 <2e-16
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 29: sandwiches
+R> ###################################################
+R> t(sapply(c("const", "HC0", "HC1", "HC2", "HC3", "HC4"),
++ function(x) sqrt(diag(vcovHC(jour_lm, type = x)))))
+ (Intercept) log(citeprice)
+const 0.05591 0.03561
+HC0 0.05495 0.03377
+HC1 0.05526 0.03396
+HC2 0.05525 0.03412
+HC3 0.05555 0.03447
+HC4 0.05536 0.03459
+R>
+R>
+R> ###################################################
+R> ### chunk number 30: ps-anova
+R> ###################################################
+R> ps_lm <- lm(Expenditure ~ Income, data = ps)
+R> ps_lm2 <- lm(Expenditure ~ Income + I(Income^2), data = ps)
+R> anova(ps_lm, ps_lm2)
+Analysis of Variance Table
+
+Model 1: Expenditure ~ Income
+Model 2: Expenditure ~ Income + I(Income^2)
+ Res.Df RSS Df Sum of Sq F Pr(>F)
+1 48 181015
+2 47 150986 1 30030 9.35 0.0037
+R>
+R>
+R> ###################################################
+R> ### chunk number 31: ps-waldtest
+R> ###################################################
+R> waldtest(ps_lm, ps_lm2, vcov = vcovHC(ps_lm2, type = "HC4"))
+Wald test
+
+Model 1: Expenditure ~ Income
+Model 2: Expenditure ~ Income + I(Income^2)
+ Res.Df Df F Pr(>F)
+1 48
+2 47 1 0.08 0.77
+R>
+R>
+R> ###################################################
+R> ### chunk number 32: vcovHAC
+R> ###################################################
+R> rbind(SE = sqrt(diag(vcov(consump1))),
++ QS = sqrt(diag(kernHAC(consump1))),
++ NW = sqrt(diag(NeweyWest(consump1))))
+ (Intercept) dpi L(dpi)
+SE 14.51 0.2063 0.2075
+QS 94.11 0.3893 0.3669
+NW 100.83 0.4230 0.3989
+R>
+R>
+R> ###################################################
+R> ### chunk number 33: solow-lm
+R> ###################################################
+R> data("OECDGrowth")
+R> solow_lm <- lm(log(gdp85/gdp60) ~ log(gdp60) +
++ log(invest) + log(popgrowth + .05), data = OECDGrowth)
+R> summary(solow_lm)
+
+Call:
+lm(formula = log(gdp85/gdp60) ~ log(gdp60) + log(invest) + log(popgrowth +
+ 0.05), data = OECDGrowth)
+
+Residuals:
+ Min 1Q Median 3Q Max
+-0.1840 -0.0399 -0.0078 0.0451 0.3188
+
+Coefficients:
+ Estimate Std. Error t value Pr(>|t|)
+(Intercept) 2.9759 1.0216 2.91 0.0093
+log(gdp60) -0.3429 0.0565 -6.07 9.8e-06
+log(invest) 0.6501 0.2020 3.22 0.0048
+log(popgrowth + 0.05) -0.5730 0.2904 -1.97 0.0640
+
+Residual standard error: 0.133 on 18 degrees of freedom
+Multiple R-squared: 0.746, Adjusted R-squared: 0.704
+F-statistic: 17.7 on 3 and 18 DF, p-value: 1.34e-05
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 34: solow-plot eval=FALSE
+R> ###################################################
+R> ## plot(solow_lm)
+R>
+R>
+R> ###################################################
+R> ### chunk number 35: solow-lts
+R> ###################################################
+R> library("MASS")
+R> solow_lts <- lqs(log(gdp85/gdp60) ~ log(gdp60) +
++ log(invest) + log(popgrowth + .05), data = OECDGrowth,
++ psamp = 13, nsamp = "exact")
+R>
+R>
+R> ###################################################
+R> ### chunk number 36: solow-smallresid
+R> ###################################################
+R> smallresid <- which(
++ abs(residuals(solow_lts)/solow_lts$scale[2]) <= 2.5)
+R>
+R>
+R> ###################################################
+R> ### chunk number 37: solow-nohighlev
+R> ###################################################
+R> X <- model.matrix(solow_lm)[,-1]
+R> Xcv <- cov.rob(X, nsamp = "exact")
+R> nohighlev <- which(
++ sqrt(mahalanobis(X, Xcv$center, Xcv$cov)) <= 2.5)
+R>
+R>
+R> ###################################################
+R> ### chunk number 38: solow-goodobs
+R> ###################################################
+R> goodobs <- unique(c(smallresid, nohighlev))
+R>
+R>
+R> ###################################################
+R> ### chunk number 39: solow-badobs
+R> ###################################################
+R> rownames(OECDGrowth)[-goodobs]
+[1] "Canada" "USA" "Turkey" "Australia"
+R>
+R>
+R> ###################################################
+R> ### chunk number 40: solow-rob
+R> ###################################################
+R> solow_rob <- update(solow_lm, subset = goodobs)
+R> summary(solow_rob)
+
+Call:
+lm(formula = log(gdp85/gdp60) ~ log(gdp60) + log(invest) + log(popgrowth +
+ 0.05), data = OECDGrowth, subset = goodobs)
+
+Residuals:
+ Min 1Q Median 3Q Max
+-0.15454 -0.05548 -0.00651 0.03159 0.26773
+
+Coefficients:
+ Estimate Std. Error t value Pr(>|t|)
+(Intercept) 3.7764 1.2816 2.95 0.0106
+log(gdp60) -0.4507 0.0569 -7.93 1.5e-06
+log(invest) 0.7033 0.1906 3.69 0.0024
+log(popgrowth + 0.05) -0.6504 0.4190 -1.55 0.1429
+
+Residual standard error: 0.107 on 14 degrees of freedom
+Multiple R-squared: 0.853, Adjusted R-squared: 0.822
+F-statistic: 27.1 on 3 and 14 DF, p-value: 4.3e-06
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 41: quantreg
+R> ###################################################
+R> library("quantreg")
+Loading required package: SparseM
+
+Attaching package: 'SparseM'
+
+The following object is masked from 'package:base':
+
+ backsolve
+
+
+Attaching package: 'quantreg'
+
+The following object is masked from 'package:survival':
+
+ untangle.specials
+
+R>
+R>
+R> ###################################################
+R> ### chunk number 42: cps-lad
+R> ###################################################
+R> library("quantreg")
+R> data("CPS1988")
+R> cps_f <- log(wage) ~ experience + I(experience^2) + education
+R> cps_lad <- rq(cps_f, data = CPS1988)
+R> summary(cps_lad)
+
+Call: rq(formula = cps_f, data = CPS1988)
+
+tau: [1] 0.5
+
+Coefficients:
+ Value Std. Error t value Pr(>|t|)
+(Intercept) 4.24088 0.02190 193.67805 0.00000
+experience 0.07744 0.00115 67.50041 0.00000
+I(experience^2) -0.00130 0.00003 -49.97891 0.00000
+education 0.09429 0.00140 67.57171 0.00000
+R>
+R>
+R> ###################################################
+R> ### chunk number 43: cps-rq
+R> ###################################################
+R> cps_rq <- rq(cps_f, tau = c(0.25, 0.75), data = CPS1988)
+R> summary(cps_rq)
+
+Call: rq(formula = cps_f, tau = c(0.25, 0.75), data = CPS1988)
+
+tau: [1] 0.25
+
+Coefficients:
+ Value Std. Error t value Pr(>|t|)
+(Intercept) 3.78227 0.02866 131.95189 0.00000
+experience 0.09156 0.00152 60.26474 0.00000
+I(experience^2) -0.00164 0.00004 -45.39065 0.00000
+education 0.09321 0.00185 50.32520 0.00000
+
+Call: rq(formula = cps_f, tau = c(0.25, 0.75), data = CPS1988)
+
+tau: [1] 0.75
+
+Coefficients:
+ Value Std. Error t value Pr(>|t|)
+(Intercept) 4.66005 0.02023 230.39734 0.00000
+experience 0.06377 0.00097 65.41364 0.00000
+I(experience^2) -0.00099 0.00002 -44.15591 0.00000
+education 0.09434 0.00134 70.65855 0.00000
+R>
+R>
+R> ###################################################
+R> ### chunk number 44: cps-rqs
+R> ###################################################
+R> cps_rq25 <- rq(cps_f, tau = 0.25, data = CPS1988)
+R> cps_rq75 <- rq(cps_f, tau = 0.75, data = CPS1988)
+R> anova(cps_rq25, cps_rq75)
+Quantile Regression Analysis of Deviance Table
+
+Model: log(wage) ~ experience + I(experience^2) + education
+Joint Test of Equality of Slopes: tau in { 0.25 0.75 }
+
+ Df Resid Df F value Pr(>F)
+1 3 56307 115 <2e-16
+R>
+R>
+R> ###################################################
+R> ### chunk number 45: cps-rq-anova
+R> ###################################################
+R> anova(cps_rq25, cps_rq75, joint = FALSE)
+Quantile Regression Analysis of Deviance Table
+
+Model: log(wage) ~ experience + I(experience^2) + education
+Tests of Equality of Distinct Slopes: tau in { 0.25 0.75 }
+
+ Df Resid Df F value Pr(>F)
+experience 1 56309 339.41 <2e-16
+I(experience^2) 1 56309 329.74 <2e-16
+education 1 56309 0.35 0.55
+R>
+R>
+R> ###################################################
+R> ### chunk number 46: rqbig
+R> ###################################################
+R> cps_rqbig <- rq(cps_f, tau = seq(0.05, 0.95, by = 0.05),
++ data = CPS1988)
+R> cps_rqbigs <- summary(cps_rqbig)
+Warning message:
+In summary.rq(xi, U = U, ...) : 18 non-positive fis
+R>
+R>
+R> ###################################################
+R> ### chunk number 47: rqbig-plot eval=FALSE
+R> ###################################################
+R> ## plot(cps_rqbigs)
+R>
+R>
+R> ###################################################
+R> ### chunk number 48: rqbig-plot1
+R> ###################################################
+R> plot(cps_rqbigs)
+R>
+R>
+R>
+> proc.time()
+ user system elapsed
+ 16.812 0.044 16.859
diff --git a/vignettes/AER.Rnw b/vignettes/AER.Rnw
new file mode 100644
index 0000000..604fb8f
--- /dev/null
+++ b/vignettes/AER.Rnw
@@ -0,0 +1,281 @@
+\documentclass[nojss]{jss}
+
+%% need no \usepackage{Sweave}
+\usepackage{thumbpdf}
+
+%% new commands
+\newcommand{\class}[1]{``\code{#1}''}
+\newcommand{\fct}[1]{\code{#1()}}
+
+\SweaveOpts{engine=R, eps=FALSE, keep.source = TRUE}
+<<options, echo=FALSE>>=
+options(prompt = "R> ", digits = 4, show.signif.stars = FALSE)
+@
+%%\VignetteIndexEntry{Applied Econometrics with R: Package Vignette and Errata}
+%%\VignettePackage{AER}
+%%\VignetteDepends{AER}
+%%\VignetteKeywords{econometrics, statistical software, R}
+
+\author{Christian Kleiber\\Universit\"at Basel
+ \And Achim Zeileis\\Universit\"at Innsbruck}
+\Plainauthor{Christian Kleiber, Achim Zeileis}
+\title{Applied Econometrics with \proglang{R}:\\Package Vignette and Errata}
+\Plaintitle{Applied Econometrics with R: Package Vignette and Errata}
+\Shorttitle{\pkg{AER}: Package Vignette and Errata}
+
+\Keywords{econometrics, statistical software, \proglang{R}}
+\Plainkeywords{econometrics, statistical software, R}
+
+\Abstract{
+ ``Applied Econometrics with \proglang{R}''
+ \citep[Springer-Verlag, ISBN~978-0-387-77316-2, pp.~vii+222]{aer:Kleiber+Zeileis:2008}
+ is the first book on applied econometrics using the \proglang{R}~system
+ for statistical computing and graphics \citep{aer:R:2016}.
+ It presents hands-on examples for a
+ wide range of econometric models, from classical linear regression models for
+ cross-section, time series or panel data and the common non-linear models of
+ microeconometrics, such as logit, probit, tobit models as well as regression
+ models for count data, to recent
+ semiparametric extensions. In addition, it provides a chapter on programming,
+ including simulations, optimization and an introduction to \proglang{R} tools
+ enabling reproducible econometric research.
+ The methods are presented by illustrating, among other things, the fitting
+ of wage equations, growth regressions, dynamic
+ regressions and time series models as well as various models of microeconometrics.
+
+ The book is accompanied by the \proglang{R} package
+ \pkg{AER} \citep{aer:Kleiber+Zeileis:2016} which contains some new \proglang{R}
+ functionality, some 100 data sets
+ taken from a wide variety of sources, the full source code for all examples
+ used in the book, as well as further worked examples, e.g., from popular textbooks.
+
+ This vignette provides an overview of the package contents and contains
+ a list of errata for the book.
+}
+
+\Address{
+ Christian Kleiber\\
+ Faculty of Business and Economics\\
+ Universit\"at Basel\\
+ Peter Merian-Weg 6\\
+ 4002 Basel, Switzerland\\
+ E-mail: \email{Christian.Kleiber at unibas.ch}\\
+ URL: \url{https://wwz.unibas.ch/kleiber/}\\
+
+ Achim Zeileis\\
+ Department of Statistics\\
+ Faculty of Economics and Statistics\\
+ Universit\"at Innsbruck\\
+ Universit\"atsstr.~15\\
+ 6020 Innsbruck, Austria\\
+ E-mail: \email{Achim.Zeileis at R-project.org}\\
+ URL: \url{https://eeecon.uibk.ac.at/~zeileis/}
+}
+
+\begin{document}
+
+\section{Package overview}
+
+\subsection[R code from the book]{\proglang{R} code from the book}
+
+The full \proglang{R} code from the book is provided in the demos for the package \pkg{AER}.
+The source scripts can be found in the \code{demo}
+directory of the package and executed interactively by calling
+\fct{demo}, as in
+%
+<<demo, eval=FALSE>>=
+demo("Ch-Intro", package = "AER")
+@
+%
+One demo per chapter is provided:
+\begin{itemize}
+ \item \code{Ch-Intro} (Chapter~1: Introduction),
+ \item \code{Ch-Basics} (Chapter~2: Basics),
+ \item \code{Ch-LinearRegression} (Chapter~3: Linear Regression),
+ \item \code{Ch-Validation} (Chapter~4: Diagnostics and Alternative Methods of Regression),
+ \item \code{Ch-Microeconometrics} (Chapter~5: Models of Microeconometrics),
+ \item \code{Ch-TimeSeries} (Chapter~6: Time Series),
+ \item \code{Ch-Programming} (Chapter~7: Programming Your Own Analysis).
+\end{itemize}
+This list of demos is also shown by \code{demo(package = "AER")}.
+
+The same scripts are contained in the \code{tests} directory of the package
+so that they are automatically checked and compared with the desired output
+provided in \code{.Rout.save} files.
+
+To make the code fully reproducible and to avoid some lengthy computations
+in the daily checks, a few selected code chunks are commented out in the
+scripts. Also, for technical reasons, some graphics code chunks are repeated,
+once commented out and once without comments.
+
+
+\subsection{Data sets}
+
+The \pkg{AER} package includes some 100 data sets from leading applied
+econometrics journals and popular econometrics textbooks. Many data sets
+have been obtained from the data archive of the \emph{Journal of Applied
+Econometrics} and the (now defunct) data archive of the
+\emph{Journal of Business \& Economic Statistics} (see note below).
+Some of these are used in recent textbooks, among them
+\cite{aer:Baltagi:2002}, \cite{aer:Davidson+MacKinnon:2004}, \cite{aer:Greene:2003},
+\cite{aer:Stock+Watson:2007}, and \cite{aer:Verbeek:2004}. In addition, we provide
+all further data sets from \cite{aer:Baltagi:2002}, \cite{aer:Franses:1998},
+\cite{aer:Greene:2003}, \cite{aer:Stock+Watson:2007}, and \cite{aer:Winkelmann+Boes:2009}.
+Selected data sets from \cite{aer:Franses+vanDijk+Opschoor:2014} are also included.
+
+Detailed information about the source of each data set, descriptions of
+the variables included, and usually also examples for typical analyses
+are provided on the respective manual pages. A full list of all data sets
+in \pkg{AER} can be obtained via
+%
+<<data, eval=FALSE>>=
+data(package = "AER")
+@
+%
+In addition, manual pages corresponding to selected textbooks are available.
+They list all data sets from the respective book and provide extensive
+code for replicating many of the empirical examples. See, for example,
+<<help, eval=FALSE>>=
+help("Greene2003", package = "AER")
+@
+for data sets and code for \cite{aer:Greene:2003}.
+Currently available manual pages are:
+
+\begin{itemize}
+ \item \code{Baltagi2002} for \cite{aer:Baltagi:2002},
+ \item \code{CameronTrivedi1998} for \cite{aer:Cameron+Trivedi:1998},
+ \item \code{Franses1998} for \cite{aer:Franses:1998},
+ \item \code{Greene2003} for \cite{aer:Greene:2003},
+ \item \code{StockWatson2007} for \cite{aer:Stock+Watson:2007}.
+ \item \code{WinkelmannBoes2009} for \cite{aer:Winkelmann+Boes:2009}.
+\end{itemize}
+
+
+\subsection[New R functions]{New \proglang{R} functions}
+
+\pkg{AER} provides a few new \proglang{R} functions extending
+or complementing methods previously available in \proglang{R}:
+\begin{itemize}
+ \item \fct{tobit} is a convenience interface to \fct{survreg}
+ from package \pkg{survival} for fitting tobit regressions
+ to censored data. In addition to the fitting function itself,
+ the usual set of accessor and extractor functions is
+ provided, e.g., \fct{print}, \fct{summary}, \fct{logLik},
+ etc. For more details see \code{?tobit}.
+ \item \fct{ivreg} fits instrumental-variable regressions
+ via two-stage least squares. It provides a formula
+ interface and calls the workhorse function \fct{ivreg.fit}
+ which in turn calls \fct{lm.fit} twice. In addition to the fitting functions,
+ the usual set of accessor and extractor functions is
+ provided, e.g., \fct{print}, \fct{summary}, \fct{anova}, etc.
+ For more details see \code{?ivreg}, \code{?ivreg.fit},
+ and \code{?summary.ivreg}, respectively.
+ \item \fct{dispersiontest} tests the null hypothesis of
+ equidispersion in Poisson regressions against the alternative
+ of overdispersion and/or underdispersion. For more details
+ see \code{?dispersiontest}.
+\end{itemize}
+
+
+
+\section{Errata and comments}
+
+Below we list the errors that have been found in the book so far. Please report any further errors you find to us.
+
+We also provide some comments, for example on functions whose interface has changed.
+
+\begin{itemize}
+ \item p.~5--9, 46--53: There are now very minor differences in the plots pertaining to
+ Example~2 (Determinants of wages) in Chapter~1.1 and Chapter~2.8 (Exploratory Data Analysis with \proglang{R})
+ due to a missing observation. Specifically, the version of the \code{CPS1985} data used
+ for the book contained only 533~observations, the original observation~1 had been omitted inadvertently.
+ \item p.~38, 48, 85: By default there is less rounding in calls to \code{summary()} starting from
+ \proglang{R}~3.4.0.
+ \item p.~63--65, 130, 143: The function \fct{linear.hypothesis} from the \pkg{car} package has
+ been renamed to \fct{linearHypothesis} starting from \pkg{car}~2.0-0. The old interface
+ is currently still supported but results in a warning.
+ \item p.~85--86: Due to a bug in the \code{summary()} method for ``\code{plm}'' objects,
+ the degrees of freedom reported for the $F$~statistics were interchanged and thus the
+ $p$~values were not correct. Therefore, the $p$~values printed in the book at the end
+ of \code{summary(gr_fe)} and \code{summary(gr_re)} are not correct,
+ they should both be \code{< 2.22e-16}. Using \pkg{plm} 1.1-1 or higher, the code produces
+ the correct output.
+ \item pp.~88--89: As of version 1.3-1 of the \pkg{plm} package, summaries of ``\code{pgmm}''
+ objects provide robust standard errors by default. The output presented on pp.~88--89 is
+ still available, but now requires \code{summary(empl_ab, robust = FALSE)}.
+
+ Also, the formula interface for \fct{pgmm} has changed. Using the new interface,
+ the function call for the Arellano-Bond example is
+%
+<<pgmm-new, eval=FALSE>>=
+empl_ab <- pgmm(log(emp) ~ lag(log(emp), 1:2) + lag(log(wage), 0:1)
+ + log(capital) + lag(log(output), 0:1) | lag(log(emp), 2:99),
+ data = EmplUK, effect = "twoways", model = "twosteps")
+@
+%
+ The function call given in the book is still valid though.
+
+ \item p.~92: Exercise~6 cannot be solved using \code{PSID1982} since that data set only
+ contains a cross-section while Hausman-Taylor requires panel data. A panel version has
+ been available in the \pkg{plm} package under the name \code{Wages}; we have now added
+ \code{PSID7682} to \pkg{AER} for completeness (and consistent naming conventions).
+ Use \code{PSID7682} for the exercise.
+ \item pp.~98--100: \proglang{R} only provides a function \code{dffits()} but not \code{dffit()}
+ as claimed on p.~99. Somewhat confusingly the corresponding column in the output of
+ \code{influence.measures()} (as shown on p.~100) is called \code{dffit} by \proglang{R}
+ (rather than \code{dffits}).
+ \item p.~141: The log-likelihood for the tobit model lacked a minus sign. The correct version is
+%
+\[
+\ell(\beta, \sigma^2)
+= \sum_{y_i > 0} \left( \log\phi\{(y_i - x_i^\top \beta)/\sigma\} - \log\sigma \right)
+ + \sum_{y_i = 0} \log \Phi( - x_i^\top \beta /\sigma).
+\]
+%
+ \item p.~149: The standard error (and hence the corresponding $z$~test) of \code{admin|manage}
+ in the output of \code{coeftest(bank_polr)} is wrong, it should be \code{1.4744}.
+ This was caused by an inconsistency between \fct{polr} and its \fct{vcov} method which
+ has now been improved in the \pkg{MASS} package ($\ge$ 7.3-6).
+ \item p.~169: The comment regarding the output from the Johansen test is in error.
+ The null hypothesis of no cointegration is not rejected at the 10\% level. Nonetheless,
+ the table corresponding to Case~2 in \citet[][p.~420]{aer:Juselius:2006} reveals that the
+ trace statistic is significant at the 15\% level, thus the Johansen test weakly confirms
+ the initial two-step approach.
+ \item p.~179: For consistency, the GARCH code should be preceded by \code{data("MarkPound")}.
+
+ \item p.~192: The likelihood for the generalized production function was in error (code and computations were correct though).
+
+The correct likelihood for the model is
+%
+\[
+\mathcal{L} =
+\prod_{i=1}^n \left\{ \frac{1}{\sigma} \phi \left(\frac{\varepsilon_i}{\sigma}\right) \cdot \frac{1 + \theta Y_i}{Y_i} \right\} .
+\]
+%
+giving the log-likelihood
+%
+\[
+\ell = \sum_{i=1}^n \left\{ \log (1 + \theta Y_i) - \log Y_i \right\}
+ - n \log \sigma + \sum_{i=1}^n \log \phi (\varepsilon_i/\sigma) .
+\]
+
+ \item p.~205: The reference for Henningsen (2008) should be: %% FIXME: will be package vignette
+ \begin{quote}
+ Henningsen A (2008). ``Demand Analysis with the Almost Ideal Demand System
+ in \proglang{R}: Package \pkg{micEcon},'' Unpublished.
+ URL~\url{http://CRAN.R-project.org/package=micEcon}.
+ \end{quote}
+\end{itemize}
+
+
+\emph{Note:} Currently, all links on manual pages corresponding to data sets taken from
+the Journal of Business \& Economic Statistics (JBES) archive are broken (data sets
+\code{MarkPound}, and \code{RecreationDemand}). The reason is the redesign of the American
+Statistical Association (ASA) website, rendering the old ASA data archive nonfunctional.
+The ASA journals manager currently appears to supply data on a case-by-case basis.
+The problem awaits a more permanent solution.
+
+
+\bibliography{aer}
+
+\end{document}
diff --git a/vignettes/Sweave-journals.Rnw b/vignettes/Sweave-journals.Rnw
new file mode 100644
index 0000000..4a08ff3
--- /dev/null
+++ b/vignettes/Sweave-journals.Rnw
@@ -0,0 +1,23 @@
+%\VignetteIndexEntry{Sweave Example: Linear Regression for Economics Journals Data}
+\documentclass[a4paper]{article}
+
+\begin{document}
+
+We fit a linear regression for the economic journals demand model.
+
+<<>>=
+data("Journals", package = "AER")
+journals_lm <- lm(log(subs) ~ log(price/citations), data = Journals)
+journals_lm
+@
+
+A scatter plot with the fitted regression line is shown below.
+
+\begin{center}
+<<fig=TRUE, echo=FALSE>>=
+plot(log(subs) ~ log(price/citations), data = Journals)
+abline(journals_lm)
+@
+\end{center}
+
+\end{document}
diff --git a/vignettes/aer.bib b/vignettes/aer.bib
new file mode 100644
index 0000000..689d0dd
--- /dev/null
+++ b/vignettes/aer.bib
@@ -0,0 +1,121 @@
+ at Book{aer:Baltagi:2002,
+ author = {Badi H. Baltagi},
+ title = {Econometrics},
+ edition = {3rd},
+ year = {2002},
+ pages = {401},
+ publisher = {Springer-Verlag},
+ address = {New York},
+ url = {http://www.springeronline.com/sgw/cda/frontpage/0,10735,4-165-2-107420-0,00.html}
+}
+
+ at Book{aer:Cameron+Trivedi:1998,
+ author = {A. Colin Cameron and Pravin K. Trivedi},
+ title = {Regression Analysis of Count Data},
+ year = {1998},
+ pages = {411},
+ publisher = {Cambridge University Press},
+ address = {Cambridge}
+}
+
+ at Book{aer:Davidson+MacKinnon:2004,
+ author = {Russell Davidson and James G. MacKinnon},
+ title = {Econometric Theory and Methods},
+ year = {2004},
+ pages = {750},
+ publisher = {Oxford University Press},
+ address = {Oxford}
+}
+
+ at Book{aer:Franses:1998,
+ author = {Philip Hans Franses},
+ title = {Time Series Models for Business and Economic Forecasting},
+ publisher = {Cambridge University Press},
+ year = {1998},
+ address = {Cambridge},
+ url = {http://www.few.eur.nl/few/people/franses/research/book2.htm}
+}
+
+ at Book{aer:Franses+vanDijk+Opschoor:2014,
+ author = {Philip Hans Franses and Dick van Dijk and Anne Opschoor},
+ title = {Time Series Models for Business and Economic Forecasting},
+ edition = {2nd},
+ publisher = {Cambridge University Press},
+ year = {2014},
+ address = {Cambridge},
+ url = {http://www.cambridge.org/us/academic/subjects/economics/econometrics-statistics-and-mathematical-economics/time-series-models-business-and-economic-forecasting-2nd-edition}
+}
+
+ at Book{aer:Greene:2003,
+ author = {William H. Greene},
+ title = {Econometric Analysis},
+ edition = {5th},
+ year = {2003},
+ pages = {1026},
+ publisher = {Prentice Hall},
+ address = {Upper Saddle River, NJ},
+ url = {http://pages.stern.nyu.edu/~wgreene/Text/econometricanalysis.htm}
+}
+
+ at Book{aer:Juselius:2006,
+ author = {Katarina Juselius},
+ title = {The Cointegrated {VAR} Model},
+ year = {2006},
+ publisher = {Oxford University Press},
+ address = {Oxford}
+}
+
+ at Book{aer:Kleiber+Zeileis:2008,
+ title = {Applied Econometrics with \proglang{R}},
+ author = {Christian Kleiber and Achim Zeileis},
+ year = {2008},
+ publisher = {Springer-Verlag},
+ address = {New York},
+ note = {{ISBN} 978-0-387-77316-2},
+}
+
+ at Manual{aer:Kleiber+Zeileis:2016,
+ title = {\pkg{AER}: Applied Econometrics with \proglang{R}},
+ author = {Christian Kleiber and Achim Zeileis},
+ year = {2016},
+ note = {\proglang{R}~package version~1.2-5},
+ url = {http://CRAN.R-project.org/package=AER}
+}
+
+ at Manual{aer:R:2016,
+ title = {\proglang{R}: {A} Language and Environment for Statistical Computing},
+ author = {{\proglang{R} Core Team}},
+ organization = {\proglang{R} Foundation for Statistical Computing},
+ address = {Vienna, Austria},
+ year = {2016},
+ note = {{ISBN} 3-900051-07-0},
+ url = {http://www.R-project.org/}
+}
+
+ at Book{aer:Stock+Watson:2007,
+ author = {James H. Stock and Mark W. Watson},
+ title = {Introduction to Econometrics},
+ year = {2007},
+ edition = {2nd},
+ publisher = {Addison-Wesley},
+ address = {Reading, MA}
+}
+
+ at Book{aer:Verbeek:2004,
+ author = {Marno Verbeek},
+ title = {A Guide to Modern Econometrics},
+ edition = {2nd},
+ year = {2004},
+ publisher = {John Wiley \& Sons},
+ address = {Hoboken, NJ}
+}
+
+ at Book{aer:Winkelmann+Boes:2009,
+ author = {Rainer Winkelmann and Stefan Boes},
+ title = {Analysis of Microdata},
+ edition = {2nd},
+ year = {2009},
+ publisher = {Springer-Verlag},
+ address = {Berlin and Heidelberg}
+}
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/r-cran-aer.git
More information about the debian-science-commits
mailing list