Announcement

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

  • Save Regression Coefficients and Intercept for Panel Data

    Hello Stata Community,

    I have a balanced Panel Data set and am trying to run the market model (i.e. E(R)=a+b*Rmkt). In order to do this, I need to run a regression for each day on the past 200 days.

    So, I am looking for:
    • how can I estimate the intercepts and slopes based on the past 200 trading days and for each firm individually? Basically, it needs to be estimated on the range of 200 days prior to the specific date.
    • how can I save the intercepts and slopes for each observation?
    I have already prepared the panel data:

    list company companynum in 1/4114, sepby (company)
    xtset companynum xtset companynum date, daily
    My Dataset looks like this:
    input date companynum company return returnSP end

    +------------------------------------------------ --------------+
    . date companynum company return returnSP |
    . |---------------------------------------------------------------|
    1. | 3/21/2001 1 ESDI 0.04 0.65 |
    2. | 3/22/2001 1 ESDI 0.78 6.75 |
    ... | ... ... ... . .. .................................................. ...... |
    4115.| 3/21/2001 2 VWI -0.065 0.65 |
    4116.| 3/22/2001 2 VWI 1.6 6.75 |
    +--------------------------------------------------------------+
    Thank you for your help!
    Last edited by Marie Fingerhut; 21 Jun 2017, 05:51.

  • #2
    For some reason my table cannot be formated in a nice way, my apologies for that! I hope you still can seperate the variables and observations to get an idea of what I am showing.

    Comment


    • #3
      You've presented your data as a quotation; it would look better as code.

      This sounds like an application of rangestat (SSC). See e.g.

      https://www.statalist.org/forums/for...s-within-range

      https://www.statalist.org/forums/for...updated-on-ssc

      https://www.statalist.org/forums/for...ing-stock-beta and several posts here.

      Code:
      ssc inst rangestat
      
      rangestat (reg)  return returnSP, interval(date -200 -1) by(company)
      where I am guessing on which variable is response.
      Last edited by Nick Cox; 21 Jun 2017, 06:31.

      Comment


      • #4
        Thank you, Nick.

        After I ran the regression I retrieved results from day 4 on, although I thought that they would estimate based on 200 days prior to each day. How is that possible?

        Also, reg_nobs tells me that the regression contains mostly 142 observations for each firm and not the full 200. Does ragestat take a sample out of the range?

        I appreciate your help a lot!

        Comment


        • #5
          rangestat uses what is available. No sampling.

          The number of observations used in the regression will be less than 200 at the start of your data.

          Presumably you're also losing data because you don't have data at weekends or for days when there is no trading. You should know more about this than I do given that (a) you can see your dataset and I can't (b) I am not an economist and do not work with finance or business data. Business calendars are a way to tell Stata about gaps.

          Comment


          • #6
            That makes a lot of sense (and is true, since the dataset does exclude weekends and other specific days), thank you.

            Is there a way to indicate in rangestat that it defines the range with 200 cells instead of looking at the actual date?

            Comment


            • #7
              No; you need to define a business calendar for that so far as I can see. Or just define your own pseudo-time variable if weekends etc. do not appear in the data.

              Comment


              • #8
                It worked perfectly with designing the business calendar:

                I used the following code for those who are interested:

                Code:
                bcal create sincal, from(Date)
                format %tbsincal:DD/NN/CCYY Date
                generate bcaldate = bofd("sincal",Date)
                rangestat (reg)  return ReturnSP, interval(bcaldate -200 -1) by(company)
                Thank you for your help!

                Comment

                Working...
                X