Announcement

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

  • CAPM Regression for each observation in panel data, wrong command?!


    I have an unbalanced panel dataset that has observations of each firm, based on firmID, for a long time period e.g. 1970-2017. So observations of firm X for the time period 1970-2017, Firm Y for the period 1990-2012 etc.. The columns do not only have FirmID and Year, but also three other variables:

    - Rf: ''Risk-free return rate'': The return based on government bonds.

    - Rm: ''Market index-Return'' : which is the market stock return based on MSCI World Index

    - Rm-Rf : the difference between Rm and Rf which is the excess return over the government bonds

    - Re: ''Firms stock return'': the return of a particular firm for a particular year, e.g. return for Firm X in year 2012 etc..

    Now I want to regress the following for each observation, so for every year of each firm(ID): Re= Rf + x1(Rm - rf) The idea is that the x1 of each regression is saved in a separate column next to the other columns, where (in every row) the x of each year of each firm is presented.

    However, I am not sure if this is the right way. Can someone check this for me? I did: bysort FirmID (Year): regress Re Rf (Rm-Rf)

    But I do not know if it must be regress Re Rf (Rm-Rf) or regress Re (Rm-Rf), but without Rf I guess STATA would not put the same Rf in the regression but just a random constant α.


    Last but not least, the command does not do exactly what I want. What am I doing wrong?

  • #2

    I have the following at the moment:
    Code:
      
    
    xtset gvkey year  
      gen excess_returns = Re - Rf 
    
    en excess_marketreturn = Rm - Rf
    I want to calculate the beta based on the historical data (http://www.investopedia.com/articles...ating-beta.asp)

    For calculating Beta I want to regress Re on Rm historically for each year, based on the last 5 years. Starting at 1970, with the data available of a firm(id) starting at 1970 as well.

    The beta's of a stock each year, I want to let STATA store it in a new column.. I think I maybe need something like fastrollreg, But I really need some help in this one.
    Last edited by Jonathan Smits; 28 Apr 2017, 09:37.

    Comment


    • #3
      Im looking at the manual but i cannot figure it out what to do exactly. I think I need at least the following commands:

      tempname

      postfile

      foreach


      Since it is a panel data, I want to obtain the β,

      β is the coefficient I am looking to get for each year of each firm. The idea is that the Beta is estimated and stored by a regression based on the past 2 year data.

      Since I already have Rf, Rm, Rm-Rf, Re and Re-Rf, I only need to find out the values of β1 in for the regression I want to 'loop' : Re − Rf = αi + βi(Rm − Re)



      I will need to use a loop. This loop needs to execute that I make sure the resulting betas are stored ( foreach command)


      Can somebody help me out?

      Comment


      • #4
        You need to read the introductory material including the user manual first. Your question seems to reflect some misunderstandings. Stata regress works with variables so it won't accept Rm-Rf on the rhs of a regression. You also cannot "regress the following for each observation" - regression inherently uses multiple observations.

        Try following the FAQ on asking questions - provide Stata code in code delimiters, Stata output, and sample data using dataex. Also, simplify what you post to what is needed to generate the problem.

        You can do betas many different ways. You should look at statsby and rolling commands. Alternatively, you can do a loop. You set up variables to write the values into (g beta=. and g alpha=.), and a macro as a counter. Then each time you go through the loop, you write the beta and alpha into the variables in a given spot.

        Comment

        Working...
        X