Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Problem Using Matwrite, "unrecognized command" error


From   J Taylor <[email protected]>
To   [email protected]
Subject   Re: st: Problem Using Matwrite, "unrecognized command" error
Date   Fri, 15 Apr 2011 14:05:17 -0700

Nick, thank you for your help with this.  The results from applying
the trace are shown below.  Unfortunately, this was not super
informative for me, though I have never used the trace before.  Any
thoughts on what may be going on?

Thank you,
JT

. clear

. set trace on

. set obs 5000
obs was 0, now 5000

. set seed 1234

. gen x = uniform()

. gen y = 2*x + invnormal(uniform())

. matwrite x y using c:\matlabfile, replace
  ----------------------------------------------------------------
begin matwrite ---
  - version 8.2
  - syntax [anything] using/ [if] [in] [,MATrix(namelist)] [,replace]
  - local matrix : list retokenize matrix
  - local matrix : list uniq matrix
  - local anything : list retokenize anything
  - if ("`matrix'"=="") local matrix : all matrices
  = if (""=="") local matrix : all matrices
  - qui de
    --------------------------------------------------------------------
begin de ---
    - local version : di "version " string(_caller()) ":"
    - `version' describe `0'
    = version 8.2: describe
      ------------------------------------------------------------
begin describe ---
      - version 9
      - local version : di "version " string(_caller()) ":"
      - syntax [anything] [using] [, SImple REPLACE *]
      - if ("`replace'"!="") {
      = if (""!="") {
        describe_mk `0'
        return add
        exit
        }
      - local varlist `"`anything'"'
      = local varlist `""'
      - if ("`simple'" == "") {
      = if ("" == "") {
      - `version' _describe `0'
      = version 8.2: _describe
      - return add
      - }
      - else {
        if (`"`options'"' != "") {
        di as err "simple may not be combined with other options"
        exit 198
        }
        if (`"`using'"' != "") {
        qui `version' describe `varlist' `using', varlist
        if "`varlist'" == "" {
        local vars "`r(varlist)'"
        }
        else {
        local vars "`varlist'"
        }
        local wid = 2
        local n : list sizeof vars
        if `n'==0 {
        exit
        }
        foreach x of local vars {
        local wid = max(`wid', length(`"`x'"'))
        }
        local wid = `wid' + 2
        local cols = int((`c(linesize)'+1)/`wid')
        if `cols' < 2 {
        foreach x of local `vars' {
        di as txt `col' `"`x'"'
        }
        exit
        }
        local lines = `n'/`cols'
        local lines = int(cond(`lines'>int(`lines'), `lines'+1, `lines'))
        forvalues i=1(1)`lines' {
        local top = min((`cols')*`lines'+`i', `n')
        local col = 1
        forvalues j=`i'(`lines')`top' {
        local x : word `j' of `vars'
        di as txt _column(`col') "`x'" _c
        local col = `col' + `wid'
        }
        di as txt
        }
        qui `version' describe `varlist' `using', short
        return add
        }
        else {
        ds `varlist'
        qui `version' _describe `varlist', short
        return add
        }
        }
      --------------------------------------------------------------
end describe ---
    ----------------------------------------------------------------------
end de ---
  - if (`r(k)'>0) {
  = if (2>0) {
  - if ("`anything'"=="") unab anything: *
  = if ("x y"=="") unab anything: *
  - }
  - if substr("`using'",length("`using'")-3,4)~=".mat" {
  = if substr("c:\matlabfile",length("c:\matlabfile")-3,4)~=".mat" {
  - local using = "`using'" + ".mat"
  = local using = "c:\matlabfile" + ".mat"
  - }
  - local anything : subinstr local anything "[" " [ ", all
  - local anything : subinstr local anything "]" " ] ", all
  - local nVarList : list sizeof anything
  - local ++nVarList
  - local isMatrix = 0
  - forval n = 1/`nVarList' {
  = forval n = 1/3 {
  - tokenize `anything'
  = tokenize x y
  - if ("`1'"=="[") {
  = if ("x"=="[") {
    if (`isMatrix'==1) error 198
    if (index("`matNameList' `newVarList' ","`lastVar' ")>0) {
    di as error "a matrix has already been defined with name `lastVar'"
    exit 110
    }
    local startSize : list sizeof matVarList
    local matNameListOld `matNameList'
    local matNameList `"`matNameList' `lastVar'"'
    local isMatrix = 1
    local thisMatrix `lastVar'
    local lastVar ""
    }
  - else if ("`1'"=="]") {
  = else if ("x"=="]") {
    if "`lastVar'"~="" {
    unab lastVar : `lastVar'
    if (index(" `matNameList' "," `lastVar' ")>0) & (`isMatrix'==0) {
    di as error "a matrix has already been defined with name `lastVar'"
    exit 110
    }
    foreach var of varlist `lastVar' {
    local tempType : type `var'
    if (substr("`tempType'",1,3)=="str") {
    di as text "warning: ignoring string variable `var'"
    local lastVar : subinstr local lastVar "`var'" ""
    }
    }
    local matVarList `"`matVarList' `lastVar'"'
    local lastVar ""
    }
    local endSize : list sizeof matVarList
    local size = `endSize' - `startSize'
    local matNameList `"`matNameList' `size'"'
    if (`startSize'==`endSize') {
    local matNameList `matNameListOld'
    local matIndexList `matIndexListOld'
    di as text "warning: ignoring matrix `thisMatrix' with zero dimension"
    }
    local isMatrix = 0
    }
  - else {
  - if ("`lastVar'"~="") {
  = if (""~="") {
    unab lastVar : `lastVar'
    if (index(" `matNameList' "," `lastVar' ")>0) & (`isMatrix'==0) {
    di as error "a matrix has already been defined with name `lastVar'"
    exit 110
    }
    foreach var of varlist `lastVar' {
    local tempType : type `var'
    if (substr("`tempType'",1,3)=="str") {
    di as text "warning: ignoring string variable `var'"
    local lastVar : subinstr local lastVar "`var'" ""
    }
    }
    if (`isMatrix'==0) local newVarList `"`newVarList' `lastVar'"'
    if (`isMatrix'==1) local matVarList `"`matVarList' `lastVar'"'
    }
  - local lastVar `1'
  = local lastVar x
  - }
  - mac shift
  - local anything `*'
  = local anything y
  - }
  - tokenize `anything'
  = tokenize y
  - if ("`1'"=="[") {
  = if ("y"=="[") {
    if (`isMatrix'==1) error 198
    if (index("`matNameList' `newVarList' ","`lastVar' ")>0) {
    di as error "a matrix has already been defined with name `lastVar'"
    exit 110
    }
    local startSize : list sizeof matVarList
    local matNameListOld `matNameList'
    local matNameList `"`matNameList' `lastVar'"'
    local isMatrix = 1
    local thisMatrix `lastVar'
    local lastVar ""
    }
  - else if ("`1'"=="]") {
  = else if ("y"=="]") {
    if "`lastVar'"~="" {
    unab lastVar : `lastVar'
    if (index(" `matNameList' "," `lastVar' ")>0) & (`isMatrix'==0) {
    di as error "a matrix has already been defined with name `lastVar'"
    exit 110
    }
    foreach var of varlist `lastVar' {
    local tempType : type `var'
    if (substr("`tempType'",1,3)=="str") {
    di as text "warning: ignoring string variable `var'"
    local lastVar : subinstr local lastVar "`var'" ""
    }
    }
    local matVarList `"`matVarList' `lastVar'"'
    local lastVar ""
    }
    local endSize : list sizeof matVarList
    local size = `endSize' - `startSize'
    local matNameList `"`matNameList' `size'"'
    if (`startSize'==`endSize') {
    local matNameList `matNameListOld'
    local matIndexList `matIndexListOld'
    di as text "warning: ignoring matrix `thisMatrix' with zero dimension"
    }
    local isMatrix = 0
    }
  - else {
  - if ("`lastVar'"~="") {
  = if ("x"~="") {
  - unab lastVar : `lastVar'
  = unab lastVar : x
    ------------------------------------------------------------------
begin unab ---
    - version 6
    - gettoken user 0: 0, parse(" :")
    - gettoken colon 0: 0, parse(" :")
    - if `"`colon'"' != ":" { error 198 }
    = if `":"' != ":" { error 198 }
    - syntax [varlist(default=empty)] [, MIN(integer 1) MAX(integer
32767) NAME(strin
> g)]
    - c_local `user' `varlist'
    = c_local lastVar x
    - local n : word count `varlist'
    = local n : word count x
    - if `n'>=`min' & `n'<=`max' { exit }
    = if 1>=1 & 1<=32767 { exit }
    --------------------------------------------------------------------
end unab ---
  - if (index(" `matNameList' "," `lastVar' ")>0) & (`isMatrix'==0) {
  = if (index("  "," x ")>0) & (0==0) {
    di as error "a matrix has already been defined with name `lastVar'"
    exit 110
    }
  - foreach var of varlist `lastVar' {
  = foreach var of varlist x {
  - local tempType : type `var'
  = local tempType : type x
  - if (substr("`tempType'",1,3)=="str") {
  = if (substr("float",1,3)=="str") {
    di as text "warning: ignoring string variable `var'"
    local lastVar : subinstr local lastVar "`var'" ""
    }
  - }
  - if (`isMatrix'==0) local newVarList `"`newVarList' `lastVar'"'
  = if (0==0) local newVarList `" x"'
  - if (`isMatrix'==1) local matVarList `"`matVarList' `lastVar'"'
  = if (0==1) local matVarList `" x"'
  - }
  - local lastVar `1'
  = local lastVar y
  - }
  - mac shift
  - local anything `*'
  = local anything
  - }
  - tokenize `anything'
  = tokenize
  - if ("`1'"=="[") {
  = if (""=="[") {
    if (`isMatrix'==1) error 198
    if (index("`matNameList' `newVarList' ","`lastVar' ")>0) {
    di as error "a matrix has already been defined with name `lastVar'"
    exit 110
    }
    local startSize : list sizeof matVarList
    local matNameListOld `matNameList'
    local matNameList `"`matNameList' `lastVar'"'
    local isMatrix = 1
    local thisMatrix `lastVar'
    local lastVar ""
    }
  - else if ("`1'"=="]") {
  = else if (""=="]") {
    if "`lastVar'"~="" {
    unab lastVar : `lastVar'
    if (index(" `matNameList' "," `lastVar' ")>0) & (`isMatrix'==0) {
    di as error "a matrix has already been defined with name `lastVar'"
    exit 110
    }
    foreach var of varlist `lastVar' {
    local tempType : type `var'
    if (substr("`tempType'",1,3)=="str") {
    di as text "warning: ignoring string variable `var'"
    local lastVar : subinstr local lastVar "`var'" ""
    }
    }
    local matVarList `"`matVarList' `lastVar'"'
    local lastVar ""
    }
    local endSize : list sizeof matVarList
    local size = `endSize' - `startSize'
    local matNameList `"`matNameList' `size'"'
    if (`startSize'==`endSize') {
    local matNameList `matNameListOld'
    local matIndexList `matIndexListOld'
    di as text "warning: ignoring matrix `thisMatrix' with zero dimension"
    }
    local isMatrix = 0
    }
  - else {
  - if ("`lastVar'"~="") {
  = if ("y"~="") {
  - unab lastVar : `lastVar'
  = unab lastVar : y
    ------------------------------------------------------------------
begin unab ---
    - version 6
    - gettoken user 0: 0, parse(" :")
    - gettoken colon 0: 0, parse(" :")
    - if `"`colon'"' != ":" { error 198 }
    = if `":"' != ":" { error 198 }
    - syntax [varlist(default=empty)] [, MIN(integer 1) MAX(integer
32767) NAME(strin
> g)]
    - c_local `user' `varlist'
    = c_local lastVar y
    - local n : word count `varlist'
    = local n : word count y
    - if `n'>=`min' & `n'<=`max' { exit }
    = if 1>=1 & 1<=32767 { exit }
    --------------------------------------------------------------------
end unab ---
  - if (index(" `matNameList' "," `lastVar' ")>0) & (`isMatrix'==0) {
  = if (index("  "," y ")>0) & (0==0) {
    di as error "a matrix has already been defined with name `lastVar'"
    exit 110
    }
  - foreach var of varlist `lastVar' {
  = foreach var of varlist y {
  - local tempType : type `var'
  = local tempType : type y
  - if (substr("`tempType'",1,3)=="str") {
  = if (substr("float",1,3)=="str") {
    di as text "warning: ignoring string variable `var'"
    local lastVar : subinstr local lastVar "`var'" ""
    }
  - }
  - if (`isMatrix'==0) local newVarList `"`newVarList' `lastVar'"'
  = if (0==0) local newVarList `" x y"'
  - if (`isMatrix'==1) local matVarList `"`matVarList' `lastVar'"'
  = if (0==1) local matVarList `" y"'
  - }
  - local lastVar `1'
  = local lastVar
  - }
  - mac shift
  - local anything `*'
  = local anything
  - }
  - local newVarList : list uniq newVarList
  - local matSize : list sizeof matNameList
  - local matSize = 0.5*`matSize'
  = local matSize = 0.5*0
  - foreach stataMat in `matrix' {
  = foreach stataMat in  {
    if (index(" `matNameList' `newVarList' "," `stataMat' ")>0) {
    di as text "warning: ignoring Stata matrix `stataMat'. A matrix
has been defined
> with this name"
    local matrix : subinstr local matrix "`stataMat'" ""
    }
    }
  - local version = 1
  - local allNames `"`matNameList' `newVarList' `matrix'"'
  = local allNames `" x y "'
  - foreach varName in `allNames' {
  = foreach varName in  x y  {
  - if (length("`varName'")>19) {
  = if (length("x")>19) {
    di as error "the variable name `varName' is too long"
    di as error "variable and matrix names can not exceed 19 characters"
    exit 198
    }
  - }
  - if (length("`varName'")>19) {
  = if (length("y")>19) {
    di as error "the variable name `varName' is too long"
    di as error "variable and matrix names can not exceed 19 characters"
    exit 198
    }
  - }
  - local allNamesLen : length local allNames
  - plugin call _matwrite `matVarList' `newVarList' `if' `in',
"`using'" `version' `r
> eplace' `matSize' `allNamesLen'
  = plugin call _matwrite  x y  , "c:\matlabfile.mat" 1 replace 0 5
unrecognized command
  ------------------------------------------------------------------
end matwrite ---
r(199);


On Fri, Apr 15, 2011 at 1:51 AM, Nick Cox <[email protected]> wrote:
> . ssc desc matwrite
>
> --------------------------------------------------------------------------------------------------------------
> package matwrite from http://fmwww.bc.edu/repec/bocode/m
> --------------------------------------------------------------------------------------------------------------
>
> TITLE
>      'MATWRITE': module to write Stata variables as MATLAB matrices
>
> DESCRIPTION/AUTHOR(S)
>
>      matwrite is a Stata plugin that allows the user to export data to
>      the  MATLAB MAT-file format from within Stata. "matwrite" allows
>      you to export all  (or selected) variables as column vectors, and
>      all (or selected) matrices as matrices.  Furthermore, the user is
>      able to specify groups of variables to export as matrices. The
>      compiled plugin for matwrite is only currently available for
>      Windows systems.
>
>      KW: MATLAB
>      KW: export
>      KW: MAT-files
>      KW: Windows
>
>      Requires: Stata version 8.2 for Windows
>
>      Distribution-Date: 20041216
>
>      Author: Andrew Shephard, Institute for Fiscal Studies, London
>      Support: email [email protected]
>
>
> INSTALLATION FILES                             (type net install matwrite)
>      matwrite.ado
>      matwrite.hlp
>      matwrite.plugin
> --------------------------------------------------------------------------------------------------------------
> (type -ssc install matwrite- to install)
>
> From that it's evident that matwrite.ado is only a wrapper. The
> problem is likely to be with the plugin. You could -set trace on- and
> report where the error occurs.
>
> As you say, other people on Statalist may have used this, but I don't
> know that the author is a member, and if you can't get it to work you
> may need to approach him.
>
> Nick
>
> On Fri, Apr 15, 2011 at 7:58 AM, J Taylor <[email protected]> wrote:
>> I am trying to use a user-written code, Matwrite, for converting Stata
>> to Matlab.  Although it is user-written, I was hoping it would be
>> frequently enough used by Stata listers to ask a question, as I have
>> not been able to get it to work, and keep getting the error
>> "unrecognized command"
>>
>> I am using Stata 11 on PC.  First, I verify once again that I have
>> install Matwrite on computer.  I type in "ssc install matwrite,
>> replace", and Stata shows the following:
>>
>> . ssc install matwrite, replace
>> checking matwrite consistency and verifying not already installed...
>> all files already exist and are up to date.
>>
>> Next, here is some toy code that I try to call matwrite:
>>
>> clear
>> set obs 5000
>> set seed 1234
>> gen x = uniform()
>> gen y = 2*x + invnormal(uniform())
>> matwrite x y using c:\matlabfile, replace
>>
>> The last line yields the error: "unrecognized command."
>>
>> I am not sure why it says this.  If I just type matwrite, it tells me
>> "using required", as 'using' is a required option for matwrite, so
>> Stata seems to recognize matwrite somewhere on my computer.  In
>> addition, an "unrecognized command" error is different from when you
>> spell something incorrectly / you call something which is not
>> installed.  For example, if I type "reg_ress" into Stata, I get the
>> error "unrecognized command:  reg_ress".
>>
>> Does anyone know why I am receiving this error, and if so, how I might fix it?
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index