# Tietokoneharjoitus 4

Seatbelts is a balanced panel from 50 U.S. States, plus the District of Columbia, for the years 1983-1997. These data were provided by Professor Liran Einav of Stanford University and were used in his paper with Alma Cohen The Effects of Mandatory Seat Belt Laws on Driving Behavior and Traffic Fatalities,'' The Review of Economics and Statistics, 2003, Vol. 85, No. 4, pp 828-843.

Artikkeli loytyy osoitteesta http://www.stanford.edu/~leinav/pubs/RESTAT2003.pdf

• state = State (csv-tiedostossa, mutta ei txt-tiedostossa)
• year = Year
• fips = State ID Code
• vmt = Millions of traffic miles per year. (Note: Number of fatalities =fatalityrate $\times$ vmt)
• fatalityrate = Number of fatalities per million of traffic miles
• sb_usage = Seat belt usage rate
• speed65 = Binary variable for 65 mile per hour speed limit
• speed70 = Binary variable for 70 or higher mile per hour speed limit
• drinkage21 = Binary variable for age 21 drinking age
• ba08 = Binary variable for blood alcohol limit â‰¤ .08\%
• income = Per capita income
• age = Mean age
• primary = Binary variable for primary enforcement of seat belt laws
• secondary = Binary variable for secondary enforcement of seat belt laws

## Datan lukeminen R:aan

file<-"http://cc.oulu.fi/~jklemela/econometrics/SeatBelts.csv"


## Datan lukeminen SAS:iin

FILENAME myurl URL 'http://cc.oulu.fi/~jklemela/econometrics/SeatBelts.txt';

DATA SeatBelts;
INFILE myurl firstobs=2;
INPUT year fips vmt fatalityrate sb_usage speed65 speed70
drinkage21 ba08 income age primary secondary;
RUN;


## Tehtävä 5

Valitse FatalityRate y-muuttujaksi ja sb_usage, speed65, speed70, drinkage21, ba08, log(income) ja age x-muuttujiksi. Suorita OLS-regressio ja testaa hypoteesia beta3=beta4

file<-"http://cc.oulu.fi/~jklemela/econometrics/SeatBelts.csv"

y<-data[,5]
sp.usage<-data[,6]
speed65<-data[,7]
speed70<-data[,8]
drinkage21<-data[,9]
ba08<-data[,10]
log.income<-log(data[,11])
age<-data[,12]

reg.model<-lm(y ~ sp.usage+speed65+speed70+drinkage21+ba08+log.income+age)

library(car)
Q<-1
K<-8
r<-0
R<-matrix(c(0,0,1,-1,0,0,0,0),Q,K)

linearHypothesis(reg.model,R,r)

Linear hypothesis test

Hypothesis:
speed65 - speed70 = 0

Model 1: restricted model
Model 2: y ~ sp.usage + speed65 + speed70 + drinkage21 + ba08 + log.income +
age

Res.Df      RSS Df  Sum of Sq      F   Pr(>F)
1    549 0.010446
2    548 0.010318  1 0.00012848 6.8237 0.009242 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

# Waldin testi

F<-6.8237
W<-Q*F
pvalue<-1-pchisq(W, df=Q)
pvalue
# [1] 0.008995601

# Tarkistetaan tulos

ota<-!is.na(sp.usage)
K<-8
y<-data[ota,5]
n<-length(y)
x<-matrix(0,n,K)
x[,1]<-1
x[,2]<-sp.usage[ota]
x[,3]<-speed65[ota]
x[,4]<-speed70[ota]
x[,5]<-drinkage21[ota]
x[,6]<-ba08[ota]
x[,7]<-log.income[ota]
x[,8]<-age[ota]

A<-t(x)%*%x
invA<-solve(A,diag(1,K))
b<-invA%*%t(x)%*%y

Q<-1
r<-0
R<-matrix(c(0,0,1,-1,0,0,0,0),Q,K)

B<-R%*%invA%*%t(R)
invB<-solve(B,diag(1,Q))

e<-y-x%*%b
s2<-sum(e^2)/(n-K)

QF<-t(R%*%b-r)%*%invB%*%(R%*%b-r)/s2
QF
1-pchisq(QF,df=Q)

# Waldin testisuureen arvo QF
# [1,] 6.823729

# p-arvo 1-pchisq(QF,df=Q)
# [1,] 0.008995454



Kokeillaan SAS:ia

FILENAME myurl URL 'http://cc.oulu.fi/~jklemela/econometrics/SeatBelts.txt';
DATA SeatBelts;
INFILE myurl firstobs=2;
INPUT number \$ year fips vmt fatalityrate sb_usage speed65 speed70 drinkage21 ba08 income age primary secondary;
RUN;

PROC reg data=SeatBelts;
model fatalityrate =  sb_usage speed65 speed70 drinkage21 ba08 logincome age;
hogone: test speed65-speed70=0;
RUN;

PROC reg data=SeatBelts;
model fatalityrate =  sb_usage speed65 speed70 drinkage21 ba08 logincome age;
restrict speed65-speed70=0;
RUN;




The SAS System            10:26 Thursday, February 6, 2014   3

The REG Procedure
Model: MODEL1

Test hogone Results for Dependent Variable fatalityrate

Mean
Source             DF         Square    F Value    Pr > F

Numerator           1     0.00012848       6.82    0.0092
Denominator       548     0.00001883

The SAS System            10:26 Thursday, February 6, 2014   5

The REG Procedure
Model: MODEL1
Dependent Variable: fatalityrate

Parameter Estimates

Parameter       Standard
Variable        DF       Estimate          Error    t Value    Pr > |t|

Intercept        1        0.19727        0.01046      18.86     <.0001
sb_usage         1        0.00356        0.00155       2.29     0.0222
speed65          1        0.00101     0.00038486       2.64     0.0086
speed70          1        0.00101     0.00038486       2.64     0.0086
drinkage21       1     0.00062278        0.00109       0.57     0.5696
ba08             1       -0.00130     0.00056977      -2.29     0.0225
logincome        1       -0.01780        0.00118     -15.06     <.0001
age              1    -0.00015054     0.00013966      -1.08     0.2816
RESTRICT        -1       -0.05638        0.02170      -2.60     0.0092*

* Probability computed using beta distribution.