mean and var of series by every two obs

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason

metrix
Posts: 57
Joined: Sun Dec 08, 2013 9:15 am

mean and var of series by every two obs

Postby metrix » Sat Feb 20, 2016 8:12 am

hi
i have 500 obs named (rate), how can make series (mrate) like this (obs1+obs2)/2, (obs3+obs4)/2, (obs5+obs6)/2....etc
and make variance by two obs.
any idea with this.

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

Re: mean and var of series by every two obs

Postby startz » Sat Feb 20, 2016 8:41 am

Perhaps @movav, @movvar

metrix
Posts: 57
Joined: Sun Dec 08, 2013 9:15 am

Re: mean and var of series by every two obs

Postby metrix » Sat Feb 20, 2016 11:38 am

i need this:
Attachments
meanvar.png
meanvar.png (30.38 KiB) Viewed 10749 times

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

Re: mean and var of series by every two obs

Postby startz » Sat Feb 20, 2016 12:22 pm

I haven't tried this code, but something like...

Code: Select all

series m=@movav(x,2) ' calculate moving statistics series v=@movvar(x,2) m = m(1) ' line up with first observation rather than second v = v(1) series isEven= 2*@floor(@obsnum/2) = @obsum ' find even numbered observations smpl if isEven m = na ' clear out obs you don't want v = na @smpl @all

metrix
Posts: 57
Joined: Sun Dec 08, 2013 9:15 am

Re: mean and var of series by every two obs

Postby metrix » Sun Feb 21, 2016 10:21 am

the problem there is no command or function to do this , and there is no way to do this by frequency conversion methods (hight to low) for integer date.
the code work, but not this result Mr startz :cry: , thanks for all your efforts
any help.

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

Re: mean and var of series by every two obs

Postby EViews Gareth » Sun Feb 21, 2016 11:31 am

Not really sure what you're asking - Startz' code does what you want, doesn't it?

ch2324
Posts: 133
Joined: Fri May 10, 2013 10:52 am

Re: mean and var of series by every two obs

Postby ch2324 » Sun Feb 21, 2016 1:12 pm

the code of Mr startz work. thanks for his help :) .
but i explain: suppose i have 100 obs integer date or unstructured/undated, i would like to calculate mean for every two obs and so on(two observation divided by two) i can chose mean or 3 obs, four obs...... that's what i need , then the result for this manipulation will be 50 obs (new series with 50 obs), same for the variance.
all this like frequency conversion hight to low, but here I can choose the mean of obs (mean of 2 obs, or mean of 3obs,....etc).
are there a solution for this by command or to enhance frequency conversion to do this (mean, variance, median,....) that we can choose the size of observasions.
Warmest regards for Mr Gareth and Mr startz.

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

Re: mean and var of series by every two obs

Postby EViews Gareth » Sun Feb 21, 2016 2:34 pm

But startz's code does exactly what you want - you end up with 50 observations that has the mean of every two obs. If you want 3 instead of 2, change the 2s to 3s.

ch2324
Posts: 133
Joined: Fri May 10, 2013 10:52 am

Re: mean and var of series by every two obs

Postby ch2324 » Mon Feb 22, 2016 12:07 pm

this is my workfile you can see that all series m and v have one value for the first obs and NA for all, this is the code of Mr startz

Code: Select all

series m=@movav(x,2) series v=@movvar(x,2) m = m(1) v = v(1) series isEven= 2*@floor(@obsnum/2) smpl if isEven m = na ' clear out obs you don't want v = na smpl @all
for example: i have 6 obs 10 12 15 20 30 18
the fisrt mean = (10+12)/2=11
the second mean=(15+20)/2=17.5
the third mean=(30+18)/2=6.25
i need this: (x+x(-1))/2, (x(-2)+x(-3))/2,....etc
but @movav(x,2) calculate the first mean like this(x+x(-1))/2 = (10+12)/2, for the second (x(-1)+x(-2))/2 =(12+15)/2,....etc
Attachments
st.wf1
(14.81 KiB) Downloaded 372 times

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

Re: mean and var of series by every two obs

Postby EViews Gareth » Mon Feb 22, 2016 12:12 pm

You didn't copy Startz' code properly.

ch2324
Posts: 133
Joined: Fri May 10, 2013 10:52 am

Re: mean and var of series by every two obs

Postby ch2324 » Mon Feb 22, 2016 12:15 pm

because it not work, some error message appear :oops:
1)series isEven= 2*@floor(@obsnum/2) = @obsum (@obsum in not a genr or series expression function)
2)@SMPL @all (@SMPL in not defined or is an illegal command)
:cry:

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

Re: mean and var of series by every two obs

Postby startz » Mon Feb 22, 2016 12:27 pm

I think you may just have some typos.

ch2324
Posts: 133
Joined: Fri May 10, 2013 10:52 am

Re: mean and var of series by every two obs

Postby ch2324 » Tue Feb 23, 2016 1:14 pm

i have followed the code step by step Mr startz by i get error (@SMPL in not defined or is an illegal command ) but if i use smpl @all the code work; and i get just the first mean and variance of the two obs. what can i do this is my workfile. :roll:
Attachments
st.wf1
(14.81 KiB) Downloaded 342 times
mv.png
mv.png (26.48 KiB) Viewed 10609 times
error.png
error.png (24.16 KiB) Viewed 10609 times

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

Re: mean and var of series by every two obs

Postby startz » Tue Feb 23, 2016 2:54 pm

The code I posted does not say "@smpl"
I suspect that you may still be suffering from typo problems. Computers are pretty literal minded, so trivial errors can really screw things up.

ch2324
Posts: 133
Joined: Fri May 10, 2013 10:52 am

Re: mean and var of series by every two obs

Postby ch2324 » Wed Feb 24, 2016 9:43 am

ok! Mr stratz, thanks for all your efforts, same for Mr Gareth. :)


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 2 guests