Hi all:

I am gettings problems when I encode a date variable, to explain my problem I will use this example:

Code:
webuse wpi1, clear

 list in 1/10

     +--------------------------+
     |  wpi        t     ln_wpi |
     |--------------------------|
  1. | 30.7   1960q1   3.424263 |
  2. | 30.8   1960q2   3.427515 |
  3. | 30.7   1960q3   3.424263 |
  4. | 30.7   1960q4   3.424263 |
  5. | 30.8   1961q1   3.427515 |
     |--------------------------|
  6. | 30.5   1961q2   3.417727 |
  7. | 30.5   1961q3   3.417727 |
I know that dates are quaterly but for this example i will format with slash and day/month/year to describe in a beter way my problem:

Code:
format t %tdd/N/CY
I am using this format because I am using labels to make my graphs and its better to understand in spanish and not english format (january, april, etc... )

Code:
generate date = string(t, "%tdd/N/CY")
encode date, gen(date2)
Lamentably when I encode the variable: date, the values are not in order according the dates, in image below you can see that 5/01/1960 have a value=105 and not a value=5 tht is a value expected for me.

Array




When i save graph I use values (v) and not labels (vl) to avoid error with slash in directory folder. (its a fool graph I know, just one example):

Code:
levelsof date2, local(levels)
local nombre: value label date2

foreach v of local levels {
    local vl: label `nombre' `v'
    
    line wpi date2 if date2 == `v', ti(`vl')
}

 graph export  "C:\User\`v'.png", replace
But graphs are saved not in the real date order, lamentable I need real order to make an animation and need the real date order.

I know that I could use

Code:
label define order 1 "1/01/1960"...

encode date, gen(date2) label(order)
But I have a big number of dates.

Please any comments I would grateful

Thanks in advance
Rodrigo.