Page 1 of 1

Find a special day each month

Posted: Thu Oct 30, 2014 2:31 am
by johansamuelsson
Hi

For a given period, for example 1/1/2014 to 12/31/2014, I would like to create a string for the date of the third Wednesday every month (i.e. the date between the 15th and 21st , whichever such day is a Wednesday).

I.e. the string should, in this example, create 12 dates, 1/15/2014, 2/12//2014, and so on.

I'm not sure how i should start and what functions I should use.

Regards Johan

Re: Find a special day each month

Posted: Thu Oct 30, 2014 10:01 am
by EViews Chris
Here's one approach. First calculate the first Wednesday in each month:

Code: Select all

series firstwed = @recode(@weekday>3, @date+(10-@weekday), @date+(3-@weekday))
Then add on two weeks to get to the third wednesday:

Code: Select all

show @datestr(firstwed + 14, "Weekday Month day year")
I'm taking a bit of a shortcut here by adding on days to dates by simple addition rather than using @dateadd().

Re: Find a special day each month

Posted: Thu Oct 30, 2014 11:05 am
by johansamuelsson
Great!