Announcement

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

  • Month-wise regressions using daily data

    Dear Stata comunity,

    I need to run month-wise fama and french three factor model regressions using daily data. I have got the following code from one of my friends, but it has some bug. When i run this code, it works only for one stock for one year. Further i require that the code should ignore the stock-month combinations where no of daily returns observation is less than 17.


    egen ccode = group(Stock)
    egen count_check = count(ccode), by(ccode month year) /* Generate the count of the unique_id combination to check if there are minimum number of observations for the regression */
    drop if count_check <=1 /* drops all firm month combinations where the number of trading days is less than 1 */


    egen ccode_month_year = group(Stock month year) /* I have groued it by stock month and year so that you can use this code for other years too */
    gen resid_reg =. /* Creating a variable to store the residuals */

    /* You have to count the number of unique firm_month id... for that you can use the following command */
    egen max = max(ccode_month_year)
    disp max

    /* This will do the regressions and store the residuals in the resid_reg variable */

    forvalues i = 1(1)9 {
    regress Rt Mkt SMB HML if ccode_month_year==`i'
    predict temp , resid
    replace resid_reg = temp if ccode_month_year==`i'
    drop temp
    }


    Kindly look into it and advise.

  • #2
    You can use asreg for this. See this example
    Code:
    ssc install asreg
    bys ccode_month_year: asreg Rt Mkt SMB HML, fit min(17)
    1. Please note that the prefix bys ccode_month_year eliminates the need for looping.

    2. option fit will generate fitted and residuals for each ccode_month_year

    3. The option min(17) ensures that at least 17 observations are available for the regression

    You can read more about asreg here
    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


    • #3
      Thanks Prof. Attaullah Shah, I have one more small problem. I require a code that calculates for each month standard deviation from the residuals and multiplies the value with square root of number of trading days in each month. The output should get saved in same work file that contains data for calculations. I am attaching an excel file so that you have idea of the structure of data.
      Regards,
      Attached Files

      Comment


      • #4
        I hope someone might be ready to help you with this as this would need more than just quick help. And, yes, you can have a quote from us for any customized legitimate help https://fintechprofessor.com/paid-help/
        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