Announcement

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

  • Rolling regressions with asreg when time spacing is unequal.

    Hi All,

    I have a panel of data, with firms, analysts and time. So different analysts issue forecasts for different firms over time.


    I am using asreg to run a regression of y on x for each analyst-firm across all dates as follows:


    bys analyst firm: asreg y x, se

    I want to do this regression on a rolling basis, using all observations in the previous N years for each analyst and firm.

    I saw the response of Professor Attaullah Shah, https://www.statalist.org/forums/for...gression-asreg

    where he suggests something like:
    bys analyst firm : asreg y x, wind( year 9) min(5) As I understand it, in this example, the data were annual, so wind(year 9) ensures that the model uses the 9 previous observations which is the same as 9 years of data. However, my issue is that in my data the time spacing between observations (i.e. the forecasts by analyst A for company X) is irregular, i.e., it is not years or months, it when the analyst issues a forecast. So somehow the model must take into account the time between the date of a given forecast by A for X (say day t) and the previous forecasts by A for X (in days t-i), and run a regression using only the forecasts where the time gap between t and t-i is within N years. Any help on whether this could be done within asreg would be much appreciated. with best wishes, Costas

  • #2
    I have never used asreg (from SSC, as you are asked to explain: FAQ Advice #12) but rangestat (also from SSC) is more familiar to me and isn't wedded to the idea of regular spacing as a norm.

    Comment


    • #3
      Dear Nick
      Many thanks for your reply.
      Could you by any chance suggest how rangestat could achieve this and provide me with a dataset that contains the slope coefficients and number of observations in each regression?
      best wishes,
      Costas

      Comment


      • #4
        I could do that but I strongly prefer that you give a data example first. Please act on https://www.statalist.org/forums/help#stata

        Comment


        • #5
          Hi Nick,
          The code below generates a sample that looks like my data. Assume that I want to run a regression of y on x for each analyst-company on a rolling basis, say using the previous 2 years of data.
          I want a dataset created that contains the slope coefficients and number of observations of each firm-analyst-date regression.
          I hope the code below helps.
          Costas


          clear
          set seed 12345
          set obs 1000

          * Generate firm and analyst IDs
          gen firm_id = ceil(runiform() * 5)
          gen analyst_id = ceil(runiform() * 10)

          * Generate random x and y values
          gen x = rnormal(5, 2)
          gen y = rnormal(0, 10)

          * Generate random dates within 2010-2020
          gen double random_days = runiform(0, 4017)
          gen date = mdy(1, 1, 2010) + random_days
          format date %td

          sort firm_id analyst_id date

          Comment


          • #6
            Thanks.

            Code:
             rangestat (reg) y x, int(date -730 0) by(firm_id analyst_id)

            Comment


            • #7
              Thank you Nick, this works just fine.

              Comment

              Working...
              X