Page 1 of 1

Fill NA values with first non-NA value

Posted: Wed Jul 06, 2011 9:41 am
by javiersan
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

Re: Fill NA values with first non-NA value

Posted: Wed Jul 06, 2011 10:09 am
by EViews Glenn
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

Re: Fill NA values with first non-NA value

Posted: Wed Jul 06, 2011 10:12 am
by javiersan
Thanks!