Announcement

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

  • Editing e() Results and Storing Results

    Hi everyone,

    I'm running regressions, and wish to edit the results stored in e(b) or e(V) before storing the results. It is possible to extract e(b) and e(V) and edit them using standard matrix operations, but the resulting matrices must then be posted back into e(). As suggested previously (https://www.stata.com/statalist/arch.../msg00167.html), this editing of e() can be done with ereturn post.

    Code:
    version 16
    clear all
    
    sysuse auto
    reg mpg price weight gear
    matrix list e(b)
    matrix b = e(b) * 2
    matrix V = e(V) * 4
    ereturn post b V
    matrix list e(b)
    
    estimates store test
    (Sidenote: ereturn post returns a conformability error if V is supplied but b is not, but not vice versa. So updating V but not b is somewhat unwieldy).

    However, the subsequent estimates store command returns an error r(301): "last estimation results not found, nothing to store". The issue appears to arise because ereturn post clears all existing e-class results, and thus presumably estimates store does not find what it expects.

    The help file for ereturn suggests that ereturn repost allows the b or V matrix to be altered without removed previously stored results in e(). However, using it instead yields an immediate error, r(152): "non e-class program may not set e()". Perhaps I am missing something simple, but I cannot get ereturn repost to work at all.

    Code:
    version 16
    clear all
    
    sysuse auto
    reg mpg price weight gear
    matrix V = e(V) * 4
    ereturn repost V = V
    matrix list e(V)
    Can anyone provide insight into whether it is possible to get around these issues and accomplish the goal of editing and updating e() using ereturn?

    Sidenote: It appears there is a way to get around this issue by using a user-written function, erepost, but nonetheless it would be good to understand what is happening with the built-in functions.

    Code:
    version 16
    
    clear all
    
    sysuse auto
    reg mpg price weight gear
    mat V = e(V) * 4
    erepost V = V
    mat list e(V)
    estimates store test
    Thanks,
    Matthew

  • #2
    I believe the issue is that the -ereturn repost- command has to happen inside an e-class program. I'm no expert here, but the following seemed to work:
    Code:
    cap prog drop wrapper
    prog wrapper, eclass
    reg mpg price weight gear
    di "original"
    mat list e(V)
    matrix V = e(V) * 4
    ereturn repost V = V
    end
    //
    sysuse auto
    wrapper
    di "new"
    mat list e(V)

    Comment


    • #3
      You are correct, you need a program with -eclass- in order to use ereturn repost.

      But see the manual of the erepost command on SSC, as well as its source code: it copies all e-return values and macros and rebuilds them afterwards. And the documentation states that:

      However, erepost is allowed after estimation commands that do not post their results using -ereturn post- (e.g. logit) and erepost can be used outside of eclass programs.

      Comment


      • #4
        Great, thank you both.

        Comment

        Working...
        X