Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using nlogit: Level 2 branches Different for Each caseid

    I am working on a project that examines factors affecting college and route choice. For this I am using nested logit.

    I have data on travel routes:
    - that students actually take to the college they are currently attending and
    - that students could have taken to the college they are attending
    - that students could have taken to the other colleges in their choice set (these are the colleges that the student ultimately did not choose)

    For the nested logit I have colleges (as the first level) and the routes within each college (as the second level). I have data at the route, college and student level. Here every student has a different route available so there is no overlap across nests in the second level branches.

    Below is the tree structure of a student's decision:


    I have 3,000 students, 56 colleges and up to 12 routes per college.

    I run the following code in Stata:

    * create list of routes for each college
    local coll_lab_list 1 2 3 4 6 7 9 11 12 13 14 17 18 19 20 21 22 24 26 28 29 30 ///
    31 34 35 36 38 39 41 42 43 46 47 48 50 51 52 53 54 55 56 57 60 62 63 64 65 66 67 68 69 ///
    70 72 75 76 77
    foreach c of local coll_lab_list{
    levelsof route_id if A1_co==`c', local(r`c') s("|") clean
    }

    * each college is a separate nest
    * level 1: college
    * level 2 (branch) : routes

    * nest routes to each college

    nlogitgen coll = route_id(1:`r1',2:`r2',3:`r3',4:`r4',6:`r6',7:`r7' ,9:`r9',11:`r11',12:`r12',13:`r13',14:`r14',17:`r1 7', ///
    18:`r18',19:`r19',20:`r20',21:`r21',22:`r22',24:`r 24',26:`r26',28:`r28',29:`r29',30:`r30', ///
    31:`r31',34:`r34',35:`r35',36:`r36',38:`r38',39:`r 39',41:`r41',42:`r42',43:`r43',46:`r46', ///
    47:`r47',48:`r48',50:`r50',51:`r51',52:`r52',53:`r 53',54:`r54',55:`r55',56:`r56',57:`r57', ///
    60:`r60',62:`r62',63:`r63',64:`r64',65:`r65',66:`r 66',67:`r67',68:`r68',69:`r69', ///
    70:`r70',72:`r72',75:`r75',76:`r76',77:`r77')
    nlogit chosen m_route_cost route_saf_mode route_time rank_1co sdist || coll:d_fem ses_ind, base(1) || route_id:, noconst case(studentid_num) notree


    I get the following error:
    exceeded the limits of tabulate when tabulating the number of categories in variable
    route_id; you probably misspecified the variable; see help limits
    r(134);

    end of do-file

    r(134);


    I want to know if there is an issue with the way I am specifying nlogit or is this is a Stata issue?

    Thanks a lot in advance for your help.

    ---
    A snapshot of the data:

    clear
    input str12 studentid float d_fem byte A1_co float(rank_1co ses_ind) double route_time float(route_saf_mode chosen sdist m_route_cost studentid_num) str5 route_id int coll
    "60_483" 1 2 9 .29160672 107.03333333333333 2.4372964 0 21.104 .115 1445 "2a" 2
    "60_365" 1 28 7 .8484412 68.48333333333333 3.947987 0 13.475 .115 1370 "28a" 20
    "52_262" 0 51 13 .6681055 36 3.84382 0 6.393 .115 959 "51a" 36
    "52_185_17_2" 1 41 3 .13093525 45 5.098433 0 17.061 3.249046 923 "41a" 29
    "39_202" 1 57 4 .422542 85.91666666666667 6.046633 0 22.271 .115 543 "57a" 42
    "52_198" 0 66 12 .9755396 64.66666666666667 5.470004 0 22.943 5.652332 928 "66a" 48
    "18_210" 0 77 10 .3285372 62.11666666666667 3.4225056 0 11.471 .115 78 "77a" 56
    "18_419" 1 60 8 .31318945 61.833333333333336 3.43428 0 13.408 .115 216 "60a" 43
    "60_324" 0 9 4 . 109.83333333333333 3.720151 0 27.598 .115 1338 "9a" 7
    "18_100" 1 52 6 .41294965 72.15 6.008688 0 21.43 .115 1 "52a" 37
    "52_Ph_15" 1 68 3 .7496403 30.316666666666666 4.028873 0 4.973 .115 1071 "68a" 50
    "52_130" 1 34 5 .035491608 49.28333333333333 4.875081 0 21.091 3.595717 901 "34a" 24
    "18_400" 1 69 1 .7985612 24.666666666666668 4.5682797 0 5.818 .115 207 "69a" 51
    "52_018" 1 64 12 .6565948 59.333333333333336 4.3181076 0 19.238 .115 838 "64a" 46
    "60_046" 1 47 9 .6498801 90.45 5.301815 0 26.06 .115 1114 "47a" 33
    "60_361" 1 13 3 .818705 22.5 5.771606 0 5.911 1.44 1367 "13a" 10
    "60_282" 1 53 8 .4422062 50.95 3.988558 0 5.892 .115 1303 "53a" 38
    "39_037" 1 72 4 . 75.96666666666667 4.7074833 0 33.621 8.937748 386 "72a" 53
    "39_366" 1 19 7 .7755396 35.266666666666666 5.137701 0 12.184 2.3686154 692 "19a" 14
    "62_390" 0 62 4 .1947242 22.2 3.826956 0 6.311 1.3500555 1834 "62a" 44
    "60_208" 1 17 12 .008153478 82.8 4.280819 0 23.752 .115 1242 "17a" 12
    "52_243" 1 29 7 .7419664 92.8 3.1439526 0 19.265 .115 946 "29a" 21
    "39_317" 1 18 4 .07721823 80.76666666666667 4.597567 0 15.494 .115 652 "18a" 13
    "52_214" 0 42 2 .8589928 49.06666666666667 5.401319 0 17.917 5.818486 936 "42a" 30
    "52_245" 1 38 15 .9007194 101.63333333333334 4.3295655 0 19.942 .115 948 "38a" 27
    "60_536" 0 54 7 .764988 71.3 4.401652 0 12.828 .115 1489 "54a" 39
    "52_130" 1 75 9 .035491608 50.416666666666664 5.800605 0 4.021 0 901 "75a" 54
    "52_280" 0 31 4 .08105516 28.95 6.245426 0 9.367 2.445563 968 "31a" 23
    "39_268" 1 76 13 .6748201 63.61666666666667 4.6695313 0 27.578 6.003877 605 "76a" 55
    "18_560" 0 36 3 . 118.4 4.868366 0 38.439 .115 307 "36a" 26
    "39_447" 1 3 3 .54196644 50.55 4.170109 0 11.475 .115 761 "3a" 3
    "39_413" 1 39 10 .6666667 35.733333333333334 4.2066207 0 12.596 2.457231 731 "39a" 28
    "60_197" 1 46 8 .8613909 100.51666666666667 4.825713 0 29.926 .115 1231 "46a" 32
    "62_332" 0 56 8 .05419664 61.666666666666664 5.251496 0 23.178 6.134215 1795 "56a" 41
    "52_359" 0 30 4 . 90.75 4.874954 0 39.738 11.817083 1000 "30a" 22
    "62_042" 0 43 9 .0618705 71.58333333333333 5.165494 0 22.996 6.056308 1557 "43a" 31
    "18_607" 0 63 8 .022541966 45 6.254658 0 3.039 0 341 "63a" 45
    "39_130" 1 11 5 .552518 55.28333333333333 6.377999 0 4.526 0 476 "11a" 8
    "52_130" 1 22 1 .035491608 58.85 4.0286407 0 12.605 .115 901 "22a" 17
    "62_300" 1 7 10 .11031175 90.23333333333333 3.621955 0 24.551 .115 1766 "7a" 6
    "52_482" 1 12 8 .11223022 95.73333333333333 2.416534 0 23.763 .115 1046 "12a" 9
    "18_345" 1 4 1 .933813 25.783333333333335 3.474081 0 15.425 3.653391 167 "4a" 4
    "52_493" 1 20 11 .3007194 94.43333333333334 4.510447 0 23.549 .115 1051 "20a" 15
    "52_106" 0 70 6 .5342926 86.15 3.899 0 16.46 .115 881 "70a" 52
    "39_344" 1 48 6 .16354915 73.43333333333334 5.798745 0 27.985 7.008739 672 "48a" 34
    "18_362" 1 26 3 .7136691 122.6 1.372678 0 62.011 .115 176 "26a" 19
    "52_Ph_66" 1 21 3 .8201439 55.86666666666667 5.854548 0 22.026 4.4239383 1085 "21a" 16
    "62_178" 1 65 2 .24028777 58.88333333333333 4.838316 0 22.518 6.103827 1668 "65a" 47
    "60_116" 1 35 3 .9443645 27.133333333333333 5.005783 0 9.097 2.1041725 1162 "35a" 25
    "52_194" 0 67 6 .8892086 49.56666666666667 5.88242 0 19.539 3.835126 926 "67a" 49
    "62_224" 1 6 10 . 111.31666666666666 4.3588796 0 37.817 .115 1707 "6a" 5
    "60_480" 1 1 9 .8091127 87.23333333333333 5.03019 0 30.085 1.08 1442 "1a" 1
    "62_192" 1 24 1 .05995204 32.483333333333334 6.325516 0 10.349 2.223323 1682 "24a" 18
    "60_581" 1 50 7 .03021583 42.983333333333334 3.746676 0 19.438 4.2468925 1509 "50a" 35
    "18_231" 0 14 1 .3870504 37.4 3.678676 0 7.107 .115 89 "14a" 11
    "62_432" 1 9 2 .54820144 23.2 5.299485 0 2.451 .115 1867 "9b" 7
    "18_320" 1 11 12 .8551559 107.71666666666667 4.49406 0 51.601 12.785723 148 "11b" 8
    "52_112" 1 75 9 . 63.78333333333333 3.910383 0 13.073 .115 886 "75b" 54
    "39_233" 1 60 1 .8844125 109.25 4.998173 0 33.683 .115 572 "60b" 43
    "60_459" 0 69 4 .3270983 48.75 4.92663 0 20.19 6.116456 1434 "69b" 51
    "52_031" 1 24 4 . 32.8 5.959293 0 9.758 2.2226954 845 "24b" 18
    "18_440" 0 22 2 . 28.75 4.381566 0 9.722 2.674412 228 "22b" 17
    "60_536" 0 47 8 .764988 66.36666666666666 3.501942 0 19.886 .115 1489 "47b" 33
    "60_078" 0 76 7 .15155876 100.31666666666666 3.3935664 0 18.573 .115 1140 "76b" 55
    "39_502" 1 28 3 .7472422 81.8 4.2046504 0 17.816 .115 798 "28b" 20
    "60_263" 1 34 7 .15107913 103.83333333333333 3.046311 0 29.95 .115 1286 "34b" 24
    "62_177" 1 50 8 . 52.68333333333333 5.643046 0 23.935 5.671828 1667 "50b" 35
    "62_046" 1 56 6 .08585132 54.3 4.890033 0 21.851 4.551508 1561 "56b" 41
    "60_104" 0 48 5 .23309353 37.2 4.182206 0 12.483 1.8847015 1153 "48b" 34
    "39_ph_20" 1 39 4 .8263789 50.05 3.5849776 0 8.222 .115 823 "39b" 28
    "52_Ph_35" 1 12 3 .9280576 120.9 5.394639 0 55.358 13.686092 1081 "12b" 9
    "39_080" 1 72 4 .9851319 60.55 4.7460027 0 23.535 7.476259 428 "72b" 53
    "62_348" 0 4 1 .041247 66.3 5.411363 0 23.893 2.8475444 1804 "4b" 4
    "60_253" 0 66 8 .23165467 56.666666666666664 4.380632 0 21.832 5.777723 1278 "66b" 48
    "39_188" 1 21 4 .2182254 32.333333333333336 5.549502 0 8.314 1.9955077 531 "21b" 16
    "62_315" 1 17 11 .2561151 59.833333333333336 5.006739 0 20.938 5.546436 1779 "17b" 12
    "18_569" 1 38 3 .752518 67.46666666666667 3.927286 0 17.225 .115 316 "38b" 27
    "60_048" 1 6 9 .7501199 100.83333333333333 3.317789 0 22.558 .115 1116 "6b" 5
    "52_244" 1 65 15 .9750599 50.35 4.219356 0 22.005 4.387016 947 "65b" 47
    "52_232" 1 3 7 .4532374 38.083333333333336 5.074451 0 13.412 3.182031 944 "3b" 3
    "60_060" 1 13 4 .4215827 35 2.6368654 0 4.969 .115 1123 "13b" 10
    "52_010" 0 70 6 .003357314 70.15 2.935914 0 19.719 .115 834 "70b" 52
    "18_337" 1 18 6 .7294964 19.183333333333334 4.5038996 0 2.355 .384 161 "18b" 13
    "52_171" 1 14 3 .6671463 67.28333333333333 3.715578 0 16.56 .115 917 "14b" 11
    "52_349" 0 52 3 .07817746 63.6 5.470286 0 19.998 4.562769 995 "52b" 37
    "39_359" 1 57 3 .764988 38.68333333333333 5.258113 0 14.31 3.138646 687 "57b" 42
    "18_365" 0 53 12 .1146283 33.6 5.466794 0 11.377 2.8053415 179 "53b" 38
    "62_278" 1 62 2 .5731415 94.5 3.694975 0 21.673 .115 1748 "62b" 44
    "62_093" 1 77 2 .13381295 30.25 4.143455 0 9.242 2.1199384 1601 "77b" 56
    "18_440" 0 63 6 . 50.983333333333334 3.529816 0 5.397 .115 228 "63b" 45
    "60_284" 0 51 11 .3832134 101.4 3.296451 0 25.647 .115 1305 "51b" 36
    "60_320" 1 2 6 .247482 129.63333333333333 3.349264 0 36.337 .115 1335 "2b" 2
    "60_205" 1 64 8 .45131895 47.483333333333334 3.2407224 0 9.563 .115 1239 "64b" 46
    "18_345" 1 26 3 .933813 43.2 3.8616035 0 10.195 .115 167 "26b" 19
    "18_337" 1 7 9 .7294964 70.68333333333334 3.5461795 0 18.502 .115 161 "7b" 6
    "60_004" 1 1 1 .3002398 76.03333333333333 5.442924 0 26.504 .115 1090 "1b" 1
    "18_302" 1 30 2 .59232616 105.7 3.494309 0 19.464 .115 133 "30b" 22
    "62_111" 1 19 6 .4417266 60.93333333333333 3.584975 0 13.774 .115 1617 "19b" 14
    "52_052" 1 29 4 .9376499 62.75 4.0533967 0 19.928 .115 856 "29b" 21
    "52_063" 1 36 6 .9098321 70.4 3.49946 0 17.254 .115 864 "36b" 26
    end

Working...
X