Announcement

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

  • New code for mean portfolio return and excess portfolio return, a simple code or a complex one ?

    Dear Statalist

    In my data set , I have firms that are classified into 10 portfolios each year suing the following code:
    egen portfolio = xtile(op2WA) , by(yr) p(10(10)90)

    This groups firms into 10 portfolios (deciles) each year, based on the ranking variable (op2WA).
    Obviously each portfolio will contain a number of firms and those firms have available stock returns , each year.

    My first task now is to calculate the portfolio mean return and excess return ( portfolio return minus risk free rate RF) each year, so I can use excess returns later in a time series regression for each portfolio.

    I was calculating mean returns and excess returns using a simple code, which I doubt now , might not be correct.
    **The simple code
    egen portret=mean(ret), by (portfolio yr) // for mean portfolio returns

    gen portret_excess= portret-RF // for excess returns

    I doubted this code, and now changed it to this code:

    **The new code
    forvalues i = 1(1)10 {
    egen portret`i'm = mean(ret), by (yr)
    //to calculate portfolio return
    }


    forvalues i = 1(1)10 {
    gen portret`i'e = portret`i'm - RF //
    to calculate portfolio excess return
    }


    Now, the problem seems to be in running the time series regression (aim is run an annual time series regression for each portfolio and estimate each portfolio intercept and its t statistics). I tried with the following code:
    gen alpha==.
    gen alpha_t==.
    forvalues i=1/10 {

    reg portret`i'e MKT SMB HML MOM
    // MKT , SMB, HML, MOM are returns on risk factors
    replace alpha=_b[_cons] if portfolio==`i'
    replace alpha_t= alpha/_se[_cons] if portfolio==`i'

    }


    The good news is that the code seems to work, but the bad news is that all alpha and alpha_t are the same ? It does not seems to do what I intend to do !!


    My questions are:
    1- Is the simple code for mean and excess return incorrect? is the new code better ?
    2- Can anyone debug the time series code

    The following link, chapter 5 , was recommended by a Stata user here in the forum to run a very similar regression....That's why I tried to do something similar, but failed
    http://lipas.uwasa.fi/~sjp/Teaching/...ectures/p5.pdf

    Best
    Ahmed

  • #2
    Ahmed,

    I think your original code was better. The revised code calculates 10 different variables, but each one is the same, since it refers to all portfolios. This is why all the alphas are the same.

    That said, I don't understand enough of what you are doing to be sure what the best solution should be. When you are learning Stata and exploring a new data set, the best strategy is to try different things and then look at the data and see if it is doing what you want. There's no point in waiting until after you are done your analysis and trying to guess whether your data was structured the way you wanted it to be.

    Regards,
    Joe

    Comment


    • #3
      Thanks Joe
      Unfortunately,both codes does not work when I run the time series regression.
      My aim is simple, I want to estimate the intercept for each portfolio of the 10 portfolios from running annual times series regression . I have investigated my data and done all analysis and this is the last robustness test in the paper. Hopefully, I get some comments from the forum users....

      Best wishes
      Ahmed

      Comment


      • #4
        Your regression is for all portfolios. It needs an if qualifier too.

        Comment


        • #5
          Nick,
          I thought that having portret`i' should be enough and I do not need if portfolio==`i' in this case, as the depended variable will take each portfolio separately, right ?

          Comment


          • #6
            No, you still need the if. Portret`i' will create 10 different variabls but you still need the if to put the right thing in each one.

            Comment


            • #7
              Ahmed, my approach is
              Code:
              egen portfolio = xtile( return12_1 ) nquantiles(10) by(dm)
              sort portfolio dm
              collapse (mean) futurereturn1 , by(dm portfolio)  
              gen monthly_12_1= futurereturn1
              But unfortunately this does not replicate the paper I use, I am using a strategy that looks at the past 12 months cumulated skipping the most recent month(that simply means I look at 11 month cumulated returns), meaning I look at the cumulated return from t-12 to t-2, t-1 I do not take into account and invest in t and hold it for 1 month. The commands are the following:
              Code:
              gen return12_1=s11.prc/l11.prc the first should be the cumulative return over the 11 month, second is a control variable, needed for the future return
              gen return1=s1.prc/l1.prc
              gen futurereturn1= f2.return1
              Last edited by Thomas Maurer; 17 May 2014, 10:06.

              Comment


              • #8
                Ahmed I've checked out your code, it gives completely different results then my portfolio formation, and also portfolios with no value i.e. ==.

                Comment


                • #9
                  Thomas,
                  I am not sure how do you calculate your return, can you clarify more. Also, do you use prices directly from CRSP ? don't you need to adjust for stock splits ?

                  Ahmed

                  Comment


                  • #10
                    I did not account for stock splits, first I did not know how to do it, you can help me out there, but second I guess when a stock split occurs a different permno(stock identifier) will be generated, so since I rebalance my portfolio monthly I will simply invest in two stocks in the next period, I treated them as new individual stocks. The commands in post 7, split the stocks available at time t, into 10 stock portfolios. But which return you have to rank the stocks and form the portfolios based on the cumulated return, so if you have id over 6 months then return=s6.price/l6.price, but you have to use overlapping portfolios if you use holding periods larger than 1 month (1unit).

                    Comment

                    Working...
                    X