Question on @date and @obssmpl functions.

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

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

Liu
Posts: 90
Joined: Tue Jun 08, 2010 6:22 am

Question on @date and @obssmpl functions.

Postby Liu » Mon Jul 26, 2010 11:42 am

Hi.
I have a question on using @date and @obssmpl function.
My goal is to return the first date and last date of a series (say series1) as well as how many observations totally there are in the series.
and eventually return observations of the exact dates from another series. I tried to use both @date and @enddate for the purpose but it
returns errors. Besides, both functions are supposed to return start date and end date of the work file, rather than the start date and end date of non"NA"
observations of my series.

Similar thing happens to !y=series1.@obssmpl.

Could anybody tell me how to return first/last date of a series ( not the two ends of a wf), as well as observation counts?

Thanks for your help.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Question on @date and @obssmpl functions.

Postby EViews Glenn » Mon Jul 26, 2010 2:17 pm

@obs(seriesname) should always give you the number of observations accounting for missings, as in

Code: Select all

scalar obs = @obs(series01)
To find the starts of the set the sample to the non-missings for your series

Code: Select all

smpl if series1<>na
then @otods(1) will give you the start date of the sample, and @otods(@obs(seriesname)) will given the end date of the sample, as in

Code: Select all

string firstdate = @otods(1) string lastdate = @otods(obs)

Liu
Posts: 90
Joined: Tue Jun 08, 2010 6:22 am

Re: Question on @date and @obssmpl functions.

Postby Liu » Tue Jul 27, 2010 2:40 pm

Thanks so much for your help.

I want to use the observation of the same date from two different series (s1 and s2), to adjust the first
series. Here is my code but the firstdate string is not recognized. (With or without the quote on firstdate string.)

smpl if s1<>na
string firstdate=@otods(1)
series s1adj=s1*@elem(s2, "firstdate")/@elem(s1, "firstdate")


Also can you tell me if I need to specify the series name for the code: string firstdate=@otods(1). ?

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

Re: Question on @date and @obssmpl functions.

Postby EViews Gareth » Tue Jul 27, 2010 2:50 pm

Further to Glenn's answer, you'll probably find the series.@first and series.@last data members useful - I believe they do exactly what you want (return the date of the first non-missing observation).

Using your existing code though, use this:

Code: Select all

smpl if s1<>na %firstdate=@otods(1) series s1adj=s1*@elem(s2, %firstdate)/@elem(s1, %firstdate)

Liu
Posts: 90
Joined: Tue Jun 08, 2010 6:22 am

Re: Question on @date and @obssmpl functions.

Postby Liu » Wed Jul 28, 2010 12:40 pm

Thank you Gareth for the command. I tried it and it totally works.

Still I have a quick question. Actually I want to extract two first non"NA" dates and compare them, so that I can tell which series is "older"
How can I specify series name in the %firstdate=@otods(1) statement?

Also, is there a way to compare two date string and report which is older? Or to say, can I write something like %firstdate1 > %firstdate2 without
doing any string conversion ?

Thanks so much again!

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

Re: Question on @date and @obssmpl functions.

Postby EViews Gareth » Wed Jul 28, 2010 1:19 pm

Code: Select all

smpl if s1<>na %firstdate1=@otods(1) smpl if s2<>na %firstdate2=@otods(1) !diff =@datediff(@dateval(%firstdate1), @dateval(%firstdate2),"dd")
!diff will be the number of days between firstdate1 and firstdate2. If it is positive, then s2 is older.

Liu
Posts: 90
Joined: Tue Jun 08, 2010 6:22 am

Re: Question on @date and @obssmpl functions.

Postby Liu » Mon Aug 02, 2010 3:02 pm

Thanks Gareth again. It totally works now, based on your program!

I just have a quick question about another command. I use series.setconvert to change the default of conversion
method of a series when I was trying to save this serise to a db, so that next time when I extract it from the db,
I don't need to specify again.

I wrote:
myseries.setconvert c nf
store(d=db) myseries


However after I saved it to my db, I double click the series, and the windows shows that the conversion methods are
still default( this is the case for both "low to high" and "high to low" .) Can you tell me how to change this default? Thank you in advance.

EViews Jason
EViews Developer
Posts: 870
Joined: Tue Sep 16, 2008 3:50 pm

Re: Question on @date and @obssmpl functions.

Postby EViews Jason » Mon Aug 02, 2010 3:54 pm

What version of EViews are you using? Be sure that your copy is also up to date. The latest of version EViews 7.1 works as desired.

Liu
Posts: 90
Joined: Tue Jun 08, 2010 6:22 am

Re: Question on @date and @obssmpl functions.

Postby Liu » Tue Aug 03, 2010 5:40 am

Hi Jason. Thank you for your reply.

You are right. I updated it (I didn't know that there is a new update on July 30th) and it works now.
I use Eviews 7 Enterprise version. I realized that I should delete the old series from the database and store new ones.
If I just overwrite, the window doesn't change. In short, It all works perfectly now. Thanks so much again.


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 1 guest