Calculating average of a part of a vector

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

Akavall
Posts: 14
Joined: Tue Mar 09, 2010 10:01 am

Calculating average of a part of a vector

Postby Akavall » Tue Mar 09, 2010 1:02 pm

Hello,

I think my question is pretty basic, but I am new to e-views, so here it is:

Let's say I have a 4x1 vector X [1,2,3,4] and I want to calculate the average of the first two cells, i.e, [1,2]

What would be the syntax to do that?

Would the same thing work if X is a series?

Thanks in advance.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Calculating average of a part of a vector

Postby EViews Glenn » Tue Mar 09, 2010 2:35 pm

For the vector

Code: Select all

scalar meanval = @mean(@subextract(vec, 1, 1, 2, 1))
The arguments to @subextract are startrow, startcol, endrow, endcol.

For a series, set the sample, then compute the mean.
Last edited by EViews Glenn on Tue Mar 09, 2010 4:27 pm, edited 1 time in total.

Akavall
Posts: 14
Joined: Tue Mar 09, 2010 10:01 am

Re: Calculating average of a part of a vector

Postby Akavall » Tue Mar 09, 2010 3:27 pm

Got it! Thanks a lot!

Riaz
Posts: 33
Joined: Wed Jul 01, 2009 1:46 am
Location: Western Australia

Re: Calculating average of a part of a vector

Postby Riaz » Mon Mar 15, 2010 12:50 am

Hello

I have the following series called GSP and I wonder how I could apply the SUBEXTRACT above to calculate the last 3 observations of the series.

2004Q1 31890.13
2004Q2 32013.67
2004Q3 32206.76
2004Q4 32558.51
2005Q1 33615.45
2005Q2 33444.33
2005Q3 34124.03
2005Q4 34598.91
2006Q1 34958.63
2006Q2 36176.06
2006Q3 36060.56
2006Q4 36767.85
2007Q1 37248.44
2007Q2 37909.00
2007Q3 38322.54
2007Q4 38559.05
2008Q1 39835.42
2008Q2 38782.91
2008Q3 39639.01
2008Q4 38996.22
2009Q1 38112.44
2009Q2 39838.41
2009Q3 ?
2009Q4 ?
2010Q1 ?

To obtain the 2009Q3 figure I want to multiply the 2009Q2 by the last 4 period average growth rate of GSP. Similarly, for the 2009Q4 I want to multiply the 2009Q3 by the last 4 period average growth rate of GSP and so forth..

Many thanks, Riaz

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

Re: Calculating average of a part of a vector

Postby EViews Gareth » Mon Mar 15, 2010 8:27 am

smpl 2009:3 2010:1

GSP = gdp(-1)*growth


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 2 guests