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!
Merging series - backward from an unspecified date
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
- Posts: 101
- Joined: Tue Jun 29, 2010 7:09 am
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13380
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Merging series - backward from an unspecified date
Need more information on the structure of what you're trying to do. Perhaps an example workfile.
Follow us on Twitter @IHSEViews
-
- Posts: 101
- Joined: Tue Jun 29, 2010 7:09 am
Re: Merging series - backward from an unspecified date
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.
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 232 times
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13380
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Merging series - backward from an unspecified date
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
-
- Posts: 101
- Joined: Tue Jun 29, 2010 7:09 am
Re: Merging series - backward from an unspecified date
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:
Thanks once again!
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
Who is online
Users browsing this forum: Google [Bot], Semrush [Bot] and 2 guests