Announcement

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

  • ASREG version update: Rolling regression, newey, Fama and MacBeth regressions ...

    Thanks to Kit Baum. Version 2.0 of asreg is now available on SSC. To install or update it, type:
    Code:
    ssc install asreg, replace
    Details related to syntax and options with examples are listed on this page of my website : https://StataProfessor.com/stata-pro...ions-in-stata/

    Description

    asreg can fit three types of regression models; (1) a model of depvar on indepvars using linear regression in a user's defined rolling window or recursive window (2) cross-sectional regressions or regressions by a grouping variable (3) Fama and MacBeth (1973) two-step procedure. asreg is order of magnitude faster than estimating rolling window regressions through conventional methods such as Stata loops or using the Stata's official rolling command. asreg has the same speed efficiency as asrol. All the rolling window calculations, estimation of regression parameters, and writing of results to Stata variables are done in the Mata language. asreg reports most commonly used regression statistics such as number of observations, r-squared, adjusted r-squared, constant, slope coefficients, standard errors of the coefficients, fitted values, and regression residuals.

    Here, I would like to highlight only the updates in this version.


    1. Fama and MacBeth(1973) regression

    This version of asreg has option fmb. Option fmb applies a two-step Fama-MacBeth procedure. The first step involves estimation of N cross-sectional regressions and the second steps involves T time-series averages of the coefficients of the N-cross-sectional regressions. The standard errors are adjusted for cross-sectional dependence. This is generally an acceptable solution when there is a large number of cross-sectional units and a relatively small time series for each cross-sectional unit. However, if both cross-sectional and time-series dependencies are suspected in the data set, then Newey-West consistent standard errors can be used. asreg uses the first method as a default. To know more about this option, visit my web page


    2. Newey-West standard errors
    Option newey specifies the number of lags for estimation of Newey-West consistent standard errors. asreg allows option newey to be used in both the rolling regressions and Fama-MacBeth regressions. In the rolling regressions, newey will work only when option se is used. Also, please note that without using option newey, option se estimates normal standard errors of OLS.


    3. RMSE
    This option is used in rolling regression, and hence it will work only when option window is specified. This option reports root-mean-square error of OLS regression


    4. Rolling window algorithm
    Since real-life data can come in a variety of structures, a static code for extracting the rolling-window from the data is always costly in terms of time. This version of asreg has more than 6 routines in the Mata language that are meant for different data structures. Therefore, asreg speed efficiency is ensured whether the data is rectangular (balanced panel), non-rectangular, has duplicates, has missing values, or has both duplicates and missing values.
    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

  • #2
    Hi everyone
    There is a small update for asreg. Version 2.0 has a small bug that causes error when option newey is specified with more than one lags, e.g., newey(2). Version 2.1 is available from the following web page to fix this bug. Further, the updated version will also be soon available on SSC. To update, type:
    Code:
    net install asreg, from(http://stataprofessor.com) replace
    .
    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


    • #3
      Hi Attaullah,

      Thanks so much for writing this command. It's super efficient when handling large panel data.
      I'm having 1 question. I need to retrieve r2 for each regression for each firmid_quarter. However the asreg output files only give me r2 for each quarter.
      My command is as follow. Can you help? Thanks again.

      bys id quarter: asreg y x, wind(quarter 12) fmb save(eq1) first

      Regards,

      April Nguyen
      PhD Student in Management, Accounting track
      Questrom School of Business
      Boston University

      Comment


      • #4
        Dear Ngan Nguyen
        I think you have already studied the Fama & MacBeth (1973) methodology. This is a two-step procedure. In the first step, we estimate N cross-sectional regressions. For example, load the grunfeld dataset from web
        Code:
        webuse grunfeld
        In this data set, we have 10 companies, each one having 20 years of data. Therefore, the first stage in FMB procedure is to estimate 20 regressions (i.e. one regression in each year), each regression having 10 companies. Using asreg with fmb and first options will report these regressions. see below;

        Code:
         asreg invest mvalue, fmb save(eq1) first
        
        
        First stage Fama-McBeth regression results
        
              +-------------------------------------------------+
              | _TimeVar   _obs       _R2   _b_mva~e      _Cons |
              |-------------------------------------------------|
              |     1935     10    .86526    .102534    .205841 |
              |     1936     10    .69566    .084087    10.8287 |
              |     1937     10    .65365    .078748    15.9915 |
              |     1938     10   .634906    .078951    10.6719 |
              |     1939     10   .786631     .07066    4.19547 |
              |     1940     10   .819947    .099193    .778946 |
              |     1941     10   .844383    .119614    9.58541 |
              |     1942     10   .854649    .146412   -6.30129 |
              |     1943     10   .835023    .121626   -3.24821 |
              |     1944     10   .871591    .118681    -1.0518 |
              |     1945     10   .904664    .109082   -.206266 |
              |     1946     10   .894734    .138123    -4.9362 |
              |     1947     10   .891227    .163409   -4.39361 |
              |     1948     10   .786845    .170411    1.09255 |
              |     1949     10   .861598    .154097   -2.14842 |
              |     1950     10   .857179     .17149   -16.4937 |
              |     1951     10   .863529    .162703    3.02421 |
              |     1952     10   .843368    .183678   -6.36933 |
              |     1953     10   .885967    .206258   -29.2206 |
              |     1954     10   .855808    .242492   -74.9082 |
              |-------------------------------------------------|
         Mean |   1944.5     10   .825331    .136112   -4.64516 |
              +-------------------------------------------------+

        In the second stage, we then find time-series averages of the coefficients and their standard errors. See that the mvalue coefficient is the same as the average of the 20 cross-sectional regressions.

        Code:
        Fama-MacBeth (1973) Two-Step procedure           Number of obs     =       200
                                                         Num. time periods =        20
                                                         F(  1,    19)     =    174.39
                                                         Prob > F          =    0.0000
                                                         avg. R-squared    =    0.8253
        ------------------------------------------------------------------------------
                     |            Fama-MacBeth
              invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
              mvalue |   .1361124    .010307    13.21   0.000     .1145396    .1576852
               _cons |  -4.645156    4.30825    -1.08   0.294    -13.66243    4.372114
        ------------------------------------------------------------------------------
        Summary:
        The possibility you are asking for is not supported by the Fama and MacBeth procedure. You are asking for R2 for each company and in each period, that is not possible as there are no company-specific regressions in FMB.
        Please also note that bys id quarter prefix and option window() are not required while using fmb option. Hence results with or without this prefix will remain the same.

        And if you intend to just estimate rolling regression, then drop the options fmb, first, and save i.e.

        Code:
        bys company year: asreg invest mvalue, wind(year 6)
        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


        • #5
          Version 2.1 is now available on SSC.
          Code:
          ssc install asreg, replace
          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


          • #6
            Dear Attaullah Shah,

            I have 2 questions for you, as i am using the asreg, fmb command.

            1)
            In the examples it looks like that the independent variables are NOT the Beta-variables obtained from a first run Time-series regression (to run the Cross-section with obtained Beta's)

            So is it true that to use ASREG I don't have to obtain the Beta's myself, but that i can just put in the variables in the regression? It looks also like that for xtfmb, but i can't be sure.

            Put differently, does the asreg code obtain the Beta's from Time-series regression automatically before performing the first-stage Cross-sectional regression obtaining the CS coefficients (Lambda's)


            I have tried to follow the 3 steps:
            1) obtain TS Beta's
            2) run CS with TS Beta's
            3) average the CS coefficient Lambda's

            Does ASREG perform all 3 steps or only 2 and 3?
            Thing is that I get very strange results when running asreg DependendVar BetaA BetaB, fmb, instead asreg DependendVar A B, fmb looks te perform more coherent with the research results I would like to replicate, but I am uncertain about the variables to put in the command, just the normal variables or instead the TS Beta's

            2)
            The goal of my cross-sectional regression would be to obtain the Cross-sectional residual (error term)

            Is it true that the constant provided by saving the FirstStage output resembles the error term per time unit?

            Thanks for consideration

            Comment


            • #7
              Dear Thomas Hunfeld
              If you read my reply in post # 4 above, it reads "This is a two-step procedure. In the first step, we estimate N cross-sectional regressions". Therefore, to your question
              Does ASREG perform all 3 steps or only 2 and 3?
              My answer is that asreg performs only the last two steps.
              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


              • #8
                Thank you for this answer and I am grateful for the command, because in the example normal variable-names were used, I was confused, but now I know for certain that it should be the TS Beta's.

                Would you be so kind to state that i am correct when: i obtain the FMB cross-sectional residual by running predict residual after the asreg cons beta1 beta3, fmb? Or would there be a other option command?

                Yours sincerely,

                Thomas

                Comment


                • #9
                  Dear Professor Shah,


                  thank you very much for the update! This command has been very useful in my thesis work.

                  If allowed, I'd like to ask a question about an error message when using asreg command:

                  tsset id yrm
                  bys id: asreg re rme, wind(yrm 24)


                  id is the stock number, yrm is the month of observation. I wanted to run a rolling regression for each stock using a 24-month window. However, it returns this error message...

                  ASREG2(): 3001 expected 1 arguments but received 8
                  ASREGW(): - function returned error
                  <istmt>: - function returned error
                  r(3001);


                  I used another set of test data, and it could run smoothly. But with my original data, it just couldn't get through. Would you help me identify where might be wrong?

                  Thank you very much!


                  Best regards,
                  Yaqi Wang

                  Comment


                  • #10
                    Dear Yaqi Wang, please update asreg by typing
                    Code:
                      
                     ssc install asreg, replace
                    If the problem still exists, please privately share your dataset with me through Dropbox. My Dropbox email is attashah15@hotmail.com
                    Thanks for your comments.
                    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


                    • #11
                      Thank you very much. It worked well now! I guess my update to the newest version hadn't finished yet and I somehow interrupted it...
                      Thanks again for all the great commands you wrote!


                      Best,
                      Yaqi Wang

                      Comment


                      • #12
                        Dear Dr Shah,

                        Thank you very much for providing asreg, which is a very efficient way to estimate Fama-MacBeth regression. I would like to ask how I can report the Avg. R-square (into Excel), using outreg2.

                        Best regards,
                        Wendy

                        Comment


                        • #13
                          Dear Professor Shah,

                          I would like to ask whether we have an option for no constant (set constant equals zero) when using asreg for Fama and Macbeth regression.

                          Sincerely,
                          Huong

                          Comment


                          • #14
                            Option noconstant was added to asreg version 3.1.1 (26 July, 2018). However, that option works only with rolling window regressions and by-group regressions. I shall consider adding noconstant for option fmb in the next update.
                            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


                            • #15
                              Thank you, Professor Shah.
                              Sincerely,
                              Huong

                              Comment

                              Working...
                              X