Announcement

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

  • Regression on daily, monthly and yearly seasonal dummies

    I have some time series variables at a daily frequency for about 3000 firms. I want to remove the seasonal effect by regressing day-of-the-week, month-of-the-year and year dummies on these variables and then use the residuals for further analysis.

    For simplicity, I ignore that it's a panel data and assume that the time series variables only belong to one firm(I will use the statsby command to run regressions and store residuals for each firm).

    For example, I run a regression as follows.

    reg dep_var i.day i.month i.year

    Where "dep_var" is the time series variable."day" is the dummy variable for day-of-the-week (1 for Monday, 2 for Tuesday, and so on). "month" is the dummy variable for month-of-the-year (1 for January, 2 for February, and so on). "year" is the year variable (with values ranging from 2003 to 2019).

    Does running a regression like above allows the day-of-the-week and month-of-the-year to vary by year? In other words, a "January" for the year 2013 will be considered the same as a "January" for the next year, i.e. 2004. All Januarys will be treated equally. The same goes for the day-of-the week.

    How should I specify the regression such that the day-of-the-week and month-of-the-year vary by each year? Should I interact the day and month dummies with the year dummy? What would be the command in Stata?

    Since I only need the residuals from these regressions, I am not interested in the coefficients of these regressions.

  • #2
    In other words, a "January" for the year 2013 will be considered the same as a "January" for the next year, i.e. 2004. All Januarys will be treated equally. The same goes for the day-of-the week.
    That is a correct description of what the code you show will do.

    How should I specify the regression such that the day-of-the-week and month-of-the-year vary by each year? Should I interact the day and month dummies with the year dummy? What would be the command in Stata?
    You could do it that way, but the output will be a mess to read. Instead, it wold be better to just create a single daily date variable and use that as your fixed-effect in a model that suppresses display of their coefficients:

    Code:
    gen date = mdy(month, day, year)
    format date %td
    
    reghdfe dep_var, absorb(date)
    -reghdfe- is written by Sergio Correa and is available from SSC.

    Comment


    • #3
      Thank you Clyde.

      Your suggestion makes perfect sense.

      Seasonal effects of the day, the month and the year are handled simultaneously by the daily date fixed-effect.

      Comment


      • #4
        I used the command:
        Code:
        reghdfe dep_var, absorb(date)
        However, since daily date is recognized as a singleton group (i.e. there is only one observation for a particular date), it is dropped by Stata automatically. Consequently, all observations get dropped and the regression cannot run.

        I am running this regression for each firm separately in a loop.

        Here, the usual regress command with interaction of the day and month dummies with the year variable seems to be the workable way. Since only the residuals are needed, the huge number of coefficients does not matter.
        Code:
        gen resid = .
        levelsof firm_id, local(firm_id)
        foreach i of local firm_id {
        quietly regress dep_var i.day##i.year i.month##i.year if firm_id== `i'
        quietly predict temp, resid
        quietly replace resid = temp if firm_id == `i'
        drop temp
        }
        Last edited by arbab cheema; 14 Dec 2020, 17:22.

        Comment

        Working...
        X