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
normalize a group of variables
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13323
- Joined: Tue Sep 16, 2008 5:38 pm
Re: normalize a group of variables
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
Re: normalize a group of variables
Thanks a lot Gareth!
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).
Can you provide some advice? Many thanks in advance!
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!
-
- 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 Developer
- Posts: 564
- 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...
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.
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.
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 Developer
- Posts: 564
- 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:
Reading specifically regarding EViews programming? Here are some ideas:
Re: normalize a group of variables
Thank you so much!
Re: normalize a group of variables
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.
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.
-
- Non-normality and collinearity are NOT problems!
- Posts: 3775
- Joined: Wed Sep 17, 2008 2:25 pm
Re: normalize a group of variables
Look at @meansby()
Re: normalize a group of variables
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
http://www.eviews.com/help/helpintro.ht ... 23ww132503
Who is online
Users browsing this forum: No registered users and 15 guests