-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDCM.txt
More file actions
34 lines (26 loc) · 718 Bytes
/
DCM.txt
File metadata and controls
34 lines (26 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
model<-function(dataset){
#upload the libraries
library(mlogit)
library(stargazer)
#upload the file
library(readxl)
dat<-read_excel(dataset)
#create the formula
names<-names(dat[,2:length(dat)-1])
q<-as.formula(dat[,c(names)])
#create the mlogit dataset
a<-names(dat)[1]
b<-names(dat)[length(dat)]
dat<-mlogit_dataset<-mlogit.data(dat, shape="long",choice=a,alt.var=b)
#calculate the multinomial logit
mod<-mlogit(q,data=dat)
summary<-summary(mod)
#create a table
summary<-summary$CoefTable
# Write the data to a csv file
fileName <- sprintf("%s_%s.csv", as.integer(Sys.time()), digest::digest(summary))
file<-write.csv(summary,file=fileName)
write.csv(summary,file=fileName)
z<-list(summary, file)
return(z)
}