Page 1 of 1
mean and var of series by every two obs
Posted: Sat Feb 20, 2016 8:12 am
by metrix
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.
Re: mean and var of series by every two obs
Posted: Sat Feb 20, 2016 8:41 am
by startz
Perhaps @movav, @movvar
Re: mean and var of series by every two obs
Posted: Sat Feb 20, 2016 11:38 am
by metrix
i need this:
Re: mean and var of series by every two obs
Posted: Sat Feb 20, 2016 12:22 pm
by startz
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
Re: mean and var of series by every two obs
Posted: Sun Feb 21, 2016 10:21 am
by metrix
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

, thanks for all your efforts
any help.
Re: mean and var of series by every two obs
Posted: Sun Feb 21, 2016 11:31 am
by EViews Gareth
Not really sure what you're asking - Startz' code does what you want, doesn't it?
Re: mean and var of series by every two obs
Posted: Sun Feb 21, 2016 1:12 pm
by ch2324
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.
Re: mean and var of series by every two obs
Posted: Sun Feb 21, 2016 2:34 pm
by EViews Gareth
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.
Re: mean and var of series by every two obs
Posted: Mon Feb 22, 2016 12:07 pm
by ch2324
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
Re: mean and var of series by every two obs
Posted: Mon Feb 22, 2016 12:12 pm
by EViews Gareth
You didn't copy Startz' code properly.
Re: mean and var of series by every two obs
Posted: Mon Feb 22, 2016 12:15 pm
by ch2324
because it not work, some error message appear

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)

Re: mean and var of series by every two obs
Posted: Mon Feb 22, 2016 12:27 pm
by startz
I think you may just have some typos.
Re: mean and var of series by every two obs
Posted: Tue Feb 23, 2016 1:14 pm
by ch2324
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.

Re: mean and var of series by every two obs
Posted: Tue Feb 23, 2016 2:54 pm
by startz
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.
Re: mean and var of series by every two obs
Posted: Wed Feb 24, 2016 9:43 am
by ch2324
ok! Mr stratz, thanks for all your efforts, same for Mr Gareth. :)