Announcement

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

  • Change the label/ variable name only in regression output

    Dear Statalist,

    Thank you so much for all your previous help in my projects.

    I would like to now change the labels of the variables that appear in my regression output.

    Code:
                                     (Std. err. adjusted for 175 clusters in CASE)
    ------------------------------------------------------------------------------
                 |               Robust
           action| Coefficient  std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             T_C |
        3 years  |   .0014682   .0586037     0.03   0.980    -.1141975    .1171339
                 |
     return_numb |
              2  |   .0415479   .0820218     0.51   0.613    -.1203379    .2034337
              3  |  -.0802777   .0850249    -0.94   0.346    -.2480905    .0875352
              4  |   .0261982   .0848565     0.31   0.758    -.1412823    .1936786
              5  |   .0324653    .083936     0.39   0.699    -.1331984    .1981291
              6  |  -.0118075   .0792168    -0.15   0.882    -.1681571     .144542
              7  |    .018131   .0873436     0.21   0.836    -.1542583    .1905204
              8  |  -.0442845   .0773675    -0.57   0.568    -.1969842    .1084151
              9  |  -.0373382   .0917166    -0.41   0.684    -.2183585    .1436821
             10  |   .1418209   .0865785     1.64   0.103    -.0290584    .3127002
                 |
            risk |
              2  |   .0302998   .0427611     0.71   0.480    -.0540975     .114697
              3  |  -.0454869   .0468423    -0.97   0.333    -.1379392    .0469654
              4  |  -.0730557   .0513766    -1.42   0.157    -.1744573    .0283459
                 |
           round |
              2  |   .0446484   .0467053     0.96   0.340    -.0475335    .1368303
              3  |   .0342588   .0460236     0.74   0.458    -.0565775    .1250951
              4  |  -.0182757   .0466819    -0.39   0.696    -.1104114    .0738601
    Particularly, I want to rename T_C "time frame" and return_numb "Return year" in this regression. Specifically, the 2 should say 2021, 3 2020 and so on until 10 -2013.

    I tried
    Code:
    label variable return_numb "Return year"
    label variable T_C "Time frame"
    but when I reran the regression, I still had T_C and return_numb in the regressions.

    Then I tried the method described here https://www.statalist.org/forums/for...abel-vairables but this suggested I rename the variable and this would also mean that in future regressions I need to type action i.Time frame instead of the short, preferred i.T_C as before.

    Next, in the data edit mode in Stata, I labeled the variable and also included a label under data, but still without success.

    YouTube videos suggested exporting the regressions to Excel or Latex and manually changing the variable names. Since I'm running quite a few regressions I would like to avoid this manual work.

    Using https://www.statalist.org/forums/for...lable-from-ssc and SSC's elabel,I tried
    Code:
     elabel define T_C "Time frame"
    but received an error message that says "Time frame" invalid name
    r(198);


    I would be most grateful for any help or advice.

    Kind regards,
    Matt

  • #2
    regerss won't show variable labels; for that you need estimates table or some community-contributed command. regress will show value labels.

    Consider:

    Code:
    . sysuse auto
    (1978 automobile data)
    
    . 
    . label define rep78 ///
    >     1 "one"        ///
    >     2 "two"        ///
    >     3 "three"      ///
    >     4 "four"       ///
    >     5 "five"
    
    .     
    . label values rep78 rep78
    
    . 
    . regress price mpg i.rep78
    
          Source |       SS           df       MS      Number of obs   =        69
    -------------+----------------------------------   F(5, 63)        =      4.39
           Model |   149020603         5  29804120.7   Prob > F        =    0.0017
        Residual |   427776355        63  6790100.88   R-squared       =    0.2584
    -------------+----------------------------------   Adj R-squared   =    0.1995
           Total |   576796959        68  8482308.22   Root MSE        =    2605.8
    
    ------------------------------------------------------------------------------
           price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             mpg |  -280.2615   61.57666    -4.55   0.000    -403.3126   -157.2103
                 |
           rep78 |
            two  |   877.6347   2063.285     0.43   0.672     -3245.51     5000.78
          three  |   1425.657   1905.438     0.75   0.457    -2382.057    5233.371
           four  |   1693.841   1942.669     0.87   0.387    -2188.274    5575.956
           five  |   3131.982   2041.049     1.53   0.130    -946.7282    7210.693
                 |
           _cons |   10449.99   2251.041     4.64   0.000     5951.646    14948.34
    ------------------------------------------------------------------------------
    
    . 
    . estimates table , varlabel
    
    ---------------------------------------
                    Variable |   Active    
    -------------------------+-------------
               Mileage (mpg) | -280.26149  
                             |             
          Repair record 1978 |             
                        two  |  877.63472  
                      three  |   1425.657  
                       four  |   1693.841  
                       five  |  3131.9822  
                    Constant |  10449.991  
    ---------------------------------------

    To get something similar you could

    Code:
    label variable return_numb "Return year"
    label variable T_C         "Time frame"
    
    elabel define return_numb:return_numb_lbl ///
        (1/10) (=strofreal(2023-#))
    where the elabel syntax is short for

    Code:
    label define return_numb_lbl 1 "2022" 2 "2021" ... 10 "2013"
    label values return_numb return_numb_lbl

    Comment


    • #3
      Dear Daniel,

      Thank you very much for your reply. Following your suggestion, I implemented
      Code:
      label variable return_numb "Return year"
      label variable T_C         "Time frame"
      
      elabel define return_numb:return_numb_lbl ///
          (1/10) (=strofreal(2022-#))
      and it worked in the regress regression output in Stata
      Code:
                                       (Std. err. adjusted for 175 clusters in CASE)
      ------------------------------------------------------------------------------
                   |               Robust
             action | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
      -------------+----------------------------------------------------------------
               T_C |
          3 years  |   .0014682   .0586037     0.03   0.980    -.1141975    .1171339
                   |
       return_numb |
             2021  |   .0415479   .0820218     0.51   0.613    -.1203379    .2034337
             2020  |  -.0802777   .0850249    -0.94   0.346    -.2480905    .0875352
             2019  |   .0261982   .0848565     0.31   0.758    -.1412823    .1936786
             2018  |   .0324653    .083936     0.39   0.699    -.1331984    .1981291
             2017  |  -.0118075   .0792168    -0.15   0.882    -.1681571     .144542
             2016  |    .018131   .0873436     0.21   0.836    -.1542583    .1905204
             2015  |  -.0442845   .0773675    -0.57   0.568    -.1969842    .1084151
             2014  |  -.0373382   .0917166    -0.41   0.684    -.2183585    .1436821
             2013  |   .1418209   .0865785     1.64   0.103    -.0290584    .3127002
                   |
              risk |
                2  |   .0302998   .0427611     0.71   0.480    -.0540975     .114697
                3  |  -.0454869   .0468423    -0.97   0.333    -.1379392    .0469654
                4  |  -.0730557   .0513766    -1.42   0.157    -.1744573    .0283459
                   |
             round |
                2  |   .0446484   .0467053     0.96   0.340    -.0475335    .1368303
                3  |   .0342588   .0460236     0.74   0.458    -.0565775    .1250951
                4  |  -.0182757   .0466819    -0.39   0.696    -.1104114    .0738601
      However not in my exported file, using outreg2 from ssc
      Code:
      outreg2 using myfile.doc, replace ctitle(Basic) dec(3)
      I obtained the following when I clicked on myfile.doc:
      As you can see the years are no longer displayed but instead it's gone back to return_numb etc.
      (1)
      VARIABLES Basic
      1.T_C 0.001
      (0.059)
      2.return_numb 0.042
      (0.082)
      3.return_numb -0.080
      (0.085)
      4.return_numb 0.026
      (0.085)
      5.return_numb 0.032
      (0.084)
      6.return_numb -0.012
      (0.079)
      7.return_numb 0.018
      (0.087)
      8.return_numb -0.044
      (0.077)
      9.return_numb -0.037
      (0.092)
      10.return_numb 0.142
      (0.087)
      2.risk 0.030
      (0.043)
      3.risk -0.045
      (0.047)
      4.risk -0.073
      (0.051)
      2.round 0.045
      (0.047)
      3.round 0.034
      (0.046)
      4.round -0.018
      (0.047)
      Constant 0.308***
      (0.087)
      Observations 574
      R-squared 0.026

      Robust standard errors in parentheses
      *** p<0.01, ** p<0.05, * p<0.1

      I omitted parts of the regression output for better readability (which is why the constant, observations and r^2 don't line up anymore).

      Further, I am using outreg2 (from SSC) because I have many factor variables and outreg2 suppresses the base dummies while estout does not anymore (nobaselevels option no longer available).

      I would be most grateful for any help or comments.

      Thank you very much.








      Comment


      • #4
        I have not used outreg2 for about a decade or so. My guess is that it has an option (or more) to display variable and value labels that you need to specify. I cannot tell you what it is. Read

        Code:
        help outreg2

        Comment


        • #5
          Thank you! It's the option label for anyone else wondering.

          Comment

          Working...
          X