# Computer code for example 3.13
# HINT:
# The program assumes that all files are stored in
# C:\monographregression\computercode
# and corresponding subfolders.
# Change directory if code is located elsewhere.
# change working directory
setwd("c:/monographregression/computercode")
library(foreign)
library(car)
# read data
rent99 <- read.dta(file="data/stata/rent98_00.dta")
# estimate the model rentsqm = beta_0 + beta_1*(1/area) + beta_2*yearc + beta_3*yearc^2 + beta_4*yearc^3 + beta_5 nkitchen + beta_6 pkitchen + beta_7 year01 + epsilon
# using 1/area centered and orthogonal polynomials for yearc
# note that the results printed in the book are obatined with STATA. In contrast to R STATA uses orthoNORMAL polynomials. Therefore
# the estimated coefficients are different to the printed results.
mod <- lm(rentsqm_euro ~ I(1/area - mean(1/area)) + poly(yearc,3) + nkitchen + pkitchen +year01 , data = rent99)
summary(mod)
# testing linear hypothesis: beta_5 = 0, beta_6=0
linearHypothesis(mod, c("nkitchen = 0", "pkitchen = 0"))
# testing linear hypothesis: beta_5-beta_6 = 0
linearHypothesis(mod, "1*nkitchen - 1*pkitchen = 0")