Announcement

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

  • Finding the first business day of a fiscal year

    I have fiscal-year data for a panel of years which includes the following pertinent variables:
    firmid (firm id)
    fyear (fiscal year)
    begdate (first calendar day of fiscal year)
    enddate (last calendar day of fiscal year)

    I also have a file of daily stock market data for each firm. Ultimately, I want to add fiscal year to that file. I think I know how to do that if I can figure out the first business day of each fiscal year. While in the US fiscal years commonly start on January 1, they don't always, and the first day of the fiscal year is often not a business day. (To make the problem more complicated, fiscal years are not always 12 months long, though I believe they never begin or end mid-month.) Using Stata's business calendar functions, I can easily find which dates are not business dates. What I can't figure out is how to get the next business day when the business date is missing.


    To make a toy example easier, let me recast the problem so as to look for the first business day of what I will call a fiscal month (fmonth), so that I can use sp500 to generate a business calendar The toy data looks like the following:

    obs firmid fmonth begdate enddate
    1 1 1 Mo 1Jan01 We 31Jan01
    2 1 2 Th 1Feb01 We 28Feb01
    3 2 3 Sa 1Sep01 Su 30Sep01
    4 2 4 Mo 1Oct01 We 31Oct01



    What I would like to end up with is the following, where begbizdate is the first business day of the month:


    obs firmid fmonth begdate enddate begbizdate
    1 1 1 Mo 1Jan01 We 31Jan01 2Jan01
    2 1 2 Th 1Feb01 We 28Feb01 1Feb2001
    3 2 3 Sa 1Sep01 Su 30Sep01 3Sept01
    4 2 4 Mo 1Oct01 We 31Oct01 1oct2001


    The code below generates

    obs firmid fmonth begdate enddate begbizdate
    1 1 1 Mo 1Jan01 We 31Jan01 .
    2 1 2 Th 1Feb01 We 28Feb01 1Feb2001
    3 2 3 Sa 1Sep01 Su 30Sep01 .
    4 2 4 Mo 1Oct01 We 31Oct01 1oct2001


    How do I fill in the missing values for observations 1 and 3?

    Thanks,
    Devra


    Code:
    sysuse sp500
    bcal create sp500, from(date) gen(bizdate) replace
    
    clear
    input obs firmid fmonth str7 begdatestr str7 enddatestr
    1 1 1 01Jan01 31Jan01
    2 1 2 01Feb01 28Feb01
    3 2 3 01Sep01 30Sep01
    4 2    4    01Oct01 31Oct01
    end
    
    gen begdate=date(begdatestr, "DM20Y")
    gen enddate=date(enddatestr, "DM20Y")
    format begdate enddate %tdDa_ddMonYY
    drop begdatestr enddatestr
    generate begbizdate=bofd("sp500", begdate)
    format begbizdate %tbsp500
    Devra Golbe
    Professor Emerita, Dept. of Economics
    Hunter College, CUNY

  • #2
    Hi Devra. You will want to re-post this in the General Forum. This forum is for practice, e.g. you want to try out Latex or some formatting feature.
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    Stata Version: 17.0 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      Thanks, Richard! Already did that. I posted it here first (with a badly chosen subject line) exactly because I wanted to make sure I knew how to best post output and code.
      Devra Golbe
      Professor Emerita, Dept. of Economics
      Hunter College, CUNY

      Comment

      Working...
      X