normalize a group of variables

For questions regarding programming in the EViews programming language.

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

veni
Posts: 9
Joined: Fri Sep 02, 2016 6:04 am

normalize a group of variables

Postby veni » Fri Sep 02, 2016 6:16 am

Hi All.
I have a group of more than 100variables and I'd like to normalize the members (x(:,i)-mean/std) and then create a new group. Is it a way to do that?
Thanks in advance.Veni

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

Re: normalize a group of variables

Postby EViews Gareth » Fri Sep 02, 2016 8:10 am

Something like:

Code: Select all

group mynewgroup
for !i=1 to mygroup.@count
   %sn = mygroup.@seriesname(!i)
   series {%sn}_norm = ({%sn}-@mean({%sn}))/@stdev({%sn})
   mynewgroup.add {%sn}
next
Follow us on Twitter @IHSEViews

veni
Posts: 9
Joined: Fri Sep 02, 2016 6:04 am

Re: normalize a group of variables

Postby veni » Mon Sep 05, 2016 12:18 am

Thanks a lot Gareth!

veni
Posts: 9
Joined: Fri Sep 02, 2016 6:04 am

Construct a series from a series

Postby veni » Thu Jan 19, 2017 6:34 am

Hi All
I have the following simple thing to do; given two series, namely phase and x, I'd like to construct four new series subject to some constraints fulfilled for the first one. That is if phase(i)=1, create a new series ret1, where ret1(i)=x(i), if phase(i)=2, then ret2(i)=x(i) etc.
Doing this

for !i=2 to @rows(x)-1
if phase(!i)=1 then
!count1=!count1+1
ret1{!count1}=x{!i}
'I exclude the other options
endif

I've got an error that !count1 is not defined in !count1=!count1+1

and doing this
!count1=0
scalar phase1=0
for !i=2 to @rows(x)-1
if phase(!i)=1 then
!count1=!count1+1
phase1=phase1+1
series ret1(!count1)=x(!i)
endif
next

I'm getting the series ret1 which has the same size as the original one (although the goal is to have as many rows as the count1).

Can you provide some advice? Many thanks in advance!

CharlieEVIEWS
Posts: 202
Joined: Tue Jul 17, 2012 9:47 am

Re: normalize a group of variables

Postby CharlieEVIEWS » Thu Jan 19, 2017 8:08 am

Bit late in seeing this, but the the MacroTrans add-in was built for this (at least - the first post) type of purpose in a dated workfile context.

EViews Matt
EViews Developer
Posts: 430
Joined: Thu Apr 25, 2013 7:48 pm

Re: normalize a group of variables

Postby EViews Matt » Thu Jan 19, 2017 11:38 am

Hello,

EViews can do the heavy lifting of matching and iterating through all the rows for you...

Code: Select all

for !i = @min(phase) to @max(phase)
   smpl if phase = !i
   vector ret{!i} = x
next
smpl @all


Since you want the four new result structures to contain only as many rows as are copied from series x, those structures need to vector objects instead of series objects. Series objects always contain as many rows (observations) as their enclosing workfile page, but vector objects can have any number of rows. Using the "smpl" command followed by an assignment/copy command is an easy way to get EViews to find and copy only the rows of data you want. I've wrapped that in a loop going through all your phase numbers, assuming they're always consecutive integers. You could add or remove phases without modifying the above code.

veni
Posts: 9
Joined: Fri Sep 02, 2016 6:04 am

Re: normalize a group of variables

Postby veni » Fri Jan 20, 2017 1:30 am

Matt, thank you so much for replying so quickly and for the code. Can you suggest some reading? Unfortunately, I'm matlab user.

EViews Matt
EViews Developer
Posts: 430
Joined: Thu Apr 25, 2013 7:48 pm

Re: normalize a group of variables

Postby EViews Matt » Fri Jan 20, 2017 9:47 am


veni
Posts: 9
Joined: Fri Sep 02, 2016 6:04 am

Re: normalize a group of variables

Postby veni » Sat Jan 21, 2017 7:13 am

Thank you so much!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 10 guests