name nlogit "Two Level Nested Logit Model - 5 x 10 branches" ; ? ? NLOGIT ? TSP Version 4.2b ? Bronwyn H. Hall (November 1987, revised February 1993) ? ? This example shows how to estimate a complex 2-level ? nested logit model with 10 branches at the upper level ? and 5 branches at each lower node (50 in all) using ML. ? The model being constructed is for acquisition choice ? conditional on 1-1/2 digit manufacturing industry. The ? upper level is the 10 industries: ? list ilist n ? Non-manufacturing f ? Food & chemicals o ? Oil, rubber, & plastics m ? Primary metals, stone, clay, & glass d ? Drugs g ? Engines & machinery c ? Computers & scientific instruments e ? Electrical equipment & electronics a ? Autos & aircraft s ? Misc mfg NEC ; ? The lower level for each industry is 5 possible acquisition ? candidates, arranged so that the first is always the one chosen. ? A sampling technique originally suggested by McFadden has been ? used to select the other 4 candidates from the raw data. ? ? Construct the basic likelihood equation. ? Upper level denominator is sum of equations for each industry. ? frml denom eqin+eqif+eqio+eqim+eqid+eqig+eqic+eqie+eqia+eqis ; ? ? Upper level numerator is sum of equations for each industry; ? only one equation (for the chosen industry) will actually ? enter. ? frml eqj eqjn+eqjf+eqjo+eqjm+eqjd+eqjg+eqjc+eqje+eqja+eqjs ; frml nestlog logl = eqj - log(denom) ; eqsub nestlog eqj ; ? ? Now loop over industries and 5 choices to define lower level ? equations. ? dot ilist ; dot 1-5 ; ? Equation for choice in ind j of firm i (1-5). frml eq.. exp((gam1*x1..+gam2*x2..)/lam.) ; ? 2 rhs vars for match. enddot ; ? ? Define inclusive value for each industry. ? frml inc. eq.1+eq.2+eq.3+eq.4+eq.5 ; eqsub inc. eq.1-eq.5 ; ? ? Define equations for denominator of likelihood. ? frml eqi. alpha.*inc.**lam. ; eqsub denom eqi. inc. ; ? ? Define equation for numerator. Remember, firm 1 is always the ? chosen alternative and cha. is 1 for the chosen industry and 0 ? otherwise. ? frml eqj. cha.* [log(alpha.) + (gam1*x1.1 + gam2*x2.1)/lam. + (lam.-1)*log(inc.) ] ; eqsub nestlog eqj. inc. ; enddot ; eqsub nestlog denom ; print nestlog ; ? ? Here is the output of the above print command. You could ? just use this equation as a frml after you have constructed ? it via the methods in this program, but then it would be ? hard to add and subtract regressor variables. ? ? FRML NESTLOG LOGL = (((((((((CHAN* ((LOG (ALPHAN)+ (GAM1* X1N1+ GAM2* ?X2N1)/ LAMN)+ (LAMN- 1)* LOG ((((EXP ((GAM1* X1N1+ GAM2* X2N1)/ LAM1)+ EXP ?((GAM1* X1N2+ GAM2* X2N2)/ LAM2))+ EXP ((GAM1* X1N3+ GAM2* X2N3)/ LAM3))+ EXP ?((GAM1* X1N4+ GAM2* X2N4)/ LAM4))+ EXP ((GAM1* X1N5+ GAM2* X2N5)/ LAM5)))+ ?CHAF* ((LOG (ALPHAF)+ (GAM1* X1F1+ GAM2* X2F1)/ LAMF)+ (LAMF- 1)* LOG ((((EXP ?((GAM1* X1F1+ GAM2* X2F1)/ LAM1)+ EXP ((GAM1* X1F2+ GAM2* X2F2)/ LAM2))+ EXP ?((GAM1* X1F3+ GAM2* X2F3)/ LAM3))+ EXP ((GAM1* X1F4+ GAM2* X2F4)/ LAM4))+ EXP ?((GAM1* X1F5+ GAM2* X2F5)/ LAM5))))+ CHAO* ((LOG (ALPHAO)+ (GAM1* X1O1+ GAM2* ?X2O1)/ LAMO)+ (LAMO- 1)* LOG ((((EXP ((GAM1* X1O1+ GAM2* X2O1)/ LAM1)+ EXP ?((GAM1* X1O2+ GAM2* X2O2)/ LAM2))+ EXP ((GAM1* X1O3+ GAM2* X2O3)/ LAM3))+ EXP ?((GAM1* X1O4+ GAM2* X2O4)/ LAM4))+ EXP ((GAM1* X1O5+ GAM2* X2O5)/ LAM5))))+ ?CHAM* ((LOG (ALPHAM)+ (GAM1* X1M1+ GAM2* X2M1)/ LAMM)+ (LAMM- 1)* LOG ((((EXP ?((GAM1* X1M1+ GAM2* X2M1)/ LAM1)+ EXP ((GAM1* X1M2+ GAM2* X2M2)/ LAM2))+ EXP ?((GAM1* X1M3+ GAM2* X2M3)/ LAM3))+ EXP ((GAM1* X1M4+ GAM2* X2M4)/ LAM4))+ EXP ?((GAM1* X1M5+ GAM2* X2M5)/ LAM5))))+ CHAD* ((LOG (ALPHAD)+ (GAM1* X1D1+ GAM2* ?X2D1)/ LAMD)+ (LAMD- 1)* LOG ((((EXP ((GAM1* X1D1+ GAM2* X2D1)/ LAM1)+ EXP ?((GAM1* X1D2+ GAM2* X2D2)/ LAM2))+ EXP ((GAM1* X1D3+ GAM2* X2D3)/ LAM3))+ EXP ?((GAM1* X1D4+ GAM2* X2D4)/ LAM4))+ EXP ((GAM1* X1D5+ GAM2* X2D5)/ LAM5))))+ ?CHAG* ((LOG (ALPHAG)+ (GAM1* X1G1+ GAM2* X2G1)/ LAMG)+ (LAMG- 1)* LOG ((((EXP ?((GAM1* X1G1+ GAM2* X2G1)/ LAM1)+ EXP ((GAM1* X1G2+ GAM2* X2G2)/ LAM2))+ EXP ?((GAM1* X1G3+ GAM2* X2G3)/ LAM3))+ EXP ((GAM1* X1G4+ GAM2* X2G4)/ LAM4))+ EXP ?((GAM1* X1G5+ GAM2* X2G5)/ LAM5))))+ CHAC* ((LOG (ALPHAC)+ (GAM1* X1C1+ GAM2* ?X2C1)/ LAMC)+ (LAMC- 1)* LOG ((((EXP ((GAM1* X1C1+ GAM2* X2C1)/ LAM1)+ EXP ?((GAM1* X1C2+ GAM2* X2C2)/ LAM2))+ EXP ((GAM1* X1C3+ GAM2* X2C3)/ LAM3))+ EXP ?((GAM1* X1C4+ GAM2* X2C4)/ LAM4))+ EXP ((GAM1* X1C5+ GAM2* X2C5)/ LAM5))))+ ?CHAE* ((LOG (ALPHAE)+ (GAM1* X1E1+ GAM2* X2E1)/ LAME)+ (LAME- 1)* LOG ((((EXP ?((GAM1* X1E1+ GAM2* X2E1)/ LAM1)+ EXP ((GAM1* X1E2+ GAM2* X2E2)/ LAM2))+ EXP ?((GAM1* X1E3+ GAM2* X2E3)/ LAM3))+ EXP ((GAM1* X1E4+ GAM2* X2E4)/ LAM4))+ EXP ?((GAM1* X1E5+ GAM2* X2E5)/ LAM5))))+ CHAA* ((LOG (ALPHAA)+ (GAM1* X1A1+ GAM2* ?X2A1)/ LAMA)+ (LAMA- 1)* LOG ((((EXP ((GAM1* X1A1+ GAM2* X2A1)/ LAM1)+ EXP ?((GAM1* X1A2+ GAM2* X2A2)/ LAM2))+ EXP ((GAM1* X1A3+ GAM2* X2A3)/ LAM3))+ EXP ?((GAM1* X1A4+ GAM2* X2A4)/ LAM4))+ EXP ((GAM1* X1A5+ GAM2* X2A5)/ LAM5))))+ ?CHAS* ((LOG (ALPHAS)+ (GAM1* X1S1+ GAM2* X2S1)/ LAMS)+ (LAMS- 1)* LOG ((((EXP ?((GAM1* X1S1+ GAM2* X2S1)/ LAM1)+ EXP ((GAM1* X1S2+ GAM2* X2S2)/ LAM2))+ EXP ?((GAM1* X1S3+ GAM2* X2S3)/ LAM3))+ EXP ((GAM1* X1S4+ GAM2* X2S4)/ LAM4))+ EXP ?((GAM1* X1S5+ GAM2* X2S5)/ LAM5))))- LOG (((((((((ALPHAN* ((((EXP ((GAM1* ?X1N1+ GAM2* X2N1)/ LAM1)+ EXP ((GAM1* X1N2+ GAM2* X2N2)/ LAM2))+ EXP ((GAM1* ?X1N3+ GAM2* X2N3)/ LAM3))+ EXP ((GAM1* X1N4+ GAM2* X2N4)/ LAM4))+ EXP ((GAM1* ?X1N5+ GAM2* X2N5)/ LAM5))** LAMN+ ALPHAF* ((((EXP ((GAM1* X1F1+ GAM2* X2F1)/ ?LAM1)+ EXP ((GAM1* X1F2+ GAM2* X2F2)/ LAM2))+ EXP ((GAM1* X1F3+ GAM2* X2F3)/ ?LAM3))+ EXP ((GAM1* X1F4+ GAM2* X2F4)/ LAM4))+ EXP ((GAM1* X1F5+ GAM2* X2F5)/ ?LAM5))** LAMF)+ ALPHAO* ((((EXP ((GAM1* X1O1+ GAM2* X2O1)/ LAM1)+ EXP ((GAM1* ?X1O2+ GAM2* X2O2)/ LAM2))+ EXP ((GAM1* X1O3+ GAM2* X2O3)/ LAM3))+ EXP ((GAM1* ?X1O4+ GAM2* X2O4)/ LAM4))+ EXP ((GAM1* X1O5+ GAM2* X2O5)/ LAM5))** LAMO)+ ?ALPHAM* ((((EXP ((GAM1* X1M1+ GAM2* X2M1)/ LAM1)+ EXP ((GAM1* X1M2+ GAM2* ?X2M2)/ LAM2))+ EXP ((GAM1* X1M3+ GAM2* X2M3)/ LAM3))+ EXP ((GAM1* X1M4+ GAM2* ?X2M4)/ LAM4))+ EXP ((GAM1* X1M5+ GAM2* X2M5)/ LAM5))** LAMM)+ ALPHAD* ((((EXP ?((GAM1* X1D1+ GAM2* X2D1)/ LAM1)+ EXP ((GAM1* X1D2+ GAM2* X2D2)/ LAM2))+ EXP ?((GAM1* X1D3+ GAM2* X2D3)/ LAM3))+ EXP ((GAM1* X1D4+ GAM2* X2D4)/ LAM4))+ EXP ?((GAM1* X1D5+ GAM2* X2D5)/ LAM5))** LAMD)+ ALPHAG* ((((EXP ((GAM1* X1G1+ ?GAM2* X2G1)/ LAM1)+ EXP ((GAM1* X1G2+ GAM2* X2G2)/ LAM2))+ EXP ((GAM1* X1G3+ ?GAM2* X2G3)/ LAM3))+ EXP ((GAM1* X1G4+ GAM2* X2G4)/ LAM4))+ EXP ((GAM1* X1G5+ ?GAM2* X2G5)/ LAM5))** LAMG)+ ALPHAC* ((((EXP ((GAM1* X1C1+ GAM2* X2C1)/ ?LAM1)+ EXP ((GAM1* X1C2+ GAM2* X2C2)/ LAM2))+ EXP ((GAM1* X1C3+ GAM2* X2C3)/ ?LAM3))+ EXP ((GAM1* X1C4+ GAM2* X2C4)/ LAM4))+ EXP ((GAM1* X1C5+ GAM2* X2C5)/ ?LAM5))** LAMC)+ ALPHAE* ((((EXP ((GAM1* X1E1+ GAM2* X2E1)/ LAM1)+ EXP ((GAM1* ?X1E2+ GAM2* X2E2)/ LAM2))+ EXP ((GAM1* X1E3+ GAM2* X2E3)/ LAM3))+ EXP ((GAM1* ?X1E4+ GAM2* X2E4)/ LAM4))+ EXP ((GAM1* X1E5+ GAM2* X2E5)/ LAM5))** LAME)+ ?ALPHAA* ((((EXP ((GAM1* X1A1+ GAM2* X2A1)/ LAM1)+ EXP ((GAM1* X1A2+ GAM2* ?X2A2)/ LAM2))+ EXP ((GAM1* X1A3+ GAM2* X2A3)/ LAM3))+ EXP ((GAM1* X1A4+ GAM2* ?X2A4)/ LAM4))+ EXP ((GAM1* X1A5+ GAM2* X2A5)/ LAM5))** LAMA)+ ALPHAS* ((((EXP ?((GAM1* X1S1+ GAM2* X2S1)/ LAM1)+ EXP ((GAM1* X1S2+ GAM2* X2S2)/ LAM2))+ EXP ?((GAM1* X1S3+ GAM2* X2S3)/ LAM3))+ EXP ((GAM1* X1S4+ GAM2* X2S4)/ LAM4))+ EXP ?((GAM1* X1S5+ GAM2* X2S5)/ LAM5))** LAMS) ? ? ? Now transform the data to be suitable for this estimation ? strategy. There are N observations, each of which describes an ? actual acquisition. The observations consist of characteristics ? of the acquiring firms and of 50 (=5*10) potential acquirees, one ? of which is the actual acquiree. ? The rhs variables x1.. and x2.. will be functions of both the ? acquiring and acquired firms in general; they are constructed in ? the following loop to be the distance between the acquiree x and ? that of the acquirer (ax.) : ? smpl 1 N ; dot ilist ; dot 1-5 ; x1.. = abs(x1..-ax1) ; x2.. = abs(x2..-ax2) ; enddot ; enddot ; ? ? Distance for actual acquisition (s for seller): dx1 = abs(ax1-sx1) ; dx2 = abs(ax2-sx2) ; ? ? Now make the first alternative the chosen one in all cases ? and define the cha. variables as industry dummies. The industry ? code ind is a number between 1 and 10. ? set index=1 ; dot ilist ; smpl 1 N ; cha. = (ind=index) ; select cha. ; x1.1 = dx1 ; x2.1 = dx2 ; ? Chosen alternative in chosen industry. set index = index+1 ; enddot ; smpl 1 N ; ? ? Define parameter lists. The lambdas (lam.) are the inclusive ? value coefficients for the different industries (the top level), ? and the alphas (alpha.) are free weights which adjust for ? different sampling probabilities on the different industries. ? Gam1 and gam2 are the structural parameters of interest: they ? are coefficients on characteristics of the acquired firm or of ? the match between acquirer and acquiree. ? list lamlist lamn lamf lamo lamm lamd lamg lamc lame lama lams ; list alphlist alphan alphaf alphao alpham alphad alphag alphac alphae alphaa alphas ; param gam1 1 gam2 1 ; dot ilist ; param alpha. 1 lam. 1 ; enddot ; ml nestlog ; stop ; end ;