Replace NA by 0

For questions regarding programming in the EViews programming language.

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

MoneyMarcus
Posts: 2
Joined: Tue Oct 12, 2010 6:31 am

Replace NA by 0

Postby MoneyMarcus » Tue Oct 12, 2010 6:55 am

Hi,
my series contains 1641 observations and some of them are NA-entries. I want to write a program that replaces them by zero. I tried it this way:

for !i = 1 to 1641
if @isna(@elem(series, !i)) then
@elem(series, !i} = 0
endif
next

Unfortunately, my code returns an error message, telling me that "an unnamed object cannot be converted to a string in IF...". What shall I do?

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

Replace NA by 0

Postby EViews Gareth » Tue Oct 12, 2010 7:06 am

Code: Select all

X=@recode(X=na,0,X)

tchaithonov
Posts: 168
Joined: Mon Apr 13, 2009 7:39 am
Location: New York City

Re: Replace NA by 0

Postby tchaithonov » Tue Oct 12, 2010 7:26 am

Code: Select all

X=@nan(X,0)

MoneyMarcus
Posts: 2
Joined: Tue Oct 12, 2010 6:31 am

Re: Replace NA by 0

Postby MoneyMarcus » Tue Oct 12, 2010 7:30 am

Great, thanks for your fast help!

canboardrp
Posts: 17
Joined: Tue Mar 06, 2012 9:11 am

Re: Replace NA by 0

Postby canboardrp » Tue Jul 17, 2012 11:41 am

I got a number of series where I have this same problem and I've tried the recode approach as below and it hasn't worked. I'm still left with NA's in the series and it's throwing things off for me.

Code: Select all

Nonwork=@recode(na,0,0)
What have I got wrong in the programming?

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

Re: Replace NA by 0

Postby EViews Gareth » Tue Jul 17, 2012 1:37 pm

Looks like you got the syntax wrong:

Code: Select all

X=@recode(X=na,0,X)


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests