Page 1 of 1

How to calculate the number of month between two dates

Posted: Wed Feb 24, 2016 11:29 am
by DBel2012
Hi,

I'm using EViews 9.

A very simple one that I can't figure out...

I'm working with monthly data. In my program, I need to calculate the number of months between two dates

for instance, if I've got this code :

smpl %end_est %end_forecast

What formula would give me the number of months in that current sample ?

Thanks!

Danny

Re: How to calculate the number of month between two dates

Posted: Wed Feb 24, 2016 12:05 pm
by EViews Gareth
Depends. Are you asking how many observations are there between the end and start of the current sample? If so @obssmpl.

If you want to know how many months there are between two dates, you can use @datediff.

Re: How to calculate the number of month between two dates

Posted: Thu Feb 25, 2016 6:33 am
by DBel2012
Hi,

@obssmpl works fine as long as there are no missing values in the sample period.

Given two dates (ex. smpl 2008m12 and 2012m06), is there another way to determine the number of months covered by that sample period?

Thanks!

Danny

Re: How to calculate the number of month between two dates

Posted: Thu Feb 25, 2016 7:04 am
by EViews Gareth
Not sure what you are askibg

Re: How to calculate the number of month between two dates

Posted: Thu Feb 25, 2016 7:35 am
by DBel2012
Hi,

I want to run a program that ask the user to provide a sample period of two dates (ex. 2008m12 and 2012m06) and I need a command or formula that will determine the number of months between these two dates. That number will be used later in the program in a For loop.

Is there a way other than using the @obssmpl?

Thanks!

Danny

Re: How to calculate the number of month between two dates

Posted: Thu Feb 25, 2016 7:39 am
by EViews Gareth
Depends. Are you asking how many observations are there between the end and start of the current sample? If so @obssmpl.

If you want to know how many months there are between two dates, you can use @datediff.

Re: How to calculate the number of month between two dates

Posted: Thu Feb 25, 2016 11:13 am
by DBel2012
Hi Gareth,

@datediff works perfectly.

Thanks a lot!

Danny

Re: How to calculate the number of month between two dates

Posted: Thu Feb 25, 2016 11:21 am
by EViews Gareth
That's why I mentioned it the first time :D