How to calculate the number of month between two dates

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator

DBel2012
Posts: 69
Joined: Sun Sep 30, 2012 5:37 am

How to calculate the number of month between two dates

Postby DBel2012 » Wed Feb 24, 2016 11:29 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13317
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Wed Feb 24, 2016 12:05 pm

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.
Follow us on Twitter @IHSEViews

DBel2012
Posts: 69
Joined: Sun Sep 30, 2012 5:37 am

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

Postby DBel2012 » Thu Feb 25, 2016 6:33 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13317
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Thu Feb 25, 2016 7:04 am

Not sure what you are askibg
Follow us on Twitter @IHSEViews

DBel2012
Posts: 69
Joined: Sun Sep 30, 2012 5:37 am

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

Postby DBel2012 » Thu Feb 25, 2016 7:35 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13317
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Thu Feb 25, 2016 7:39 am

EViews Gareth wrote: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.
Follow us on Twitter @IHSEViews

DBel2012
Posts: 69
Joined: Sun Sep 30, 2012 5:37 am

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

Postby DBel2012 » Thu Feb 25, 2016 11:13 am

Hi Gareth,

@datediff works perfectly.

Thanks a lot!

Danny

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13317
Joined: Tue Sep 16, 2008 5:38 pm

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

Postby EViews Gareth » Thu Feb 25, 2016 11:21 am

That's why I mentioned it the first time :D


Return to “Data Manipulation”

Who is online

Users browsing this forum: Google [Bot] and 23 guests