Replacing the NAs by the last observation preceding the NA

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

Sissy
Posts: 30
Joined: Thu Apr 19, 2012 1:59 am

Replacing the NAs by the last observation preceding the NA

Postby Sissy » Tue Apr 24, 2012 1:27 pm

Hello,

In order to get a continuous sample to run an EGARCH regression, I'd like to replace the NAs by the last observation preceding the NA. How can I do that in Eviews 7 sv, please ?

Thanks in advance.

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

Re: Replacing the NAs by the last observation preceding the

Postby EViews Glenn » Tue Apr 24, 2012 2:00 pm

I'm not going to comment on the econometric issues associated with doing what you propose, but if A is the original series and you want to create a new series Y that has A or the last valid value for A, the following should do it for you.

Code: Select all

series y=@recode(a=na, y(-1), a)
This assumes that the first observation for A is valid.

Sissy
Posts: 30
Joined: Thu Apr 19, 2012 1:59 am

Re: Replacing the NAs by the last observation preceding the

Postby Sissy » Tue Apr 24, 2012 11:22 pm

Very good, it's ok :lol: Thank you very much.

chris2012
Posts: 2
Joined: Thu May 28, 2015 7:45 am

Re: Replacing the NAs by the last observation preceding the

Postby chris2012 » Thu May 28, 2015 7:58 am

This is a very useful tip, especially for those of us that import long series from external databases. I was wondering whether it would be possible to apply this command of filling NA values (either with lag, lead or 0 values) for all the series contained in the workfile simultaneously (i.e. a short script) and not just one-by-one.
P.S. Those kind of tricks may be a wonderful addition to a future update of EViews, they are real time savers!!

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

Re: Replacing the NAs by the last observation preceding the

Postby EViews Gareth » Thu May 28, 2015 8:28 am

Code: Select all

%list = @wlookup("*", "series") for %j {%list} {%j} = @recode({%j}=NA, {%j}(-1), {%j}) next

chris2012
Posts: 2
Joined: Thu May 28, 2015 7:45 am

Re: Replacing the NAs by the last observation preceding the

Postby chris2012 » Fri May 29, 2015 2:53 pm

DONE! Thank you for your prompt response. Is there a manual for all the symbols and commands you used to write this loop? In data transformation process, there are several loops that one may find helpful. I know that there exist some, like "EViews 5 Command and Programming Reference" or "EViews j Illustrated", but I find them quite case-specific. Maybe an extensive command index with short examples?
For instance, how to generate new returns series (named 'ret_GDP') for all existing prices variables (named 'GDP') contained in the workfile. It may seem trivial for someone familiar with coding techniques, yet every software has its own language!
Thanks again for your helpful insights!
All the best!

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

Re: Replacing the NAs by the last observation preceding the

Postby EViews Gareth » Fri May 29, 2015 3:10 pm

The Command and Programming Reference, available from the Help menu


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 2 guests