Fill NA values with first non-NA value

For questions regarding programming in the EViews programming language.

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

javiersan
Posts: 184
Joined: Mon Jan 19, 2009 8:18 am

Fill NA values with first non-NA value

Postby javiersan » Wed Jul 06, 2011 9:41 am

Hi,

I have a series that has NAs for the first, say, 20 periods and then non-na values. How do I "fill" the NAs up to the first non-na value with the first non-na value?

If the NAs were located at the end of the series, x=@recode(x=na,x(-1),x) works but I can't manage to work a variation of this expression for the question above.

Could you please help?

Thanks,

Javier

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

Re: Fill NA values with first non-NA value

Postby EViews Glenn » Wed Jul 06, 2011 10:09 am

Identify the first obs, get the value in that period, assign to the prior obs...

Code: Select all

smpl @all series newx = x scalar val = @first(x) scalar id = @ifirst(x) smpl @first @first+id-2 newx = val smpl @all show newx x

javiersan
Posts: 184
Joined: Mon Jan 19, 2009 8:18 am

Re: Fill NA values with first non-NA value

Postby javiersan » Wed Jul 06, 2011 10:12 am

Thanks!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests