Announcement

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

  • Date and missing values on the original database

    Dear all,
    first of all, sorry if my question has already been posted (I'm looking for 1 hour now and don't find anything which fitted perfectly). I have Stata 14.
    my problem is the following:
    I have an excel file that I import in stata. Several variables contain dates. some of these variables have missing values (2 or 3 for example), then Stata recognizes them as string (whereas variables without missing values are already dealt as dates). the function date generates missing values for all the observations of a same variable if some of them are missing.
    I can not drop the observations, moreover the data have to be merged with other files.
    I hope I'm clear enough. Could you help me please? Thanks in advance.
    Cécile

  • #2
    Normally date can handle missings. Can you add a data sample using -dataex-? That would help us identify the problem.

    Comment


    • #3
      sorry, but I can't install dataex (don't have the rights)

      Comment


      • #4
        As Jesse suggests, this statement reflects a misunderstanding:

        the function date generates missing values for all the observations of a same variable if some of them are missing
        In general Stata does not work that way, especially with functions used with the generate command (as opposed to the egen command).

        The chances seem strong that you have an error in your use of the date function.

        Consider restricting your data to just a few observations for which the data is not missing (for example, using something like keep in 1/5 assuming it is not missing in observatons 1 through 5) and developing your code on those observations. When you have the answer you expect, then use that code on the full dataset.

        Comment


        • #5
          Originally posted by Cecile Montreuil View Post
          sorry, but I can't install dataex (don't have the rights)
          You can also attach a sample of dataset. E.g.
          Code:
          keep in 1/50
          save <filename>
          And attach <filename> to your post.

          Comment


          • #6
            Jesse, thanks for your advice, I've attached the dates.
            William, it works if I drop the observations with missing values, but it doesn't when I keep them
            Attached Files

            Comment


            • #7
              I downloaded your data and the date() function works for me. Below I post my example, which instead uses the daily() function - it's identical to the date() function but has the benefit that its name reminds the reader of the type of Stata date being generated. Regardless, neither generated missing values for all the observations if any were missing.

              In general, we can better help you if we know what commands you have tried and what Stata told you to indicate that there was a problem. For future reference, please 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. See 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, as described in section 12 of the FAQ, as I have done below.

              Code:
              . codebook D42
              
              ------------------------------------------------------------------------------------------------
              D42                                                                                          D42
              ------------------------------------------------------------------------------------------------
              
                                type:  string (str10)
              
                       unique values:  8                        missing "":  0/29
              
                          tabulation:  Freq.  Value
                                           7  "8/1/2014"
                                           8  "8/5/2014"
                                           2  "8/6/2014"
                                           4  "8/8/2014"
                                           1  "7/22/2014"
                                           2  "-"
                                           1  "."
                                           4  "10/15/2014"
              
                             warning:  variable has leading blanks
              
              . generate D42d = daily(D42,"MDY")
              (3 missing values generated)
              
              . format D42d %td
              
              . codebook D42d
              
              ------------------------------------------------------------------------------------------------
              D42d                                                                                 (unlabeled)
              ------------------------------------------------------------------------------------------------
              
                                type:  numeric daily date (float)
              
                               range:  [19926,20011]                units:  1
                     or equivalently:  [22jul2014,15oct2014]        units:  days
                       unique values:  6                        missing .:  3/29
              
                          tabulation:  Freq.  Value
                                           1  19926  22jul2014
                                           7  19936  01aug2014
                                           8  19940  05aug2014
                                           2  19941  06aug2014
                                           4  19943  08aug2014
                                           4  20011  15oct2014
                                           3  .              .
              
              . list D42 D42d, clean noobs
              
                         D42        D42d  
                    8/6/2014   06aug2014  
                    8/6/2014   06aug2014  
                    8/5/2014   05aug2014  
                    8/5/2014   05aug2014  
                    8/5/2014   05aug2014  
                    8/5/2014   05aug2014  
                    8/5/2014   05aug2014  
                    8/5/2014   05aug2014  
                    8/5/2014   05aug2014  
                    8/5/2014   05aug2014  
                           -           .  
                   7/22/2014   22jul2014  
                  10/15/2014   15oct2014  
                  10/15/2014   15oct2014  
                           .           .  
                  10/15/2014   15oct2014  
                  10/15/2014   15oct2014  
                    8/1/2014   01aug2014  
                           -           .  
                    8/1/2014   01aug2014  
                    8/1/2014   01aug2014  
                    8/1/2014   01aug2014  
                    8/1/2014   01aug2014  
                    8/1/2014   01aug2014  
                    8/1/2014   01aug2014  
                    8/8/2014   08aug2014  
                    8/8/2014   08aug2014  
                    8/8/2014   08aug2014  
                    8/8/2014   08aug2014

              Comment

              Working...
              X