Announcement

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

  • If tin not working with calendar dates (bofd)

    Hello everyone,

    Let's say I have a timeseries dataset containing number of admissions in a day. However we only track admissions every Monday and Thursday. In order to really utilize time series operator such as lags (L), I need to generate calendar dates (due to the date gaps). I think I did this successfully. However when I use the tin option it does not work. Am I missing something?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int dt float los
    18994 146.97275
    18997 143.96909
    19001 137.86528
    19004  137.9362
    19008 139.04283
    end
    format %td dt
    Code:
    Listed 5 out of 5 observations
    . bcal create OBCCLOS, from(dt) replace 
      Business calendar OBCCLOS (format %tbOBCCLOS):
        purpose:  
    
          range:  02jan2012  16jan2012
                     18994      19008   in %td units
                         0          4   in %tbOBCCLOS units
    
         center:  02jan2012
                     18994              in %td units
                         0              in %tbOBCCLOS units
    
        omitted:        10              days
                       243.5            approx. days/year
    
       included:         5              days
                       121.8            approx. days/year
    
      Notes:
        business calendar file OBCCLOS.stbcal saved
    . 
    . generate dtcal = bofd("OBCCLOS",dt)
    . format %tbOBCCLOS dtcal
    . listsome dt dtcal
    
         +-----------------------+
         |        dt       dtcal |
         |-----------------------|
      1. | 02jan2012   02jan2012 |
      2. | 05jan2012   05jan2012 |
      3. | 09jan2012   09jan2012 |
      4. | 12jan2012   12jan2012 |
      5. | 16jan2012   16jan2012 |
         +-----------------------+
    . assert dt!=. if dtcal!=.
    . tsset dtcal
            time variable:  dtcal, 02jan2012 to 16jan2012
                    delta:  1 day
    . list los L1.los
    
         +---------------------+
         |                   L.|
         |      los        los |
         |---------------------|
      1. | 146.9727          . |
      2. | 143.9691   146.9727 |
      3. | 137.8653   143.9691 |
      4. | 137.9362   137.8653 |
      5. | 139.0428   137.9362 |
         +---------------------+
    
    . tsline los L1.los if tin(02jan2012, 09jan2012)
    invalid syntax
    This is pnly a subset of my data. the ultimate goal is to generate a line chart(tsline) for only 2018 and compared it with previous years (L12, L24 etc)

    Code:
    tsline los L12.los L24.los if tin(01jan2018, 31oct2018)



  • #2
    You are getting the "invalid syntax" error message with tsline because function tin() currently does not support business calendar dates (%tb format).

    As a workaround, since the Stata internal format (SIF) for business dates are integers relative to a reference date (centerdate), you can use those integers as arguments to tin() (see help tin). You can obtain the integer values for the two dates you want to use in tin() by using function bofd(). That is,

    Code:
    local bdate1 = bofd("OBCCLOS", date("02jan2012","DMY"))
    local bdate2 = bofd("OBCCLOS", date("09jan2012","DMY"))
    tsline los L1.los if tin(`bdate1', `bdate2')
    We will look into a cleaner solution by supporting business dates formats in tin().

    -- Kreshna

    Comment


    • #3
      Thank you Kreshna Gopal (StataCorp) !

      Comment


      • #4
        FYI, functions tin() and twithin() now support dates in business calendar (%tb) format in Stata 15. For the latest updates, type
        Code:
        update all

        Comment

        Working...
        X