Merging series - backward from an unspecified date

For questions regarding programming in the EViews programming language.

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

maragloria
Posts: 101
Joined: Tue Jun 29, 2010 7:09 am

Merging series - backward from an unspecified date

Postby maragloria » Thu Oct 12, 2023 7:17 am

Hi there,

I would like to merge two series, backward from an unspecified date. The first series have missing observations up to a date that can vary per country and variable. I would like to backfill these observations based on the rate of change of a 2nd series.

The difficulty for me lies in getting the observation date to start from. For instance, series 1 starts at 2004Q4 for country A, but at 2006Q1 for country B (with other dates for the remaining countries and variables). How can I get the different dates for each country, from which I should start the backfill? Could you give some tips of how best I could program this task?

many thanks!

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

Re: Merging series - backward from an unspecified date

Postby EViews Gareth » Thu Oct 12, 2023 7:43 am

Need more information on the structure of what you're trying to do. Perhaps an example workfile.
Follow us on Twitter @IHSEViews

maragloria
Posts: 101
Joined: Tue Jun 29, 2010 7:09 am

Re: Merging series - backward from an unspecified date

Postby maragloria » Thu Oct 12, 2023 8:46 am

Thanks for the quick reply, Gareth.

Please find a sample wf attached.

I've grouped the series I would like to merge for China and Chile as an example. It contains stock of reserves (% GDP) for a few countries, from two different sources.

For China, the series cg_rsrvsa_chn starts only in 2004Q4. I would use the observations (rate of change) from the 2nd series ns_rsrvsa_chn to backfill it.

For Chile, the starting date is 2003Q4 (cg_rsrvsa_chl). I would backfill it with ns_rsrvsa_chl.

The starting date can vary for the remaining countries.
Attachments
merge_series.wf1
(98.48 KiB) Downloaded 65 times

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

Re: Merging series - backward from an unspecified date

Postby EViews Gareth » Thu Oct 12, 2023 9:24 am

So assuming you have some sort of loop that goes through the countries, you can use the series.@first data member to retrieve the date of the first non-NA observation and then use that to set the sample:

Code: Select all

%start = cg_rsrvsa_{%country}.@first
smpl @first {%start}
Follow us on Twitter @IHSEViews

maragloria
Posts: 101
Joined: Tue Jun 29, 2010 7:09 am

Re: Merging series - backward from an unspecified date

Postby maragloria » Thu Oct 12, 2023 3:44 pm

Quite simple! Thank you for the suggestion. I've implemented it in a for loop for the remaining countries.

The backward filling (staring from later date and moving back up to first date) proved a bit more challenging. I've implemented with a while loop:

Code: Select all

   smpl @all
   series cg_{%country}_{%pays} =  {%1}_{%country}

   'get date of the first non-NA observation
   %start = cg_{%seriesname}_{%country}.@first   
   smpl @first {%start}
   if @obssmpl > 1 then
      !temp = @obssmpl
      while !temp > 1
         smpl @first @first+!temp-2   
         series cg_{%seriesname}_{%country} = cg_{%seriesname}_{%country}(+1)*({%2}_{%country}/{%2}_{%country}(+1)) 'backward filling
         !temp=!temp-1
      wend
   endif


Thanks once again!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 20 guests