Announcement

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

  • Adding macros into matrix after -lincomestadd- and -reghdfe-

    Hi

    Im using Stata MP 15.0 Windows 10 (64 bits) with -lincomestadd- and -reghdfe-

    Code:
    .which lincomestadd
    M:\Ado\plus\l\lincomestadd.ado
    
    .which reghdfe
    M:\Ado\plus\r\reghdfe.ado
    *! version 5.7.2 29jul2019

    I generated macros and scalars from linear combinations tested using -lincomestadd-, and attached them to different regressions using -reghdfe-. I can clearly see that scalars and macros from these linear combinations have been added to the stored high density fixed effects regressions. So far, so good. However, I'm having problems when adding some of the macros generated by -lincomestadd- into a matrix. Suppose a have a matrix 2x2, where each column corresponds to models 1 and 2, while row 1 and row 2 corresponds to their tested combination and s.e. respectively. For doing that I'm generating one matrix, then calling the estimates stored by using -estimates restore- and then adding the scalars into the matrix.

    Code:
    . webuse union, clear
    (NLS Women 14-24 in 1968)
    
    . eststo m1: quietly reghdfe age c.union##c.black if south == 0, absorb(year) vce(robust)
    . lincomestadd _b[union] + _b[black] + _b[c.union#c.black] , statname(ex)
    
     ( 1)  union + black + c.union#c.black = 0
    
    ------------------------------------------------------------------------------
             age |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             (1) |  -.0682821   .0909671    -0.75   0.453    -.2465884    .1100242
    ------------------------------------------------------------------------------
    
    added macro:
                    e(exb) : "-0.068"
    
    added macro:
                   e(exse) : "(0.091)"
    
    added macro:
                    e(ext) : "-0.751"
    
    added scalar:
                e(exb_num) =  -.0682821
    
    added scalar:
               e(exse_num) =  .09096709
    
    added scalar:
                e(ext_num) =  -.75062429
    
    . eststo m2: quietly reghdfe age c.union##c.black if south == 1, absorb(year) vce(robust)
    . lincomestadd _b[union] + _b[black] + _b[c.union#c.black] , statname(ex)
    
     ( 1)  union + black + c.union#c.black = 0
    
    ------------------------------------------------------------------------------
             age |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             (1) |  -.1811774   .0992281    -1.83   0.068    -.3756827    .0133278
    ------------------------------------------------------------------------------
    
    added macro:
                    e(exb) : "-0.181*"
    
    added macro:
                   e(exse) : "(0.099)"
    
    added macro:
                    e(ext) : "-1.826"
    
    added scalar:
                e(exb_num) =  -.18117743
    
    added scalar:
               e(exse_num) =  .09922808
    
    added scalar:
                e(ext_num) =  -1.8258685
    
    
    . matrix mat = J(2,2,.)
    
    . forvalues i = 1/2 {
      2. estimates restore m`i'
      3. matrix mat[1,`i'] = e(exb_num)
      4. matrix mat[2,`i'] = e(exse_num)
      5. }
    (results m1 are active now)
    (results m2 are active now)
    
    . matlist mat
    
                 |     c1         c2
    -------------+----------------------
              r1 | -.0682821  -.1811774
              r2 |  .0909671   .0992281
    However, because I want to preserve the format from the macros (stars for coefficients and parenthesis for s.e.) I would prefer to use them instead scalars. Something visually like this:


    Code:
                 |     c1         c2
    -------------+----------------------
              r1 |  -0.068     0.181*
              r2 |  (0.091)   (0.099)
    What I tried to do was to save the macros as "strings" or local values, but something is not working, it says value is not found:
    (added -display- just to double check the figures and format were correct)

    Code:
    . matrix mat = J(2,2,.)
    . forvalues i = 1/2 {
      2. estimates restore m`i'
      3. local ex_coef : display e(exb)
      4. display "`ex_coef'"
      5. local ex_se : display e(exse)
      6. display "`ex_se'"
      7. matrix mat[1,`i'] = `ex_coef'
      8. matrix mat[2,`i'] = `ex_se'
      9. }
    (results m1 are active now)
    -0.068
    (0.091)
    (results m2 are active now)
    -0.181*
    (0.099)
    0.181* not found
    r(111);

    Any help will be appreciated
    Roberto
    Last edited by Ricardo Bautista; 18 Sep 2019, 12:29. Reason: Too much white space

  • #2
    You cannot input a string into a Stata matrix. The following thread may be helpful.

    https://www.statalist.org/forums/for...gression-table

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      You cannot input a string into a Stata matrix. The following thread may be helpful.

      https://www.statalist.org/forums/for...gression-table

      Hi Andrew

      Thanks for the quick response. In fact what you suggested is already done by -lincomestadd- instead of -lincomest-. This is, to store the lincom output as macros with specific format (stars and parenthesis for the coefficient and s.e., respectively) that can be used in some commands such as -esttab-. I'm already doing using esttab for doing something similar, comparing just a few models.
      My problem got bigger when I created a big matrix (5x5) to compare many models based on two main dimensions, so that results change along this matrix (vertical and horizontal directions) and then wanted to format it by using -frmttable- or -esttab-. I guess the solution will be to skip this middle step (creating one matrix) and go direct with -esttab-, appending the results.

      Comment


      • #4
        Thanks for the extra detail describing the command (from SSC). I usually write my own code if I need anything custom, but I will add a link to the other thread for the benefit of others.

        Comment

        Working...
        X