Announcement

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

  • Creating Idiosyncratic and Syncratic Risk Variables

    Hi all,

    I am attempting to create Idiosyncratic, and Systematic risk variables outlined in the steps below.

    "A firm's idiosyncratic risk is the standard deviation of residuals from a regression of its daily excess stock returns (raw returns less the riskless rate) on the market factor (i.e., the value-weighted market return less the riskless rate).3 One firm-year observation of idiosyncratic risk is computed using firm-specific daily stock returns from one calendar year."

    "Systematic Risk = A firm's systematic risk is the standard deviation of the predicted value from the above regression used to define idiosyncratic risk."

    I currently have the following code;

    *Calculate Beta
    gen mofd = mofd(stata_date)
    gen year = year(stata_date)
    ssc install asreg
    bys gvkey : asreg excess_return mkt_fct, wind(mofd 24)
    *Or change window
    bys gvkey : asreg excess_return mkt_fct, wind(year 1)
    rename _b_cons Beta

    *Calculating Idosyncratic risk
    bys gvkey : asreg excess_return mkt_fct, wind (mofd 24)
    predict resid, resid
    summ resid
    egen IDIO_RISK = sd(resid), by(gvkey Year)


    I am struggling to reconcile the these monthly rolling window observations to one yearly firm observations. Whatsmore many of the observations appear to be negative which cannot be right.

    Please let me know where I have gone wrong.

    Cheers,
    Flynn

  • #2
    Code:
    clear all
    version 18
    
    getsymbols     AMZN ^GSPC , fm(1) fd(1) fy(2018) lm(12) ld(31) ly(2023)              ///
                frequency(d) price(adjclose) clear yahoo keepall
    g t = _n
    tsset t
    
    g year = year(period)
    tab year
    
    capture drop _*
    asreg r_AMZN r__GSPC , by(year) fitted
    tabstat _b_r__GSPC, by(year) stats(mean)
    tabstat _residuals, by(year) stats(sd)

    Comment


    • #3
      Thanks George, thats helpful.

      Apologies I was not initially clear, I am working with a panel dataset with daily firm observations.

      Comment


      • #4
        You can do it with a panel. Do you want it by year, or a rolling value over 251 trading days?

        Comment


        • #5
          By year end, for the entire year. Ideally then I could drop all other 250 daily observations and then merge that with annual firm fundamental data. I would assume rolling would take a long time to run that many daily iterations?

          Comment


          • #6
            Code:
            getsymbols     AMZN GOOG T AAPL TSLA ^GSPC , fm(1) fd(1) fy(2018) lm(12) ld(31) ly(2023)              ///
                        frequency(d) price(adjclose) clear yahoo keepall
            
            keep daten period r_*
            ren r__GSPC mkt
            ren r_* return_*
            
            reshape long return_, i(period) j(which) string
            
            g year = year(period)
            tab year
            
            egen firm_year = group(firm year)
            
            asreg return mkt , by(firm_year) fitted
            rename _b_mkt beta
            collapse (mean) beta (sd) _residuals, by(firm year)

            Comment


            • #7
              Fantastic, thanks George, and this is just for systematic risk?

              Comment


              • #8
                _residuals gives you the stan dev of the residuals.

                Comment


                • #9
                  Thanks George, apologies for peppering you with questions, but while i've got you here I was wondering if you had any experience running Fama Macbeth regressions with unbalanced panel data.

                  The data in question is unbalanced as I have firm fundamental information by year over the period 1987 - 2023. Naturally firms IPO at later dates or cease trading at various stages over this period.

                  I am running the following code;

                  logit DivPayer idiosyncratic_volatility M2B Asset_Growth Profitability SIZE

                  estimates store logit_model
                  estimates table logit_model, eform
                  xtset gvkey stata_date

                  newey DivPayer Legislation_Dummy idiosyncratic_volatility M2B Asset_Growth sqrt_profitability SIZE, lag(2)

                  However I get a

                  "year is not regularly spaced
                  r(198);"

                  error when attempting to run the code. Any idea how to resolve this issue?

                  Cheers,
                  Flynn






                  Comment


                  • #10
                    xtset and lag models will mess with you when you have irregularly spaced data.

                    look at asreg. it does fmh analysis, but not sure it will help with the spacing.

                    Comment

                    Working...
                    X