Announcement

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

  • how to output the results from mata to stata variable?

    I want to store the reuslts "1", how to do that?
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(k61 gender) float age byte edu
    0 1 40 5
    0 1 73 5
    0 2 54 5
    0 1 41 5
    0 2 35 5
    0 1 49 5
    0 1 46 5
    0 1 45 5
    2 2 37 5
    1 1 40 4
    end
    reg k61 i.gender age edu
    
    matrix list r(table)
    mata : table = st_matrix("r(table)")
    
    mata : sum(table[4, .] :< 0.2)

  • #2
    I'm guessing that you mean you want to store the value produced by your last Mata statement, but you don't say whether you want to store it in Mata, or in Stata as a local or as a scalar.
    Code:
    mata: MyResult = sum(table[4, .] :< 0.2)  // Mata variable
    mata: st_local("MyResult1", strofreal(sum(table[4, .] :< 0.2)))  // Stata local
    mata:  mata: st_numscalar("MyResult2", sum(table[4, .] :< 0.2)) // Stata scalar
    For more information, take a look at -help m4_stata-, which describes " Stata interface functions."

    Comment


    • #3
      Note, by the way, that assigning that result value to a Stata *variable* would make no sense, as the result is a single value and variables have values for each observation.

      Comment


      • #4
        Originally posted by Mike Lacy View Post
        Note, by the way, that assigning that result value to a Stata *variable* would make no sense, as the result is a single value and variables have values for each observation.
        Thanks so much Mike! I solved this problem. This is part of my loop statement, therefore, the values make sense. Thanks again!

        Comment

        Working...
        X