Announcement

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

  • asreg : Updated 2021: new flexible window | Fastest rolling regressions in Stata

    Thanks to Kit Baum, the updated version of asreg is now available on the SSC. The new version is version: 4.2; Date Jan 31, 2021.
    Following are the key highlights of the new version

    1. Changes made to the window() option
    Version 4.0 of asreg introduces a more flexible window to identify observation in a given range. Previously, the window() option of asreg would take two inputs: the first one as the range variable (such as date) and the second one as the length of the rolling window. In the older versions, the window would always look backward. This has changed in version 4.0.

    The window argument can now take up to three arguments. The window can now look backward, forward, and both back and forward. More details can be read in the help file under the option window()

    2. Improved algorithm for rolling window indices
    This version of asreg (version 4.0) significantly improves the calculation speed of the required statistics, thanks to the development of a more efficient algorithm for extracting rolling window indices. This has resulted in a significant speed advantage for asreg compared to its previous versions or other available programs. The speed efficiency matters more in larger datasets.

    3. Exclude observations with option exclude()
    Option exclude() can be used to exclude specific observations from regressions. This option requires three arguments, with or without using the comma character. The first is the range variable such as daily, weekly, monthly or yearly date; the second and third arguments are the lower and upper bounds of the range variable. The definitions and working of option exclude(rangevar #low #high) are similar to that of the option window(rangevar #from #upto).

    Examples:

    Example 1: Regression for each company in a rolling window of last 10 years

    Code:
        . webuse grunfeld, clear
     
        . bys company: asreg invest mvalue kstock, wind(year 10)
    OR

    Code:
        . bys company: asreg invest mvalue kstock, wind(year -10 0)

    Example 2: Regression for each company in a rolling window of 10 years; 5 past and 5 forward

    Code:
     . bys company: asreg invest mvalue kstock, wind(year -5 5)

    Example 3: Regression for each company in a rolling window of 10 leading years

    Code:
      . bys company: asreg invest mvalue kstock, wind(year 0 10)
    Example 4: Regression for each company in a recursive window

    .
    Code:
    webuse grunfeld, clear
     
        . bys company: asreg invest mvalue kstock, wind(year 10) rec
    OR

    Code:
    . bys company: asreg invest mvalue kstock, wind(year 1000)

    Example 5: Using option minimum - Limit regression to a minimum of 5 observations

    .
    Code:
     webuse grunfeld, clear
     
     . bys company: asreg invest mvalue kstock, wind(year 10) min(5)


    Example 6: Reporting standard errors

    Code:
      . webuse grunfeld, clear
     
     . bys company: asreg invest mvalue kstock, wind(year 10) se

    Example 7: Newey-West standard errors, lag(1)

    Code:
    . webuse grunfeld, clear
     
     . bys company: asreg invest mvalue kstock, wind(year 10) se newey(1)

    Example 8: Robust standard errors

    Code:
      . webuse grunfeld, clear
     
     . bys company: asreg invest mvalue kstock, wind(year 10) robust


    Example 9: Reporting standard errors, fitted values and residuals

    Code:
        . webuse grunfeld, clear
     
     . bys company: asreg invest mvalue kstock, wind(year 10) se fit

    Example 10: Regressions without constant

    Code:
     . webuse grunfeld, clear
     
     . bys company: asreg invest mvalue kstock, wind(year 10) noc


    Example 11: No window - by groups regressions

    Code:
      . webuse grunfeld, clear
     
     . bys company: asreg invest mvalue kstock


    Example 12: Yearly cross-sectional regressions

    Code:
        . webuse grunfeld, clear
     
     . bys year: asreg invest mvalue kstock

    Example 13: Rolling regression - reporting RMSE

    Code:
      . webuse grunfeld, clear
     
     . bys company: asreg invest mvalue kstock, w(year 10) rmse

    Example 14: Fama and McBeth Regression

    Code:
      . webuse grunfeld, clear
     
     . asreg invest mvalue kstock, fmb
    Example 15: Fama and McBeth Regression - using Newey-West errors

    Code:
    . webuse grunfeld, clear
     
     . asreg invest mvalue kstock, fmb newey(1)

    Example 16: Fama and McBeth Regression - report first stage regression

    Code:
      . webuse grunfeld, clear
     
     . asreg invest mvalue kstock, fmb first

    Example 17: Fama and McBeth Regression - save first stage results

    Code:
    . webuse grunfeld, clear
     
        . asreg invest mvalue kstock, fmb save(FirstStage)

    Example 18: Exclude focal observation in cross-sectional regressions

    Code:
      . webuse grunfeld, clear
     
     . bys company: asreg invest mvalue kstock, exclude(year 0 0)
    Example 19: Exclude 5 most recent observations (the focal observation and 4 others from the recent past)

    Code:
     . webuse grunfeld, clear
     
        . bys company: asreg invest mvalue kstock, exclude(year -4 0)
    For more discussion and example, visit the asreg webpage 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.

  • #2
    Dear Pof. Attaullah Shah,
    I have a panel data with variables: firmid, year, and rdexpenditure. I want to use asreg to get the standard deviation of the residuals from the R&D expenditure trend of the firm over the past 3 years. The commands are:

    asreg rdexpenditure year, window(year 3) by(firmid) fitted
    predict e, res

    Results are attached.
    I'm comfused about the differences between the new generated _residuals and predicted e. Could you help? Thank you very munch!
    Attached Files

    Comment


    • #3
      Using just three observations for a regression is not a good idea. Anyway, _fitted values are the predicted values and _residuals are the residuals, which I think what you are trying to find out. You cannot use the predict command after asreg, as asreg is synonymous to reg. Given that you have use a window, asreg finds the predicted and residual values based on that window.
      Last edited by Attaullah Shah; 28 Jul 2021, 09:14.
      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


      • #4
        Originally posted by Attaullah Shah View Post
        Using just three observations for a regression is not a good idea. Anyway, _fitted values are the predicted values and _residuals are the residuals, which I think what you are trying to find out. You cannot use the predict command after asreg, as asreg is synonymous to reg. Given that you have use a window, asreg finds the predicted and residual values based on that window.
        Thank your for your reply. I can use more obervations for each window. Yet, I'm still confused. Since _residuals=rdexpenditure-_fitted , why the first two residuals of each group are missing? Normally we can use predict after reg to get the residuals. Do you mean asreg returns predicted _residuals based on group and window regression while the e I got are residuals based on a regular regression?

        Comment


        • #5
          That's true, asreg finds residuals within the context of each group or window regression. Since the first two observations do not have estimated regression coefficients, residuals cannot be calculated.
          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