Page 1 of 1

Extracting data from multipel series

Posted: Mon Mar 09, 2015 8:18 am
by bananen
Good evening,

I'm trying to program a script to extract observations from different series into a new one. I have series in the naming format of aW_Y & bW_Y where W=week number and Y=year. Example: a01_06, b52_96. The observations are dated about 5 times a week, and I want to take the 7th last observation from every series, and input into a new time series. It would be greatly appreciated if someone could offer support.

Code: Select all

series new for !i = 1 to 53 for !j = 95 to 99 series new = A{i}_{j}.(@dateadd(@last, -7, "dd")) next next for !i = 1 to 53 for !j =00 to 99 series new = B{i}_{j}.(@dateadd(@last, -7, "dd")) next next

Re: Extracting data from multipel series

Posted: Mon Mar 09, 2015 8:56 am
by EViews Gareth
Something like:

Code: Select all

%alist = @wlookup("a*", "series") for %j {%alist} smpl if {%j}<>na !obs = @obssmpl-7+1 %date = @otods(!obs) smpl {%date} {%date} series new = {%j} next %blist = @wlookup("b*", "series") for %j {%blist} smpl if {%j}<>na !obs = @obssmpl-7+1 %date = @otods(!obs) smpl {%date} {%date} series new = {%j} next

Re: Extracting data from multipel series

Posted: Mon Mar 09, 2015 11:38 am
by bananen
Thank you very much Gareth! Works like a charm when the series are modified for missing values.

Re: Extracting data from multipel series

Posted: Wed Mar 25, 2015 8:30 am
by bananen
I have another question. If I have a panel, and would like to extract the last value of each cross section, that is not NA, in a series, into a new one, and fill all observations within that cross section with the same value. How would one address this issue?

I made an example below. X symoblises the original series, and the line separates the cross sections.

Code: Select all

x y na 176,5 na 176,5 173 176,5 175 176,5 176,5 176,5 na 176,5 na 176,5 -------------- na 174 177 174 174 174 na 174 na 174
I tried experimenting with some new code but did not get it to work out. Would be grateful if you have some input.

Re: Extracting data from multipel series

Posted: Wed Mar 25, 2015 10:23 am
by EViews Gareth

Code: Select all

'make some data create a 1990 2000 10 rndseed 1 smpl if nrnd<0.6 series x = @floor(rnd*10)+160 smpl @all 'do the series generation for !i=1 to 10 'loop over the cross-sections smpl if @crossid=!i series y = @last(x) 'set series y equal to the last value in x next

Re: Extracting data from multipel series

Posted: Wed Mar 25, 2015 11:04 am
by EViews Glenn
Think this works a little better

Code: Select all

series adjtrend = @recode(x<>na, @trend, na) series lasttrend = @maxsby(adjtrend, @crossid) series y = @meansby(x, @crossid, "if @trend=lasttrend")

Re: Extracting data from multipel series

Posted: Mon Mar 30, 2015 2:57 am
by bananen
Thanks for the idea and effort. Unfortunately, none of the suggestions did work out, as both of them filled y with the last value of x, from the last cross section.

Code: Select all

for !i=1 to 1018 smpl if @crossid=!i series adjtrend = @recode(x<>na, @trend, na) series lasttrend = @maxsby(adjtrend, @crossid) series y = @meansby(x, @crossid, "if @trend=lasttrend") next

Code: Select all

'make some data create a 1990 2000 10 rndseed 1 smpl if nrnd<0.6 series x = @floor(rnd*10)+160 smpl @all 'do the series generation for !i=1 to 10 'loop over the cross-sections smpl if @crossid=!i series y = @last(x) 'set series y equal to the last value in x next
Think this works a little better

Code: Select all

series adjtrend = @recode(x<>na, @trend, na) series lasttrend = @maxsby(adjtrend, @crossid) series y = @meansby(x, @crossid, "if @trend=lasttrend")

Re: Extracting data from multipel series

Posted: Mon Mar 30, 2015 7:58 am
by EViews Gareth
Did you try running our example codes?

Re: Extracting data from multipel series

Posted: Mon Mar 30, 2015 2:05 pm
by bananen
Did you try running our example codes?
Yes, like I said, unfortunately none of the examples worked out. The code i posted was my attempt after running both your ideas first.