Announcement

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

  • Display "Robust" at the top of Std.Err. column using -ereturn display-

    Dear Statalist,

    I have a rather technical question regarding displaying estimation commands. I am writing a command that fits a model and also computes the robust standard errors. Unfortunately, I am using my own Mata routine to compute robust standard errors, mainly because my model is fitted using an ml -d0- evaluator and those evaluators do not provide score functions. Later, I invoke -eretun repost- to replace the original variance-covariance matrix with the robust one. The problem is that when doing so, I don't know how to change the title of the Std. Err. on the display to include the Robust. label. Below is a simple routine that exemplifies my question.
    1. Ado file MyReg.ado
    Code:
    program MyReg 
        version 12
        if replay() {
        if ("`e(cmd)'" != "MyReg") error 301
        Replay `0'
        }
        else Estimate `0'
    end
    
    
    program Estimate, eclass sortpreserve 
        syntax varlist(fv) [if] [in] , [Robust]
    
        // check syntax
        gettoken lhs rhs : varlist
        qui reg `lhs' `rhs'
    
        tempname b V
        matrix `b' = e(b)
        matrix `V' = e(V)
    
        // "Fake" Sandwich Matrix, just for illustration. 
        mata: V_r = st_matrix("`V'") + J(cols(st_matrix("`V'")), rows(st_matrix("`V'")),100)
        mata: st_matrix("V_r", V_r)
    
        if "`robust'" !="" {
            ereturn repost b=`b' V=V_r , rename
            ereturn display             
        }
        else ereturn display          
    end
    2.- Do file that invoked MyReg.ado

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . MyReg price mpg 
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             mpg |  -238.8943   53.07669    -4.50   0.000    -344.7008   -133.0879
           _cons |   11253.06   1170.813     9.61   0.000     8919.088    13587.03
    ------------------------------------------------------------------------------
    
    
    . MyReg price mpg , r
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             mpg |  -238.8943   54.01051    -4.42   0.000    -346.5623   -131.2264
           _cons |   11253.06   1170.855     9.61   0.000     8919.003    13587.12
    ------------------------------------------------------------------------------
    3.-What I want to be displayed is
    Code:
    . 
    . MyReg price mpg , r
    
    ------------------------------------------------------------------------------
                 |               Robust
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             mpg |  -238.8943   54.01051    -4.42   0.000    -346.5623   -131.2264
           _cons |   11253.06   1170.855     9.61   0.000     8919.003    13587.12
    ------------------------------------------------------------------------------

    Finally, headers are not an issue because I am writing my own. In fact, in the header, I already wrote a message telling the user that robust standard errors were computed, but I need to confess that the lack of the word Robust at the top makes my eye twitch a bit...

    Thanks you a lot for your time.

    Álvaro
    Stata 16.1 MP
    Win10/Linux Mint 19.1
    https://alvarogutyerrez.github.io/

  • #2
    This thread might be answering your question:

    https://www.stata.com/statalist/arch.../msg00029.html

    Comment


    • #3
      Dear Joro,

      Thank you a lot for your reply, it was confusing how to find the answer just because the word robust triggered so many results associated with it on the search engine, aka, Google.

      My example modified in order to get the desired result is listed below. It was ridiculously easy after all.


      Code:
      program MyReg
          version 12
          if replay() {
          if ("`e(cmd)'" != "MyReg") error 301
          Replay `0'
          }
          else Estimate `0'
      end
      
      
      program Estimate, eclass sortpreserve
          syntax varlist(fv) [if] [in] , [Robust]
      
          // check syntax
          gettoken lhs rhs : varlist
          qui reg `lhs' `rhs'
      
          tempname b V
          matrix `b' = e(b)
          matrix `V' = e(V)
      
          // "Fake" Sandwich Matrix, just for illustration.
          mata: V_r = st_matrix("`V'") + J(cols(st_matrix("`V'")), rows(st_matrix("`V'")),100)
          mata: st_matrix("V_r", V_r)
      
          if "`robust'" !="" {
              ereturn repost b=`b' V=V_r, rename
              ereturn local vcetype Robust  // <---- Just this line was needed!
              ereturn display            
          }
          else ereturn display          
      end

      Best,


      Álvaro
      Stata 16.1 MP
      Win10/Linux Mint 19.1
      https://alvarogutyerrez.github.io/
      Last edited by Alvaro Gutierrez; 11 Aug 2020, 09:00. Reason: typo

      Comment


      • #4
        This thread was really useful, thank you.

        Following on from your query, do you know how to obtain "Observed" on top of "coefficient" and "Normal-based" on top of "[95% conf. interval]" when parsing a bootstrap vce type? It was easy to add "Bootstrap" on top of the std. error, thanks to this thread, but it's not clear how to change the coefficient or 95% conf. interval.

        Thanks!

        Click image for larger version

Name:	Untitled.png
Views:	2
Size:	3.0 KB
ID:	1655481
        Attached Files

        Comment


        • #5
          SOLVED! Include the following lines before ereturn display:

          ereturn local vce bootstrap
          ereturn local vcetype Bootstrap

          Comment

          Working...
          X