Find a special day each month

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

johansamuelsson
Posts: 165
Joined: Thu Mar 03, 2011 10:07 pm
Contact:

Find a special day each month

Postby johansamuelsson » Thu Oct 30, 2014 2:31 am

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

EViews Chris
EViews Developer
Posts: 161
Joined: Wed Sep 17, 2008 10:39 am

Re: Find a special day each month

Postby EViews Chris » Thu Oct 30, 2014 10:01 am

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().

johansamuelsson
Posts: 165
Joined: Thu Mar 03, 2011 10:07 pm
Contact:

Re: Find a special day each month

Postby johansamuelsson » Thu Oct 30, 2014 11:05 am

Great!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest