Announcement

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

  • Describing/listing matrices in mata

    Hi everyone,
    I have a quick "general" programming question when using mata. Why doesn't the mata describe command display all the working matrices/columns when placed in a function? Although it works fine when not in a function. I want to see a list of the matrices (and their dimensions) that I have to work with. For example, I use macro list and display when programming in Stata for reference. What would you use in place of this? Below is a silly example:

    Code:
    // Mata describe in a function
    mata:
        mata set matastrict on
        void calcextrema(string scalar varname)
        {
        real colvector x, cmm
        x = st_data(., varname)
        cmm = colminmax(x)
        }
        mata describe
    end
    
    sysuse auto, clear
    mata: calcextrema("price")
    
    
    // Mata describe not a function
    mata
        x = st_data(., "price")
        cmm = colminmax(x)
        mata describe
    end








  • #2
    Your function consists of everything between the void and the right brace. The mata describe command is not "in" the function, and is being run immediately after the function is defined, so no matrices are available. Consider the following elaboration on your example.
    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . mata: calcextrema("price")
    
    . mata: calcextrema("weight")
    
    . 
    . mata: mata describe
    
          # bytes   type                        name and extent
    -------------------------------------------------------------------------------
              132   void                        calcextrema()
    -------------------------------------------------------------------------------
    
    .
    Note that no output from mata describe appears after either call to calcextrema. And the mata describe that is run does not show the matrices, which are local to calcextrema.

    Comment


    • #3
      Thanks William Lisowski, I understand that. My question is why can't I describe the matrices that are local to the function? If I put the mata describe inside the function brackets, the code returns an error. I want to know the matrix sizes that are passed to the function, and created in the function, for conformability issues.

      Comment


      • #4
        Eric,

        The -mata describe- command just doesn't work that way (it's a bit confusing as you cannot use it in the same way as -describe-). If you want to inspect the sizes, you can just write "rows(x), cols(x)" within the functin, and that will be output to the screen.

        Comment

        Working...
        X