Announcement

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

  • Dates in years

    Hello,
    The three variables given below are the interview dates in my dataset.
    1. How do I first of all convert it into an understandable format - say 13january2005?
    2. How do I isolate just the year and month, to create year and month variables separately?
    3. I know that the interview years should turn out to be 2004, 2005, and maybe some observations in 2006- because that's when the survey was administered.






    dataex HS2 CD2 CD2C

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str6(HS2 CD2) int CD2C
    "180705" "180705" 1267
    "180705" "180705" 1267
    "180705" "180705" 1267
    "180705" "180705" 1267
    "190705" "190705" 1267
    "180705" "180705" 1267
    "170705" "170705" 1267
    "190705" "190705" 1267
    "180705" "180705" 1267
    "170705" "170705" 1267
    "190705" "190705" 1267
    "170705" "170705" 1267
    "170705" "170705" 1267
    "170705" "170705" 1267
    "170705" "170705" 1267
    "170705" "170705" 1267
    "190705" "190705" 1267
    "170705" "170705" 1267
    "180705" "180705" 1267
    "180705" "180705" 1267
    "310705" "310705" 1267
    "290705" "90705"  1267
    "290705" "290705" 1267
    "290705" "290705" 1267
    "310705" "310705" 1267
    "290705" "290705" 1267
    "310705" "310705" 1267
    "310705" "310705" 1267
    "310705" "310705" 1267
    "310705" "310705" 1267
    "290705" "290705" 1267
    "310705" "310705" 1267
    "290705" "290705" 1267
    "290705" "290705" 1267
    "290705" "290705" 1267
    "310705" "310705" 1267
    "310705" "310705" 1267
    "290705" "290705" 1267
    "290705" "290705" 1267
    "310705" "310705" 1267
    "250705" "250705" 1267
    "230705" "230705" 1267
    "230705" "230705" 1267
    "220705" "220705" 1267
    "220705" "220705" 1267
    "250705" "250705" 1267
    "240705" "240705" 1267
    "240705" "240705" 1267
    "250705" "250705" 1267
    "250705" "250705" 1267
    "240705" "240705" 1267
    "250705" "250705" 1267
    "240705" "240705" 1267
    "220705" "220705" 1267
    "230705" "230705" 1267
    "230705" "230705" 1267
    "250705" "250705" 1267
    "250705" "250705" 1267
    "270505" "250705" 1267
    "230705" "230705" 1267
    "100705" "100705" 1267
    "90705"  "90705"  1267
    "120705" "120705" 1267
    "140705" "140705" 1267
    "90705"  "90705"  1267
    "100705" "100705" 1267
    "100705" "100705" 1267
    "110705" "110705" 1267
    "110705" "110705" 1267
    "110705" "110705" 1267
    "100705" "90705"  1267
    "90705"  "90705"  1267
    "140705" "140705" 1267
    "100705" "110705" 1267
    "120705" "120705" 1267
    "110705" "110705" 1267
    "120705" "120705" 1267
    "120705" "120705" 1267
    "150705" "150705" 1267
    "120705" "120705" 1267
    "30805"  "30805"  1268
    "30805"  "30805"  1268
    "30805"  "30805"  1268
    "30805"  "30805"  1268
    "30805"  "30805"  1268
    "30805"  "30805"  1268
    "30805"  "30805"  1268
    "30805"  "30805"  1268
    "30805"  "30805"  1268
    "40805"  "40805"  1268
    "40805"  "40805"  1268
    "30805"  "30805"  1268
    "40805"  "40805"  1268
    "30805"  "40805"  1268
    "30805"  "30805"  1268
    "30805"  "30805"  1268
    "30805"  "30805"  1268
    "30805"  "30805"  1268
    "40805"  "40805"  1268
    "30805"  "30805"  1268
    end
    ------------------ copy up to and including the previous line ---------


  • #2
    See

    Code:
    help datetime
    The manipulations are standard except for some awkwardness with 5 digit dates.

    Try

    Code:
    gen HS2ddate = daily(HS2, “DM20Y”)
    replace HS2ddate = daily(“0” + HS2, “DM20Y”) if missing(HS2ddate)
    format HS2ddate %td
    Then use functions like month() and year() to extract components.

    There is no road to understanding dates in any software that does not go through reading the documentation.

    Comment

    Working...
    X