Announcement

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

  • Need Guidance regarding Fiscal Year Variable

    Dear Concerns, My Year data for a research paper is as
    1980-81
    1981-82
    1982-83
    upto 2019.
    STATA is reading it as string variable and returning an error upon analysis, Please help me how the STATA can read these YEARS as time.
    Best Regards

  • #2
    The range cannot be read as a numerical variable. You can create a time variable that maps 1980-81 to 1, 1981-82 to 2, and so on.

    Code:
    egen time= group(Year), label
    The -group- function of egen should work fine here as1980-81 should be alphabetically sorted before 1981-82. Alternatively, you may just want to create a time variable based on the year when the fiscal year starts, in which case you need

    Code:
    gen time2= real(substr(trim(Year), 1, 4))
    Then use either time or time2 in place of Year.

    Comment


    • #3
      A footnote to Andrew Musau's fine answer:

      The group() method should work fine if there are no gaps in the data. If there are any gaps, then the second method is better, and you can still assign value labels (e.g. using labmask from the Stata Journal or a loop).

      So suppose there was a gap within time2. Then you could still go

      Code:
      levelsof time2, local(levels) 
      
      foreach y of local levels { 
            local y2 : di %02.0f  mod(`y' + 1, 100) 
            label def time2 `y'  "`y'-`y2'", add 
      } 
      
      label val time2 time2

      Comment

      Working...
      X