Announcement

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

  • Business Calendar

    Dear friends, I wish to create a business calendar for the attached data- which is a panel of stocks and regular dates. The version of stata am using is 12 and it seems to give me trouble. i have tried some suggestions but they do not seem to be working. kindly help
    Attached Files

  • #2
    Looking at your previous posts, you have not had much success in getting help from Statalist.

    To increase the likelihood that Statalist readers will be able to assist you, please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

    Two particular points from the FAQ bear on the current post.

    12.1 What to say about your commands and your problem
    Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
    ...
    Never say just that something "doesn't work" or "didn't work", but explain precisely in what sense you didn't get what you wanted.
    12.5 Posting attachments: please don't...
    There are several "please don't" requests here, but good reasons for them all.
    ...
    You are asked not to post attachments that are in Word or Excel file formats (.doc, .docx, .xls, .xlsx), because
    • many members just don't have or don't use such software
    • obliging other members to open those programs to see your problem is at best awkward and indirect
    • many members have zero-risk policies on not opening such files from third parties
    • there are better ways to show the information, as explained just above.

    Comment


    • #3
      Hello Rogers,

      In Stata 12, you have to "manually" create a business calendar file. That is, you will have to identify the business holidays in your dataset, and specify them in a business calendar file (a text file named calname.stbcal).

      In Stata 13, subcommand create was added to bcal to automatically create a business calendar file. bcal create infers business holidays from gaps in the dataset based on a date variable. Our online manual for bcal has more details.

      Coming back to Stata 12, if you do help bcal and scroll down, you will find a link to [D] datetime_business_calendars_creation that describes how to create a business calendar file.

      Here is the code I used to identify, in Stata 12, business holidays in your Excel file:

      Code:
      import excel using bcal.xls, firstrow
      gen diff = date[_n]-date[_n-1] if _n > 1
      tab diff
      gen dow = dow(date)
      tab dow
      The variable diff tells the absolute number of days between 2 consecutive business dates. The variable dow is the day of the week (Sunday is 0, Monday is 1, etc.).

      The code shows that all Saturdays are holidays, but there is one Sunday that is not (27nov2011). There is a large gap of 327 days between two consecutive business days (26May10 to 18Apr11); this is because of different issuers. Also, there are two days that are repeated: 28nov2011 and 23nov2011.

      You can also use tsfill to identify holidays, but you would need to delete repeated dates and then tsset the date variable. For example, the following will list business holidays (other than Saturdays and Sundays) if the issuer is ARM:

      Code:
      import excel using bcal.xls, firstrow
      keep if issuer == "ARM"
      tsset date
      tsfill
      gen dow = dow(date)
      list if issuer == "" & dow != 0 & dow != 6
      I used bcal create with your dataset in Stata 14. If I split the dataset into two (for issuers ARM and KNRE), and drop that one odd working Sunday, then I get the following two business calendars with these commands:

      Code:
      import excel using bcal.xls, firstrow
      keep if issuer == "ARM"
      bcal create arm, from(date) gen(bdate)
      
      clear
      import excel using bcal.xls, firstrow
      drop if dow(date) == 0
      keep if issuer == "KNRE"
      bcal create knre, from(date) gen(bdate)
      ------------ start of arm.stbcal -----------------------
      * Business calendar "arm" created by -bcal create-
      * Created/replaced on 26 Aug 2016

      version 14
      dateformat ymd

      range 2009jan06 2010may26
      centerdate 2009jan06

      omit dayofweek (Sa Su)
      omit date 2009apr10
      omit date 2009apr13
      omit date 2009may01
      omit date 2009jun01
      omit date 2009aug10
      omit date 2009aug11
      omit date 2009aug25
      omit date 2009sep21
      omit date 2009oct20
      omit date 2009dec02
      omit date 2009dec25
      omit date 2010jan01
      omit date 2010apr02
      omit date 2010apr05
      ---------- end of arm.stbcal -----------------------

      ------------ start of knre.stbcal -----------------------
      * Business calendar "knre" created by -bcal create-
      * Created/replaced on 26 Aug 2016

      version 14
      dateformat ymd

      range 2011apr18 2013jan25
      centerdate 2011apr18

      omit dayofweek (Sa Su)
      omit date 2011apr22
      omit date 2011apr25
      omit date 2011may02
      omit date 2011jun01
      omit date 2011aug01
      omit date 2011aug02
      omit date 2011aug03
      omit date 2011aug31
      omit date 2011oct20
      omit date 2011nov01
      omit date 2011dec12
      omit date 2011dec23
      omit date 2011dec26
      omit date 2011dec27
      omit date 2011dec28
      omit date 2012jan02
      omit date 2012apr06
      omit date 2012apr09
      omit date 2012may01
      omit date 2012jun01
      omit date 2012aug20
      omit date 2012sep03
      omit date 2012sep07
      omit date 2012oct11
      omit date 2012nov06
      omit date 2012dec12
      omit date 2012dec25
      omit date 2012dec26
      omit date 2013jan01
      omit date 2013jan17
      omit date 2013jan23
      ---------- end of knre.stbcal ----------------------
      -

      If you do not want to drop the working Sunday, and keep one dataset, then you can edit the business calendar file and use from/to to specify business holidays in a range. For example:

      Code:
      from 06jan2009 to 16may2010: omit dayofweek (Sa Su)
      I hope this helps.

      -- Kreshna

      Comment

      Working...
      X