I'm trying to loop over dates in Stata.
I have an issue as I believe that my string variable is recognized as a date type.
For instance,
forvalues day = 1/31 {
if `day' < 10 {
local file_date ="2017-07-0`day'"
di `file_date'
}
else {
local file_date ="2017-07-`day'"
di `file_date'
}
*insert operation here
}
is printing 2009, 2008, 2007, etc.
even though the results should be 2017-07-01, 2017-07-02, etc.
Does anyone have a clue why this is happening?
By the way,
forvalues day=1/31 {
if `day' < 10 {
local file_date ="2017070`day'"
di `file_date'
}
else {
local file_date ="201707`day'"
di `file_date'
}
*insert operation here
}
works fine, but I want the hyphens in the variable.