Summary Statistics Table by group

34 views (last 30 days)
mo
mo on 25 Oct 2018
Answered: Steven Lord on 25 Oct 2018
Hi,
I'm new in Matlab and I'm completely lost. I would like to create a table of summary statistics (mean, median, mode, std, max, min, skewness, kurtosis) of different caracteristics such as Common Equity Tier 1 ratio, Leverage ratio..... I imported my data form my excel folder. I already create and define my variables.
Here is my code : %Create and define my date data.return1018=data.data(:,1); data.return1w=data.data(:,2); data.LVGR0617=data.data(:,3); data.CET1R0617=data.data(:,7); data.TLRE0617=data.data(:,11); data.NPA0617=data.data(:,25); data.OBS0617=data.data(:,27);
dsa=({'data.CET1R0617', 'data.LVGR0617', 'data.NPA0617', 'data.OBS0617', 'data.return1w', 'data.return1018'})
statarray = grpstats(dsa,{'mean','median','mode','std','min','max','skewness','kurtosis'})
The problem is that my group stats doesn't work... and I really don't know why.
Thank you in advance for your help,
  1 Comment
jonas
jonas on 25 Oct 2018
Well, your syntax is wrong and it's not possible to help you with the limited information you have provided. What is dsa? Why is the table not passed to the function? Are all your variables numeric?
Would be easier if you just uploaded your table.

Sign in to comment.

Answers (2)

jonas
jonas on 25 Oct 2018
You need to pass the table as input to grpstats. Assuming that dsa is a cell array with grouping variables, then change your code as follows:
dsa = {'CET1R0617', 'LVGR0617', 'NPA0617', 'OBS0617', 'return1w', 'return1018'}
statarray = grpstats(data,dsa,{'mean','median','mode','std','min','max','skewness','kurtosis'})

Steven Lord
Steven Lord on 25 Oct 2018
Instead of reading your data into a matrix and post-processing to create a struct from that matrix, consider using readtable to read the data directly into a table array.
Once you have your data in a table use groupsummary with one or more of your table variables as a grouping variable, or use findgroups and splitapply, or depending on the specific summary statistics you want to generate call summary on the table.

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!