Announcement

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

  • Rangestat to regress multiple values in panel

    Hello everyone,

    I have a panel along the variables Dates and gvkey and am trying to calculate the volatility of the residuals of my regressions along daily values within the panel. I am currently stuck with the rangestat code as I get a return "no result for all obs: reg exret MktRF SMB HML"

    I understood that the code below would go through each row for given Dates (for each gvkey value, so they is only one observation for given Dates) and create the regression. But maybe I misunderstood the instructions?

    Any help would be most appreciated!

    Thanks
    Micha

    Code:
    rangestat (reg) exret MktRF SMB HML, by (gvkey) interval(Dates 0 0)
    
    
    Dates    gvkey    exret    SMB    HML    MktRF
    04jan2005    1045    -.1012971    -.58    .44    -1.3
    05jan2005    1045    -.1039042    -1.11    0    -.51
    06jan2005    1045    -.0411491    -.14    .13    .34
    07jan2005    1045    .0034286    -.76    -.02    -.22
    10jan2005    1045    -.0147796    .27    .04    .42
    11jan2005    1045    -.0136883    -.35    .3    -.68
    12jan2005    1045    -.0205858    -.04    -.16    .38
    13jan2005    1045    -.0311749    .13    .38    -.77
    14jan2005    1045    .0240284    .55    .07    .66
    18jan2005    1045    .0115402    .16    -.17    .97
    19jan2005    1045    -.0204013    -.13    .48    -.97
    20jan2005    1045    -.0171325    -.12    -.05    -.77
    21jan2005    1045    -.0471705    .29    .25    -.56
    24jan2005    1045    -.0691511    -.8    .62    -.49
    25jan2005    1045    .0443627    .2    -.37    .34
    26jan2005    1045    -.0055729    .95    -.21    .62
    27jan2005    1045    -.0092107    .17    .04    .08
    04jan2005    1078    -.0180707    -.58    .44    -1.3
    05jan2005    1078    -.0194719    -1.11    0    -.51
    06jan2005    1078    .0145532    -.14    .13    .34
    07jan2005    1078    .0091306    -.76    -.02    -.22
    10jan2005    1078    .0016842    .27    .04    .42
    11jan2005    1078    -.0263486    -.35    .3    -.68
    12jan2005    1078    -.0110956    -.04    -.16    .38
    13jan2005    1078    -.0271775    .13    .38    -.77
    14jan2005    1078    -.0032205    .55    .07    .66
    18jan2005    1078    -.0125405    .16    -.17    .97
    19jan2005    1078    -.0077828    -.13    .48    -.97
    20jan2005    1078    -.0145146    -.12    -.05    -.77
    21jan2005    1078    -.0029727    .29    .25    -.56
    24jan2005    1078    -.0090875    -.8    .62    -.49
    25jan2005    1078    -.0084355    .2    -.37    .34
    26jan2005    1078    -.0084357    .95    -.21    .62
    27jan2005    1078    -.0173702    .17    .04    .08

  • #2
    The -rangestat- command you wrote goes through the observations one by one. For each observation it identifies all other observations in the data set that have the same gvkey and the same value of Dates. Since gvkey and Dates uniquely identify observations in the data, there is only one such observation, and you cannot do a regression on a single observation.

    But as I don't know what you actually wanted to do, I can't tell you how to fix it. I do not know what you mean by "calculate the volatility of the residuals of my regressions along daily values within the panel."

    I imagine that you want to restrict the regression to observations with the same gvkey, but it is unclear which dates for that gvkey you want to include in the regression.

    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 15.1 or a fully updated version 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      In the following codes, I am using asreg for estimating regression over groups with residuals for each observation. asreg can be downloaded from SSC. You can read further about asreg on my website here.
      Code:
      * Install asreg
      ssc install asreg
      
      * The sample dataset
      clear
      input int(Dates gvkey) double(exret SMB HML MktRF)
      16440 1045 -.1012971  -.58  .44 -1.3
      16441 1045 -.1039042 -1.11    0 -.51
      16442 1045 -.0411491  -.14  .13  .34
      16443 1045  .0034286  -.76 -.02 -.22
      16446 1045 -.0147796   .27  .04  .42
      16447 1045 -.0136883  -.35   .3 -.68
      16448 1045 -.0205858  -.04 -.16  .38
      16449 1045 -.0311749   .13  .38 -.77
      16450 1045  .0240284   .55  .07  .66
      16454 1045  .0115402   .16 -.17  .97
      16455 1045 -.0204013  -.13  .48 -.97
      16456 1045 -.0171325  -.12 -.05 -.77
      16457 1045 -.0471705   .29  .25 -.56
      16460 1045 -.0691511   -.8  .62 -.49
      16461 1045  .0443627    .2 -.37  .34
      16462 1045 -.0055729   .95 -.21  .62
      16463 1045 -.0092107   .17  .04  .08
      16440 1078 -.0180707  -.58  .44 -1.3
      16441 1078 -.0194719 -1.11    0 -.51
      16442 1078  .0145532  -.14  .13  .34
      16443 1078  .0091306  -.76 -.02 -.22
      16446 1078  .0016842   .27  .04  .42
      16447 1078 -.0263486  -.35   .3 -.68
      16448 1078 -.0110956  -.04 -.16  .38
      16449 1078 -.0271775   .13  .38 -.77
      16450 1078 -.0032205   .55  .07  .66
      16454 1078 -.0125405   .16 -.17  .97
      16455 1078 -.0077828  -.13  .48 -.97
      16456 1078 -.0145146  -.12 -.05 -.77
      16457 1078 -.0029727   .29  .25 -.56
      16460 1078 -.0090875   -.8  .62 -.49
      16461 1078 -.0084355    .2 -.37  .34
      16462 1078 -.0084357   .95 -.21  .62
      16463 1078 -.0173702   .17  .04  .08
      end
      format %tddd-Mon-YY Dates
      
      * The asreg code
      bys gvkey: asreg exret SMB HML MktRF, fit
      
      * List the first 10 observations
      list _* in 1/10
      
           +-----------------------------------------------------------------------------------------------------------+
           | _Nobs         _R2      _adjR2      _b_SMB       _b_HML    _b_MktRF      _b_cons      _fitted   _residuals |
           |-----------------------------------------------------------------------------------------------------------|
        1. |    17   .53629473   .42928582   .03110007   -.04176739   .01098966   -.01589142   -.06659367   -.03470343 |
        2. |    17   .53629473   .42928582   .03110007   -.04176739   .01098966   -.01589142   -.05601723   -.04788697 |
        3. |    17   .53629473   .42928582   .03110007   -.04176739   .01098966   -.01589142   -.02193871   -.01921039 |
        4. |    17   .53629473   .42928582   .03110007   -.04176739   .01098966   -.01589142   -.04110985    .04453845 |
        5. |    17   .53629473   .42928582   .03110007   -.04176739   .01098966   -.01589142   -.00454944   -.01023016 |
           |-----------------------------------------------------------------------------------------------------------|
        6. |    17   .53629473   .42928582   .03110007   -.04176739   .01098966   -.01589142   -.04677963    .03309133 |
        7. |    17   .53629473   .42928582   .03110007   -.04176739   .01098966   -.01589142   -.00627657   -.01430923 |
        8. |    17   .53629473   .42928582   .03110007   -.04176739   .01098966   -.01589142   -.03618206    .00500716 |
        9. |    17   .53629473   .42928582   .03110007   -.04176739   .01098966   -.01589142    .00554308    .01848532 |
       10. |    17   .53629473   .42928582   .03110007   -.04176739   .01098966   -.01589142    .00684502    .00469518 |
           +-----------------------------------------------------------------------------------------------------------+
      Regards
      --------------------------------------------------
      Attaullah Shah, PhD.
      Associate Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
      www.FinTechProfessor.com
      If you use MS Word, do check my asdoc program that easily sends Stata output to MS Word

      Comment


      • #4
        Hi Clyde,

        very sorry, my bad, for a second I forgot how regressions work (was a bit late in the day). Got it working now. Thanks!

        @Attaullah: thanks for the hint will check out asreg!

        Best,
        Micha

        Comment

        Working...
        X