Announcement

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

  • Format datadate to year

    Hi all,

    I have a problem with converting the variable datadate (e.g.15jan2001) to a variable structured like fiscal year (e.g. 2001). Anybody an idea how the command can look like? I am absolute beginner in using stata, so hope I can find help here

    Thanks a lot.

  • #2
    Sabrina,
    Please could you use dataex (a per FAQ) to provide some sample of your data?
    This would be useful to know the exact format of your variable.
    It is string, numeric with label or date format?

    The way to only keep the year would change according to the way the variable is encoded.
    Best,
    Charlie

    Comment


    • #3
      Assuming that your variable datadate is an actual Stata internal format numeric date variable, you can extract the year part with:

      Code:
      gen year = year(datadate)
      If your variable datadate is a string variable, you would need to first use the -date()- function to convert it to a Stata internal format date variable.

      Stata offers a broad palette of functions to create and transform dates and times. It is so broad that most of us can't remember the details and frequently have to refer back to the -help- files for details on the functions that we don't use regularly. But you should definitely read -help datetime- and the corresponding section of the manual so that you familiarize yourself with the various tools that are available to you.

      Comment

      Working...
      X