Announcement

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

  • Unexpected Missing Values in Matrix after Using mkmat in Stata: Can't Correct setting it to zero with matrix Command

    Hello Statalisters,

    I am facing an issue with the mkmat command, where zeros in the original variables are being converted to missing values in the matrix. I need assistance in addressing this problem.

    Here's what I've done:
    1. I generated a matrix using:
    mkmat var1 var2, matrix(Mat)
    1. On examining the matrix, I noticed that some values which are zero in var1 and var2 become missing in Mat.
    2. I tried addressing the missing value by setting it to zero:
    matrix Mat[1, 2] = 0

    But the value remains missing. However, if I set it to another number like 3:

    matrix Mat[1, 2] = 3

    It updates correctly to 3.

    The presence of these missing values prevents me from inverting the matrix and proceeding with my computations.

    Would anyone have insights or suggestions on how to address this? Thank you in advance for your help!




  • #2
    What you are describing is not the normal behavior of -mkmat-, and I have never seen Stata do that. As you can see from the following example, there is nothing in Stata that tells mkmat to convert 0 to missing values.

    Code:
    . clear*
    
    .
    . set obs 5
    Number of observations (_N) was 0, now 5.
    
    . set seed 1234
    
    . forvalues i = 1/5 {
      2.         gen var`i' = runiformint(0, 2)
      3. }
    
    .
    . mkmat var*, matrix(M)
    
    . matrix list M
    
    M[5,5]
        var1  var2  var3  var4  var5
    r1     0     0     0     0     2
    r2     0     0     1     0     1
    r3     0     0     0     0     1
    r4     0     0     2     2     2
    r5     1     2     2     2     2
    So to troubleshoot this, one would need to see the data that was being used. Please post back using the -dataex- command to show example data that reproduces your problem. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment

    Working...
    X