Announcement

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

  • Quaterly date in Stata Reader Form (SRF)

    Hi,

    I have tried all possible suggestions I have seen and nothing is working.

    I have quarterly date in this format and I need to convert to SRF. Can someone helps me.

    Format of my date data.

    Date
    2000q1
    2000q2
    2000q3
    2000q4
    2001q1
    2001q2
    2001q3
    2001q4
    2002q1
    2002q2
    2002q3
    2002q4
    2003q1
    2003q2
    2003q3
    2003q4
    2004q1
    2004q2
    2004q3
    2004q4
    2005q1
    2005q2
    2005q3
    2005q4
    2006q1
    2006q2
    2006q3
    2006q4
    2007q1
    2007q2
    2007q3
    2007q4
    2008q1
    2008q2
    2008q3
    2008q4
    2009q1
    2009q2
    2009q3
    2009q4
    2010q1
    2010q2
    2010q3
    2010q4
    2011q1
    2011q2
    2011q3
    2011q4
    2012q1
    2012q2
    2012q3
    2012q4
    2013q1
    2013q2
    2013q3
    2013q4
    Nigel

  • #2
    Nigel: You didn't use dataex (SSC) as we request to show a data example -- please see https://www.statalist.org/forums/help#stata -- so it's ambiguous whether you have a string variable or a numeric variable already assigned a quarterly date display format. But if it was the latter, presumably you wouldn't be asking this question.

    Assuming that you have a string variable there, then

    Code:
    . di quarterly("2000q1", "YQ")
    160
    
    . di %tq quarterly("2000q1", "YQ")
    2000q1
    shows that the function quarterly() is what is needed to convert string dates of that form to a numeric variable, say

    Code:
    gen QDate = quarterly(Date, "YQ")
    format QDate %tq
    Reports of the form "I have tried all possible suggestions I have seen and nothing is working" are not helpful if you want an explanation of what you did wrong. The function quarterly() is documented in help datetime which is the port of first call for questions such as these.

    New users often tend to try to Google everything; experienced users look at the help and manuals within Stata, although understanding their structure and style is what comes with experience.

    The entire FAQ Advice gives hints on asking questions.
    Last edited by Nick Cox; 20 Jul 2017, 06:53.

    Comment


    • #3
      Hi Nick, thank you for your help. This is how Stata is seeing my data

      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str6 date
      "2000q1"
      "2000q2"
      "2000q3"
      "2000q4"
      "2001q1"
      "2001q2"
      "2001q3"
      "2001q4"
      "2002q1"
      "2002q2"
      "2002q3"
      "2002q4"
      "2003q1"
      "2003q2"
      "2003q3"

      This is just my first week of using Stata. I normally use Eviews but it is suggested that I move over to Stata.

      Comment


      • #4
        I tried this code gen date2 = date(date, "QY") and I got this message (2520 missing values generated).

        Date is the original date data that I need SRF.

        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input str6 date float date2
        "2000q1" .
        "2000q2" .
        "2000q3" .
        "2000q4" .
        "2001q1" .
        "2001q2" .
        "2001q3" .
        "2001q4" .
        "2002q1" .
        "2002q2" .
        "2002q3" .
        "2002q4" .
        "2003q1" .
        "2003q2" .
        "2003q3" .
        end

        I also used this code



        . gen QDate = date(date, "YQ")
        (2520 missing values generated)

        .
        . format QDate %tq

        I am using Stata 13 on Window 10.

        What am I missing?
        Last edited by Nigel Taylor; 20 Jul 2017, 07:28.

        Comment


        • #5
          I didn't recommend that because it's wrong. date() yields daily dates. You need quarterly() to get quarterly dates. The exact code you need was in #2.

          Comment


          • #6
            Thanks a lot Nick. It works. Many thanks.

            Comment


            • #7
              Welcome to Statalist, and to Stata, Nigel.

              I'm sympathetic to you as a new user of Stata - it's a lot to absorb. And even worse if perhaps you are under pressure to produce some output quickly. Nevertheless, I'd like to encourage you to take a step back from your immediate tasks.

              When I began using Stata in a serious way, I started, as have others here, by reading my way through the Getting Started with Stata manual relevant to my setup. Chapter 18 then gives suggested further reading, much of which is in the Stata User's Guide, and I worked my way through much of that reading as well. There are a lot of examples to copy and paste into Stata's do-file editor to run yourself, and better yet, to experiment with changing the options to see how the results change.

              All of these 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 objective in doing the reading was not so much to master Stata as to be sure I'd become familiar with a wide variety of important basic techniques, so that when the time came that I needed them, I might recall their existence, if not the full syntax, and know how to find out more about them in the help files and PDF manuals.

              The Stata documentation is really exemplary - there's just a lot of it. The path I followed surfaces the things you need to know to get started in a hurry and to work effectively.

              In particular, it would have take you to the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, which should be the first stop for anyone new to working with Stata dates and times. After that, the help datetime documentation will usually be enough to point the way.

              ​​​​​​​Good luck!

              Comment


              • #8
                Thanks William for your kind words. After a few days, I think I am doing ok with Stata. I am now wondering why I did not start using this software earlier.

                Comment

                Working...
                X