Announcement

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

  • Time format

    Hello all,
    I have a dataset read in from Excel and I have a problem with the variable of the date.
    I have 12 observations per year for each of several countries (from January 2005 to November 2020) in my dataset and these are read into Stata as "int" and then displayed as 01Jan2005. How can I reformulate the date so that I can use it to plot only a specific period, for example.

    For example, I would like to say plot for the period of 2008-2010.

  • #2
    Stata's "date and time" variables are complicated and there is a lot to learn. If you have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. If you have, it's time for a refresher. After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

    All Stata manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

    The simplest thing is to add an if clause to whatever command you hope to use to plot your data:
    Code:
    line y date if inrange(yofd(date),2008,2010)

    Comment


    • #3
      Originally posted by William Lisowski View Post
      Stata's "date and time" variables are complicated and there is a lot to learn. If you have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. If you have, it's time for a refresher. After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

      All Stata manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

      The simplest thing is to add an if clause to whatever command you hope to use to plot your data:
      Code:
      line y date if inrange(yofd(date),2008,2010)
      Hello, thank you already for the answer. When I try it this way, I get the feedback "type mismatch". The other variables are of type "double".

      Comment


      • #4
        Your problem really isn't clear without more detail, or at a minimum it is too difficult to guess at a good answer from what you have shared, since my first guess didn't solve your problem.

        Please help us help you. Show some of your data, using the dataex command to list it in a way that is thorough and useful. Run your code, copy the commands and output from your Stata Results window, and paste them into your Statalist post using code delimiters [CODE] and [/CODE]. The Statalist FAQ provides advice on effectively posing your questions, posting data, and sharing Stata output.

        Let me add one more guess. Did your date variable originally come from Excel as a string and then you used encode to convert it to numeric? (I was wondering how it got to be type int and I realized this is a possibility.) If so that is a mistake and you must redo your conversion of your date from string to numeric. What you have now will be of little or no use.

        Stata's "date and time" variables are complicated and there is a lot to learn. If you have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. If you have, it's time for a refresher. After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

        All Stata manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

        Comment

        Working...
        X