Announcement

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

  • Making program's standard error results available for _se[var] call?

    Hi everyone,

    So I'm working on extracting output from a user generated program (traj). I can get the B coefficients to post as vector matrix e(b) without any trouble. This means I type something like:

    local test=[eq1]_b[varname]

    and it will return the regression coefficient.

    How do I get stata to post the SE values (a 1 x 60 matrix) as a similar vector matrix that I can call then in the same fashion (local test=[eq1]_se[varname] )? Stata's programs do this but I can't figure out how to do for my own program. I see that the SEs are stored in r(table), but I can't figure out how to get stata to post results to that table and recognize _se.

    The complication here that the SEs have to be entered manually- the B's are returned by the original program but not the SEs, and the program is run through a C plugin that is beyond my skill to even open at the moment.

    This summarizes the situation I'm dealing with and my end goal:

    program quicktest, eclass
    regress price mpg headroom
    tempvar b se
    matrix define `b'=e(b)
    *SE values from above regression must be entered manually in my case*
    matrix define `se'=(58.42, 399.549, 2074.497)
    ereturn post `b'
    end

    (the end goal is just):
    di _b[mpg]/_se[mpg]

    Thank you!

  • #2
    There are indeed better ways of getting the standard errors after a regression. Here is one and I hope to be trumped with a yet better method:

    Code:
    . sysuse auto, clear 
    (1978 Automobile Data)
    
    . regress price mpg headroom 
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(2, 71)        =     10.44
           Model |   144280501         2  72140250.4   Prob > F        =    0.0001
        Residual |   490784895        71  6912463.32   R-squared       =    0.2272
    -------------+----------------------------------   Adj R-squared   =    0.2054
           Total |   635065396        73  8699525.97   Root MSE        =    2629.2
    
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             mpg |  -259.1057   58.42485    -4.43   0.000    -375.6015   -142.6098
        headroom |  -334.0215   399.5499    -0.84   0.406    -1130.701    462.6585
           _cons |   12683.31   2074.497     6.11   0.000     8546.885    16819.74
    ------------------------------------------------------------------------------
    
    . mata: st_matrix("myse", sqrt(diagonal(st_matrix("e(V)")))) 
    
    . mat li myse 
    
    myse[3,1]
               c1
    r1   58.42485
    r2  399.54994
    r3  2074.4972
    I don't know what this means for traj (provenance not stated), which I have never seen.

    Comment


    • #3
      Thank you for that suggestion- generally a mata solution like this would work but in this case Traj (found here: https://www.andrew.cmu.edu/user/bjones/index.htm ) doesn't return an e(V) for the regression model at the end of the day. The model is handled within a plugin so I can't just tweak the traj code to get it to give me the values, unfortunately. I would just run the mlogit model outside of traj but that is inappropriate in this case because traj uses a mlogit model that is modified to account for uncertainty in group membership assignment. As such, I can't see any other option other than just manually entering the SEs into a matrix.

      The solution I've thought of is just to bypass the _se[variable] idea and draw from the matrix I inputted.

      Something along the lines of this pseudocode- I haven't gotten the chance to implement yet.

      local list = var1 var 2 var 3
      foreach var of varlist `list' {
      local temp`var'= rownumb(SEmatrix,`var')
      }

      Comment

      Working...
      X