Announcement

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

  • Lags in time series with only trading days

    Hello together,

    for my thesis I have a dataset which contains stock prices over a period of 28 years. My time variable has a daily format but because of Saturdays, Sundays and holydays gaps occur.
    Therefore the lag operater produces variables with missing values. I've thought about just using [_n-1] as I have all observations for all stocks in the given time period. This is what it looks like when i try to generate laged variables. i_totm_lag2 equals the [_n-1] variable and i_totm_lag represents the lag operator.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int date double i_totm float(i_totm_lag i_totm_lag2)
    10955 276.32      .      .
    10959 280.93      . 276.32
    10960 280.76 280.93 280.93
    10961 278.55 280.76 280.76
    10962 275.89 278.55 278.55
    10965 276.98      . 275.89
    10966 273.86 276.98 276.98
    10967 271.94 273.86 273.86
    10968 272.81 271.94 271.94
    10969 266.25 272.81 272.81
    end
    format %td date

    Thank you in advance!

  • #2
    The best fix for this is to use a business calendar.

    Code:
    help datetime business calendars

    Comment


    • #3
      I'll take a look at it. Thank you.

      Comment

      Working...
      X