## ---------------------- ##

## R Tutorial on Testing  ##

## Linear Hypotheses      ##

##                        ##

## Author: Tony Cookson   ##

## ---------------------- ##

## --------------------------- ##

## This tutorial will use      ##

## the "car" library, which is ##

## not preinstalled in R       ##

##                             ##

## This first set of code will ##

## install "car" on your       ##

## computer.                   ##

## --------------------------- ##

install.packages("car", dependencies = T)

## -------------------------------------------- ##

## Notes:                                       ##

## 1. You will have to pick one of the servers  ##

##    to download "car." It doesn't matter      ##

##    which one you pick.                       ##

## 2. This command will install a bunch of      ##

##    "helper" packages, so R will look like it ##

##    is working for a while.  This is normal.  ##

## -------------------------------------------- ##

## ---------------------- ##

## Start here if you have ##

## "car" on your computer ##

## already.               ##

## ---------------------- ##

library(car)      ## Loads the "car" library

## ---------------------- ##

## Read and Explore Data  ##

## ---------------------- ##

 

library(foreign)                           ## To read Stata Files

edudat.df = read.dta("C://R//edudat2.dta") ## Reads Data

summary(edudat.df)

## ------------------- ##

## Estimate Regression ##

## ------------------- ##

wage.lm = lm(log(wage)~educ+exper+pareduc+gender,data=edudat.df)

summary(wage.lm)

## ------------------------------------ ##

## Test beta_educ + beta_exper = 0.10   ##

## ------------------------------------ ##

linearHypothesis(wage.lm, "educ+exper=0.1")

## ------------------------------------ ##

## Test beta_educ + beta_exper = 0.10   ##

## AND  beta_genderMALE = 0.05          ##

## AND  beta_pareduc + beta_educ = 0    ##

## ------------------------------------ ##

linearHypothesis(wage.lm, c("educ+exper=0.1","genderMALE=0.05","pareduc+educ=0"))