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: 12
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: 13307
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: 12
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: 12
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: 560
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: 12
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: 560
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: 12
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!

shunkar
Posts: 6
Joined: Sat Aug 08, 2020 6:45 am

Re: normalize a group of variables

Postby shunkar » Sat Apr 24, 2021 3:33 am

Hello,
I have a related question. I have a panel data sample with various IDs and dates. How can I normalize each variable so that the new series will reflect only the means and standard deviations of each subsample based on ID? Let's says I have three firms X, Y, and Z for the variable Income. When I use "genr Norm_Income = (Income - @mean(Income))/@stdev(Income)" I get normalized variable across the whole sample but in my case, each of them is independent and using the full sample mean and standard deviation makes no sense. I need to use a function that will estimate means and standard deviations for each frim. Dividing the whole sample into subsamples (using smpl) and standardizing the Income for each firm, as in the method above, is not an option as I have more than 5'000 firms.

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: normalize a group of variables

Postby startz » Sat Apr 24, 2021 7:00 am

Look at @meansby()

shunkar
Posts: 6
Joined: Sat Aug 08, 2020 6:45 am

Re: normalize a group of variables

Postby shunkar » Sun Apr 25, 2021 1:50 am

Thank you, that's exactly what I have been looking for. For those who have a similar issue, here is the link:
http://www.eviews.com/help/helpintro.ht ... 23ww132503


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 22 guests