Announcement

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

  • Convert YYYY-MM-DD to YYYYMM

    I want to create a yearmonth variable from my date variable (YYYY-MM-DD)
    i.e convert "2005-04-03" to "200504"
    The commands I am using keep throwing up missing values or mismatch errors.
    Anyone know how to do this on Stata?

  • #2
    Please provide data examples using dataex (SSC) and show what code you tried to get explanations of what you are doing wrong (FAQ Advice #12).

    Code:
    . clear
    
    . set obs 1
    number of observations (_N) was 0, now 1
    
    . gen ddate = daily("2005-04-03", "YMD")
    
    . gen mdate = mofd(ddate)
    
    . format mdate %tmCYN
    
    . l
    
         +----------------+
         | ddate    mdate |
         |----------------|
      1. | 16529   200504 |
         +----------------+
    mofd() is documented under help dates: see SIF-to-SIF conversion.

    Comment

    Working...
    X