Announcement

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

  • Change date variable to one stata can read

    Hello Statalist,

    I've a question regarding my dataset. I want to extract the year and month separate from my "first_payment_date" variable but nothing seems to work.
    I have uploaded an attachment to see what my dataset looks like. This is for 1 loanid, and then I've 10,000 of different loanids and each loanid has one first payment date.
    It looks like stata doesn't recognize that first payment date is a date which stands in this case for May 2007 (200705).
    Could someone help me out with this?

    Kind regards,
    Gabe
    Attached Files

  • #2
    Welcome to Statalist.

    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.

    And, some advice on making effective use of Statalist. Take a few moments to review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. It's particularly helpful to copy commands and output from your Stata Results window and paste them into your Statalist post using code delimiters [CODE] and [/CODE], and to use the dataex command to provide sample data, as described in section 12 of the FAQ.

    The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

    Comment


    • #3
      The excellent advice from William Lisowski is gently underlining that you are not yet following our requests on how to show data.

      If first_payment_date is numeric, then this example shows some technique:

      Code:
      . display %tm ym(floor(200705/100), mod(200705, 100))
       2007m5
      So you need in that case

      Code:
      gen mdate = ym(floor(first_payment_date/100), mod(first_payment_date, 100)) 
      format mdate %tm
      If the variable is string you need to do this first

      Code:
      destring first_payment_date, replace
      A more general issue is this: How is Stata supposed to know that 200705 is a date?

      Comment

      Working...
      X