Introduction
The nested logit model expands the use of logit modeling techniques to allow for dependence across responses, by grouping alternatives into broader categories or nests.
The observed outcome then becomes the result of a multi-level decision process. At each level of that process, there are observed outcomes and attributes associated with specific choices. In addition, individuals making a decision may have specific characteristics that impact the outcomes but are NOT outcome specific.
In this example we consider the mode of transportation choice model found in Greene (2010). The dependent data, mode, measures mode of transportation across four possible choices: air, train, bus, or car. The choice specific attributes considered include terminal waiting time ( ttme ) and generalized cost ( GC ). In addition, an interaction term between each individuals' income level and the choice to fly is included ( AIRHINC ). Outcomes are considered on two nest levels: first the decision to fly or travel by ground, then the decision of what mode of air or ground transportation.
Step 1: Load the data
The data for this model is first loaded from an existing GAUSS matrix file (.fmt).
new;
cls;
library dc;
// Load data
y = loadd("hensher_mat.fmt");
Step 2: Create a control structure
Once the data is loaded in GAUSS, the estimation features are specified using the dcControl
structure.
// Declare dcControl structure
struct dcControl dcCt;
// Fill with default settings
dcCt = dcControlCreate();
Step 3: Specify data
Next, use dcSet
procedures to specify the data structure of the model.
// Dependent variable
dcSetYVar(&dcCt,y[.,1]);
dcSetYLabel(&dcCt,"Mode");
// Category labels
dcSetYCategoryLabels(&dcCt,"Air,Train,Bus,Car");
// Reference category
dcSetReferenceCategory(&dcCt, "Car");
// Independent variables
dcSetAttributeVars(&dcCt,y[.,2]~y[.,5]~y[.,8]);
dcSetAttributeLabels(&dcCt,"TTME,GC,AIRHINC");
Step 4: Create nests
Once the data description is complete, nests can be set up. The first step is to create the number of desired nests, in this case, two.
// Create nests
dcMakeLogitNests(&dcCt,2);
With nests made, level specific attributes and outcomes categories are specified.
// Set attributes and categories for lower nest (Nest One)
dcSetLogitNestAttributes(&dcCt,1,"TTME,GC");
dcSetLogitNestCategories(&dcCt,1,"Air,Train,Bus,Car");
// Set attributes and categories for upper nest (Nest Two)
dcSetLogitNestAttributes(&dcCt,2,"AIRHINC");
dcSetLogitNestCategories(&dcCt,2,"Fly,Ground");
Finally, lower level outcomes are assigned to proper branches:
// Make nest assignments
dcAssignLogitNests(&dcCt, 1,"Air,Train,Bus,Car", "Fly,Ground,Ground,Ground");
Step 5: Estimate nested logit model and print results
Once data and nests are set up the model is ready for estimation using the nestedLogit
procedure.
// Declare structure to hold estimation results
struct dcout dcout1;
// Perform estimation and store results in 'dcout1'
dcout1 = nestedLogit(dcCt);
// Print output report
call printDCOut(dcOut1);
A model and data description is printed to screen.
Nested Logit Results Number of Observations: 210 Degrees of Freedom: 202 1 - Air 2 - Train 3 - Bus 4 - Car Distribution Among Outcome Categories For Mode Dependent Variable Proportion Air 0.2762 Train 0.3000 Bus 0.1429 Car 0.2810Model coefficients and associated odd ratios are printed to screen:
COEFFICIENTS Coefficient Estimates ----------------------------------------------------------------------------------------------- Variables Coefficient se tstat pval Constant: Air 6.04*** 1.33 4.54 5.66e-006 Constant: Train 5.06*** 0.676 7.49 6.79e-014 Constant: Bus 4.1*** 0.629 6.51 7.33e-011 TTME -0.113*** 0.0118 -9.52 1.68e-021 GC -0.0316*** 0.00743 -4.25 2.15e-005 AIRHINC 0.0153 0.0111 1.38 0.168 Corr: Fly 0.586*** 0.113 5.18 2.18e-007 Corr: Ground 0.389** 0.158 2.46 0.0138 ----------------------------------------------------------------------------------------------- *p-val<0.1 **p-val<0.05 ***p-val<0.001 ODDS RATIO Odds Ratio ---------------------------------------------------------------------------- Variables Odds Ratio 95% Lower Bound 95% Upper Bound TTME 0.89349 0.87302 0.91444 GC 0.96891 0.95489 0.98313 AIRHINC 1.0154 0.99355 1.0378 Corr: Fly 1.7968 1.4397 2.2425 Corr: Ground 1.4754 1.0827 2.0106 ----------------------------------------------------------------------------As are the marginal effects:
MARGINAL EFFECTS Partial probability with respect to mean attributes Marginal Effects for Attribute: TTME --------------------------------------------------------------------------- Variables Air Train Bus Car Air -0.013*** 0.00364* 0.00113** 0.00384 ( 0.00303) ( 0.00214) ( 0.00036) ( 4.69) Train 0.00549** -0.0216*** 0.00409** 0.0139 ( 0.00183) ( 0.00362) ( 0.00132) ( 9.02) Bus 0.00171** 0.00409** -0.00954*** 0.00432 ( 0.000571) ( 0.00137) ( 0.00243) ( 1.67) Car 0.00579*** 0.0139*** 0.00432** -0.022 ( 0.00162) ( 0.00329) ( 0.00174) ( 5.16) --------------------------------------------------------------------------- Attribute equations in separate columns Estimate se in parentheses. *p-val<0.1 **p-val<0.05 ***p-val<0.001 Marginal Effects for Attribute: GC --------------------------------------------------------------------------- Variables Air Train Bus Car Air -0.00364** 0.00102*** 0.000318 0.00108** ( 0.00126) ( 0.000246) ( 0.000215) ( 0.00043) Train 0.00154** -0.00606*** 0.00115** 0.00389** ( 0.00078) ( 0.00146) ( 0.000397) ( 0.00123) Bus 0.000479* 0.00115** -0.00268*** 0.00121** ( 0.000275) ( 0.000372) ( 0.000725) ( 0.000415) Car 0.00162 0.00389*** 0.00121** -0.00618*** ( 0.00108) ( 0.000945) ( 0.000499) ( 0.00113) --------------------------------------------------------------------------- Attribute equations in separate columns Estimate se in parentheses. *p-val<0.1 **p-val<0.05 ***p-val<0.001 MARGINAL EFFECTS Partial probability with respect to mean attributes Marginal Effects for Attribute: AIRHINC ------------------------------------------ Variables Fly Ground Fly 0.00302 -0.00302 ( 0.00303) ( 0.00214) Ground -0.00128 0.00128 ( 0.00183) ( 0.00362) ------------------------------------------ Attribute equations in separate columns Estimate se in parentheses. *p-val<0.1 **p-val<0.05 ***p-val<0.001Finally summary and diagnostic statistics are printed to screen:
********************SUMMARY STATISTICS******************** MEASURES OF FIT: -2 Ln(Lu): 387.3123 -2 Ln(Lr): All coeffs equal zero 582.2436 -2 Ln(Lr): J-1 intercepts 567.5175 LR Chi-Square (coeffs equal zero): 194.9313 d.f. 8.0000 p-value = 0.0000 LR Chi-Square (J-1 intercepts): 180.2052 d.f. 5.0000 p-value = 0.0000 Count R2, Percent Correctly Predicted: 148.0000 Adjusted Percent Correctly Predicted: 0.5782 Madalla's pseudo R-square: 0.5760 McFadden's pseudo R-square: 0.3175 Ben-Akiva and Lerman's Adjusted R-square: 0.3175 Cragg and Uhler's pseudo R-square: 0.0976 Akaike Information Criterion: 1.9205 Bayesian Information Criterion1: 0.1275 Hannan-Quinn Information Criterion: 1.9721 OBSERVED AND PREDICTED OUTCOMES | Predicted Observed | Air Train Bus Car Total ------------------------------------------------------------------- Air | 37 3 2 16 58 Train | 2 49 1 11 63 Bus | 0 3 23 4 30 Car | 5 14 1 39 59 ------------------------------------------------------------------- Total | 44 69 27 70 210