This script analyzes transport mode preferences (Car, Plane, Transit) based on travel time and subjects' age. Data is first created internally then restructured to match the format required by discrete choice models (one row per alternative). The script then compares two Bayesian approaches: a nested logit model grouping ground transportation (Car, Transit) versus air travel, and a classical multinomial logit model.
Data Analysis
Type : INTERNAL_CREATION
The 'Travel' data is created via DATALINES. The 'Travel2' table is derived from 'Travel' to transform the data structure from wide format to long format.
1 Code Block
DATA STEP Data
Explanation : Creation of the source table 'Travel' containing travel times for each mode, the subject's age, and the observed final choice.
Explanation : Data restructuring: conversion to long format where each row represents a choice alternative for a subject. Creation of the binary variable 'Choice' (1 if chosen, 0 otherwise).
Copied!
data Travel2(keep=Subject Mode TravTime Age AgeCtr Choice);
array Times[3] AutoTime PlanTime TranTime;
array Allmodes[3] $ _temporary_ ('Auto' 'Plane' 'Transit');
set Travel;
Subject = _n_;
do i = 1 to 3;
Mode = Allmodes[i];
TravTime = Times[i];
Choice = (Chosen eq Mode);
output;
end;
run;
1
DATA Travel2(keep=Subject Mode TravTime Age AgeCtr Choice);
Explanation : Estimation of a Nested Logit model. The 'nest=(1 2 1)' option defines the hierarchical structure by grouping modes 1 (Car) and 3 (Transit) into a nest, separate from mode 2 (Plane).
model Choice = Mode TravTime / choiceset=(Subject) type=nlogit nest=(121);
4
RUN;
4 Code Block
PROC BCHOICE
Explanation : Estimation of a standard Multinomial Logit model (without nesting structure) on the same data to allow comparison of information criteria (DIC).
model Choice = Mode TravTime / choiceset=(Subject);
4
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.