Announcement

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

  • Generating rows for missing date

    I want to do the interpolation for last copper price. However, original data has missing rows for date. I would want to first fill in rows for missing date with other variables with value 0 and then do the interpolation, but I do not know how to do it.

    The date looks like this:
    TransactionDate last closingbid closingask
    1/1/1904
    1/2/1904 6 6.25
    1/4/1904 5 7
    1/5/1904 7 5.5 6.25
    1/6/1904 6 5.75 6.5
    1/8/1904 5.75 7
    1/9/1904 6 9
    1/9/1904 6
    1/11/1904 6.75 8.5
    1/12/1904 6.25 6 8
    1/13/1904 6.25 8
    1/14/1904 6.25 8
    1/15/1904 6.25 8
    1/16/1904 6.25
    1/18/1904 6.25 8
    1/19/1904 8 6.25 8
    1/20/1904 6.25 9
    1/21/1904 6 9
    1/22/1904 6 9
    1/23/1904 8
    1/25/1904 6 9
    1/26/1904 6 9
    1/27/1904 7 10
    1/28/1904 7 10
    1/29/1904 7 10
    1/30/1904 7 10

  • #2
    You should tsset your data, and then just use the command tsfill. This assumes your TransactionDate variable is already in a numeric form that Stata understands as a date. If not, you will need to create such a variable first. E.g. if it is a string variable, you will need to use the daily() function. Check the Stata help for these, if they are new to you.

    Comment


    • #3
      Various questions:

      1. Have you really got data for 1904? Sometimes there is a translation problem because other software calculates daily dates relative to a zero in 1900.

      2. There seems to one day of the week that is never present in the data. Contrary to #1, if the dates are taken literally, they were Sundays.


      Code:
      : absent = mdy(1, (3, 10, 17, 24), 1904)
      
      : absent
                  1        2        3        4
          +-------------------------------------+
        1 |  -20452   -20445   -20438   -20431  |
          +-------------------------------------+
      
      : dow(absent)
             1   2   3   4
          +-----------------+
        1 |  0   0   0   0  |
          +-----------------+
      
      :
      This situation calls for a business calendar, not the invention of what would be 1/7 of your dataset, with a spuriously inflated sample size.

      3. Duplicates can be seen in the data example, which would prohibit the use of tsset until fixed.

      Comment


      • #4
        Thank you so much!

        Comment

        Working...
        X