Announcement

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

  • Problem sorting dates using "sort" command

    Hello,

    I am conducting a data analysis involving date variables (date of birth, date of evaluation etc.) and I am trying to 1) sort my dates in ascending order, 2) group the dates by year ONLY to be able to create a "year of birth" variable. However, when I try to sort my dates using the sort command, Stata fails to do so. The dates are still mixed up when I browse the data. I have tried converting my date string variable into a numeric variable and put the dates into date format, but this has not worked. The dates are still out of order.

    Has anyone else had this issue before? Would be grateful for any advice.

    Thank you!

    Marie



  • #2
    Data example pleass

    Comment


    • #3
      Your question, unfortunately, does not provide sufficient information to enable a helpful response. For that, you will need to show:
      1. The exact commands you have tried, along with any output (including error messages) those may have produced in your Results window. To assure that all of this is portrayed exactly as it happened, these should be copy/pasted from the Results window or your log file into the Forum editor and surrounded by code delimiters to enhance readability here. If you are unfamiliar with code delimiters, please see Forum FAQ #12 for additional information.
      2. An example of your data and metadata, as provided by the -dataex- command. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.
      Added: Crossed with #2.

      Comment


      • #4
        I have tried converting my date string variable into a numeric variable and put the dates into date format, but this has not worked.
        You don't tell us precisely what your date sting variable looks like (no data example), and precisely what commands you used to convert it to a numeric variable and assign an appropriate display format, but it seems very likely that you did not use the proper commands to do so.

        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 and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

        Comment


        • #5
          Thank you all for the messages. I am new to Statalist so sorry for any mistakes! I will post an example next time

          Comment

          Working...
          X