Announcement

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

  • Help to work with matrix in STATA 12

    I'm calculating some indexes in the STATA 12 and I'm putting together the schedule so that you can run without error, but in one of those steps I ran into the following error:
    matrix operators that return matrices not allowed in this context
    r (509);

    The commands I'm using were:
    gen KK1 = J1 * Z

    I'm trying to generate a variable KK1, from the multiplication of another variable J1 and an matrix Z

    To generate J1 I used:
    gen J1=(1/5564)*QLa
    list J1


    What am I doing wrong?
    Can someone help me?

  • #2
    Rafaella,

    Your question is a general Stata question, hence may get more responses in the General forum.

    That said, multiplication between a variable and a Stata matrix is not allowed since it is generally ambiguous. Imaging the following, J1 has 3 observations, Z is a 1 by 4 matrix, do you want the resulted J1*Z to be a 3 by 4 matrix as a 3 by1 matrix multiply a 1 by 4 matrix? How is the result assigned back to a variable if that is the case?

    For me or other users to be able offer more help, you need describable what the matrix Z looks like,

    Code:
    mat list Z
    and what do you want to get for the resulted KK1.

    Comment


    • #3
      Z is an matrix of dimension (1x5564)
      and J1 is a scalar variable according to localities considered (J1j), and has a particular value, for each j (region) total 5564 localities (or region).
      The commands to generate Z, I used:
      const gene = 1
      mkmat const, matrix (1)
      matrix V = i '
      matrix list V (1x5564)
      The matrix V is formed by a matrix a vector of dimension (1x5564) and the S is the matrix of spatial weight (S) of dimension (5564x5564).
      matrix Z = V * S
      matrix list Z
      I want to generate a new variable, called KKK1, from the multiplication of J1 and the matrix Z of dimension (1x5564):
      gen KKK1 = J1 * Z
      And is giving the following error:
      matrix operators that return matrices not allowed in this context
      r (509);

      Comment

      Working...
      X