Announcement

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

  • Generate daily data from weekly data

    Hi all,

    I have a dataset looks like below

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str24 order_data float index
    "2019-10-13" 6
    "2019-10-20" 6
    "2019-10-27" 5
    "2019-11-03" 5
    "2019-11-10" 4
    "2019-11-17" 5
    "2019-11-24" 5
    "2019-12-01" 6
    "2019-12-08" 5
    "2019-12-15" 5
    "2019-12-22" 4
    end
    The index is on the weekly basis. However, I want to merge it with a daily data set. For instance, 2019-10-14 6, 2019-10-17 6, etc. I wonder if anyone knows there's command in Stata to achieve this?

    Thanks

  • #2
    Melody, you may try the code below.

    Code:
    gen date = date(order_data, "YMD")
    sort date
    tsset date
    tsfill
    replace index = index[_n-1] if mi(index) & !mi(index[_n-1])
    format date %td

    Comment


    • #3
      Originally posted by Fei Wang View Post
      Melody, you may try the code below.

      Code:
      gen date = date(order_data, "YMD")
      sort date
      tsset date
      tsfill
      replace index = index[_n-1] if mi(index) & !mi(index[_n-1])
      format date %td
      Hi Fei,

      The code works perfectly for me. Thanks a lot for your help!

      Comment

      Working...
      X