Announcement

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

  • Append coefficients and t-statistics in the same matrix.

    Hello,

    I don't know if this can be considered as a mata programming question, but I am trying to insert t-statistics and the coefficients in the same matrix (10x5).

    So far, I have been able to create two distinct matrices (5x5): K_m for the coefficients and K_t for the t-stats. I would like to have a K matrix instead with t-stats below my coefficients (and if possible within parenthesis).

    The data structure has 5 id variables (univ_cut) and 5 numerical variables as varliest. For the syntax, tid is a time variable.

    This is my code:

    Code:
    mat K_m = J(5,5,.)
    mat K_t = J(5,5,.)
    local j = 1
    
    foreach v in f1r_rf100 f1m1W_36_b_cons100 f1m2W_36_b_cons100 f1m3W_36_b_cons100 f1m4W_36_b_cons100  {
        forvalues i = 1(1)5 {
            qui: newey2 `v' if  univ_cut==`i', lag(2)  t(tid) force
            matrix mattest= r(table)
            matrix K[`i',`j']=mattest[1,1]
            matrix K[`i',`j']=mattest[3,1]
        }
    local ++j
    
    }
    I have been struggling with the iterators (j and i) inside the matrices to append the t-stats in a matrix K (`i'+1,`j').

    Code:
    mat K = J(10,5,.)
    local j= 1
    
    foreach v in f1r_rf100 f1m1W_36_b_cons100 f1m2W_36_b_cons100 f1m3W_36_b_cons100 f1m4W_36_b_cons100  {
        
        forvalues i = 1(1)5 {
            qui: newey2 `v' if  univ_cut==`i', lag(2)  t(tid) force
            matrix mattest= r(table)
            matrix K[`i',`j']=mattest[1,1]
            matrix K[`i'+1,`j']=mattest[3,1]
        }
    local ++j
    }
    Or similar, maybe I need to include another double loop? But I can't figure out how.











  • #2
    It's not really a mata question - you are using Stata matrices, which is different from Mata.

    But with that said, in your first code you must have meant
    Code:
    mat K_m = J(5,5,.)
    mat K_t = J(5,5,.)
    local j = 1
    
    foreach v in f1r_rf100 f1m1W_36_b_cons100 f1m2W_36_b_cons100 f1m3W_36_b_cons100 f1m4W_36_b_cons100  {
        forvalues i = 1(1)5 {
            qui: newey2 `v' if  univ_cut==`i', lag(2)  t(tid) force
            matrix mattest= r(table)
            matrix K_m[`i',`j']=mattest[1,1]
            matrix K_t[`i',`j']=mattest[3,1]
        }
    local ++j
    
    }
    For your second code, you need something like
    Code:
    mat K = J(10,5,.)
    local j= 1
    
    foreach v in f1r_rf100 f1m1W_36_b_cons100 f1m2W_36_b_cons100 f1m3W_36_b_cons100 f1m4W_36_b_cons100  {
        
        forvalues i = 1(1)5 {
            qui: newey2 `v' if  univ_cut==`i', lag(2)  t(tid) force
            matrix mattest= r(table)
            matrix K[2*`i'-1,`j']=mattest[1,1]
            matrix K[2*`i',`j']=mattest[3,1]
        }
    local ++j
    }

    Comment


    • #3
      Thank you William. This is exactly what I was looking for.
      Sorry the category mistake.

      Comment

      Working...
      X