Announcement

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

  • Matrix with Dynamic size

    I would like to create empty matrixes within mata, whose size is given by a parameter. My program first asks for which tests should be executed and then I create the matrix size accordingly, such that I can save all p-values in one matrix. In particular:

    program ...
    syntax varlist, POOLED(integer) GROUP_mean(integer) MEDIAN(integer) B(integer) DC(integer)
    matrix test = (`pooled'\ `group_mean' \ `median')
    local nt = test[1,1]+test[2,1]+test[3,1]
    end

    mata:
    void initialize()
    {
    st_local("nt")
    real matrix pval
    pval = J(nt, 1,0)
    }

    end


    However that doesn't seem to work. My suspicion is that J will only take integer numbers as arguments. Is this right or is there other mistakes I am running into?

    Thank you.

  • #2
    My suspicion is that J will only take integer numbers as arguments.

    J()
    wants integer matrix dimensions. You can't have a 2.71 by 3.14 matrix.

    is there other mistakes I am running into?
    You are running into a different problem. Mata's nt is not initialized. You need something like:
    Code:
    nt=strtoreal(st_local("nt"))
    in your Mata portion of the code to transfer the value of the nt visible in Stata to Mata.

    All matrices are dynamic, in a sense that you can always do (for conforming matrices A and B)
    Code:
    A=A,B
    And the matrix A will be growing in size. No need to do anything fancy.

    I would like to create empty matrixes within mata
    Empty matrix has dimensions 0x0:
    Code:
    mata A=J(0,0,.)
    J() will create a matrix of given dimensions. You can initialize it to any value. Missings and zeroes are popular choices.

    Best, Sergiy Radyakin

    Comment

    Working...
    X