Announcement

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

  • finding standard deviation from residuals

    Hi,
    I am quite new with stata and statistical research. For my thesis, I would like to find a list of standard deviation from regression's residuals. Basically I will do the following;
    Regress y = a + Bx + Cx
    Find residuals from the regression results
    Create list of standard deviation from residuals
    Use this standard deviation as a new variable for further regression tests.

    I am using stata edition 12.1 and 13.0

    Thank you.
    C
    Last edited by Camille Iman; 11 Jun 2015, 07:08.

  • #2
    your question is not at all clear; you can certainly obtain residuals after estimating your regression:
    Code:
    predict resid, r
    but what do you want next; if you just want the sd of these residuals that is easy also: just summarize and you will see the sd (and it will be "kept" in r(sd)

    but that is just one number and thus not appropriate for inclusion in a regression

    so, what "list of standard deviation from residuals" are you talking about?

    Comment


    • #3
      The standard deviation of the residuals is stored directly after regress in e(rmse). I assume you want to do many regressions for different groups (countries, companies, industries, herds, ...). In that case statsby is your friend:

      Code:
      // open an example dataset
      sysuse nlsw88, clear
      
      // store the standard deviation of the residual
      // for each industry
      statsby rmse=e(rmse), by(industry) : ///
          regress wage grade ttl_exp
      
      // admire the result
      list

      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Thank you.
        I want to use the standard deviation of residuals to find idiosyncratic risk.
        The literature that I am looking at find this risk by using 'The standard deviation of residuals that are obtained by regressing daily returns from pairs of cross-listed shares with the returns from the home market index and the returns of US index'.
        Please help.

        Comment


        • #5
          You ask for help, but don't ask a question. So it is hard to respond to that.
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment


          • #6
            In the regression output below, the Root MSE (3.4389) is the standard error of the regression, which is the standard deviation of the residuals corrected for degrees of freedom.
            Code:
            . reg mpg weight
            
                  Source |       SS       df       MS              Number of obs =      74
            -------------+------------------------------           F(  1,    72) =  134.62
                   Model |   1591.9902     1   1591.9902           Prob > F      =  0.0000
                Residual |  851.469256    72  11.8259619           R-squared     =  0.6515
            -------------+------------------------------           Adj R-squared =  0.6467
                   Total |  2443.45946    73  33.4720474           Root MSE      =  3.4389
            
            ------------------------------------------------------------------------------
                     mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
                  weight |  -.0060087   .0005179   -11.60   0.000    -.0070411   -.0049763
                   _cons |   39.44028   1.614003    24.44   0.000     36.22283    42.65774
            ------------------------------------------------------------------------------
            Edit: 3.4389 = square root of 851.469256 divided by 72
            Last edited by Eric de Souza; 12 Jun 2015, 09:49.

            Comment


            • #7
              Could you please tell me if it is also correct to calculate the idiosyncratic risk as the standard deviation of the residuals by using Stata command sd(residuals)? Or Root MSE measure should be used instead? The values generated from sd(residuals) and Root MSE are almost the same.

              Comment


              • #8
                Originally posted by Maarten Buis View Post
                The standard deviation of the residuals is stored directly after regress in e(rmse). I assume you want to do many regressions for different groups (countries, companies, industries, herds, ...). In that case statsby is your friend:

                Code:
                // open an example dataset
                sysuse nlsw88, clear
                
                // store the standard deviation of the residual
                // for each industry
                statsby rmse=e(rmse), by(industry) : ///
                regress wage grade ttl_exp
                
                // admire the result
                list
                Hello Maarten Buis, I am also trying to compute the idiosyncratic volatility as based on the standard deviation of regression residuals.

                I computed the residuals as

                bys DSCode : asreg Excess_USD_w MKT SMB HML, wind(ymdate 24) min(24) fit

                This eliminated 24 months of observations. Now, I want to compute the standard deviation of the residuals. Would you have any feedback on how to do that?

                I tried the your method, but it didnt work.

                Thank you kindly.

                Comment


                • #9
                  Kate Lussy I don't think it will help you to ask this here. This thread doesn't touch on the issues specific to your kind of problem, i.e. moving windows and volatility. (At a rough guess, 5% of readers here are comfortable with volatility.)

                  Also, "I tried your method, but it didn't work" is unfortunately unanswerable. See FAQ Advice #12 (where also it's explained that references to community-contributed commands should include an explanation of where they come from -- e.g. asreg is from SSC.)

                  You have already posted in several threads. Whatever question you still have is much, much better pursued elsewhere in one of the threads in which you have already posted.

                  Comment


                  • #10
                    Kate Lussy I would recommend studying the help file of asreg. It will be an investment for the future.
                    Code:
                    ssc install asreg
                    help asreg
                    The reason I am saying this is that you have asked several questions in different posts related to asreg, and these questions had kind of answers in the help file of asreg. For the RMSE question, the help file of asreg has some details and examples. So for reporting rmse, your code will be
                    Code:
                    bys DSCode : asreg Excess_USD_w MKT SMB HML, wind(ymdate 24) min(24) fit rmse
                    stastby vs asreg

                    Maarten suggested statsby for finding rmse if several regressions are to be estimated. I would recommend asreg here as an alternative to stastby on the basis of speed. If the dataset is huge, statsby can be considerably slower. asreg is an order of magnitude faster than statsby for by-group regressions; and faster than rolling for rolling window regressions. To reproduce the results of post #2 with asreg, the code would be:
                    Code:
                    sysuse nlsw88, clear
                    
                    bys industry: asreg wage grade ttl_exp, rmse
                    bys industry: keep if _n == 1
                    list industry _*
                    
                         +-----------------------------------------------------------------------------------------------------------+
                         |                industry       _rmse   _Nobs         _R2      _adjR2    _b_grade   _b_ttl_exp      _b_cons |
                         |-----------------------------------------------------------------------------------------------------------|
                      1. |   Ag/Forestry/Fisheries   2.4269003      17   .50499407   .43427894    .2901732    .38743288   -2.1341333 |
                      2. |                  Mining   15.708194       4   .40870436   .11305653   7.0731403   -4.9845504            0 |
                      3. |            Construction   4.6487536      29   .22703437   .16757548   .99978563    .07680074   -5.5147319 |
                      4. |           Manufacturing   4.9607801     366   .15308072    .1484145   .88453042    .17910773   -5.5858387 |
                      5. |  Transport/Comm/Utility   5.9029501      90   .09287709   .07202369   .31476356    .36747008    1.9577005 |
                         |-----------------------------------------------------------------------------------------------------------|
                      6. |  Wholesale/Retail Trade   5.3327527     333   .06928114   .06364042   .44335271    .20198193   -1.5458622 |
                      7. | Finance/Ins/Real Estate   7.9309108     192   .10401973   .09453846   1.1658305    .44940966   -11.295337 |
                      8. |     Business/Repair Svc   6.1767782      86   .10395108   .08235954   .63918271    .15574091   -2.2791327 |
                      9. |       Personal Services   2.5729809      97   .04681653   .02653603   .18827182     .0760337    1.5362852 |
                     10. |   Entertainment/Rec Svc   3.1128365      17   .48867465   .41562817   .03640715    .52391517    .53918414 |
                         |-----------------------------------------------------------------------------------------------------------|
                     11. |   Professional Services   4.6239428     823   .18492817   .18294019   .70233479    .17569274   -4.3006081 |
                     12. |   Public Administration   4.3371759     176   .26513799   .25664247   1.0191996    .28726858   -8.7086121 |
                     13. |                       .   2.5888026      14    .5182716   .43068461   .47510307    .28944586   -3.4181648 |
                         +-----------------------------------------------------------------------------------------------------------+
                    
                    .
                    Last edited by Attaullah Shah; 06 May 2019, 10:24.
                    Regards
                    --------------------------------------------------
                    Attaullah Shah, PhD.
                    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                    FinTechProfessor.com
                    https://asdocx.com
                    Check out my asdoc program, which sends outputs to MS Word.
                    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                    Comment

                    Working...
                    X