## 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

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?

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

### Re: normalize a group of variables

Something like:

Code: Select all

`group mynewgroupfor !i=1 to mygroup.@count   %sn = mygroup.@seriesname(!i)   series {%sn}_norm = ({%sn}-@mean({%sn}))/@stdev({%sn})   mynewgroup.add {%sn}next`

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

### Re: normalize a group of variables

Thanks a lot Gareth!

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

### Construct a series from a series

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).

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

### Re: normalize a group of variables

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

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} = xnextsmpl @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

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

You're welcome.

Reading specifically regarding EViews programming? Here are some ideas:

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

### Re: normalize a group of variables

Thank you so much!

### Who is online

Users browsing this forum: No registered users and 15 guests