Announcement

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

  • From double (%tc) to long (%tdnn/dd/YY) - Dates

    Hello,

    I have two types of date variables in my data. System date of survey and self-reported date of survey. I would like to have these two date saved in the same format. How can I make my sytem date which is saved as double format (%tc) to long (%tdnn/dd/YY).

    I would appreciate any help,
    Best,
    Marvin

  • #2
    Marvin,

    This is not hard to do but you should be aware that %tc is for date/time variables, whereas %td is for date variables. Thus, you would be losing information (the time part) if you converted from date/time (%tc) to date (%td).

    That said, if you want to convert a date/time variable to a date variable, use the dofc() function.

    Regards,
    Joe

    Comment


    • #3
      Joe gives good advice. In addition, note that double and long are storage types, not formats.

      Comment


      • #4
        This is the information of my variables:

        SystemDate double %tc Surveyed Date
        DateToday long %tdnn/dd/YY Today's Date

        I try:


        gen SystemDateRC=dofc( SystemDate ) and it returns numbers. Can you please write the command.

        I would greatly appreciate it

        Best,
        Marvin

        Comment


        • #5
          Having generated SystemDateRC, you also need to assign a format to it so that the numbers are displayed as the dates they represent. See help datetime for guidance, and for important background on working effectively with Stata dates and times. Your time spent mastering this will be well rewarded as you continue to use Stata.
          Last edited by William Lisowski; 10 Jul 2015, 15:08.

          Comment


          • #6
            Marvin: the thread you started on 27 April raised essentially the same question.

            Comment


            • #7

              Hi William, I tried gen SystemDateRC2 = dofc(SystemDateRC) But I guess I am doing something wrong. I would appreciate any help. On the other hand, when I command help sometimes a get only a partial explanation of the command. I guess I have also seen full explanations with examples. How can I access to those documents. BEst, Marvin

              Comment


              • #8
                William's #5 remains the advice to you.

                Extraction of a daily date using dofc() should be followed by assigning some kind of %td display format.

                There is nothing in your post to substantiate what you mean by "I guess I am doing something wrong".

                The fuller documents behind the help you allude to are the Stata manuals, presumably.

                Once again, I cross-refer you to the thread you started http://www.statalist.org/forums/foru...-hour-variable which refers to the same problem of extracting a daily date from a date-time variable.

                Comment

                Working...
                X