How to get the median of each row of a matrix

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
zcmcgurk
Posts: 5
Joined: Sat Nov 29, 2014 10:40 am

How to get the median of each row of a matrix

Unread post by zcmcgurk »

So I guess this is similar question to one posted previously. I was wondering how you can get the median value for each row in a matrix. So here is some of the code I am using but I keep on getting this error "## SX22. Expected Type REAL, Got VECTOR[REAL] Instead >>>>(forecastA,i),0.5)<<<<"

Code: Select all

ewise medforecast(i)=%fractiles(%xrow(forecastA,i),0.5)
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: How to get the median of each row of a matrix

Unread post by TomDoan »

%fractiles returns a VECTOR (since it can take a VECTOR of desired quantiles). So you have to reference the 1st element---note the (1) at the end.

ewise medforecast(i)=%fractiles(%xrow(forecastA,i),0.5)(1)
Post Reply