Announcement

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

  • rangestat: regress by group, but not rolling window (for entire time window)

    Just two quick questions.

    1) Is it possible to use rangestat to do regressions by group, but not for a rolling window. I want to do one individual regression for each group (over the entire time window). Is it possible to run rangestat without

    Code:
    interval(keyvar low high)
    2) If it is not possible to use rangestat, by group (without using a rolling window), is there another command that would allow me to do that and save the resulting residuals?


  • #2
    You can't omit the -interval()- option, but you can use it to specify that you want the entire window with -interval(keyvar . .)-.

    Added: Since you want to get the residuals, you might find it easier to do this with -runby- (by Robert Picard and me, available form SSC). The technique, here illustrated with the auto.dta is:
    Code:
    clear*
    sysuse auto
    
    capture program drop one_group
    program define one_group
        regress price mpg headroom
        predict residual, residual
        foreach v of varlist mpg headroom {
            gen b_`v' = _b[`v']
            gen se_`v' = _se[`v']
        }
        exit
        gen reg_nobs = e(N)
        gen reg_r2 = e(r2)
        gen reg_adj_r2 = e(adj_r2)
    end
    
    runby one_group, by(rep78)
    Last edited by Clyde Schechter; 09 Jul 2021, 18:10.

    Comment


    • #3
      Thank you very much Clyde. Perfect.

      Have a good weekend.

      Comment


      • #4
        For reference, here is the equivalent code with rangestat (from SSC, as you are asked to explain):

        Code:
        clear*
        sysuse auto
        
        rangestat (reg) price mpg headroom, interval(mpg . .) by(rep78)
        
        gen double residual = price - b_mpg * mpg - b_headroom * headroom - b_cons

        Comment


        • #5
          Yet, another solution using asreg is presented below.
          Code:
          ssc install asreg
          
          bys rep78: asreg price mpg headroom, fit
          
               +----------------------------------------------------------------------+
               | _Nobs         _R2       _b_mpg   _b_headr~m     _b_cons   _residuals |
               |----------------------------------------------------------------------|
            1. |     .           .            .            .           .            . |
            2. |     .           .            .            .           .            . |
            3. |     8   .81320598   -1349.3739   -2856.1494   41413.904    1215.5722 |
            4. |     8   .81320598   -1349.3739   -2856.1494   41413.904   -1690.5772 |
            5. |     8   .81320598   -1349.3739   -2856.1494   41413.904     720.1236 |
               |----------------------------------------------------------------------|
            6. |     8   .81320598   -1349.3739   -2856.1494   41413.904   -911.38055 |
            7. |     8   .81320598   -1349.3739   -2856.1494   41413.904    1973.8526 |
            8. |     8   .81320598   -1349.3739   -2856.1494   41413.904    -2513.325 |
            9. |     8   .81320598   -1349.3739   -2856.1494   41413.904    350.36719 |
           10. |     8   .81320598   -1349.3739   -2856.1494   41413.904    855.36719 |
               +----------------------------------------------------------------------+
          More details on asreg can be found here
          https://fintechprofessor.com/2017/12...ions-in-stata/
          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