?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& PART 1 ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ? ? 1. Test for significance of squared term ? CLOGIT ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,Asc4 $ CALC ; L0 = logl $ CLOGIT ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,Pricesq,Asc4 $ CALC ; L1 = logl $ CALC ; list ; chisq = 2*(l1 - l0) $ ? ? 2. Test for homogeneity. Are men the same as women ? ? SAMPLE ; All $ CLOGIT ; For[Male = 0] ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,Asc4 $ CALC ; LoglF = LogL $ MATRIX ; db = b ; dv = varb $ CLOGIT ; For[ Male = 1] ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,Asc4 $ CALC ; LoglM = LogL $ MATRIX ; db = db - b ; dv = dv + varb $ CLOGIT ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,Asc4 $ CALC ; LoglMF = LogL $ ? Likelihood Ratio Test CALC ; List ; Chisq = 2*(LoglM + LogLF - LOGLMF) ; Ctb(.95,8) $ ? Wald test MATRIX ; List ; Wald = db'db $ ? A convenient way to compute all three models. CLOGIT ; For[Male = *,1,0] ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,Asc4 $ ? ? 3. Examine the marginal effect of price on brand choice ? SAMPLE ; All $ CLOGIT ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,Asc4 ; Effects : Price (*) $ ? ? 4. What would happen to the market shares of the three brands ? If the price of Brand 1 of shoes rose by 50%. What would ? happen to the market shares if the prices of all three ? brands rose by 50%? ? SAMPLE ; All $ CLOGIT ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,Asc4 ; Effects : Price (*) $ CLOGIT ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,Asc4 ; Simulation = * ; Scenario: Price (Brand1) = [*] 1.5 $ CLOGIT ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,Asc4 ; Simulation = * ; Scenario: Price (Brand1,Brand2,Brand3) = [*] 1.5 $ ? ? 5. Testing for IIA ? SAMPLE ; All $ CLOGIT ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,Asc4 $ CLOGIT ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,Asc4 ; IAS = Brand3 $ ? ? 6. Do men pay different attention to fashion than women? ? Is the difference statistically significant? ? Create ; MaleFash = Male*Fash $ CLOGIT ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,Asc4,MaleFash $ CLOGIT ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,Asc4,MaleFash ; Simulation = * ; Scenario: MaleFash(*) = [*] 0 $ ? ? 7. Building heterogeneity into the model ? NLOGIT (none) ; Lhs = Choice ; Choices = Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,ASC4 ; Effects: Price(Brand1,Brand2,Brand3) $ NLOGIT (het) ; Lhs = Choice ; Choices = Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,ASC4 ; Het ; Effects: Price(Brand1,Brand2,Brand3) $ NLOGIT (variance, het) ; Lhs = Choice ; Choices = Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,ASC4 ; Het ; Hfn = Male,age25,age39 ; Effects: Price(Brand1,Brand2,Brand3) $ ? ? 8. Testing for homoscedasticity with a Wald test ? NLOGIT (het) ; Lhs = Choice ; Choices = Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,ASC4 ; Het ; Par $ MATRIX ; c = b(5:7) ; vc = Varb(5:7,5:7) ; List ; WaldStat = c'c $ ? ? 9. Testing for heterogeneity in the heteroscedasticity ? NLOGIT (het) ; Lhs = Choice ; Choices = Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,ASC4 ; Het $ CALC ; LogLR = LogL $ NLOGIT (variance, het) ; Lhs = Choice ; Choices = Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,ASC4 ; Het ; Hfn = Male,age25,age39 $ CALC ; LoglU = LogL $ CALC ; List ; LRTest = 2*(LogLU - LogLR) ; Ctb(.95,3) $ ?************************************************************************ ?************************************************************************ ?************************************************************************ ? ? These exercises are based on the travel model data, clogit.lpj ? ?************************************************************************ ?************************************************************************ ?************************************************************************ ? ? 1. Basic nested logit ? NLOGIT ; Lhs = Mode ; Choices=Air,Train,Bus,Car ; Rhs = One,GC,TTME,INVT,INVC ; Tree = Private(Air,Car),Public(Train,Bus) ; Show Tree $ CALC ; LOGLU = LOGL $ ? ? 2. Different normalization ? NLOGIT ; Lhs = Mode ; Choices=Air,Train,Bus,Car ; Rhs = One,GC,TTME,INVT,INVC ; Tree = Private(Air,Car),Public(Train,Bus) ; RU2 ; CrossTab$ ? ? 3. Constrain IV parameters to produce MNL model ? NLOGIT ; Lhs = Mode ; Choices=Air,Train,Bus,Car ; Rhs = One,GC,TTME,INVT,INVC ; Tree = Private(Air,Car),Public(Train,Bus) ; IVSET:(Private,Public)=[1] $ CALC ; LOGLR = LOGL $ CALC ; List ; LRTEST = 2*(LOGLU - LOGLR) $ ? ? 4. Degenerate branch. Two normalizations ? NLOGIT ; Lhs = Mode ; Choices=Air,Train,Bus,Car ; Rhs = One,GC,TTME,INVT,INVC ; Tree = Fly(Air),Ground(Car,Train,Bus) $ NLOGIT ; Lhs = Mode ; Choices=Air,Train,Bus,Car ; Rhs = One,GC,TTME,INVT,INVC ; Tree = Fly(Air),Ground(Car,Train,Bus) ; RU2 $ ? ? 5. Use nested logit to reveal scaling. ? NLOGIT ; Lhs = Mode ; Choices=Air,Train,Bus,Car ; Rhs = One,GC,TTME,INVT,INVC ; Tree = Fly(Air),Drive(Car),Rail(Train),Ride(Bus) ; IVSET: (Ride) = [1] ; Par $ NLOGIT ; Lhs = Mode ; Choices=Air,Train,Bus,Car ; Rhs = One,GC,TTME,INVT,INVC ; HET ; SDV = SA,ST,1.0,SC $ ? ? 6. A Generalized Nested Logit Model ? NLOGIT ; Lhs = Mode ; Choices=Air,Train,Bus,Car ; Rhs = One,GC,TTME,INVT,INVC ; Tree = Fast(Air,Car,Train),Public(Train,Bus) ; GNL $ ? ? 7. Homoscedastic vs. Heteroscedastic Extreme Value ? NLOGIT ; Lhs = Mode ; Choices = Air,Train,Bus,Car ; Rhs = TTME,INVC,INVT,GC,One ; Effects: INVT(*) $ CALC ; LR = LogL $ NLOGIT ; Lhs = Mode ; Choices = Air,Train,Bus,Car ; Rhs = TTME,INVC,INVT,GC,One ; Het ; Effects: INVT(*) $ CALC ; LU = LogL $ CALC ; List ; LRTEST = 2*(LU - LR); Ctb(.95,3) $ ? ? 8.Heterogeneous. Does Income affect the means or the variances? ? SAMPLE ; All $ NLOGIT ; Lhs = Mode ; Choices = Air,Train,Bus,Car ; Rhs = TTME,INVC,INVT,GC; Rh2=One,Hinc $ CREATE ; LOGLMean = Logl_Obs $ NLOGIT ; Lhs = Mode ; Choices = Air,Train,Bus,Car ; Rhs = TTME,INVC,INVT,GC,one ; Het ; Hfn = HINC $ CREATE ; LoglVar = Logl_Obs $ CREATE ; V = LoglMean - LogLVar $ REJECT ; CASC = 0 $ CALC ; List ; Vuong = sqr(n) * xbr(v) / sdv(v) $ ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& PART 2 ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ? Using the clogit.lpj data ? ? 1. Multinomial Probit Model ? NLOGIT ; Lhs = Mode ; output=ic ; Choices = Air,Train,Bus,Car ; Rhs = TTME,INVC,INVT,GC; Rh2=One,Hinc ; Effects:GC(*) $ NLOGIT ; Lhs = Mode ; MNP ; PTS = 10 ; Maxit = 10 ; Halton ; Choices = Air,Train,Bus,Car ; Rhs = TTME,INVC,INVT,GC; Rh2=One,Hinc ; Effects:GC(*) $ ? ? Using Brand Choices Data, brandchoicesSP.lpj ? ?(1) Basic 3 class model ? Nlogit ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,ASC4 ; LCM ; Pds = 8 ; Pts = 3 $ ? ? (2) 3 class model. Class probabilities depend on covariates ? Nlogit ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,ASC4 ; LCM=Male,Age25,Age39 ; Pds = 8 ; Pts = 3 $ ? ? (3) Overspecified model. 4 class model. The true model ? underlying the data has three classes Nlogit ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,ASC4 ; LCM ; Pds = 8 ; Pts = 4 $ ? ? (4) Random parameters model ? Nlogit ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,ASC4 ; RPL ; Fcn= Fash(n),Price(n) ; Pds = 8 ; Pts = 25 $ ? ? (5) Correlated parameters ? Nlogit ; Lhs = Choice ; Choices=Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,ASC4 ; RPL ; Fcn= Fash(n),Price(n) ; Correlated ; Pds = 8 ; Pts = 25 $ ? ? (6). An Error Components Logit model ? ECLOGIT ; Lhs = Choice ; Choices = Brand1,Brand2,Brand3,None ; Rhs = Fash,Qual,Price,ASC4 ; Pts = 10 ; Pds = 8 ; ECM = (Brand1,Brand2,Brand3),(none) $ ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& PART 3 ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ?&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& /* ? ? Data for this application are in SPRP.LPJ ? ? Application of revealed/stated preference data ? Uses nested logit to handle scaling. ? Sample is also choice based, as shown by weights. ? ? Documented in several Hensher papers from ITS in Sydney. ? ? Choice variable is CHOSEN ? Number of choices in choice set is CSET ? Specific choices from master set given by ALTIJ ? FCOST = fuel cost ? AUTOTIME = time spent commuting by car. ? Numerous other variables in the data set. ? */ NLOGIT ;lhs=chosen,cset,altij ;choices=RPDA,RPRS,RPBS,RPTN,SPDA,SPRS,SPBS,SPTN,SPLR,SPBW /.592,.208,.089,.111, 1.0, 1.0, 1.0, 1.0,1.0,1.0 ;tree=Commute [ rp (RPDA,RPRS,RPBS,RPTN), spda(SPDA), sprs(SPRS),spbs(SPBS),sptn(SPTN), splr(SPLR),spbw(SPBW)] ;ivset: (rp)=[1.0] ;ru1 ;maxit=150 ;model: U(RPDA) = rdasc + invc*fcost+tmrs*autotime / U(RPRS) = rrsasc + invc*fcost+tmrs*autotime / U(RPBS) = rbsasc + invc*mptrfare+mtpt*mptrtime/ U(RPTN) = cstrs*mptrfare+mtpt*mptrtime/ U(SPDA) = sdasc + invc*fueld + tmrs*time+cavda*carav / U(SPRS) = srsasc + invc*fueld + tmrs*time/? cavrs*carav/ U(SPBS) = invc*fared + mtpt*time +acegt*spacegtm/ U(SPTN) = stnasc + invc*fared + mtpt*time+acegt*spacegtm/ U(SPLR) = slrasc + invc*fared + mtpt*time+acegt*spacegtm/ U(SPBW) = sbwasc + invc*fared + mtpt*time+acegt*spacegtm$