楼主: 蓝莲花开12
11797 27

[编程问题求助] stata mixlogit函数一直报错matrix __000002 not found [推广有奖]

11
蓝莲花开12 发表于 2016-10-12 09:54:57
夏目贵志 发表于 2016-10-11 22:29
运行这个命令之前运行一下set trace on。然后把结果贴出来看看呢?
       ---------------------------------------------------------------------------------------------------------- begin _get_diopts ---
        - version 11
        - syntax namelist(max=2) [, *]
        - gettoken name1 namelist : namelist
        - gettoken name2 namelist : namelist
        - GetDiopts diopts options, `options'
        = GetDiopts diopts options,
          ---------------------------------------------------------------------------------------------- begin _get_diopts.GetDiopts ---
          - local DIOPTS Level(cilevel) vsquish NOALLBASElevels ALLBASElevels NOBASElevels BASElevels noCNSReport FULLCNSReport NOEMPTYc
> ells EMPTYcells NOOMITted OMITted NOLSTRETCH LSTRETCH COEFLegend SELEGEND cformat(string) sformat(string) pformat(string) CODING VERSU
> S COMPARE FVWRAP(passthru) FVWRAPON(string) NOFVLABel FVLABel NOCI NOPValues
          - syntax namelist(max=2) [, `DIOPTS' *]
          = syntax namelist(max=2) [, Level(cilevel) vsquish NOALLBASElevels ALLBASElevels NOBASElevels BASElevels noCNSReport FULLCNSRe
> port NOEMPTYcells EMPTYcells NOOMITted OMITted NOLSTRETCH LSTRETCH COEFLegend SELEGEND cformat(string) sformat(string) pformat(string)
>  CODING VERSUS COMPARE FVWRAP(passthru) FVWRAPON(string) NOFVLABel FVLABel NOCI NOPValues *]
          - opts_exclusive "`allbaselevels' `noallbaselevels'"
          = opts_exclusive " "
            --------------------------------------------------------------------------------------------------- begin opts_exclusive ---
            - version 8.2
            - args opts optname errcode
            - local opts `opts'
            = local opts  
            - local n 0
            - while `"`opts'"' != "" {
            = while `""' != "" {
              local ++n
              gettoken item`n' opts : opts, bind
              }
            - if `n' < 2 {
            = if 0 < 2 {
            - exit
            ----------------------------------------------------------------------------------------------------- end opts_exclusive ---
          - opts_exclusive "`allbaselevels' `nobaselevels'"
          = opts_exclusive " "
            --------------------------------------------------------------------------------------------------- begin opts_exclusive ---
            - version 8.2
            - args opts optname errcode
            - local opts `opts'
            = local opts  
            - local n 0
            - while `"`opts'"' != "" {
            = while `""' != "" {
              local ++n
              gettoken item`n' opts : opts, bind
              }
            - if `n' < 2 {
            = if 0 < 2 {
            - exit
            ----------------------------------------------------------------------------------------------------- end opts_exclusive ---
          - opts_exclusive "`baselevels' `nobaselevels'"
          = opts_exclusive " "
            --------------------------------------------------------------------------------------------------- begin opts_exclusive ---
            - version 8.2
            - args opts optname errcode
            - local opts `opts'
            = local opts  
            - local n 0
            - while `"`opts'"' != "" {
            = while `""' != "" {
              local ++n
              gettoken item`n' opts : opts, bind
              }
            - if `n' < 2 {
            = if 0 < 2 {
            - exit
            ----------------------------------------------------------------------------------------------------- end opts_exclusive ---
          - opts_exclusive "`emptycells' `noemptycells'"
          = opts_exclusive " "
            --------------------------------------------------------------------------------------------------- begin opts_exclusive ---
            - version 8.2
            - args opts optname errcode
            - local opts `opts'
            = local opts  
            - local n 0
            - while `"`opts'"' != "" {
            = while `""' != "" {
              local ++n
              gettoken item`n' opts : opts, bind
              }
            - if `n' < 2 {
            = if 0 < 2 {
            - exit
            ----------------------------------------------------------------------------------------------------- end opts_exclusive ---
          - opts_exclusive "`fvlabel' `nofvlabel'"
          = opts_exclusive " "
            --------------------------------------------------------------------------------------------------- begin opts_exclusive ---
            - version 8.2
            - args opts optname errcode
            - local opts `opts'
            = local opts  
            - local n 0
            - while `"`opts'"' != "" {
            = while `""' != "" {
              local ++n
              gettoken item`n' opts : opts, bind
              }
            - if `n' < 2 {
            = if 0 < 2 {
            - exit
            ----------------------------------------------------------------------------------------------------- end opts_exclusive ---
          - opts_exclusive "`omitted' `noomitted'"
          = opts_exclusive " "
            --------------------------------------------------------------------------------------------------- begin opts_exclusive ---
            - version 8.2
            - args opts optname errcode
            - local opts `opts'
            = local opts  
            - local n 0
            - while `"`opts'"' != "" {
            = while `""' != "" {
              local ++n
              gettoken item`n' opts : opts, bind
              }
            - if `n' < 2 {
            = if 0 < 2 {
            - exit
            ----------------------------------------------------------------------------------------------------- end opts_exclusive ---
          - opts_exclusive "`lstretch' `nolstretch'"
          = opts_exclusive " "
            --------------------------------------------------------------------------------------------------- begin opts_exclusive ---
            - version 8.2
            - args opts optname errcode
            - local opts `opts'
            = local opts  
            - local n 0
            - while `"`opts'"' != "" {
            = while `""' != "" {
              local ++n
              gettoken item`n' opts : opts, bind
              }
            - if `n' < 2 {
            = if 0 < 2 {
            - exit
            ----------------------------------------------------------------------------------------------------- end opts_exclusive ---
          - opts_exclusive "`cnsreport' `fullcnsreport'"
          = opts_exclusive " "
            --------------------------------------------------------------------------------------------------- begin opts_exclusive ---
            - version 8.2
            - args opts optname errcode
            - local opts `opts'
            = local opts  
            - local n 0
            - while `"`opts'"' != "" {
            = while `""' != "" {
              local ++n
              gettoken item`n' opts : opts, bind
              }
            - if `n' < 2 {
            = if 0 < 2 {
            - exit
            ----------------------------------------------------------------------------------------------------- end opts_exclusive ---
          - opts_exclusive "`coeflegend' `selegend'"
          = opts_exclusive " "
            --------------------------------------------------------------------------------------------------- begin opts_exclusive ---
            - version 8.2
            - args opts optname errcode
            - local opts `opts'
            = local opts  
            - local n 0
            - while `"`opts'"' != "" {
            = while `""' != "" {
              local ++n
              gettoken item`n' opts : opts, bind
              }
            - if `n' < 2 {
            = if 0 < 2 {
            - exit
            ----------------------------------------------------------------------------------------------------- end opts_exclusive ---
          - local K : list sizeof namelist
          - gettoken c_diopts c_opts : namelist
          - opts_exclusive "`coding' `compare'"
          = opts_exclusive " "
            --------------------------------------------------------------------------------------------------- begin opts_exclusive ---

12
蓝莲花开12 发表于 2016-10-12 10:00:28
夏目贵志 发表于 2016-10-11 22:29
运行这个命令之前运行一下set trace on。然后把结果贴出来看看呢?
- sort `id' `group'
  = sort  obs
  - local kfix: word count `fixed'
  = local kfix: word count  delta
  - local krnd: word count `rand'
  = local krnd: word count distobus area
  - mata: mixl_X = st_data(., tokens(st_local("rhs")))
  - mata: mixl_Y = st_data(., st_local("lhs"))
  - mata: mixl_CSID = st_data(., st_local("csid"))
  - mata: mixl_nrep = strtoreal(st_local("nrep"))
  - mata: mixl_kfix = strtoreal(st_local("kfix"))
  - mata: mixl_krnd = strtoreal(st_local("krnd"))
  - mata: mixl_krln = strtoreal(st_local("ln"))
  - mata: mixl_burn = strtoreal(st_local("burn"))
  - mata: mixl_robust = 0
  - mata: mixl_cluster = 0
  - if ("`weight'" != "") {
  = if ("" != "") {
    capture confirm number `exp'
    if _rc != 0 {
    mata: mixl_WGT = st_data(., st_local("exp"), st_local("last"))
    }
    else {
    mata: mixl_WGT = J(mixl_np,1,strtoreal(st_local("exp")))
    }
    mata: mixl_wgttyp = st_local("weight")
    }
  - else {
  - mata: mixl_WGT = J(mixl_np,1,1)
  - mata: mixl_wgttyp = ""
  - }
  - if ("`cluster'" != "") {
  = if ("" != "") {
    mata: mixl_CLUST = st_data(., st_local("cluster"), st_local("last"))
    qui duplicates report `cluster'
    mata: mixl_nclust = st_numscalar("r(unique_value)")
    local nclust = r(unique_value)
    }
  - restore
  - local mean (Mean: `rhs', noconst)
  = local mean (Mean: delta distobus area, noconst)
  - if ("`corr'" == "") {
  = if ("" == "") {
  - mata: mixl_corr = 0
  - local sd (SD: `rand', noconst)
  = local sd (SD: distobus area, noconst)
  - local max `mean' `sd'
  = local max (Mean: delta distobus area, noconst) (SD: distobus area, noconst)
  - }
  - else {
    mata: mixl_corr = 1
    local cho = `krnd'*(`krnd'+1)/2
    mata: mixl_ncho = strtoreal(st_local("cho"))
    local max `mean'
    forvalues i = 1(1)`krnd' {
    forvalues j = `i'(1)`krnd' {
    local max `max' /l`j'`i'
    }
    }
    }
  - if ("`from'" == "") {
  = if ("" == "") {
  - tempname b from
  - matrix `b' = e(b)
  = matrix __000002 = e(b)
  - if ((`kfix'+`krnd')>`ln') matrix `from' = `b'[1,1..(`kfix'+`krnd'-`ln')]
  = if ((1+2)>0) matrix __000003 = __000002[1,1..(1+2-0)]
matrix __000002 not found
    forvalues i = 1(1)`ln' {
    if (`b'[1,(`kfix'+`krnd'-`ln'+`i')] <= 0) {
    di in red "Variables specified to have log-normally distributed coefficients should have positive"
    di in red "coefficients in the conditional logit model. Try multiplying the variable by -1."
    exit 498
    }
    if ((`kfix'+`krnd')==`ln' & `i'==1) matrix `from' = ln(`b'[1,1])
    else matrix `from' = `from', ln(`b'[1,(`kfix'+`krnd'-`ln'+`i')])
    }
    if ("`corr'" == "") matrix `from' = `from', J(1,`krnd',0.1)
    else matrix `from' = `from', J(1,`cho',0.1)
    local copy , copy
    }
  ------------------------------------------------------------------------------------------------------------ end mixlogit.Estimate ---
----------------------------------------------------------------------------------------------------------------------- end mixlogit ---
r(111);

抱歉code太长一次贴不下,这个是最后出现错误的地方

13
蓝莲花开12 发表于 2016-10-12 10:02:18
夏目贵志 发表于 2016-10-11 22:29
运行这个命令之前运行一下set trace on。然后把结果贴出来看看呢?
- sort `id' `group'
  = sort  obs
  - local kfix: word count `fixed'
  = local kfix: word count  delta
  - local krnd: word count `rand'
  = local krnd: word count distobus area
  - mata: mixl_X = st_data(., tokens(st_local("rhs")))
  - mata: mixl_Y = st_data(., st_local("lhs"))
  - mata: mixl_CSID = st_data(., st_local("csid"))
  - mata: mixl_nrep = strtoreal(st_local("nrep"))
  - mata: mixl_kfix = strtoreal(st_local("kfix"))
  - mata: mixl_krnd = strtoreal(st_local("krnd"))
  - mata: mixl_krln = strtoreal(st_local("ln"))
  - mata: mixl_burn = strtoreal(st_local("burn"))
  - mata: mixl_robust = 0
  - mata: mixl_cluster = 0
  - if ("`weight'" != "") {
  = if ("" != "") {
    capture confirm number `exp'
    if _rc != 0 {
    mata: mixl_WGT = st_data(., st_local("exp"), st_local("last"))
    }
    else {
    mata: mixl_WGT = J(mixl_np,1,strtoreal(st_local("exp")))
    }
    mata: mixl_wgttyp = st_local("weight")
    }
  - else {
  - mata: mixl_WGT = J(mixl_np,1,1)
  - mata: mixl_wgttyp = ""
  - }
  - if ("`cluster'" != "") {
  = if ("" != "") {
    mata: mixl_CLUST = st_data(., st_local("cluster"), st_local("last"))
    qui duplicates report `cluster'
    mata: mixl_nclust = st_numscalar("r(unique_value)")
    local nclust = r(unique_value)
    }
  - restore
  - local mean (Mean: `rhs', noconst)
  = local mean (Mean: delta distobus area, noconst)
  - if ("`corr'" == "") {
  = if ("" == "") {
  - mata: mixl_corr = 0
  - local sd (SD: `rand', noconst)
  = local sd (SD: distobus area, noconst)
  - local max `mean' `sd'
  = local max (Mean: delta distobus area, noconst) (SD: distobus area, noconst)
  - }
  - else {
    mata: mixl_corr = 1
    local cho = `krnd'*(`krnd'+1)/2
    mata: mixl_ncho = strtoreal(st_local("cho"))
    local max `mean'
    forvalues i = 1(1)`krnd' {
    forvalues j = `i'(1)`krnd' {
    local max `max' /l`j'`i'
    }
    }
    }
  - if ("`from'" == "") {
  = if ("" == "") {
  - tempname b from
  - matrix `b' = e(b)
  = matrix __000002 = e(b)
  - if ((`kfix'+`krnd')>`ln') matrix `from' = `b'[1,1..(`kfix'+`krnd'-`ln')]
  = if ((1+2)>0) matrix __000003 = __000002[1,1..(1+2-0)]
matrix __000002 not found
    forvalues i = 1(1)`ln' {
    if (`b'[1,(`kfix'+`krnd'-`ln'+`i')] <= 0) {
    di in red "Variables specified to have log-normally distributed coefficients should have positive"
    di in red "coefficients in the conditional logit model. Try multiplying the variable by -1."
    exit 498
    }
    if ((`kfix'+`krnd')==`ln' & `i'==1) matrix `from' = ln(`b'[1,1])
    else matrix `from' = `from', ln(`b'[1,(`kfix'+`krnd'-`ln'+`i')])
    }
    if ("`corr'" == "") matrix `from' = `from', J(1,`krnd',0.1)
    else matrix `from' = `from', J(1,`cho',0.1)
    local copy , copy
    }
  ------------------------------------------------------------------------------------------------------------ end mixlogit.Estimate ---
----------------------------------------------------------------------------------------------------------------------- end mixlogit ---
r(111);
code太长了,一次贴不下,这个是出错的地方大概倒数十几行的位置,十分感谢!

14
蓝莲花开12 发表于 2016-10-12 10:07:50
statax 发表于 2016-10-12 09:47
试一下set matsize 10000,还报不报错?
还是会报错,和原来一样,样本量目前是9900,自变量是3个

15
蓝莲花开12 发表于 2016-10-12 10:18:10
这个是mixlogit运行全部的代码,错误在倒数十几行的地方,谢谢! 新建文本文档 (2).txt (88.43 KB)

16
蓝莲花开12 发表于 2016-10-12 17:23:30 来自手机
夏目贵志 发表于 2016-10-11 22:29
运行这个命令之前运行一下set trace on。然后把结果贴出来看看呢?
全部code贴在15楼的附件里了,麻烦了,谢谢

17
夏目贵志 发表于 2016-10-12 21:40:46
运行一下
markout __000000 obs distobus area
clogit choice delta distobus area if __000000 , group(obs)
mat list e(b)
然后贴接过来看看

18
蓝莲花开12 发表于 2016-10-13 08:31:12
是在运行完mixlogit命令以后运行这几行吗,前两行都会报错,第三行可以运行。

19
蓝莲花开12 发表于 2016-10-13 08:31:48
夏目贵志 发表于 2016-10-12 21:40
运行一下
markout __000000 obs distobus area
clogit choice delta distobus area if __000000 , group( ...
代码贴在18楼,谢谢!

20
夏目贵志 发表于 2016-10-13 12:02:08
蓝莲花开12 发表于 2016-10-13 08:31
代码贴在18楼,谢谢!
不用先运行mixlogit。加载好数据之后直接
gen byte spl=.
markout spl obs distobus area
clogit choice delta distobus area if spl , group(obs)
mat list e(b)
结果是什么?

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-28 22:01