setInternet2(TRUE) # solution for https files
download.file("https://sites.google.com/site/econometriks/docs/h09.rda", "h09.RData")
load("h09.RData")
library(mlogit)
library(psych)
library(xtable)
library(htmlTable)
names(h09)
## [1] "id" "alt" "chair" "hinc" "psize" "aasc" "tasc"
## [8] "basc" "casc" "psizea" "mode" "twait" "invc" "invt"
## [15] "gc" "mc" "hinca" "hincb" "hinct" "psizeb" "psizet"
## [22] "t" "choice"
attach(h09)
h09a <- h09[ which(mc== "yes"),]
detach(h09)
tab1<-table(h09a$alt); tab2<-tab1/sum(tab1)*100
print(xtable(cbind("mode share (%)"= tab2)), type="html")
|
mode share (%)
|
air
|
27.62
|
bus
|
14.29
|
car
|
28.10
|
train
|
30.00
|
tab3=xtable(cbind(tab2))
htmlTable(txtRound(tab3,2), rowlabel = "mode of travel",
header ="percentage of respondents")
mode of travel
|
percentage of respondents
|
air
|
27.62
|
bus
|
14.29
|
car
|
28.10
|
train
|
30.00
|
attach(h09a)
tab3<-describeBy(cbind(twait, invc, invt, hinc, psize), alt, mat=TRUE , range=F, skew=F)
print(xtable(tab3, digits=c(0,0,0,0,0,2,2,2)), type="html")
|
item
|
group1
|
vars
|
n
|
mean
|
sd
|
se
|
twait1
|
1
|
air
|
1
|
58
|
46.53
|
24.39
|
3.20
|
twait2
|
2
|
bus
|
1
|
30
|
25.20
|
14.92
|
2.72
|
twait3
|
3
|
car
|
1
|
59
|
0.00
|
0.00
|
0.00
|
twait4
|
4
|
train
|
1
|
63
|
28.52
|
19.35
|
2.44
|
invc1
|
5
|
air
|
2
|
58
|
97.57
|
31.73
|
4.17
|
invc2
|
6
|
bus
|
2
|
30
|
33.73
|
11.02
|
2.01
|
invc3
|
7
|
car
|
2
|
59
|
15.64
|
9.63
|
1.25
|
invc4
|
8
|
train
|
2
|
63
|
37.46
|
20.68
|
2.60
|
invt1
|
9
|
air
|
3
|
58
|
124.83
|
50.29
|
6.60
|
invt2
|
10
|
bus
|
3
|
30
|
618.83
|
273.61
|
49.95
|
invt3
|
11
|
car
|
3
|
59
|
527.37
|
301.13
|
39.20
|
invt4
|
12
|
train
|
3
|
63
|
532.67
|
249.36
|
31.42
|
hinc1
|
13
|
air
|
4
|
58
|
41.72
|
19.12
|
2.51
|
hinc2
|
14
|
bus
|
4
|
30
|
29.70
|
16.85
|
3.08
|
hinc3
|
15
|
car
|
4
|
59
|
42.22
|
17.69
|
2.30
|
hinc4
|
16
|
train
|
4
|
63
|
23.06
|
17.29
|
2.18
|
psize1
|
17
|
air
|
5
|
58
|
1.57
|
0.82
|
0.11
|
psize2
|
18
|
bus
|
5
|
30
|
1.33
|
0.66
|
0.12
|
psize3
|
19
|
car
|
5
|
59
|
2.20
|
1.27
|
0.17
|
psize4
|
20
|
train
|
5
|
63
|
1.67
|
0.90
|
0.11
|
detach(h09a)
data1 <- mlogit.data (h09,choice="mc",shape="long",id.var="id",
alt.var= "alt")
mod.1<-mlogit(mc~ gc + twait +hinca ,data1,reflevel="car")
mod.2<-mlogit(mc~ gc + twait +hinca ,data1,reflevel="air")
fit1<-fitted(mod.2,outcome=F)
library(stargazer)
##
## Please cite as:
##
## Hlavac, Marek (2014). stargazer: LaTeX code and ASCII text for well-formatted regression and summary statistics tables.
## R package version 5.1. http://CRAN.R-project.org/package=stargazer
stargazer(mod.1, mod.2, type="html", no.space=TRUE,
dep.var.labels = c("travel mode choice"),
title="Discrete Choice Models", covariate.labels = c("air intercept",
"bus intercept", "car intercept", "train intercept", "generalized cost",
"terminal wait times", "household income (air only)") )
Discrete Choice Models
|
|
Dependent variable:
|
|
|
|
travel mode choice
|
|
(1)
|
(2)
|
|
air intercept
|
5.207***
|
|
|
(0.779)
|
|
bus intercept
|
3.163***
|
-2.044***
|
|
(0.450)
|
(0.555)
|
car intercept
|
|
-5.207***
|
|
|
(0.779)
|
train intercept
|
3.869***
|
-1.338**
|
|
(0.443)
|
(0.543)
|
generalized cost
|
-0.016***
|
-0.016***
|
|
(0.004)
|
(0.004)
|
terminal wait times
|
-0.096***
|
-0.096***
|
|
(0.010)
|
(0.010)
|
household income (air only)
|
0.013
|
0.013
|
|
(0.010)
|
(0.010)
|
|
Observations
|
210
|
210
|
R2
|
0.298
|
0.298
|
Log Likelihood
|
-199.128
|
-199.128
|
LR Test (df = 6)
|
169.261***
|
169.261***
|
|
Note:
|
p<0.1; p<0.05; p<0.01
|
tab1<-describe(fit1, skew=F, range=F)
print(xtable(tab1, digits=c(0,0,0,2,2,2)), type="html")
|
vars
|
n
|
mean
|
sd
|
se
|
air
|
1
|
210
|
0.28
|
0.28
|
0.02
|
bus
|
2
|
210
|
0.14
|
0.19
|
0.01
|
car
|
3
|
210
|
0.28
|
0.18
|
0.01
|
train
|
4
|
210
|
0.30
|
0.27
|
0.02
|
names(h09)[1]<-"person id"
names(h09)[2]<-"alternatives"
names(h09)[3]<-"air ones"
names(h09)[4]<-"household income ('000)"
names(h09)[5]<-"party size"
names(h09)[6]<-"air ASC"
names(h09)[7]<-"train ASC"
names(h09)[8]<-"bus ASC"
names(h09)[9]<-"car ASC"
names(h09)[10]<-"party size- air"
names(h09)[11]<-"chosen mode"
names(h09)[12]<-"wait time"
names(h09)[13]<-"in-vehicle cost"
names(h09)[14]<-"in-vehicle time"
names(h09)[15]<-"generalized cost"
names(h09)[16]<-"binary choice"
names(h09)[17]<-"income-air"
names(h09)[18]<-"income-bus"
names(h09)[19]<-"inc-train"
names(h09)[20]<-"party size-bus"
names(h09)[21]<-"party size-train"
names(h09)[22]<-"dummy t"
names(h09)[23]<-"numeric choice"
w.air = .14/.28
w.train = .13/.3
w.bus = .09/.14
w.car = .64/.28
attach(h09)
h09$wts[alt=="air"] <-w.air
h09$wts[alt=="train"] <-w.train
h09$wts[alt=="bus"] <-w.bus
h09$wts[alt=="car"] <-w.car
data2 <- mlogit.data (h09,choice="mc",shape="long",id.var="id",
alt.var= "alt")
summary(mod2<-mlogit(mc~ gc + twait +hinca ,data2, weights=wts, reflevel="car"))
summary(mod2<-mlogit(mc~ gc + twait +hinca ,data2, reflevel="car"))
aggregate( wts, by=list(alternatives=alt), data = h09, mean)