%% Master Thesis

% NB: High performance code

%Setup
clc
clear all

%Import file
opts = delimitedTextImportOptions("NumVariables", 22);
opts.DataLines = [2, Inf];
opts.Delimiter = "\t";
opts.VariableNames = ["pcid", "yr", "currency", "item_15302", "item_15304", "item_4", "item_9", "item_11102", "item_13420", "item_78", "item_63", "item_30", "item_35", "item_39", "item_87", "item_82", "item_105", "item_114", "item_15307", "item_50109", "item_14507", "item_14018"];
opts.VariableTypes = ["double", "double", "string", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double"];
opts.ImportErrorRule = "omitrow";
opts.MissingRule = "omitrow";
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
opts = setvaropts(opts, "currency", "WhitespaceRule", "preserve");
opts = setvaropts(opts, "currency", "EmptyFieldRule", "auto");
opts = setvaropts(opts, ["item_11102", "item_50109"], "TrimNonNumeric", true);
opts = setvaropts(opts, ["item_11102", "item_50109"], "ThousandsSeparator", ",");
Data = readtable("/Users/joakim/Desktop/CCGR Data/J.txt", opts);
clear opts

%% Sorting variables
clc
%Create new variable names
NewData=table;
NewData.pcid=Data.pcid;
NewData.yr=Data.yr;
NewData.LargestFamilySumUltOwnership=Data.item_15302;
NewData.LargestFamilyHasCEO=Data.item_15304;
NewData.CEOBirthYear=Data.item_4;
NewData.Revenue=Data.item_9;
NewData.IndustryCodes=Data.item_11102;
NewData.CompanyAge=Data.item_13420;
NewData.TotalCurrentAssets=Data.item_78;
NewData.TotalFixedAssets=Data.item_63;
NewData.OtherInterestExpenses=Data.item_30;
NewData.IncomeBeforeExtraoridinaryItems=Data.item_35;
NewData.NetIncome=Data.item_39;
NewData.TotalEquity=Data.item_87;
NewData.TotalPaidinCapital=Data.item_82;
NewData.DividendsPayable=Data.item_105;
NewData.CEOSalary=Data.item_114;
NewData.LargestFamilyNumberOfOwners=Data.item_15307;
NewData.NumberOfEmployees=Data.item_50109;
NewData.IsIndependent=Data.item_14507;
NewData.AggregateFractionHeldByInstitutionalOwners=Data.item_14018;


% Create new variables
NewData.EBIT = NewData.NetIncome - NewData.OtherInterestExpenses;
NewData.TotalAssets = NewData.TotalCurrentAssets + NewData.TotalFixedAssets;
NewData.ROA = NewData.EBIT ./ NewData.TotalAssets;
NewData.ROE = NewData.NetIncome ./ NewData.TotalEquity;

toDelete = NewData.Revenue == 0;
NewData(toDelete,:) = [];

toDelete = NewData.NetIncome == 0;
NewData(toDelete,:) = [];

toDelete = NewData.TotalAssets == 0;
NewData(toDelete,:) = [];

toDelete = NewData.TotalAssets == 0;
NewData(toDelete,:) = [];

toDelete = NewData.TotalAssets == 0;
NewData(toDelete,:) = [];

toDelete = NewData.NumberOfEmployees == 0;
NewData(toDelete,:) = [];


%% Yearly tables
i=1;
for i=1:1
YearlyData.Data2000=NewData;
toDelete = NewData.yr ~= 2000;
YearlyData.Data2000(toDelete,:) = [];

YearlyData.Data2001=NewData;
toDelete = NewData.yr ~= 2001;
YearlyData.Data2001(toDelete,:) = [];

YearlyData.Data2002=NewData;
toDelete = NewData.yr ~= 2002;
YearlyData.Data2002(toDelete,:) = [];

YearlyData.Data2003=NewData;
toDelete = NewData.yr ~= 2003;
YearlyData.Data2003(toDelete,:) = [];

YearlyData.Data2004=NewData;
toDelete = NewData.yr ~= 2004;
YearlyData.Data2004(toDelete,:) = [];

YearlyData.Data2005=NewData;
toDelete = NewData.yr ~= 2005;
YearlyData.Data2005(toDelete,:) = [];

YearlyData.Data2006=NewData;
toDelete = NewData.yr ~= 2006;
YearlyData.Data2006(toDelete,:) = [];

YearlyData.Data2007=NewData;
toDelete = NewData.yr ~= 2007;
YearlyData.Data2007(toDelete,:) = [];

YearlyData.Data2008=NewData;
toDelete = NewData.yr ~= 2008;
YearlyData.Data2008(toDelete,:) = [];

YearlyData.Data2009=NewData;
toDelete = NewData.yr ~= 2009;
YearlyData.Data2009(toDelete,:) = [];

YearlyData.Data2010=NewData;
toDelete = NewData.yr ~= 2010;
YearlyData.Data2010(toDelete,:) = [];

YearlyData.Data2011=NewData;
toDelete = NewData.yr ~= 2011;
YearlyData.Data2011(toDelete,:) = [];

YearlyData.Data2012=NewData;
toDelete = NewData.yr ~= 2012;
YearlyData.Data2012(toDelete,:) = [];

YearlyData.Data2013=NewData;
toDelete = NewData.yr ~= 2013;
YearlyData.Data2013(toDelete,:) = [];

YearlyData.Data2014=NewData;
toDelete = NewData.yr ~= 2014;
YearlyData.Data2014(toDelete,:) = [];

YearlyData.Data2015=NewData;
toDelete = NewData.yr ~= 2015;
YearlyData.Data2015(toDelete,:) = [];

clear toDelete
end%Family

%% Statistic overview family control 2000
toDelete = YearlyData.Data2000.LargestFamilySumUltOwnership < 100;
YearlyData.Data2000(toDelete,:) = [];

toDelete = YearlyData.Data2000.LargestFamilyHasCEO < 1;
YearlyData.Data2000(toDelete,:) = [];

toDelete = YearlyData.Data2000.CompanyAge > 1;
YearlyData.Data2000(toDelete,:) = [];

toDelete = YearlyData.Data2000.IsIndependent < 1;
YearlyData.Data2000(toDelete,:) = [];

toDelete = YearlyData.Data2000.Revenue == 0;
YearlyData.Data2000(toDelete,:) = [];

toDelete = YearlyData.Data2000.NetIncome == 0;
YearlyData.Data2000(toDelete,:) = [];

toDelete = YearlyData.Data2000.NumberOfEmployees == 0;
YearlyData.Data2000(toDelete,:) = [];

toDelete = YearlyData.Data2000.TotalAssets == 0;
YearlyData.Data2000(toDelete,:) = [];



%% Statistic overview family control 2001
idlist = YearlyData.Data2000.pcid;
Data2001Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2001);
    for k=1:length(idlist)
        if YearlyData.Data2001.pcid(i) == idlist(k)
            Data2001Temp(s,:) = YearlyData.Data2001(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2001 = Data2001Temp;
clear Data2001Temp

%% Statistic overview family control 2002
idlist = YearlyData.Data2001.pcid;
Data2002Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2002);
    for k=1:length(idlist)
        if YearlyData.Data2002.pcid(i) == idlist(k)
            Data2002Temp(s,:) = YearlyData.Data2002(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2002 = Data2002Temp;
clear Data2002Temp

%% Statistic overview family control 2003
idlist = YearlyData.Data2002.pcid;
Data2003Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2003);
    for k=1:length(idlist)
        if YearlyData.Data2003.pcid(i) == idlist(k)
            Data2003Temp(s,:) = YearlyData.Data2003(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2003 = Data2003Temp;
clear Data2003Temp

%% Statistic overview family control 2004
idlist = YearlyData.Data2003.pcid;
Data2004Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2004);
    for k=1:length(idlist)
        if YearlyData.Data2004.pcid(i) == idlist(k)
            Data2004Temp(s,:) = YearlyData.Data2004(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2004 = Data2004Temp;
clear Data2004Temp

%% Statistic overview family control 2005
idlist = YearlyData.Data2004.pcid;
Data2005Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2005);
    for k=1:length(idlist)
        if YearlyData.Data2005.pcid(i) == idlist(k)
            Data2005Temp(s,:) = YearlyData.Data2005(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2005 = Data2005Temp;
clear Data2005Temp

%% Statistic overview family control 2006
idlist = YearlyData.Data2005.pcid;
Data2006Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2006);
    for k=1:length(idlist)
        if YearlyData.Data2006.pcid(i) == idlist(k)
            Data2006Temp(s,:) = YearlyData.Data2006(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2006 = Data2006Temp;
clear Data2006Temp

%% Statistic overview family control 2007
idlist = YearlyData.Data2006.pcid;
Data2007Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2007);
    for k=1:length(idlist)
        if YearlyData.Data2007.pcid(i) == idlist(k)
            Data2007Temp(s,:) = YearlyData.Data2007(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2007 = Data2007Temp;
clear Data2007Temp

%% Statistic overview family control 2008
idlist = YearlyData.Data2007.pcid;
Data2008Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2008);
    for k=1:length(idlist)
        if YearlyData.Data2008.pcid(i) == idlist(k)
            Data2008Temp(s,:) = YearlyData.Data2008(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2008 = Data2008Temp;
clear Data2008Temp

%% Statistic overview family control 2009
idlist = YearlyData.Data2008.pcid;
Data2009Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2009);
    for k=1:length(idlist)
        if YearlyData.Data2009.pcid(i) == idlist(k)
            Data2009Temp(s,:) = YearlyData.Data2009(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2009 = Data2009Temp;
clear Data2009Temp

%% Statistic overview family control 2010
idlist = YearlyData.Data2009.pcid;
Data2010Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2010);
    for k=1:length(idlist)
        if YearlyData.Data2010.pcid(i) == idlist(k)
            Data2010Temp(s,:) = YearlyData.Data2010(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2010 = Data2010Temp;
clear Data2010Temp

%% Statistic overview family control 2011
idlist = YearlyData.Data2010.pcid;
Data2011Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2011);
    for k=1:length(idlist)
        if YearlyData.Data2011.pcid(i) == idlist(k)
            Data2011Temp(s,:) = YearlyData.Data2011(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2011 = Data2011Temp;
clear Data2011Temp

%% Statistic overview family control 2012
idlist = YearlyData.Data2011.pcid;
Data2012Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2012);
    for k=1:length(idlist)
        if YearlyData.Data2012.pcid(i) == idlist(k)
            Data2012Temp(s,:) = YearlyData.Data2012(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2012 = Data2012Temp;
clear Data2012Temp

%% Statistic overview family control 2013
idlist = YearlyData.Data2012.pcid;
Data2013Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2013);
    for k=1:length(idlist)
        if YearlyData.Data2013.pcid(i) == idlist(k)
            Data2013Temp(s,:) = YearlyData.Data2013(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2013 = Data2013Temp;
clear Data2013Temp

%% Statistic overview family control 2014
idlist = YearlyData.Data2013.pcid;
Data2014Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2014);
    for k=1:length(idlist)
        if YearlyData.Data2014.pcid(i) == idlist(k)
            Data2014Temp(s,:) = YearlyData.Data2014(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2014 = Data2014Temp;
clear Data2014Temp

%% Statistic overview family control 2015
idlist = YearlyData.Data2014.pcid;
Data2015Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2015);
    for k=1:length(idlist)
        if YearlyData.Data2015.pcid(i) == idlist(k)
            Data2015Temp(s,:) = YearlyData.Data2015(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2015 = Data2015Temp;
clear Data2015Temp


%% Yearly tables NF
i=1;
for i=1:1
YearlyDataNF.Data2000=NewData;
toDelete = NewData.yr ~= 2000;
YearlyDataNF.Data2000(toDelete,:) = [];

YearlyDataNF.Data2001=NewData;
toDelete = NewData.yr ~= 2001;
YearlyDataNF.Data2001(toDelete,:) = [];

YearlyDataNF.Data2002=NewData;
toDelete = NewData.yr ~= 2002;
YearlyDataNF.Data2002(toDelete,:) = [];

YearlyDataNF.Data2003=NewData;
toDelete = NewData.yr ~= 2003;
YearlyDataNF.Data2003(toDelete,:) = [];

YearlyDataNF.Data2004=NewData;
toDelete = NewData.yr ~= 2004;
YearlyDataNF.Data2004(toDelete,:) = [];

YearlyDataNF.Data2005=NewData;
toDelete = NewData.yr ~= 2005;
YearlyDataNF.Data2005(toDelete,:) = [];

YearlyDataNF.Data2006=NewData;
toDelete = NewData.yr ~= 2006;
YearlyDataNF.Data2006(toDelete,:) = [];

YearlyDataNF.Data2007=NewData;
toDelete = NewData.yr ~= 2007;
YearlyDataNF.Data2007(toDelete,:) = [];

YearlyDataNF.Data2008=NewData;
toDelete = NewData.yr ~= 2008;
YearlyDataNF.Data2008(toDelete,:) = [];

YearlyDataNF.Data2009=NewData;
toDelete = NewData.yr ~= 2009;
YearlyDataNF.Data2009(toDelete,:) = [];

YearlyDataNF.Data2010=NewData;
toDelete = NewData.yr ~= 2010;
YearlyDataNF.Data2010(toDelete,:) = [];

YearlyDataNF.Data2011=NewData;
toDelete = NewData.yr ~= 2011;
YearlyDataNF.Data2011(toDelete,:) = [];

YearlyDataNF.Data2012=NewData;
toDelete = NewData.yr ~= 2012;
YearlyDataNF.Data2012(toDelete,:) = [];

YearlyDataNF.Data2013=NewData;
toDelete = NewData.yr ~= 2013;
YearlyDataNF.Data2013(toDelete,:) = [];

YearlyDataNF.Data2014=NewData;
toDelete = NewData.yr ~= 2014;
YearlyDataNF.Data2014(toDelete,:) = [];

YearlyDataNF.Data2015=NewData;
toDelete = NewData.yr ~= 2015;
YearlyDataNF.Data2015(toDelete,:) = [];

clear toDelete
end %NoFamily

%% Statistic overview no family control 2000
toDelete = YearlyDataNF.Data2000.LargestFamilySumUltOwnership >= 50;
YearlyDataNF.Data2000(toDelete,:) = [];

toDelete = YearlyDataNF.Data2000.CompanyAge > 1;
YearlyDataNF.Data2000(toDelete,:) = [];

toDelete = YearlyDataNF.Data2000.IsIndependent < 1;
YearlyDataNF.Data2000(toDelete,:) = [];

toDelete = YearlyDataNF.Data2000.Revenue == 0;
YearlyDataNF.Data2000(toDelete,:) = [];

toDelete = YearlyDataNF.Data2000.NetIncome == 0;
YearlyDataNF.Data2000(toDelete,:) = [];

toDelete = YearlyDataNF.Data2000.NumberOfEmployees == 0;
YearlyDataNF.Data2000(toDelete,:) = [];

toDelete = YearlyDataNF.Data2000.TotalAssets == 0;
YearlyDataNF.Data2000(toDelete,:) = [];



%% Statistic overview no family control 2001
idlist = YearlyDataNF.Data2000.pcid;
Data2001Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2001);
    for k=1:length(idlist)
        if YearlyDataNF.Data2001.pcid(i) == idlist(k)
            Data2001Temp(s,:) = YearlyDataNF.Data2001(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2001 = Data2001Temp;
clear Data2001Temp

%% Statistic overview no family control 2002
idlist = YearlyDataNF.Data2001.pcid;
Data2002Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2002);
    for k=1:length(idlist)
        if YearlyDataNF.Data2002.pcid(i) == idlist(k)
            Data2002Temp(s,:) = YearlyDataNF.Data2002(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2002 = Data2002Temp;
clear Data2002Temp

%% Statistic overview no family control 2003
idlist = YearlyDataNF.Data2002.pcid;
Data2003Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2003);
    for k=1:length(idlist)
        if YearlyDataNF.Data2003.pcid(i) == idlist(k)
            Data2003Temp(s,:) = YearlyDataNF.Data2003(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2003 = Data2003Temp;
clear Data2003Temp

%% Statistic overview no family control 2004
idlist = YearlyDataNF.Data2003.pcid;
Data2004Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2004);
    for k=1:length(idlist)
        if YearlyDataNF.Data2004.pcid(i) == idlist(k)
            Data2004Temp(s,:) = YearlyDataNF.Data2004(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2004 = Data2004Temp;
clear Data2004Temp

%% Statistic overview no family control 2005
idlist = YearlyDataNF.Data2004.pcid;
Data2005Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2005);
    for k=1:length(idlist)
        if YearlyDataNF.Data2005.pcid(i) == idlist(k)
            Data2005Temp(s,:) = YearlyDataNF.Data2005(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2005 = Data2005Temp;
clear Data2005Temp

%% Statistic overview no family control 2006
idlist = YearlyDataNF.Data2005.pcid;
Data2006Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2006);
    for k=1:length(idlist)
        if YearlyDataNF.Data2006.pcid(i) == idlist(k)
            Data2006Temp(s,:) = YearlyDataNF.Data2006(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2006 = Data2006Temp;
clear Data2006Temp

%% Statistic overview no family control 2007
idlist = YearlyDataNF.Data2006.pcid;
Data2007Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2007);
    for k=1:length(idlist)
        if YearlyDataNF.Data2007.pcid(i) == idlist(k)
            Data2007Temp(s,:) = YearlyDataNF.Data2007(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2007 = Data2007Temp;
clear Data2007Temp

%% Statistic overview no family control 2008
idlist = YearlyDataNF.Data2007.pcid;
Data2008Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2008);
    for k=1:length(idlist)
        if YearlyDataNF.Data2008.pcid(i) == idlist(k)
            Data2008Temp(s,:) = YearlyDataNF.Data2008(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2008 = Data2008Temp;
clear Data2008Temp

%% Statistic overview no family control 2009
idlist = YearlyDataNF.Data2008.pcid;
Data2009Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2009);
    for k=1:length(idlist)
        if YearlyDataNF.Data2009.pcid(i) == idlist(k)
            Data2009Temp(s,:) = YearlyDataNF.Data2009(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2009 = Data2009Temp;
clear Data2009Temp

%% Statistic overview no family control 2010
idlist = YearlyDataNF.Data2009.pcid;
Data2010Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2010);
    for k=1:length(idlist)
        if YearlyDataNF.Data2010.pcid(i) == idlist(k)
            Data2010Temp(s,:) = YearlyDataNF.Data2010(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2010 = Data2010Temp;
clear Data2010Temp

%% Statistic overview no family control 2011
idlist = YearlyDataNF.Data2010.pcid;
Data2011Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2011);
    for k=1:length(idlist)
        if YearlyDataNF.Data2011.pcid(i) == idlist(k)
            Data2011Temp(s,:) = YearlyDataNF.Data2011(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2011 = Data2011Temp;
clear Data2011Temp

%% Statistic overview no family control 2012
idlist = YearlyDataNF.Data2011.pcid;
Data2012Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2012);
    for k=1:length(idlist)
        if YearlyDataNF.Data2012.pcid(i) == idlist(k)
            Data2012Temp(s,:) = YearlyDataNF.Data2012(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2012 = Data2012Temp;
clear Data2012Temp

%% Statistic overview no family control 2013
idlist = YearlyDataNF.Data2012.pcid;
Data2013Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2013);
    for k=1:length(idlist)
        if YearlyDataNF.Data2013.pcid(i) == idlist(k)
            Data2013Temp(s,:) = YearlyDataNF.Data2013(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2013 = Data2013Temp;
clear Data2013Temp

%% Statistic overview no family control 2014
idlist = YearlyDataNF.Data2013.pcid;
Data2014Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2014);
    for k=1:length(idlist)
        if YearlyDataNF.Data2014.pcid(i) == idlist(k)
            Data2014Temp(s,:) = YearlyDataNF.Data2014(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2014 = Data2014Temp;
clear Data2014Temp

%% Statistic overview no family control 2015
idlist = YearlyDataNF.Data2014.pcid;
Data2015Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyDataNF.Data2015);
    for k=1:length(idlist)
        if YearlyDataNF.Data2015.pcid(i) == idlist(k)
            Data2015Temp(s,:) = YearlyDataNF.Data2015(i,:);
            s=s+1;
        end
    end
end
YearlyDataNF.Data2015 = Data2015Temp;
clear Data2015Temp

%% Export to excel 
writetable(YearlyData.Data2000,'Data2000.xlsx')
writetable(YearlyData.Data2001,'Data2001.xlsx')
writetable(YearlyData.Data2002,'Data2002.xlsx')
writetable(YearlyData.Data2003,'Data2003.xlsx')
writetable(YearlyData.Data2004,'Data2004.xlsx')
writetable(YearlyData.Data2005,'Data2005.xlsx')
writetable(YearlyData.Data2006,'Data2006.xlsx')
writetable(YearlyData.Data2007,'Data2007.xlsx')
writetable(YearlyData.Data2008,'Data2008.xlsx')
writetable(YearlyData.Data2009,'Data2009.xlsx')
writetable(YearlyData.Data2010,'Data2010.xlsx')
writetable(YearlyData.Data2011,'Data2011.xlsx')
writetable(YearlyData.Data2012,'Data2012.xlsx')
writetable(YearlyData.Data2013,'Data2013.xlsx')
writetable(YearlyData.Data2014,'Data2014.xlsx')
writetable(YearlyData.Data2015,'Data2015.xlsx')

writetable(YearlyDataNF.Data2000,'Data2000NF.xlsx')
writetable(YearlyDataNF.Data2001,'Data2001NF.xlsx')
writetable(YearlyDataNF.Data2002,'Data2002NF.xlsx')
writetable(YearlyDataNF.Data2003,'Data2003NF.xlsx')
writetable(YearlyDataNF.Data2004,'Data2004NF.xlsx')
writetable(YearlyDataNF.Data2005,'Data2005NF.xlsx')
writetable(YearlyDataNF.Data2006,'Data2006NF.xlsx')
writetable(YearlyDataNF.Data2007,'Data2007NF.xlsx')
writetable(YearlyDataNF.Data2008,'Data2008NF.xlsx')
writetable(YearlyDataNF.Data2009,'Data2009NF.xlsx')
writetable(YearlyDataNF.Data2010,'Data2010NF.xlsx')
writetable(YearlyDataNF.Data2011,'Data2011NF.xlsx')
writetable(YearlyDataNF.Data2012,'Data2012NF.xlsx')
writetable(YearlyDataNF.Data2013,'Data2013NF.xlsx')
writetable(YearlyDataNF.Data2014,'Data2014NF.xlsx')
writetable(YearlyDataNF.Data2015,'Data2015NF.xlsx')

%% Master Thesis Part 2

%Setup
clc
clear all

%Import files
Data.Data2000 = readtable('Data2000.xlsx');
Data.Data2001 = readtable('Data2001.xlsx');
Data.Data2002 = readtable('Data2002.xlsx');
Data.Data2003 = readtable('Data2003.xlsx');
Data.Data2004 = readtable('Data2004.xlsx');
Data.Data2005 = readtable('Data2005.xlsx');
Data.Data2006 = readtable('Data2006.xlsx');
Data.Data2007 = readtable('Data2007.xlsx');
Data.Data2008 = readtable('Data2008.xlsx');
Data.Data2009 = readtable('Data2009.xlsx');
Data.Data2010 = readtable('Data2010.xlsx');
Data.Data2011 = readtable('Data2011.xlsx');
Data.Data2012 = readtable('Data2012.xlsx');
Data.Data2013 = readtable('Data2013.xlsx');
Data.Data2014 = readtable('Data2014.xlsx');
Data.Data2015 = readtable('Data2015.xlsx');


DataNF.Data2000NF = readtable('Data2000NF.xlsx');
DataNF.Data2001NF = readtable('Data2001NF.xlsx');
DataNF.Data2002NF = readtable('Data2002NF.xlsx');
DataNF.Data2003NF = readtable('Data2003NF.xlsx');
DataNF.Data2004NF = readtable('Data2004NF.xlsx');
DataNF.Data2005NF = readtable('Data2005NF.xlsx');
DataNF.Data2006NF = readtable('Data2006NF.xlsx');
DataNF.Data2007NF = readtable('Data2007NF.xlsx');
DataNF.Data2008NF = readtable('Data2008NF.xlsx');
DataNF.Data2009NF = readtable('Data2009NF.xlsx');
DataNF.Data2010NF = readtable('Data2010NF.xlsx');
DataNF.Data2011NF = readtable('Data2011NF.xlsx');
DataNF.Data2012NF = readtable('Data2012NF.xlsx');
DataNF.Data2013NF = readtable('Data2013NF.xlsx');
DataNF.Data2014NF = readtable('Data2014NF.xlsx');
DataNF.Data2015NF = readtable('Data2015NF.xlsx');

%% Removing extremevalues for variable ROE
OutliersROE2000NF = rmoutliers(DataNF.Data2000NF.ROE,'percentiles',[10 90]);
OutliersROE2001NF = rmoutliers(DataNF.Data2001NF.ROE,'percentiles',[10 90]);
OutliersROE2002NF = rmoutliers(DataNF.Data2002NF.ROE,'percentiles',[10 90]);
OutliersROE2008NF = rmoutliers(DataNF.Data2002NF.ROE,'percentiles',[10 90]);
OutliersROE2000 = rmoutliers(Data.Data2000.ROE,'percentiles',[10 90]);
OutliersROE2001 = rmoutliers(Data.Data2001.ROE,'percentiles',[10 90]);
OutliersROE2002 = rmoutliers(Data.Data2002.ROE,'percentiles',[10 90]);
OutliersROE2005 = rmoutliers(Data.Data2005.ROE,'percentiles',[10 90]);
OutliersROE2011 = rmoutliers(Data.Data2011.ROE,'percentiles',[10 90]);
OutliersROE2013 = rmoutliers(Data.Data2013.ROE,'percentiles',[10 90]);

%% Total assets table
TotalAssetsTable = table;

TotalAssetsTable.Year(1) = 2000;
TotalAssetsTable.Year(2) = 2001;
TotalAssetsTable.Year(3) = 2002;
TotalAssetsTable.Year(4) = 2003;
TotalAssetsTable.Year(5) = 2004;
TotalAssetsTable.Year(6) = 2005;
TotalAssetsTable.Year(7) = 2006;
TotalAssetsTable.Year(8) = 2007;
TotalAssetsTable.Year(9) = 2008;
TotalAssetsTable.Year(10) = 2009;
TotalAssetsTable.Year(11) = 2010;
TotalAssetsTable.Year(12) = 2011;
TotalAssetsTable.Year(13) = 2012;
TotalAssetsTable.Year(14) = 2013;
TotalAssetsTable.Year(15) = 2014;
TotalAssetsTable.Year(16) = 2015;

TotalAssetsTable.TotalAssetsFamilyFirm(1) = mean(Data.Data2000.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(2) = mean(Data.Data2001.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(3) = mean(Data.Data2002.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(4) = mean(Data.Data2003.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(5) = mean(Data.Data2004.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(6) = mean(Data.Data2005.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(7) = mean(Data.Data2006.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(8) = mean(Data.Data2007.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(9) = mean(Data.Data2008.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(10) = mean(Data.Data2009.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(11) = mean(Data.Data2010.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(12) = mean(Data.Data2011.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(13) = mean(Data.Data2012.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(14) = mean(Data.Data2013.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(15) = mean(Data.Data2014.TotalAssets);
TotalAssetsTable.TotalAssetsFamilyFirm(16) = mean(Data.Data2015.TotalAssets);

TotalAssetsTable.TotalAssetsNonFamilyFirm(1) = mean(DataNF.Data2000NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(2) = mean(DataNF.Data2001NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(3) = mean(DataNF.Data2002NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(4) = mean(DataNF.Data2003NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(5) = mean(DataNF.Data2004NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(6) = mean(DataNF.Data2005NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(7) = mean(DataNF.Data2006NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(8) = mean(DataNF.Data2007NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(9) = mean(DataNF.Data2008NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(10) = mean(DataNF.Data2009NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(11) = mean(DataNF.Data2010NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(12) = mean(DataNF.Data2011NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(13) = mean(DataNF.Data2012NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(14) = mean(DataNF.Data2013NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(15) = mean(DataNF.Data2014NF.TotalAssets);
TotalAssetsTable.TotalAssetsNonFamilyFirm(16) = mean(DataNF.Data2015NF.TotalAssets);

%% Import table to EXCEL
writetable(TotalAssetsTable,'TotalAssetsTable.xlsx');


%% Descriptive table

DescriptiveTable = table;

DescriptiveTable.Year(1) = 2000;
DescriptiveTable.Year(2) = 2001;
DescriptiveTable.Year(3) = 2002;
DescriptiveTable.Year(4) = 2003;
DescriptiveTable.Year(5) = 2004;
DescriptiveTable.Year(6) = 2005;
DescriptiveTable.Year(7) = 2006;
DescriptiveTable.Year(8) = 2007;
DescriptiveTable.Year(9) = 2008;
DescriptiveTable.Year(10) = 2009;
DescriptiveTable.Year(11) = 2010;
DescriptiveTable.Year(12) = 2011;
DescriptiveTable.Year(13) = 2012;
DescriptiveTable.Year(14) = 2013;
DescriptiveTable.Year(15) = 2014;
DescriptiveTable.Year(16) = 2015;

DescriptiveTable.NoOfFirms(1) = height(Data.Data2000);
DescriptiveTable.NoOfFirms(2) = height(Data.Data2001);
DescriptiveTable.NoOfFirms(3) = height(Data.Data2002);
DescriptiveTable.NoOfFirms(4) = height(Data.Data2003);
DescriptiveTable.NoOfFirms(5) = height(Data.Data2004);
DescriptiveTable.NoOfFirms(6) = height(Data.Data2005);
DescriptiveTable.NoOfFirms(7) = height(Data.Data2006);
DescriptiveTable.NoOfFirms(8) = height(Data.Data2007);
DescriptiveTable.NoOfFirms(9) = height(Data.Data2008);
DescriptiveTable.NoOfFirms(10) = height(Data.Data2009);
DescriptiveTable.NoOfFirms(11) = height(Data.Data2010);
DescriptiveTable.NoOfFirms(12) = height(Data.Data2011);
DescriptiveTable.NoOfFirms(13) = height(Data.Data2012);
DescriptiveTable.NoOfFirms(14) = height(Data.Data2013);
DescriptiveTable.NoOfFirms(15) = height(Data.Data2014);
DescriptiveTable.NoOfFirms(16) = height(Data.Data2015);

DescriptiveTable.OwnershipShare(1) = mean(Data.Data2000.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(2) = mean(Data.Data2001.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(3) = mean(Data.Data2002.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(4) = mean(Data.Data2003.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(5) = mean(Data.Data2004.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(6) = mean(Data.Data2005.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(7) = mean(Data.Data2006.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(8) = mean(Data.Data2007.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(9) = mean(Data.Data2008.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(10) = mean(Data.Data2009.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(11) = mean(Data.Data2010.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(12) = mean(Data.Data2011.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(13) = mean(Data.Data2012.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(14) = mean(Data.Data2013.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(15) = mean(Data.Data2014.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(16) = mean(Data.Data2015.LargestFamilySumUltOwnership);

DescriptiveTable.FamilyCEO(1) = mean(Data.Data2000.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(2) = mean(Data.Data2001.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(3) = mean(Data.Data2002.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(4) = mean(Data.Data2003.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(5) = mean(Data.Data2004.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(6) = mean(Data.Data2005.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(7) = mean(Data.Data2006.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(8) = mean(Data.Data2007.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(9) = mean(Data.Data2008.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(10) = mean(Data.Data2009.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(11) = mean(Data.Data2010.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(12) = mean(Data.Data2011.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(13) = mean(Data.Data2012.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(14) = mean(Data.Data2013.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(15) = mean(Data.Data2014.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(16) = mean(Data.Data2015.LargestFamilyHasCEO);

%% Characteristics table
CharacteristicsTable = table;

CharacteristicsTable.Year(1) = 2000;
CharacteristicsTable.Year(2) = 2001;
CharacteristicsTable.Year(3) = 2002;
CharacteristicsTable.Year(4) = 2003;
CharacteristicsTable.Year(5) = 2004;
CharacteristicsTable.Year(6) = 2005;
CharacteristicsTable.Year(7) = 2006;
CharacteristicsTable.Year(8) = 2007;
CharacteristicsTable.Year(9) = 2008;
CharacteristicsTable.Year(10) = 2009;
CharacteristicsTable.Year(11) = 2010;
CharacteristicsTable.Year(12) = 2011;
CharacteristicsTable.Year(13) = 2012;
CharacteristicsTable.Year(14) = 2013;
CharacteristicsTable.Year(15) = 2014;
CharacteristicsTable.Year(16) = 2015;

CharacteristicsTable.NoOfOwners(1) = mean(Data.Data2000.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(2) = mean(Data.Data2001.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(3) = mean(Data.Data2002.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(4) = mean(Data.Data2003.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(5) = mean(Data.Data2004.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(6) = mean(Data.Data2005.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(7) = mean(Data.Data2006.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(8) = mean(Data.Data2007.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(9) = mean(Data.Data2008.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(10) = mean(Data.Data2009.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(11) = mean(Data.Data2010.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(12) = mean(Data.Data2011.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(13) = mean(Data.Data2012.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(14) = mean(Data.Data2013.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(15) = mean(Data.Data2014.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(16) = mean(Data.Data2015.LargestFamilyNumberOfOwners);

CharacteristicsTable.TotalPaidinCapital(1) = mean(Data.Data2000.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(2) = mean(Data.Data2001.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(3) = mean(Data.Data2002.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(4) = mean(Data.Data2003.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(5) = mean(Data.Data2004.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(6) = mean(Data.Data2005.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(7) = mean(Data.Data2006.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(8) = mean(Data.Data2007.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(9) = mean(Data.Data2008.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(10) = mean(Data.Data2009.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(11) = mean(Data.Data2010.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(12) = mean(Data.Data2011.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(13) = mean(Data.Data2012.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(14) = mean(Data.Data2013.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(15) = mean(Data.Data2014.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(16) = mean(Data.Data2015.TotalPaidinCapital);

CharacteristicsTable.CEOSalary(1) = mean(Data.Data2000.CEOSalary);
CharacteristicsTable.CEOSalary(2) = mean(Data.Data2001.CEOSalary);
CharacteristicsTable.CEOSalary(3) = mean(Data.Data2002.CEOSalary);
CharacteristicsTable.CEOSalary(4) = mean(Data.Data2003.CEOSalary);
CharacteristicsTable.CEOSalary(5) = mean(Data.Data2004.CEOSalary);
CharacteristicsTable.CEOSalary(6) = mean(Data.Data2005.CEOSalary);
CharacteristicsTable.CEOSalary(7) = mean(Data.Data2006.CEOSalary);
CharacteristicsTable.CEOSalary(8) = mean(Data.Data2007.CEOSalary);
CharacteristicsTable.CEOSalary(9) = mean(Data.Data2008.CEOSalary);
CharacteristicsTable.CEOSalary(10) = mean(Data.Data2009.CEOSalary);
CharacteristicsTable.CEOSalary(11) = mean(Data.Data2010.CEOSalary);
CharacteristicsTable.CEOSalary(12) = mean(Data.Data2011.CEOSalary);
CharacteristicsTable.CEOSalary(13) = mean(Data.Data2012.CEOSalary);
CharacteristicsTable.CEOSalary(14) = mean(Data.Data2013.CEOSalary);
CharacteristicsTable.CEOSalary(15) = mean(Data.Data2014.CEOSalary);
CharacteristicsTable.CEOSalary(16) = mean(Data.Data2015.CEOSalary);

CharacteristicsTable.Dividends(1) = mean(Data.Data2000.DividendsPayable);
CharacteristicsTable.Dividends(2) = mean(Data.Data2001.DividendsPayable);
CharacteristicsTable.Dividends(3) = mean(Data.Data2002.DividendsPayable);
CharacteristicsTable.Dividends(4) = mean(Data.Data2003.DividendsPayable);
CharacteristicsTable.Dividends(5) = mean(Data.Data2004.DividendsPayable);
CharacteristicsTable.Dividends(6) = mean(Data.Data2005.DividendsPayable);
CharacteristicsTable.Dividends(7) = mean(Data.Data2006.DividendsPayable);
CharacteristicsTable.Dividends(8) = mean(Data.Data2007.DividendsPayable);
CharacteristicsTable.Dividends(9) = mean(Data.Data2008.DividendsPayable);
CharacteristicsTable.Dividends(10) = mean(Data.Data2009.DividendsPayable);
CharacteristicsTable.Dividends(11) = mean(Data.Data2010.DividendsPayable);
CharacteristicsTable.Dividends(12) = mean(Data.Data2011.DividendsPayable);
CharacteristicsTable.Dividends(13) = mean(Data.Data2012.DividendsPayable);
CharacteristicsTable.Dividends(14) = mean(Data.Data2013.DividendsPayable);
CharacteristicsTable.Dividends(15) = mean(Data.Data2014.DividendsPayable);
CharacteristicsTable.Dividends(16) = mean(Data.Data2015.DividendsPayable);

CharacteristicsTable.Revenue(1) = mean(Data.Data2000.Revenue);
CharacteristicsTable.Revenue(2) = mean(Data.Data2001.Revenue);
CharacteristicsTable.Revenue(3) = mean(Data.Data2002.Revenue);
CharacteristicsTable.Revenue(4) = mean(Data.Data2003.Revenue);
CharacteristicsTable.Revenue(5) = mean(Data.Data2004.Revenue);
CharacteristicsTable.Revenue(6) = mean(Data.Data2005.Revenue);
CharacteristicsTable.Revenue(7) = mean(Data.Data2006.Revenue);
CharacteristicsTable.Revenue(8) = mean(Data.Data2007.Revenue);
CharacteristicsTable.Revenue(9) = mean(Data.Data2008.Revenue);
CharacteristicsTable.Revenue(10) = mean(Data.Data2009.Revenue);
CharacteristicsTable.Revenue(11) = mean(Data.Data2010.Revenue);
CharacteristicsTable.Revenue(12) = mean(Data.Data2011.Revenue);
CharacteristicsTable.Revenue(13) = mean(Data.Data2012.Revenue);
CharacteristicsTable.Revenue(14) = mean(Data.Data2013.Revenue);
CharacteristicsTable.Revenue(15) = mean(Data.Data2014.Revenue);
CharacteristicsTable.Revenue(16) = mean(Data.Data2015.Revenue);

CharacteristicsTable.ROA(1) = mean(Data.Data2000.ROA);
CharacteristicsTable.ROA(2) = mean(Data.Data2001.ROA);
CharacteristicsTable.ROA(3) = mean(Data.Data2002.ROA);
CharacteristicsTable.ROA(4) = mean(Data.Data2003.ROA);
CharacteristicsTable.ROA(5) = mean(Data.Data2004.ROA);
CharacteristicsTable.ROA(6) = mean(Data.Data2005.ROA);
CharacteristicsTable.ROA(7) = mean(Data.Data2006.ROA);
CharacteristicsTable.ROA(8) = mean(Data.Data2007.ROA);
CharacteristicsTable.ROA(9) = mean(Data.Data2008.ROA);
CharacteristicsTable.ROA(10) = mean(Data.Data2009.ROA);
CharacteristicsTable.ROA(11) = mean(Data.Data2010.ROA);
CharacteristicsTable.ROA(12) = mean(Data.Data2011.ROA);
CharacteristicsTable.ROA(13) = mean(Data.Data2012.ROA);
CharacteristicsTable.ROA(14) = mean(Data.Data2013.ROA);
CharacteristicsTable.ROA(15) = mean(Data.Data2014.ROA);
CharacteristicsTable.ROA(16) = mean(Data.Data2015.ROA);

CharacteristicsTable.ROE(1) = mean(OutliersROE2000);
CharacteristicsTable.ROE(2) = mean(OutliersROE2001);
CharacteristicsTable.ROE(3) = mean(OutliersROE2002);
CharacteristicsTable.ROE(4) = mean(Data.Data2003.ROE);
CharacteristicsTable.ROE(5) = mean(Data.Data2004.ROE);
CharacteristicsTable.ROE(6) = mean(OutliersROE2005);
CharacteristicsTable.ROE(7) = mean(Data.Data2006.ROE);
CharacteristicsTable.ROE(8) = mean(Data.Data2007.ROE);
CharacteristicsTable.ROE(9) = mean(Data.Data2008.ROE);
CharacteristicsTable.ROE(10) = mean(Data.Data2009.ROE);
CharacteristicsTable.ROE(11) = mean(Data.Data2010.ROE);
CharacteristicsTable.ROE(12) = mean(OutliersROE2011);
CharacteristicsTable.ROE(13) = mean(Data.Data2012.ROE);
CharacteristicsTable.ROE(14) = mean(OutliersROE2013);
CharacteristicsTable.ROE(15) = mean(Data.Data2014.ROE);
CharacteristicsTable.ROE(16) = mean(Data.Data2015.ROE);

CharacteristicsTable.NumberOfEmployees(1) = mean(Data.Data2000.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(2) = mean(Data.Data2001.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(3) = mean(Data.Data2002.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(4) = mean(Data.Data2003.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(5) = mean(Data.Data2004.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(6) = mean(Data.Data2005.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(7) = mean(Data.Data2006.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(8) = mean(Data.Data2007.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(9) = mean(Data.Data2008.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(10) = mean(Data.Data2009.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(11) = mean(Data.Data2010.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(12) = mean(Data.Data2011.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(13) = mean(Data.Data2012.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(14) = mean(Data.Data2013.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(15) = mean(Data.Data2014.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(16) = mean(Data.Data2015.NumberOfEmployees);

%% Import table to EXCEL
writetable(CharacteristicsTable,'CharacteristicsTable.xlsx')

%% Top Decile 2000
Data.Data2000 = sortrows(Data.Data2000,'Revenue','descend');
Third = round(height(Data.Data2000)./3);
DataTop.Data2000 = Data.Data2000(1:Third,:);

%% Mid Decile 2000
CutoffTop = round(height(Data.Data2000)./3);
TwoThird = Third*2;
DataMid.Data2000 = Data.Data2000(Third:TwoThird,:);

%% Bottom Decile 2000
DataBottom.Data2000 = Data.Data2000(TwoThird:end,:);

%% Top Decile 2001
Data.Data2001 = sortrows(Data.Data2001,'Revenue','descend');
Third = round(height(Data.Data2001)./3);
DataTop.Data2001 = Data.Data2001(1:Third,:);

%% Mid Decile 2001
CutoffTop = round(height(Data.Data2001)./3);
TwoThird = Third*2;
DataMid.Data2001 = Data.Data2001(Third:TwoThird,:);

%% Bottom Decile 2001
DataBottom.Data2001 = Data.Data2001(TwoThird:end,:);

%% Top Decile 2002
Data.Data2002 = sortrows(Data.Data2002,'Revenue','descend');
Third = round(height(Data.Data2002)./3);
DataTop.Data2002 = Data.Data2002(1:Third,:);

%% Mid Decile 2002
CutoffTop = round(height(Data.Data2002)./3);
TwoThird = Third*2;
DataMid.Data2002 = Data.Data2002(Third:TwoThird,:);

%% Bottom Decile 2002
DataBottom.Data2002 = Data.Data2002(TwoThird:end,:);

%% Top Decile 2003
Data.Data2003 = sortrows(Data.Data2003,'Revenue','descend');
Third = round(height(Data.Data2003)./3);
DataTop.Data2003 = Data.Data2003(1:Third,:);

%% Mid Decile 2003
CutoffTop = round(height(Data.Data2003)./3);
TwoThird = Third*2;
DataMid.Data2003 = Data.Data2003(Third:TwoThird,:);

%% Bottom Decile 2003
DataBottom.Data2003 = Data.Data2003(TwoThird:end,:);

%% Top Decile 2004
Data.Data2004 = sortrows(Data.Data2004,'Revenue','descend');
Third = round(height(Data.Data2004)./3);
DataTop.Data2004 = Data.Data2004(1:Third,:);

%% Mid Decile 2004
CutoffTop = round(height(Data.Data2004)./3);
TwoThird = Third*2;
DataMid.Data2004 = Data.Data2004(Third:TwoThird,:);

%% Bottom Decile 2004
DataBottom.Data2004 = Data.Data2004(TwoThird:end,:);

%% Top Decile 2005
Data.Data2005 = sortrows(Data.Data2005,'Revenue','descend');
Third = round(height(Data.Data2005)./3);
DataTop.Data2005 = Data.Data2005(1:Third,:);

%% Mid Decile 2005
CutoffTop = round(height(Data.Data2005)./3);
TwoThird = Third*2;
DataMid.Data2005 = Data.Data2005(Third:TwoThird,:);

%% Bottom Decile 2005
DataBottom.Data2005 = Data.Data2005(TwoThird:end,:);

%% Top Decile 2006
Data.Data2006 = sortrows(Data.Data2006,'Revenue','descend');
Third = round(height(Data.Data2006)./3);
DataTop.Data2006 = Data.Data2006(1:Third,:);

%% Mid Decile 2006
CutoffTop = round(height(Data.Data2006)./3);
TwoThird = Third*2;
DataMid.Data2006 = Data.Data2006(Third:TwoThird,:);

%% Bottom Decile 2006
DataBottom.Data2006 = Data.Data2006(TwoThird:end,:);

%% Top Decile 2007
Data.Data2007 = sortrows(Data.Data2007,'Revenue','descend');
Third = round(height(Data.Data2007)./3);
DataTop.Data2007 = Data.Data2007(1:Third,:);

%% Mid Decile 2007
CutoffTop = round(height(Data.Data2007)./3);
TwoThird = Third*2;
DataMid.Data2007 = Data.Data2007(Third:TwoThird,:);

%% Bottom Decile 2007
DataBottom.Data2007 = Data.Data2007(TwoThird:end,:);

%% Top Decile 2008
Data.Data2008 = sortrows(Data.Data2008,'Revenue','descend');
Third = round(height(Data.Data2008)./3);
DataTop.Data2008 = Data.Data2008(1:Third,:);

%% Mid Decile 2008
CutoffTop = round(height(Data.Data2008)./3);
TwoThird = Third*2;
DataMid.Data2008 = Data.Data2008(Third:TwoThird,:);

%% Bottom Decile 2008
DataBottom.Data2008 = Data.Data2008(TwoThird:end,:);

%% Top Decile 2009
Data.Data2000 = sortrows(Data.Data2009,'Revenue','descend');
Third = round(height(Data.Data2009)./3);
DataTop.Data2009 = Data.Data2009(1:Third,:);

%% Mid Decile 2009
CutoffTop = round(height(Data.Data2009)./3);
TwoThird = Third*2;
DataMid.Data2009 = Data.Data2009(Third:TwoThird,:);

%% Bottom Decile 2009
DataBottom.Data2009 = Data.Data2009(TwoThird:end,:);

%% Top Decile 2010
Data.Data2010 = sortrows(Data.Data2010,'Revenue','descend');
Third = round(height(Data.Data2010)./3);
DataTop.Data2010 = Data.Data2010(1:Third,:);

%% Mid Decile 2010
CutoffTop = round(height(Data.Data2010)./3);
TwoThird = Third*2;
DataMid.Data2010 = Data.Data2010(Third:TwoThird,:);

%% Bottom Decile 2010
DataBottom.Data2010 = Data.Data2010(TwoThird:end,:);

%% Top Decile 2011
Data.Data2011 = sortrows(Data.Data2011,'Revenue','descend');
Third = round(height(Data.Data2011)./3);
DataTop.Data2011 = Data.Data2011(1:Third,:);

%% Mid Decile 2011
CutoffTop = round(height(Data.Data2011)./3);
TwoThird = Third*2;
DataMid.Data2011 = Data.Data2011(Third:TwoThird,:);

%% Bottom Decile 2011
DataBottom.Data2011 = Data.Data2011(TwoThird:end,:);

%% Top Decile 2012
Data.Data2012 = sortrows(Data.Data2012,'Revenue','descend');
Third = round(height(Data.Data2012)./3);
DataTop.Data2012 = Data.Data2012(1:Third,:);

%% Mid Decile 2012
CutoffTop = round(height(Data.Data2012)./3);
TwoThird = Third*2;
DataMid.Data2012 = Data.Data2012(Third:TwoThird,:);

%% Bottom Decile 2012
DataBottom.Data2012 = Data.Data2012(TwoThird:end,:);

%% Top Decile 2013
Data.Data2013 = sortrows(Data.Data2013,'Revenue','descend');
Third = round(height(Data.Data2013)./3);
DataTop.Data2013 = Data.Data2013(1:Third,:);

%% Mid Decile 2013
CutoffTop = round(height(Data.Data2013)./3);
TwoThird = Third*2;
DataMid.Data2013 = Data.Data2013(Third:TwoThird,:);

%% Bottom Decile 2013
DataBottom.Data2013 = Data.Data2013(TwoThird:end,:);

%% Top Decile 2014
Data.Data2014 = sortrows(Data.Data2014,'Revenue','descend');
Third = round(height(Data.Data2014)./3);
DataTop.Data2014 = Data.Data2014(1:Third,:);

%% Mid Decile 2014
CutoffTop = round(height(Data.Data2014)./3);
TwoThird = Third*2;
DataMid.Data2014 = Data.Data2014(Third:TwoThird,:);

%% Bottom Decile 2014
DataBottom.Data2014 = Data.Data2014(TwoThird:end,:);

%% Top Decile 2015
Data.Data2015 = sortrows(Data.Data2015,'Revenue','descend');
Third = round(height(Data.Data2015)./3);
DataTop.Data2015 = Data.Data2015(1:Third,:);

%% Mid Decile 2015
CutoffTop = round(height(Data.Data2015)./3);
TwoThird = Third*2;
DataMid.Data2015 = Data.Data2015(Third:TwoThird,:);

%% Bottom Decile 2015
DataBottom.Data2015 = Data.Data2015(TwoThird:end,:);

%% Descriptive table
DescriptiveTable.BottomDecileShare(1) = mean(DataBottom.Data2000.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(2) = mean(DataBottom.Data2001.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(3) = mean(DataBottom.Data2002.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(4) = mean(DataBottom.Data2003.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(5) = mean(DataBottom.Data2004.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(6) = mean(DataBottom.Data2005.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(7) = mean(DataBottom.Data2006.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(8) = mean(DataBottom.Data2007.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(9) = mean(DataBottom.Data2008.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(10) = mean(DataBottom.Data2009.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(11) = mean(DataBottom.Data2010.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(12) = mean(DataBottom.Data2011.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(13) = mean(DataBottom.Data2012.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(14) = mean(DataBottom.Data2013.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(15) = mean(DataBottom.Data2014.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(16) = mean(DataBottom.Data2015.LargestFamilySumUltOwnership);

DescriptiveTable.MidDecileShare(1) = mean(DataMid.Data2000.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(2) = mean(DataMid.Data2001.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(3) = mean(DataMid.Data2002.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(4) = mean(DataMid.Data2003.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(5) = mean(DataMid.Data2004.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(6) = mean(DataMid.Data2005.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(7) = mean(DataMid.Data2006.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(8) = mean(DataMid.Data2007.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(9) = mean(DataMid.Data2008.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(10) = mean(DataMid.Data2009.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(11) = mean(DataMid.Data2010.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(12) = mean(DataMid.Data2011.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(13) = mean(DataMid.Data2012.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(14) = mean(DataMid.Data2013.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(15) = mean(DataMid.Data2014.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(16) = mean(DataMid.Data2015.LargestFamilySumUltOwnership);

DescriptiveTable.TopDecileShare(1) = mean(DataTop.Data2000.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(2) = mean(DataTop.Data2001.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(3) = mean(DataTop.Data2002.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(4) = mean(DataTop.Data2003.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(5) = mean(DataTop.Data2004.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(6) = mean(DataTop.Data2005.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(7) = mean(DataTop.Data2006.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(8) = mean(DataTop.Data2007.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(9) = mean(DataTop.Data2008.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(10) = mean(DataTop.Data2009.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(11) = mean(DataTop.Data2010.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(12) = mean(DataTop.Data2011.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(13) = mean(DataTop.Data2012.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(14) = mean(DataTop.Data2013.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(15) = mean(DataTop.Data2014.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(16) = mean(DataTop.Data2015.LargestFamilySumUltOwnership);


%% Import table to EXCEL
writetable(DescriptiveTable,'DescriptiveTable.xlsx');

%% REG

ProfitabilityROA2010 = fitlm(Data.Data2010,'ROA~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners')

ProfitabilityROE2010 = fitlm(Data.Data2010,'ROE~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners')

GrowthRevenue2005 = fitlm(Data.Data2005,'Revenue~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners')

GrowthTotalAssets2005 = fitlm(Data.Data2005,'TotalAssets~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners')

GrowthNumberOfEmployees2005 = fitlm(Data.Data2005,'NumberOfEmployees~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners')

%% Survival analysis
FailureTime = table;

FailureTime.Var1(1,1) = 0;
FailureTime.Var1(2,1) = 1;
FailureTime.Var1(3) = 2;
FailureTime.Var1(4) = 3;
FailureTime.Var1(5) = 4;
FailureTime.Var1(6) = 5;
FailureTime.Var1(7) = 6;
FailureTime.Var1(8) = 7;
FailureTime.Var1(9) = 8;
FailureTime.Var1(10) = 9;
FailureTime.Var1(11) = 10;
FailureTime.Var1(12) = 11;
FailureTime.Var1(13) = 12;
FailureTime.Var1(14) = 13;
FailureTime.Var1(15) = 14;
FailureTime.Var1(16) = 15;

FailureTime = FailureTime.Var1;

Frequency = table;

Frequency.Var1(1,1) = 0;
Frequency.Var1(2,1) = 254;
Frequency.Var1(3) = 241;
Frequency.Var1(4) = 147;
Frequency.Var1(5) = 108;
Frequency.Var1(6) = 105;
Frequency.Var1(7) = 232;
Frequency.Var1(8) = 51;
Frequency.Var1(9) = 77;
Frequency.Var1(10) = 66;
Frequency.Var1(11) = 32;
Frequency.Var1(12) = 23;
Frequency.Var1(13) = 30;
Frequency.Var1(14) = 23;
Frequency.Var1(15) = 26;
Frequency.Var1(16) = 30;

Frequency = Frequency.Var1;

SurvivalTable = table(FailureTime, Frequency);


FailureTimeNF = table;

FailureTimeNF.Var1(1,1) = 0;
FailureTimeNF.Var1(2,1) = 1;
FailureTimeNF.Var1(3) = 2;
FailureTimeNF.Var1(4) = 3;
FailureTimeNF.Var1(5) = 4;
FailureTimeNF.Var1(6) = 5;
FailureTimeNF.Var1(7) = 6;
FailureTimeNF.Var1(8) = 7;
FailureTimeNF.Var1(9) = 8;
FailureTimeNF.Var1(10) = 9;
FailureTimeNF.Var1(11) = 10;
FailureTimeNF.Var1(12) = 11;
FailureTimeNF.Var1(13) = 12;
FailureTimeNF.Var1(14) = 13;
FailureTimeNF.Var1(15) = 14;
FailureTimeNF.Var1(16) = 15;

FailureTimeNF = FailureTimeNF.Var1;

FrequencyNF = table;

FrequencyNF.Var1(1,1) = 0;
FrequencyNF.Var1(2,1) = 169;
FrequencyNF.Var1(3) = 134;
FrequencyNF.Var1(4) = 71;
FrequencyNF.Var1(5) = 57;
FrequencyNF.Var1(6) = 49;
FrequencyNF.Var1(7) = 73;
FrequencyNF.Var1(8) = 36;
FrequencyNF.Var1(9) = 40;
FrequencyNF.Var1(10) = 28;
FrequencyNF.Var1(11) = 27;
FrequencyNF.Var1(12) = 14;
FrequencyNF.Var1(13) = 13;
FrequencyNF.Var1(14) = 11;
FrequencyNF.Var1(15) = 15;
FrequencyNF.Var1(16) = 16;

FrequencyNF = FrequencyNF.Var1;

SurvivalTableNF = table(FailureTimeNF, FrequencyNF);

%% Import table to EXCEL
writetable(SurvivalTable,'SurvivalTable.xlsx')

writetable(SurvivalTableNF,'SurvivalTableNF.xlsx')

%% Master Thesis Part 3

%Setup
clc
clear all

%Import files
Data.Data2000 = readtable('Data2000.xlsx');
Data.Data2001 = readtable('Data2001.xlsx');
Data.Data2002 = readtable('Data2002.xlsx');
Data.Data2003 = readtable('Data2003.xlsx');
Data.Data2004 = readtable('Data2004.xlsx');
Data.Data2005 = readtable('Data2005.xlsx');
Data.Data2006 = readtable('Data2006.xlsx');
Data.Data2007 = readtable('Data2007.xlsx');
Data.Data2008 = readtable('Data2008.xlsx');
Data.Data2009 = readtable('Data2009.xlsx');
Data.Data2010 = readtable('Data2010.xlsx');
Data.Data2011 = readtable('Data2011.xlsx');
Data.Data2012 = readtable('Data2012.xlsx');
Data.Data2013 = readtable('Data2013.xlsx');
Data.Data2014 = readtable('Data2014.xlsx');
Data.Data2015 = readtable('Data2015.xlsx');


DataNF.Data2000NF = readtable('Data2000NF.xlsx');
DataNF.Data2001NF = readtable('Data2001NF.xlsx');
DataNF.Data2002NF = readtable('Data2002NF.xlsx');
DataNF.Data2003NF = readtable('Data2003NF.xlsx');
DataNF.Data2004NF = readtable('Data2004NF.xlsx');
DataNF.Data2005NF = readtable('Data2005NF.xlsx');
DataNF.Data2006NF = readtable('Data2006NF.xlsx');
DataNF.Data2007NF = readtable('Data2007NF.xlsx');
DataNF.Data2008NF = readtable('Data2008NF.xlsx');
DataNF.Data2009NF = readtable('Data2009NF.xlsx');
DataNF.Data2010NF = readtable('Data2010NF.xlsx');
DataNF.Data2011NF = readtable('Data2011NF.xlsx');
DataNF.Data2012NF = readtable('Data2012NF.xlsx');
DataNF.Data2013NF = readtable('Data2013NF.xlsx');
DataNF.Data2014NF = readtable('Data2014NF.xlsx');
DataNF.Data2015NF = readtable('Data2015NF.xlsx');

%% Removing extremevalues for variable ROE
OutliersROE2000NF = rmoutliers(DataNF.Data2000NF.ROE,'percentiles',[10 90]);
OutliersROE2001NF = rmoutliers(DataNF.Data2001NF.ROE,'percentiles',[10 90]);
OutliersROE2002NF = rmoutliers(DataNF.Data2002NF.ROE,'percentiles',[10 90]);
OutliersROE2008NF = rmoutliers(DataNF.Data2002NF.ROE,'percentiles',[10 90]);
OutliersROE2005 = rmoutliers(Data.Data2005.ROE,'percentiles',[10 90]);
OutliersROE2011 = rmoutliers(Data.Data2011.ROE,'percentiles',[10 90]);
OutliersROE2013 = rmoutliers(Data.Data2013.ROE,'percentiles',[10 90]);

%% Total assets table
TotalAssetsTable = table;

TotalAssetsTable.Year(1) = 2000
TotalAssetsTable.Year(2) = 2001
TotalAssetsTable.Year(3) = 2002
TotalAssetsTable.Year(4) = 2003
TotalAssetsTable.Year(5) = 2004
TotalAssetsTable.Year(6) = 2005
TotalAssetsTable.Year(7) = 2006
TotalAssetsTable.Year(8) = 2007
TotalAssetsTable.Year(9) = 2008
TotalAssetsTable.Year(10) = 2009
TotalAssetsTable.Year(11) = 2010
TotalAssetsTable.Year(12) = 2011
TotalAssetsTable.Year(13) = 2012
TotalAssetsTable.Year(14) = 2013
TotalAssetsTable.Year(15) = 2014
TotalAssetsTable.Year(16) = 2015

TotalAssetsTable.TotalAssetsFamilyFirm(1) = mean(Data.Data2000.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(2) = mean(Data.Data2001.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(3) = mean(Data.Data2002.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(4) = mean(Data.Data2003.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(5) = mean(Data.Data2004.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(6) = mean(Data.Data2005.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(7) = mean(Data.Data2006.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(8) = mean(Data.Data2007.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(9) = mean(Data.Data2008.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(10) = mean(Data.Data2009.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(11) = mean(Data.Data2010.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(12) = mean(Data.Data2011.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(13) = mean(Data.Data2012.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(14) = mean(Data.Data2013.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(15) = mean(Data.Data2014.TotalAssets)
TotalAssetsTable.TotalAssetsFamilyFirm(16) = mean(Data.Data2015.TotalAssets)

TotalAssetsTable.TotalAssetsNonFamilyFirm(1) = mean(DataNF.Data2000NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(2) = mean(DataNF.Data2001NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(3) = mean(DataNF.Data2002NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(4) = mean(DataNF.Data2003NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(5) = mean(DataNF.Data2004NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(6) = mean(DataNF.Data2005NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(7) = mean(DataNF.Data2006NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(8) = mean(DataNF.Data2007NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(9) = mean(DataNF.Data2008NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(10) = mean(DataNF.Data2009NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(11) = mean(DataNF.Data2010NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(12) = mean(DataNF.Data2011NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(13) = mean(DataNF.Data2012NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(14) = mean(DataNF.Data2013NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(15) = mean(DataNF.Data2014NF.TotalAssets)
TotalAssetsTable.TotalAssetsNonFamilyFirm(16) = mean(DataNF.Data2015NF.TotalAssets)

%% Import table to EXCEL
writetable(TotalAssetsTable,'TotalAssetsTable.xlsx')


%% Descriptive table

DescriptiveTableNF = table;

DescriptiveTableNF.Year(1) = 2000;
DescriptiveTableNF.Year(2) = 2001;
DescriptiveTableNF.Year(3) = 2002;
DescriptiveTableNF.Year(4) = 2003;
DescriptiveTableNF.Year(5) = 2004;
DescriptiveTableNF.Year(6) = 2005;
DescriptiveTableNF.Year(7) = 2006;
DescriptiveTableNF.Year(8) = 2007;
DescriptiveTableNF.Year(9) = 2008;
DescriptiveTableNF.Year(10) = 2009;
DescriptiveTableNF.Year(11) = 2010;
DescriptiveTableNF.Year(12) = 2011;
DescriptiveTableNF.Year(13) = 2012;
DescriptiveTableNF.Year(14) = 2013;
DescriptiveTableNF.Year(15) = 2014;
DescriptiveTableNF.Year(16) = 2015;

DescriptiveTableNF.NoOfFirms(1) = height(DataNF.Data2000NF);
DescriptiveTableNF.NoOfFirms(2) = height(DataNF.Data2001NF);
DescriptiveTableNF.NoOfFirms(3) = height(DataNF.Data2002NF);
DescriptiveTableNF.NoOfFirms(4) = height(DataNF.Data2003NF);
DescriptiveTableNF.NoOfFirms(5) = height(DataNF.Data2004NF);
DescriptiveTableNF.NoOfFirms(6) = height(DataNF.Data2005NF);
DescriptiveTableNF.NoOfFirms(7) = height(DataNF.Data2006NF);
DescriptiveTableNF.NoOfFirms(8) = height(DataNF.Data2007NF);
DescriptiveTableNF.NoOfFirms(9) = height(DataNF.Data2008NF);
DescriptiveTableNF.NoOfFirms(10) = height(DataNF.Data2009NF);
DescriptiveTableNF.NoOfFirms(11) = height(DataNF.Data2010NF);
DescriptiveTableNF.NoOfFirms(12) = height(DataNF.Data2011NF);
DescriptiveTableNF.NoOfFirms(13) = height(DataNF.Data2012NF);
DescriptiveTableNF.NoOfFirms(14) = height(DataNF.Data2013NF);
DescriptiveTableNF.NoOfFirms(15) = height(DataNF.Data2014NF);
DescriptiveTableNF.NoOfFirms(16) = height(DataNF.Data2015NF);

DescriptiveTableNF.OwnershipShare(1) = mean(DataNF.Data2000NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(2) = mean(DataNF.Data2001NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(3) = mean(DataNF.Data2002NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(4) = mean(DataNF.Data2003NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(5) = mean(DataNF.Data2004NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(6) = mean(DataNF.Data2005NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(7) = mean(DataNF.Data2006NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(8) = mean(DataNF.Data2007NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(9) = mean(DataNF.Data2008NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(10) = mean(DataNF.Data2009NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(11) = mean(DataNF.Data2010NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(12) = mean(DataNF.Data2011NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(13) = mean(DataNF.Data2012NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(14) = mean(DataNF.Data2013NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(15) = mean(DataNF.Data2014NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.OwnershipShare(16) = mean(DataNF.Data2015NF.LargestFamilySumUltOwnership);

DescriptiveTableNF.FamilyCEO(1) = mean(DataNF.Data2000NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(2) = mean(DataNF.Data2001NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(3) = mean(DataNF.Data2002NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(4) = mean(DataNF.Data2003NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(5) = mean(DataNF.Data2004NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(6) = mean(DataNF.Data2005NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(7) = mean(DataNF.Data2006NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(8) = mean(DataNF.Data2007NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(9) = mean(DataNF.Data2008NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(10) = mean(DataNF.Data2009NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(11) = mean(DataNF.Data2010NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(12) = mean(DataNF.Data2011NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(13) = mean(DataNF.Data2012NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(14) = mean(DataNF.Data2013NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(15) = mean(DataNF.Data2014NF.LargestFamilyHasCEO);
DescriptiveTableNF.FamilyCEO(16) = mean(DataNF.Data2015NF.LargestFamilyHasCEO);

%% Characteristics table
CharacteristicsTableNF = table;

CharacteristicsTableNF.Year(1) = 2000;
CharacteristicsTableNF.Year(2) = 2001;
CharacteristicsTableNF.Year(3) = 2002;
CharacteristicsTableNF.Year(4) = 2003;
CharacteristicsTableNF.Year(5) = 2004;
CharacteristicsTableNF.Year(6) = 2005;
CharacteristicsTableNF.Year(7) = 2006;
CharacteristicsTableNF.Year(8) = 2007;
CharacteristicsTableNF.Year(9) = 2008;
CharacteristicsTableNF.Year(10) = 2009;
CharacteristicsTableNF.Year(11) = 2010;
CharacteristicsTableNF.Year(12) = 2011;
CharacteristicsTableNF.Year(13) = 2012;
CharacteristicsTableNF.Year(14) = 2013;
CharacteristicsTableNF.Year(15) = 2014;
CharacteristicsTableNF.Year(16) = 2015;

CharacteristicsTableNF.NoOfOwners(1) = mean(DataNF.Data2000NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(2) = mean(DataNF.Data2001NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(3) = mean(DataNF.Data2002NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(4) = mean(DataNF.Data2003NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(5) = mean(DataNF.Data2004NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(6) = mean(DataNF.Data2005NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(7) = mean(DataNF.Data2006NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(8) = mean(DataNF.Data2007NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(9) = mean(DataNF.Data2008NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(10) = mean(DataNF.Data2009NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(11) = mean(DataNF.Data2010NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(12) = mean(DataNF.Data2011NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(13) = mean(DataNF.Data2012NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(14) = mean(DataNF.Data2013NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(15) = mean(DataNF.Data2014NF.LargestFamilyNumberOfOwners);
CharacteristicsTableNF.NoOfOwners(16) = mean(DataNF.Data2015NF.LargestFamilyNumberOfOwners);

CharacteristicsTableNF.TotalPaidinCapital(1) = mean(DataNF.Data2000NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(2) = mean(DataNF.Data2001NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(3) = mean(DataNF.Data2002NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(4) = mean(DataNF.Data2003NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(5) = mean(DataNF.Data2004NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(6) = mean(DataNF.Data2005NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(7) = mean(DataNF.Data2006NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(8) = mean(DataNF.Data2007NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(9) = mean(DataNF.Data2008NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(10) = mean(DataNF.Data2009NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(11) = mean(DataNF.Data2010NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(12) = mean(DataNF.Data2011NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(13) = mean(DataNF.Data2012NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(14) = mean(DataNF.Data2013NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(15) = mean(DataNF.Data2014NF.TotalPaidinCapital);
CharacteristicsTableNF.TotalPaidinCapital(16) = mean(DataNF.Data2015NF.TotalPaidinCapital);

CharacteristicsTableNF.CEOSalary(1) = mean(DataNF.Data2000NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(2) = mean(DataNF.Data2001NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(3) = mean(DataNF.Data2002NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(4) = mean(DataNF.Data2003NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(5) = mean(DataNF.Data2004NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(6) = mean(DataNF.Data2005NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(7) = mean(DataNF.Data2006NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(8) = mean(DataNF.Data2007NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(9) = mean(DataNF.Data2008NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(10) = mean(DataNF.Data2009NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(11) = mean(DataNF.Data2010NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(12) = mean(DataNF.Data2011NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(13) = mean(DataNF.Data2012NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(14) = mean(DataNF.Data2013NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(15) = mean(DataNF.Data2014NF.CEOSalary);
CharacteristicsTableNF.CEOSalary(16) = mean(DataNF.Data2015NF.CEOSalary);

CharacteristicsTableNF.Dividends(1) = mean(DataNF.Data2000NF.DividendsPayable);
CharacteristicsTableNF.Dividends(2) = mean(DataNF.Data2001NF.DividendsPayable);
CharacteristicsTableNF.Dividends(3) = mean(DataNF.Data2002NF.DividendsPayable);
CharacteristicsTableNF.Dividends(4) = mean(DataNF.Data2003NF.DividendsPayable);
CharacteristicsTableNF.Dividends(5) = mean(DataNF.Data2004NF.DividendsPayable);
CharacteristicsTableNF.Dividends(6) = mean(DataNF.Data2005NF.DividendsPayable);
CharacteristicsTableNF.Dividends(7) = mean(DataNF.Data2006NF.DividendsPayable);
CharacteristicsTableNF.Dividends(8) = mean(DataNF.Data2007NF.DividendsPayable);
CharacteristicsTableNF.Dividends(9) = mean(DataNF.Data2008NF.DividendsPayable);
CharacteristicsTableNF.Dividends(10) = mean(DataNF.Data2009NF.DividendsPayable);
CharacteristicsTableNF.Dividends(11) = mean(DataNF.Data2010NF.DividendsPayable);
CharacteristicsTableNF.Dividends(12) = mean(DataNF.Data2011NF.DividendsPayable);
CharacteristicsTableNF.Dividends(13) = mean(DataNF.Data2012NF.DividendsPayable);
CharacteristicsTableNF.Dividends(14) = mean(DataNF.Data2013NF.DividendsPayable);
CharacteristicsTableNF.Dividends(15) = mean(DataNF.Data2014NF.DividendsPayable);
CharacteristicsTableNF.Dividends(16) = mean(DataNF.Data2015NF.DividendsPayable);

CharacteristicsTableNF.Revenue(1) = mean(DataNF.Data2000NF.Revenue);
CharacteristicsTableNF.Revenue(2) = mean(DataNF.Data2001NF.Revenue);
CharacteristicsTableNF.Revenue(3) = mean(DataNF.Data2002NF.Revenue);
CharacteristicsTableNF.Revenue(4) = mean(DataNF.Data2003NF.Revenue);
CharacteristicsTableNF.Revenue(5) = mean(DataNF.Data2004NF.Revenue);
CharacteristicsTableNF.Revenue(6) = mean(DataNF.Data2005NF.Revenue);
CharacteristicsTableNF.Revenue(7) = mean(DataNF.Data2006NF.Revenue);
CharacteristicsTableNF.Revenue(8) = mean(DataNF.Data2007NF.Revenue);
CharacteristicsTableNF.Revenue(9) = mean(DataNF.Data2008NF.Revenue);
CharacteristicsTableNF.Revenue(10) = mean(DataNF.Data2009NF.Revenue);
CharacteristicsTableNF.Revenue(11) = mean(DataNF.Data2010NF.Revenue);
CharacteristicsTableNF.Revenue(12) = mean(DataNF.Data2011NF.Revenue);
CharacteristicsTableNF.Revenue(13) = mean(DataNF.Data2012NF.Revenue);
CharacteristicsTableNF.Revenue(14) = mean(DataNF.Data2013NF.Revenue);
CharacteristicsTableNF.Revenue(15) = mean(DataNF.Data2014NF.Revenue);
CharacteristicsTableNF.Revenue(16) = mean(DataNF.Data2015NF.Revenue);

CharacteristicsTableNF.ROA(1) = mean(DataNF.Data2000NF.ROA);
CharacteristicsTableNF.ROA(2) = mean(DataNF.Data2001NF.ROA);
CharacteristicsTableNF.ROA(3) = mean(DataNF.Data2002NF.ROA);
CharacteristicsTableNF.ROA(4) = mean(DataNF.Data2003NF.ROA);
CharacteristicsTableNF.ROA(5) = mean(DataNF.Data2004NF.ROA);
CharacteristicsTableNF.ROA(6) = mean(DataNF.Data2005NF.ROA);
CharacteristicsTableNF.ROA(7) = mean(DataNF.Data2006NF.ROA);
CharacteristicsTableNF.ROA(8) = mean(DataNF.Data2007NF.ROA);
CharacteristicsTableNF.ROA(9) = mean(DataNF.Data2008NF.ROA);
CharacteristicsTableNF.ROA(10) = mean(DataNF.Data2009NF.ROA);
CharacteristicsTableNF.ROA(11) = mean(DataNF.Data2010NF.ROA);
CharacteristicsTableNF.ROA(12) = mean(DataNF.Data2011NF.ROA);
CharacteristicsTableNF.ROA(13) = mean(DataNF.Data2012NF.ROA);
CharacteristicsTableNF.ROA(14) = mean(DataNF.Data2013NF.ROA);
CharacteristicsTableNF.ROA(15) = mean(DataNF.Data2014NF.ROA);
CharacteristicsTableNF.ROA(16) = mean(DataNF.Data2015NF.ROA);

CharacteristicsTableNF.ROE(1) = mean(OutliersROE2000NF);
CharacteristicsTableNF.ROE(2) = mean(OutliersROE2001NF);
CharacteristicsTableNF.ROE(3) = mean(OutliersROE2002NF);
CharacteristicsTableNF.ROE(4) = mean(DataNF.Data2003NF.ROE);
CharacteristicsTableNF.ROE(5) = mean(DataNF.Data2004NF.ROE);
CharacteristicsTableNF.ROE(6) = mean(DataNF.Data2005NF.ROE);
CharacteristicsTableNF.ROE(7) = mean(DataNF.Data2006NF.ROE);
CharacteristicsTableNF.ROE(8) = mean(DataNF.Data2007NF.ROE);
CharacteristicsTableNF.ROE(9) = mean(OutliersROE2008NF);
CharacteristicsTableNF.ROE(10) = mean(DataNF.Data2009NF.ROE);
CharacteristicsTableNF.ROE(11) = mean(DataNF.Data2010NF.ROE);
CharacteristicsTableNF.ROE(12) = mean(DataNF.Data2011NF.ROE);
CharacteristicsTableNF.ROE(13) = mean(DataNF.Data2012NF.ROE);
CharacteristicsTableNF.ROE(14) = mean(DataNF.Data2013NF.ROE);
CharacteristicsTableNF.ROE(15) = mean(DataNF.Data2014NF.ROE);
CharacteristicsTableNF.ROE(16) = mean(DataNF.Data2015NF.ROE);

CharacteristicsTableNF.NumberOfEmployees(1) = mean(DataNF.Data2000NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(2) = mean(DataNF.Data2001NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(3) = mean(DataNF.Data2002NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(4) = mean(DataNF.Data2003NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(5) = mean(DataNF.Data2004NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(6) = mean(DataNF.Data2005NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(7) = mean(DataNF.Data2006NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(8) = mean(DataNF.Data2007NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(9) = mean(DataNF.Data2008NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(10) = mean(DataNF.Data2009NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(11) = mean(DataNF.Data2010NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(12) = mean(DataNF.Data2011NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(13) = mean(DataNF.Data2012NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(14) = mean(DataNF.Data2013NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(15) = mean(DataNF.Data2014NF.NumberOfEmployees);
CharacteristicsTableNF.NumberOfEmployees(16) = mean(DataNF.Data2015NF.NumberOfEmployees);

%% Import table to EXCEL
writetable(CharacteristicsTableNF,'CharacteristicsTableNF.xlsx')

%% Top Decile 2000
DataNF.Data2000NF = sortrows(DataNF.Data2000NF,'Revenue','descend');
Third = round(height(DataNF.Data2000NF)./3);
DataTop.Data2000NF = DataNF.Data2000NF(1:Third,:);

%% Mid Decile 2000
CutoffTop = round(height(DataNF.Data2000NF)./3);
TwoThird = Third*2;
DataMid.Data2000NF = DataNF.Data2000NF(Third:TwoThird,:);

%% Bottom Decile 2000
DataBottom.Data2000NF = DataNF.Data2000NF(TwoThird:end,:);

%% Top Decile 2001
DataNF.Data2001NF = sortrows(DataNF.Data2001NF,'Revenue','descend');
Third = round(height(DataNF.Data2001NF)./3);
DataTop.Data2001NF = DataNF.Data2001NF(1:Third,:);

%% Mid Decile 2001
CutoffTop = round(height(DataNF.Data2001NF)./3);
TwoThird = Third*2;
DataMid.Data2001NF = DataNF.Data2001NF(Third:TwoThird,:);

%% Bottom Decile 2001
DataBottom.Data2001NF = DataNF.Data2001NF(TwoThird:end,:);

%% Top Decile 2002
DataNF.Data2002NF = sortrows(DataNF.Data2002NF,'Revenue','descend');
Third = round(height(DataNF.Data2002NF)./3);
DataTop.Data2002NF = DataNF.Data2002NF(1:Third,:);

%% Mid Decile 2002
CutoffTop = round(height(DataNF.Data2002NF)./3);
TwoThird = Third*2;
DataMid.Data2002NF = DataNF.Data2002NF(Third:TwoThird,:);

%% Bottom Decile 2002
DataBottom.Data2002NF = DataNF.Data2002NF(TwoThird:end,:);

%% Top Decile 2003
DataNF.Data2003NF = sortrows(DataNF.Data2003NF,'Revenue','descend');
Third = round(height(DataNF.Data2003NF)./3);
DataTop.Data2003NF = DataNF.Data2003NF(1:Third,:);

%% Mid Decile 2003
CutoffTop = round(height(DataNF.Data2003NF)./3);
TwoThird = Third*2;
DataMid.Data2003NF = DataNF.Data2003NF(Third:TwoThird,:);

%% Bottom Decile 2003
DataBottom.Data2003NF = DataNF.Data2003NF(TwoThird:end,:);

%% Top Decile 2004
DataNF.Data2004NF = sortrows(DataNF.Data2004NF,'Revenue','descend');
Third = round(height(DataNF.Data2004NF)./3);
DataTop.Data2004NF = DataNF.Data2004NF(1:Third,:);

%% Mid Decile 2004
CutoffTop = round(height(DataNF.Data2004NF)./3);
TwoThird = Third*2;
DataMid.Data2004NF = DataNF.Data2004NF(Third:TwoThird,:);

%% Bottom Decile 2004
DataBottom.Data2004NF = DataNF.Data2004NF(TwoThird:end,:);

%% Top Decile 2005
DataNF.Data2005NF = sortrows(DataNF.Data2005NF,'Revenue','descend');
Third = round(height(DataNF.Data2005NF)./3);
DataTop.Data2005NF = DataNF.Data2005NF(1:Third,:);

%% Mid Decile 2005
CutoffTop = round(height(DataNF.Data2005NF)./3);
TwoThird = Third*2;
DataMid.Data2005NF = DataNF.Data2005NF(Third:TwoThird,:);

%% Bottom Decile 2005
DataBottom.Data2005NF = DataNF.Data2005NF(TwoThird:end,:);

%% Top Decile 2006
DataNF.Data2006NF = sortrows(DataNF.Data2006NF,'Revenue','descend');
Third = round(height(DataNF.Data2006NF)./3);
DataTop.Data2006NF = DataNF.Data2006NF(1:Third,:);

%% Mid Decile 2006
CutoffTop = round(height(DataNF.Data2006NF)./3);
TwoThird = Third*2;
DataMid.Data2006NF = DataNF.Data2006NF(Third:TwoThird,:);

%% Bottom Decile 2006
DataBottom.Data2006NF = DataNF.Data2006NF(TwoThird:end,:);

%% Top Decile 2007
DataNF.Data2007NF = sortrows(DataNF.Data2007NF,'Revenue','descend');
Third = round(height(DataNF.Data2007NF)./3);
DataTop.Data2007NF = DataNF.Data2007NF(1:Third,:);

%% Mid Decile 2007
CutoffTop = round(height(DataNF.Data2007NF)./3);
TwoThird = Third*2;
DataMid.Data2007NF = DataNF.Data2007NF(Third:TwoThird,:);

%% Bottom Decile 2007
DataBottom.Data2007NF = DataNF.Data2007NF(TwoThird:end,:);

%% Top Decile 2008
DataNF.Data2008NF = sortrows(DataNF.Data2008NF,'Revenue','descend');
Third = round(height(DataNF.Data2008NF)./3);
DataTop.Data2008NF = DataNF.Data2008NF(1:Third,:);

%% Mid Decile 2008
CutoffTop = round(height(DataNF.Data2008NF)./3);
TwoThird = Third*2;
DataMid.Data2008NF = DataNF.Data2008NF(Third:TwoThird,:);

%% Bottom Decile 2008
DataBottom.Data2008NF = DataNF.Data2008NF(TwoThird:end,:);

%% Top Decile 2009
DataNF.Data2000NF = sortrows(DataNF.Data2009NF,'Revenue','descend');
Third = round(height(DataNF.Data2009NF)./3);
DataTop.Data2009NF = DataNF.Data2009NF(1:Third,:);

%% Mid Decile 2009
CutoffTop = round(height(DataNF.Data2009NF)./3);
TwoThird = Third*2;
DataMid.Data2009NF = DataNF.Data2009NF(Third:TwoThird,:);

%% Bottom Decile 2009
DataBottom.Data2009NF = DataNF.Data2009NF(TwoThird:end,:);

%% Top Decile 2010
DataNF.Data2010NF = sortrows(DataNF.Data2010NF,'Revenue','descend');
Third = round(height(DataNF.Data2010NF)./3);
DataTop.Data2010NF = DataNF.Data2010NF(1:Third,:);

%% Mid Decile 2010
CutoffTop = round(height(DataNF.Data2010NF)./3);
TwoThird = Third*2;
DataMid.Data2010NF = DataNF.Data2010NF(Third:TwoThird,:);

%% Bottom Decile 2010
DataBottom.Data2010NF = DataNF.Data2010NF(TwoThird:end,:);

%% Top Decile 2011
DataNF.Data2011NF = sortrows(DataNF.Data2011NF,'Revenue','descend');
Third = round(height(DataNF.Data2011NF)./3);
DataTop.Data2011NF = DataNF.Data2011NF(1:Third,:);

%% Mid Decile 2011
CutoffTop = round(height(DataNF.Data2011NF)./3);
TwoThird = Third*2;
DataMid.Data2011NF = DataNF.Data2011NF(Third:TwoThird,:);

%% Bottom Decile 2011
DataBottom.Data2011NF = DataNF.Data2011NF(TwoThird:end,:);

%% Top Decile 2012
DataNF.Data2012NF = sortrows(DataNF.Data2012NF,'Revenue','descend');
Third = round(height(DataNF.Data2012NF)./3);
DataTop.Data2012NF = DataNF.Data2012NF(1:Third,:);

%% Mid Decile 2012
CutoffTop = round(height(DataNF.Data2012NF)./3);
TwoThird = Third*2;
DataMid.Data2012NF = DataNF.Data2012NF(Third:TwoThird,:);

%% Bottom Decile 2012
DataBottom.Data2012NF = DataNF.Data2012NF(TwoThird:end,:);

%% Top Decile 2013
DataNF.Data2013NF = sortrows(DataNF.Data2013NF,'Revenue','descend');
Third = round(height(DataNF.Data2013NF)./3);
DataTop.Data2013NF = DataNF.Data2013NF(1:Third,:);

%% Mid Decile 2013
CutoffTop = round(height(DataNF.Data2013NF)./3);
TwoThird = Third*2;
DataMid.Data2013NF = DataNF.Data2013NF(Third:TwoThird,:);

%% Bottom Decile 2013
DataBottom.Data2013NF = DataNF.Data2013NF(TwoThird:end,:);

%% Top Decile 2014
DataNF.Data2014NF = sortrows(DataNF.Data2014NF,'Revenue','descend');
Third = round(height(DataNF.Data2014NF)./3);
DataTop.Data2014NF = DataNF.Data2014NF(1:Third,:);

%% Mid Decile 2014
CutoffTop = round(height(DataNF.Data2014NF)./3);
TwoThird = Third*2;
DataMid.Data2014NF = DataNF.Data2014NF(Third:TwoThird,:);

%% Bottom Decile 2014
DataBottom.Data2014NF = DataNF.Data2014NF(TwoThird:end,:);

%% Top Decile 2015
DataNF.Data2015NF = sortrows(DataNF.Data2015NF,'Revenue','descend');
Third = round(height(DataNF.Data2015NF)./3);
DataTop.Data2015NF = DataNF.Data2015NF(1:Third,:);

%% Mid Decile 2015
CutoffTop = round(height(DataNF.Data2015NF)./3);
TwoThird = Third*2;
DataMid.Data2015NF = DataNF.Data2015NF(Third:TwoThird,:);

%% Bottom Decile 2015
DataBottom.Data2015NF = DataNF.Data2015NF(TwoThird:end,:);

%% Descriptive table
DescriptiveTableNF.BottomDecileShare(1) = mean(DataBottom.Data2000NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(2) = mean(DataBottom.Data2001NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(3) = mean(DataBottom.Data2002NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(4) = mean(DataBottom.Data2003NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(5) = mean(DataBottom.Data2004NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(6) = mean(DataBottom.Data2005NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(7) = mean(DataBottom.Data2006NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(8) = mean(DataBottom.Data2007NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(9) = mean(DataBottom.Data2008NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(10) = mean(DataBottom.Data2009NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(11) = mean(DataBottom.Data2010NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(12) = mean(DataBottom.Data2011NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(13) = mean(DataBottom.Data2012NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(14) = mean(DataBottom.Data2013NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(15) = mean(DataBottom.Data2014NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.BottomDecileShare(16) = mean(DataBottom.Data2015NF.LargestFamilySumUltOwnership);

DescriptiveTableNF.MidDecileShare(1) = mean(DataMid.Data2000NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(2) = mean(DataMid.Data2001NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(3) = mean(DataMid.Data2002NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(4) = mean(DataMid.Data2003NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(5) = mean(DataMid.Data2004NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(6) = mean(DataMid.Data2005NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(7) = mean(DataMid.Data2006NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(8) = mean(DataMid.Data2007NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(9) = mean(DataMid.Data2008NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(10) = mean(DataMid.Data2009NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(11) = mean(DataMid.Data2010NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(12) = mean(DataMid.Data2011NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(13) = mean(DataMid.Data2012NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(14) = mean(DataMid.Data2013NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(15) = mean(DataMid.Data2014NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.MidDecileShare(16) = mean(DataMid.Data2015NF.LargestFamilySumUltOwnership);

DescriptiveTableNF.TopDecileShare(1) = mean(DataTop.Data2000NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(2) = mean(DataTop.Data2001NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(3) = mean(DataTop.Data2002NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(4) = mean(DataTop.Data2003NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(5) = mean(DataTop.Data2004NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(6) = mean(DataTop.Data2005NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(7) = mean(DataTop.Data2006NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(8) = mean(DataTop.Data2007NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(9) = mean(DataTop.Data2008NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(10) = mean(DataTop.Data2009NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(11) = mean(DataTop.Data2010NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(12) = mean(DataTop.Data2011NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(13) = mean(DataTop.Data2012NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(14) = mean(DataTop.Data2013NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(15) = mean(DataTop.Data2014NF.LargestFamilySumUltOwnership);
DescriptiveTableNF.TopDecileShare(16) = mean(DataTop.Data2015NF.LargestFamilySumUltOwnership);


%% Import table to EXCEL
writetable(DescriptiveTableNF,'DescriptiveTableNF.xlsx');

%% REG
ProfitabilityROA2002 = fitlm(DataNF.Data2002,'ROA~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+NumberOfEmployees+Revenue+TotalPaidinCapital+DividendsPayable+CEOSalary');
ProfitabilityROA2005 = fitlm(DataNF.Data2005,'ROA~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+NumberOfEmployees+Revenue+TotalPaidinCapital+DividendsPayable+CEOSalary');
ProfitabilityROA2010 = fitlm(DataNF.Data2010,'ROA~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+NumberOfEmployees+Revenue+TotalPaidinCapital+DividendsPayable+CEOSalary');
ProfitabilityROA2015 = fitlm(DataNF.Data2015,'ROA~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+NumberOfEmployees+Revenue+TotalPaidinCapital+DividendsPayable+CEOSalary');

ProfitabilityROE2002 = fitlm(DataNF.Data2002,'ROE~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+NumberOfEmployees+Revenue+TotalPaidinCapital+DividendsPayable+CEOSalary');
ProfitabilityROE2005 = fitlm(DataNF.Data2005,'ROE~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+NumberOfEmployees+Revenue+TotalPaidinCapital+DividendsPayable+CEOSalary');
ProfitabilityROE2010 = fitlm(DataNF.Data2010,'ROE~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+NumberOfEmployees+Revenue+TotalPaidinCapital+DividendsPayable+CEOSalary');
ProfitabilityROE2015 = fitlm(DataNF.Data2015,'ROE~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+NumberOfEmployees+Revenue+TotalPaidinCapital+DividendsPayable+CEOSalary');

GrowthRevenue2002 = fitlm(DataNF.Data2002,'Revenue~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+TotalPaidinCapital+DividendsPayable+CEOSalary');
GrowthRevenue2005 = fitlm(DataNF.Data2005,'Revenue~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+TotalPaidinCapital+DividendsPayable+CEOSalary');
GrowthRevenue2010 = fitlm(DataNF.Data2010,'Revenue~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+TotalPaidinCapital+DividendsPayable+CEOSalary');
GrowthRevenue2015 = fitlm(DataNF.Data2015,'Revenue~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+TotalPaidinCapital+DividendsPayable+CEOSalary');

GrowthTotalAssets2002 = fitlm(DataNF.Data2002,'TotalAssets~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+TotalPaidinCapital+DividendsPayable+CEOSalary');
GrowthTotalAssets2005 = fitlm(DataNF.Data2005,'TotalAssets~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+TotalPaidinCapital+DividendsPayable+CEOSalary');
GrowthTotalAssets2010 = fitlm(DataNF.Data2010,'TotalAssets~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+TotalPaidinCapital+DividendsPayable+CEOSalary');
GrowthTotalAssets2015 = fitlm(DataNF.Data2015,'TotalAssets~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+TotalPaidinCapital+DividendsPayable+CEOSalary');

GrowthNumberOfEmployees2002 = fitlm(DataNF.Data2002,'NumberOfEmployees~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+TotalPaidinCapital+DividendsPayable+CEOSalary');
GrowthNumberOfEmployees2005 = fitlm(DataNF.Data2005,'NumberOfEmployees~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+TotalPaidinCapital+DividendsPayable+CEOSalary');
GrowthNumberOfEmployees2010 = fitlm(DataNF.Data2010,'NumberOfEmployees~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+TotalPaidinCapital+DividendsPayable+CEOSalary');
GrowthNumberOfEmployees2015 = fitlm(DataNF.Data2015,'NumberOfEmployees~LargestFamilySumUltOwnership+LargestFamilyHasCEO+CompanyAge+LargestFamilyNumberOfOwners+TotalPaidinCapital+DividendsPayable+CEOSalary');

%% Master Thesis validity 1

%Setup
clc
clear all

%Import file
opts = delimitedTextImportOptions("NumVariables", 22);
opts.DataLines = [2, Inf];
opts.Delimiter = "\t";
opts.VariableNames = ["pcid", "yr", "currency", "item_15302", "item_15304", "item_4", "item_9", "item_11102", "item_13420", "item_78", "item_63", "item_30", "item_35", "item_39", "item_87", "item_82", "item_105", "item_114", "item_15307", "item_50109", "item_14507", "item_14018"];
opts.VariableTypes = ["double", "double", "string", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double"];
opts.ImportErrorRule = "omitrow";
opts.MissingRule = "omitrow";
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
opts = setvaropts(opts, "currency", "WhitespaceRule", "preserve");
opts = setvaropts(opts, "currency", "EmptyFieldRule", "auto");
opts = setvaropts(opts, ["item_11102", "item_50109"], "TrimNonNumeric", true);
opts = setvaropts(opts, ["item_11102", "item_50109"], "ThousandsSeparator", ",");
Data = readtable("/Users/joakim/Desktop/CCGR Data/J.txt", opts);
clear opts

%% Sorting variables
clc
%Create new variable names
NewData=table;
NewData.pcid=Data.pcid;
NewData.yr=Data.yr;
NewData.LargestFamilySumUltOwnership=Data.item_15302;
NewData.LargestFamilyHasCEO=Data.item_15304;
NewData.CEOBirthYear=Data.item_4;
NewData.Revenue=Data.item_9;
NewData.IndustryCodes=Data.item_11102;
NewData.CompanyAge=Data.item_13420;
NewData.TotalCurrentAssets=Data.item_78;
NewData.TotalFixedAssets=Data.item_63;
NewData.OtherInterestExpenses=Data.item_30;
NewData.IncomeBeforeExtraoridinaryItems=Data.item_35;
NewData.NetIncome=Data.item_39;
NewData.TotalEquity=Data.item_87;
NewData.TotalPaidinCapital=Data.item_82;
NewData.DividendsPayable=Data.item_105;
NewData.CEOSalary=Data.item_114;
NewData.LargestFamilyNumberOfOwners=Data.item_15307;
NewData.NumberOfEmployees=Data.item_50109;
NewData.IsIndependent=Data.item_14507;
NewData.AggregateFractionHeldByInstitutionalOwners=Data.item_14018;


% Create new variables
NewData.EBIT = NewData.NetIncome - NewData.OtherInterestExpenses;
NewData.TotalAssets = NewData.TotalCurrentAssets + NewData.TotalFixedAssets;
NewData.ROA = NewData.EBIT ./ NewData.TotalAssets;
NewData.ROE = NewData.NetIncome ./ NewData.TotalEquity;

toDelete = NewData.Revenue == 0;
NewData(toDelete,:) = [];

toDelete = NewData.NetIncome == 0;
NewData(toDelete,:) = [];

toDelete = NewData.TotalAssets == 0;
NewData(toDelete,:) = [];

toDelete = NewData.TotalAssets == 0;
NewData(toDelete,:) = [];

toDelete = NewData.TotalAssets == 0;
NewData(toDelete,:) = [];

toDelete = NewData.NumberOfEmployees == 0;
NewData(toDelete,:) = [];


%% Yearly tables
i=1;
for i=1:1
YearlyData.Data2000=NewData;
toDelete = NewData.yr ~= 2000;
YearlyData.Data2000(toDelete,:) = [];

YearlyData.Data2001=NewData;
toDelete = NewData.yr ~= 2001;
YearlyData.Data2001(toDelete,:) = [];

YearlyData.Data2002=NewData;
toDelete = NewData.yr ~= 2002;
YearlyData.Data2002(toDelete,:) = [];

YearlyData.Data2003=NewData;
toDelete = NewData.yr ~= 2003;
YearlyData.Data2003(toDelete,:) = [];

YearlyData.Data2004=NewData;
toDelete = NewData.yr ~= 2004;
YearlyData.Data2004(toDelete,:) = [];

YearlyData.Data2005=NewData;
toDelete = NewData.yr ~= 2005;
YearlyData.Data2005(toDelete,:) = [];

YearlyData.Data2006=NewData;
toDelete = NewData.yr ~= 2006;
YearlyData.Data2006(toDelete,:) = [];

YearlyData.Data2007=NewData;
toDelete = NewData.yr ~= 2007;
YearlyData.Data2007(toDelete,:) = [];

YearlyData.Data2008=NewData;
toDelete = NewData.yr ~= 2008;
YearlyData.Data2008(toDelete,:) = [];

YearlyData.Data2009=NewData;
toDelete = NewData.yr ~= 2009;
YearlyData.Data2009(toDelete,:) = [];

YearlyData.Data2010=NewData;
toDelete = NewData.yr ~= 2010;
YearlyData.Data2010(toDelete,:) = [];

YearlyData.Data2011=NewData;
toDelete = NewData.yr ~= 2011;
YearlyData.Data2011(toDelete,:) = [];

YearlyData.Data2012=NewData;
toDelete = NewData.yr ~= 2012;
YearlyData.Data2012(toDelete,:) = [];

YearlyData.Data2013=NewData;
toDelete = NewData.yr ~= 2013;
YearlyData.Data2013(toDelete,:) = [];

YearlyData.Data2014=NewData;
toDelete = NewData.yr ~= 2014;
YearlyData.Data2014(toDelete,:) = [];

YearlyData.Data2015=NewData;
toDelete = NewData.yr ~= 2015;
YearlyData.Data2015(toDelete,:) = [];

clear toDelete
end%Family

%% Statistic overview family control 2001
toDelete = YearlyData.Data2001.LargestFamilySumUltOwnership < 100;
YearlyData.Data2001(toDelete,:) = [];

toDelete = YearlyData.Data2001.LargestFamilyHasCEO < 1;
YearlyData.Data2001(toDelete,:) = [];

toDelete = YearlyData.Data2001.CompanyAge > 1;
YearlyData.Data2001(toDelete,:) = [];

toDelete = YearlyData.Data2001.IsIndependent < 1;
YearlyData.Data2001(toDelete,:) = [];

toDelete = YearlyData.Data2001.Revenue == 0;
YearlyData.Data2001(toDelete,:) = [];

toDelete = YearlyData.Data2001.NetIncome == 0;
YearlyData.Data2001(toDelete,:) = [];

toDelete = YearlyData.Data2001.NumberOfEmployees == 0;
YearlyData.Data2001(toDelete,:) = [];

toDelete = YearlyData.Data2001.TotalAssets == 0;
YearlyData.Data2001(toDelete,:) = [];





%% Statistic overview family control 2002
idlist = YearlyData.Data2001.pcid;
Data2002Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2002);
    for k=1:length(idlist)
        if YearlyData.Data2002.pcid(i) == idlist(k)
            Data2002Temp(s,:) = YearlyData.Data2002(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2002 = Data2002Temp;
clear Data2002Temp

%% Statistic overview family control 2003
idlist = YearlyData.Data2002.pcid;
Data2003Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2003);
    for k=1:length(idlist)
        if YearlyData.Data2003.pcid(i) == idlist(k)
            Data2003Temp(s,:) = YearlyData.Data2003(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2003 = Data2003Temp;
clear Data2003Temp

%% Statistic overview family control 2004
idlist = YearlyData.Data2003.pcid;
Data2004Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2004);
    for k=1:length(idlist)
        if YearlyData.Data2004.pcid(i) == idlist(k)
            Data2004Temp(s,:) = YearlyData.Data2004(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2004 = Data2004Temp;
clear Data2004Temp

%% Statistic overview family control 2005
idlist = YearlyData.Data2004.pcid;
Data2005Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2005);
    for k=1:length(idlist)
        if YearlyData.Data2005.pcid(i) == idlist(k)
            Data2005Temp(s,:) = YearlyData.Data2005(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2005 = Data2005Temp;
clear Data2005Temp

%% Statistic overview family control 2006
idlist = YearlyData.Data2005.pcid;
Data2006Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2006);
    for k=1:length(idlist)
        if YearlyData.Data2006.pcid(i) == idlist(k)
            Data2006Temp(s,:) = YearlyData.Data2006(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2006 = Data2006Temp;
clear Data2006Temp

%% Statistic overview family control 2007
idlist = YearlyData.Data2006.pcid;
Data2007Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2007);
    for k=1:length(idlist)
        if YearlyData.Data2007.pcid(i) == idlist(k)
            Data2007Temp(s,:) = YearlyData.Data2007(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2007 = Data2007Temp;
clear Data2007Temp

%% Statistic overview family control 2008
idlist = YearlyData.Data2007.pcid;
Data2008Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2008);
    for k=1:length(idlist)
        if YearlyData.Data2008.pcid(i) == idlist(k)
            Data2008Temp(s,:) = YearlyData.Data2008(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2008 = Data2008Temp;
clear Data2008Temp

%% Statistic overview family control 2009
idlist = YearlyData.Data2008.pcid;
Data2009Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2009);
    for k=1:length(idlist)
        if YearlyData.Data2009.pcid(i) == idlist(k)
            Data2009Temp(s,:) = YearlyData.Data2009(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2009 = Data2009Temp;
clear Data2009Temp

%% Statistic overview family control 2010
idlist = YearlyData.Data2009.pcid;
Data2010Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2010);
    for k=1:length(idlist)
        if YearlyData.Data2010.pcid(i) == idlist(k)
            Data2010Temp(s,:) = YearlyData.Data2010(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2010 = Data2010Temp;
clear Data2010Temp

%% Statistic overview family control 2011
idlist = YearlyData.Data2010.pcid;
Data2011Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2011);
    for k=1:length(idlist)
        if YearlyData.Data2011.pcid(i) == idlist(k)
            Data2011Temp(s,:) = YearlyData.Data2011(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2011 = Data2011Temp;
clear Data2011Temp

%% Statistic overview family control 2012
idlist = YearlyData.Data2011.pcid;
Data2012Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2012);
    for k=1:length(idlist)
        if YearlyData.Data2012.pcid(i) == idlist(k)
            Data2012Temp(s,:) = YearlyData.Data2012(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2012 = Data2012Temp;
clear Data2012Temp

%% Statistic overview family control 2013
idlist = YearlyData.Data2012.pcid;
Data2013Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2013);
    for k=1:length(idlist)
        if YearlyData.Data2013.pcid(i) == idlist(k)
            Data2013Temp(s,:) = YearlyData.Data2013(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2013 = Data2013Temp;
clear Data2013Temp

%% Statistic overview family control 2014
idlist = YearlyData.Data2013.pcid;
Data2014Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2014);
    for k=1:length(idlist)
        if YearlyData.Data2014.pcid(i) == idlist(k)
            Data2014Temp(s,:) = YearlyData.Data2014(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2014 = Data2014Temp;
clear Data2014Temp

%% Statistic overview family control 2015
idlist = YearlyData.Data2014.pcid;
Data2015Temp = table;
i=1;
k=1;
s=1;
for i=1:height(YearlyData.Data2015);
    for k=1:length(idlist)
        if YearlyData.Data2015.pcid(i) == idlist(k)
            Data2015Temp(s,:) = YearlyData.Data2015(i,:);
            s=s+1;
        end
    end
end
YearlyData.Data2015 = Data2015Temp;
clear Data2015Temp




%% Export to excel 

writetable(YearlyData.Data2001,'Data2001.xlsx')
writetable(YearlyData.Data2002,'Data2002.xlsx')
writetable(YearlyData.Data2003,'Data2003.xlsx')
writetable(YearlyData.Data2004,'Data2004.xlsx')
writetable(YearlyData.Data2005,'Data2005.xlsx')
writetable(YearlyData.Data2006,'Data2006.xlsx')
writetable(YearlyData.Data2007,'Data2007.xlsx')
writetable(YearlyData.Data2008,'Data2008.xlsx')
writetable(YearlyData.Data2009,'Data2009.xlsx')
writetable(YearlyData.Data2010,'Data2010.xlsx')
writetable(YearlyData.Data2011,'Data2011.xlsx')
writetable(YearlyData.Data2012,'Data2012.xlsx')
writetable(YearlyData.Data2013,'Data2013.xlsx')
writetable(YearlyData.Data2014,'Data2014.xlsx')
writetable(YearlyData.Data2015,'Data2015.xlsx')

%% Master Thesis Validity Part 2

%Setup
clc
clear all

%Import files

Data.Data2001 = readtable('Data2001.xlsx');
Data.Data2002 = readtable('Data2002.xlsx');
Data.Data2003 = readtable('Data2003.xlsx');
Data.Data2004 = readtable('Data2004.xlsx');
Data.Data2005 = readtable('Data2005.xlsx');
Data.Data2006 = readtable('Data2006.xlsx');
Data.Data2007 = readtable('Data2007.xlsx');
Data.Data2008 = readtable('Data2008.xlsx');
Data.Data2009 = readtable('Data2009.xlsx');
Data.Data2010 = readtable('Data2010.xlsx');
Data.Data2011 = readtable('Data2011.xlsx');
Data.Data2012 = readtable('Data2012.xlsx');
Data.Data2013 = readtable('Data2013.xlsx');
Data.Data2014 = readtable('Data2014.xlsx');
Data.Data2015 = readtable('Data2015.xlsx');




%% Removing extremevalues for variable ROE


OutliersROE2001 = rmoutliers(Data.Data2001.ROE,'percentiles',[10 90]);
OutliersROE2007 = rmoutliers(Data.Data2007.ROE,'percentiles',[10 90]);

%% Descriptive table

DescriptiveTable = table;

DescriptiveTable.Year(1) = 2001;
DescriptiveTable.Year(2) = 2002;
DescriptiveTable.Year(3) = 2003;
DescriptiveTable.Year(4) = 2004;
DescriptiveTable.Year(5) = 2005;
DescriptiveTable.Year(6) = 2006;
DescriptiveTable.Year(7) = 2007;
DescriptiveTable.Year(8) = 2008;
DescriptiveTable.Year(9) = 2009;
DescriptiveTable.Year(10) = 2010;
DescriptiveTable.Year(11) = 2011;
DescriptiveTable.Year(12) = 2012;
DescriptiveTable.Year(13) = 2013;
DescriptiveTable.Year(14) = 2014;
DescriptiveTable.Year(15) = 2015;

DescriptiveTable.NoOfFirms(1) = height(Data.Data2001);
DescriptiveTable.NoOfFirms(2) = height(Data.Data2002);
DescriptiveTable.NoOfFirms(3) = height(Data.Data2003);
DescriptiveTable.NoOfFirms(4) = height(Data.Data2004);
DescriptiveTable.NoOfFirms(5) = height(Data.Data2005);
DescriptiveTable.NoOfFirms(6) = height(Data.Data2006);
DescriptiveTable.NoOfFirms(7) = height(Data.Data2007);
DescriptiveTable.NoOfFirms(8) = height(Data.Data2008);
DescriptiveTable.NoOfFirms(9) = height(Data.Data2009);
DescriptiveTable.NoOfFirms(10) = height(Data.Data2010);
DescriptiveTable.NoOfFirms(11) = height(Data.Data2011);
DescriptiveTable.NoOfFirms(12) = height(Data.Data2012);
DescriptiveTable.NoOfFirms(13) = height(Data.Data2013);
DescriptiveTable.NoOfFirms(14) = height(Data.Data2014);
DescriptiveTable.NoOfFirms(15) = height(Data.Data2015);

DescriptiveTable.OwnershipShare(1) = mean(Data.Data2001.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(2) = mean(Data.Data2002.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(3) = mean(Data.Data2003.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(4) = mean(Data.Data2004.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(5) = mean(Data.Data2005.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(6) = mean(Data.Data2006.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(7) = mean(Data.Data2007.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(8) = mean(Data.Data2008.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(9) = mean(Data.Data2009.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(10) = mean(Data.Data2010.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(11) = mean(Data.Data2011.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(12) = mean(Data.Data2012.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(13) = mean(Data.Data2013.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(14) = mean(Data.Data2014.LargestFamilySumUltOwnership);
DescriptiveTable.OwnershipShare(15) = mean(Data.Data2015.LargestFamilySumUltOwnership);

DescriptiveTable.FamilyCEO(1) = mean(Data.Data2001.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(2) = mean(Data.Data2002.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(3) = mean(Data.Data2003.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(4) = mean(Data.Data2004.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(5) = mean(Data.Data2005.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(6) = mean(Data.Data2006.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(7) = mean(Data.Data2007.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(8) = mean(Data.Data2008.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(9) = mean(Data.Data2009.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(10) = mean(Data.Data2010.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(11) = mean(Data.Data2011.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(12) = mean(Data.Data2012.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(13) = mean(Data.Data2013.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(14) = mean(Data.Data2014.LargestFamilyHasCEO);
DescriptiveTable.FamilyCEO(15) = mean(Data.Data2015.LargestFamilyHasCEO);

%% Characteristics table
CharacteristicsTable = table;

CharacteristicsTable.Year(1) = 2001;
CharacteristicsTable.Year(2) = 2002;
CharacteristicsTable.Year(3) = 2003;
CharacteristicsTable.Year(4) = 2004;
CharacteristicsTable.Year(5) = 2005;
CharacteristicsTable.Year(6) = 2006;
CharacteristicsTable.Year(7) = 2007;
CharacteristicsTable.Year(8) = 2008;
CharacteristicsTable.Year(9) = 2009;
CharacteristicsTable.Year(10) = 2010;
CharacteristicsTable.Year(11) = 2011;
CharacteristicsTable.Year(12) = 2012;
CharacteristicsTable.Year(13) = 2013;
CharacteristicsTable.Year(14) = 2014;
CharacteristicsTable.Year(15) = 2015;

CharacteristicsTable.NoOfOwners(1) = mean(Data.Data2001.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(2) = mean(Data.Data2002.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(3) = mean(Data.Data2003.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(4) = mean(Data.Data2004.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(5) = mean(Data.Data2005.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(6) = mean(Data.Data2006.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(7) = mean(Data.Data2007.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(8) = mean(Data.Data2008.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(9) = mean(Data.Data2009.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(10) = mean(Data.Data2010.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(11) = mean(Data.Data2011.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(12) = mean(Data.Data2012.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(13) = mean(Data.Data2013.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(14) = mean(Data.Data2014.LargestFamilyNumberOfOwners);
CharacteristicsTable.NoOfOwners(15) = mean(Data.Data2015.LargestFamilyNumberOfOwners);

CharacteristicsTable.TotalPaidinCapital(1) = mean(Data.Data2001.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(2) = mean(Data.Data2002.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(3) = mean(Data.Data2003.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(4) = mean(Data.Data2004.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(5) = mean(Data.Data2005.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(6) = mean(Data.Data2006.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(7) = mean(Data.Data2007.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(8) = mean(Data.Data2008.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(9) = mean(Data.Data2009.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(10) = mean(Data.Data2010.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(11) = mean(Data.Data2011.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(12) = mean(Data.Data2012.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(13) = mean(Data.Data2013.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(14) = mean(Data.Data2014.TotalPaidinCapital);
CharacteristicsTable.TotalPaidinCapital(15) = mean(Data.Data2015.TotalPaidinCapital);

CharacteristicsTable.CEOSalary(1) = mean(Data.Data2001.CEOSalary);
CharacteristicsTable.CEOSalary(2) = mean(Data.Data2002.CEOSalary);
CharacteristicsTable.CEOSalary(3) = mean(Data.Data2003.CEOSalary);
CharacteristicsTable.CEOSalary(4) = mean(Data.Data2004.CEOSalary);
CharacteristicsTable.CEOSalary(5) = mean(Data.Data2005.CEOSalary);
CharacteristicsTable.CEOSalary(6) = mean(Data.Data2006.CEOSalary);
CharacteristicsTable.CEOSalary(7) = mean(Data.Data2007.CEOSalary);
CharacteristicsTable.CEOSalary(8) = mean(Data.Data2008.CEOSalary);
CharacteristicsTable.CEOSalary(9) = mean(Data.Data2009.CEOSalary);
CharacteristicsTable.CEOSalary(10) = mean(Data.Data2010.CEOSalary);
CharacteristicsTable.CEOSalary(11) = mean(Data.Data2011.CEOSalary);
CharacteristicsTable.CEOSalary(12) = mean(Data.Data2012.CEOSalary);
CharacteristicsTable.CEOSalary(13) = mean(Data.Data2013.CEOSalary);
CharacteristicsTable.CEOSalary(14) = mean(Data.Data2014.CEOSalary);
CharacteristicsTable.CEOSalary(15) = mean(Data.Data2015.CEOSalary);

CharacteristicsTable.Dividends(1) = mean(Data.Data2001.DividendsPayable);
CharacteristicsTable.Dividends(2) = mean(Data.Data2002.DividendsPayable);
CharacteristicsTable.Dividends(3) = mean(Data.Data2003.DividendsPayable);
CharacteristicsTable.Dividends(4) = mean(Data.Data2004.DividendsPayable);
CharacteristicsTable.Dividends(5) = mean(Data.Data2005.DividendsPayable);
CharacteristicsTable.Dividends(6) = mean(Data.Data2006.DividendsPayable);
CharacteristicsTable.Dividends(7) = mean(Data.Data2007.DividendsPayable);
CharacteristicsTable.Dividends(8) = mean(Data.Data2008.DividendsPayable);
CharacteristicsTable.Dividends(9) = mean(Data.Data2009.DividendsPayable);
CharacteristicsTable.Dividends(10) = mean(Data.Data2010.DividendsPayable);
CharacteristicsTable.Dividends(11) = mean(Data.Data2011.DividendsPayable);
CharacteristicsTable.Dividends(12) = mean(Data.Data2012.DividendsPayable);
CharacteristicsTable.Dividends(13) = mean(Data.Data2013.DividendsPayable);
CharacteristicsTable.Dividends(14) = mean(Data.Data2014.DividendsPayable);
CharacteristicsTable.Dividends(15) = mean(Data.Data2015.DividendsPayable);

CharacteristicsTable.Revenue(1) = mean(Data.Data2001.Revenue);
CharacteristicsTable.Revenue(2) = mean(Data.Data2002.Revenue);
CharacteristicsTable.Revenue(3) = mean(Data.Data2003.Revenue);
CharacteristicsTable.Revenue(4) = mean(Data.Data2004.Revenue);
CharacteristicsTable.Revenue(5) = mean(Data.Data2005.Revenue);
CharacteristicsTable.Revenue(6) = mean(Data.Data2006.Revenue);
CharacteristicsTable.Revenue(7) = mean(Data.Data2007.Revenue);
CharacteristicsTable.Revenue(8) = mean(Data.Data2008.Revenue);
CharacteristicsTable.Revenue(9) = mean(Data.Data2009.Revenue);
CharacteristicsTable.Revenue(10) = mean(Data.Data2010.Revenue);
CharacteristicsTable.Revenue(11) = mean(Data.Data2011.Revenue);
CharacteristicsTable.Revenue(12) = mean(Data.Data2012.Revenue);
CharacteristicsTable.Revenue(13) = mean(Data.Data2013.Revenue);
CharacteristicsTable.Revenue(14) = mean(Data.Data2014.Revenue);
CharacteristicsTable.Revenue(15) = mean(Data.Data2015.Revenue);

CharacteristicsTable.ROA(1) = mean(Data.Data2001.ROA);
CharacteristicsTable.ROA(2) = mean(Data.Data2002.ROA);
CharacteristicsTable.ROA(3) = mean(Data.Data2003.ROA);
CharacteristicsTable.ROA(4) = mean(Data.Data2004.ROA);
CharacteristicsTable.ROA(5) = mean(Data.Data2005.ROA);
CharacteristicsTable.ROA(6) = mean(Data.Data2006.ROA);
CharacteristicsTable.ROA(7) = mean(Data.Data2007.ROA);
CharacteristicsTable.ROA(8) = mean(Data.Data2008.ROA);
CharacteristicsTable.ROA(9) = mean(Data.Data2009.ROA);
CharacteristicsTable.ROA(10) = mean(Data.Data2010.ROA);
CharacteristicsTable.ROA(11) = mean(Data.Data2011.ROA);
CharacteristicsTable.ROA(12) = mean(Data.Data2012.ROA);
CharacteristicsTable.ROA(13) = mean(Data.Data2013.ROA);
CharacteristicsTable.ROA(14) = mean(Data.Data2014.ROA);
CharacteristicsTable.ROA(15) = mean(Data.Data2015.ROA);

CharacteristicsTable.ROE(1) = mean(OutliersROE2001);
CharacteristicsTable.ROE(2) = mean(Data.Data2002.ROE);
CharacteristicsTable.ROE(3) = mean(Data.Data2003.ROE);
CharacteristicsTable.ROE(4) = mean(Data.Data2004.ROE);
CharacteristicsTable.ROE(5) = mean(Data.Data2005.ROE);
CharacteristicsTable.ROE(6) = mean(Data.Data2006.ROE);
CharacteristicsTable.ROE(7) = mean(OutliersROE2007);
CharacteristicsTable.ROE(8) = mean(Data.Data2008.ROE);
CharacteristicsTable.ROE(9) = mean(Data.Data2009.ROE);
CharacteristicsTable.ROE(10) = mean(Data.Data2010.ROE);
CharacteristicsTable.ROE(11) = mean(Data.Data2011.ROE);
CharacteristicsTable.ROE(12) = mean(Data.Data2012.ROE);
CharacteristicsTable.ROE(13) = mean(Data.Data2013.ROE);
CharacteristicsTable.ROE(14) = mean(Data.Data2014.ROE);
CharacteristicsTable.ROE(15) = mean(Data.Data2015.ROE);

CharacteristicsTable.NumberOfEmployees(1) = mean(Data.Data2001.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(2) = mean(Data.Data2002.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(3) = mean(Data.Data2003.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(4) = mean(Data.Data2004.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(5) = mean(Data.Data2005.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(6) = mean(Data.Data2006.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(7) = mean(Data.Data2007.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(8) = mean(Data.Data2008.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(9) = mean(Data.Data2009.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(10) = mean(Data.Data2010.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(11) = mean(Data.Data2011.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(12) = mean(Data.Data2012.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(13) = mean(Data.Data2013.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(14) = mean(Data.Data2014.NumberOfEmployees);
CharacteristicsTable.NumberOfEmployees(15) = mean(Data.Data2015.NumberOfEmployees);

%% Import table to EXCEL
writetable(CharacteristicsTable,'CharacteristicsTable.xlsx')

%% Top Decile 2001
Data.Data2001 = sortrows(Data.Data2001,'Revenue','descend');
Third = round(height(Data.Data2001)./3);
DataTop.Data2001 = Data.Data2001(1:Third,:);

%% Mid Decile 2001
CutoffTop = round(height(Data.Data2001)./3);
TwoThird = Third*2;
DataMid.Data2001 = Data.Data2001(Third:TwoThird,:);

%% Bottom Decile 2001
DataBottom.Data2001 = Data.Data2001(TwoThird:end,:);

%% Top Decile 2002
Data.Data2002 = sortrows(Data.Data2002,'Revenue','descend');
Third = round(height(Data.Data2002)./3);
DataTop.Data2002 = Data.Data2002(1:Third,:);

%% Mid Decile 2002
CutoffTop = round(height(Data.Data2002)./3);
TwoThird = Third*2;
DataMid.Data2002 = Data.Data2002(Third:TwoThird,:);

%% Bottom Decile 2002
DataBottom.Data2002 = Data.Data2002(TwoThird:end,:);

%% Top Decile 2003
Data.Data2003 = sortrows(Data.Data2003,'Revenue','descend');
Third = round(height(Data.Data2003)./3);
DataTop.Data2003 = Data.Data2003(1:Third,:);

%% Mid Decile 2003
CutoffTop = round(height(Data.Data2003)./3);
TwoThird = Third*2;
DataMid.Data2003 = Data.Data2003(Third:TwoThird,:);

%% Bottom Decile 2003
DataBottom.Data2003 = Data.Data2003(TwoThird:end,:);

%% Top Decile 2004
Data.Data2004 = sortrows(Data.Data2004,'Revenue','descend');
Third = round(height(Data.Data2004)./3);
DataTop.Data2004 = Data.Data2004(1:Third,:);

%% Mid Decile 2004
CutoffTop = round(height(Data.Data2004)./3);
TwoThird = Third*2;
DataMid.Data2004 = Data.Data2004(Third:TwoThird,:);

%% Bottom Decile 2004
DataBottom.Data2004 = Data.Data2004(TwoThird:end,:);

%% Top Decile 2005
Data.Data2005 = sortrows(Data.Data2005,'Revenue','descend');
Third = round(height(Data.Data2005)./3);
DataTop.Data2005 = Data.Data2005(1:Third,:);

%% Mid Decile 2005
CutoffTop = round(height(Data.Data2005)./3);
TwoThird = Third*2;
DataMid.Data2005 = Data.Data2005(Third:TwoThird,:);

%% Bottom Decile 2005
DataBottom.Data2005 = Data.Data2005(TwoThird:end,:);

%% Top Decile 2006
Data.Data2006 = sortrows(Data.Data2006,'Revenue','descend');
Third = round(height(Data.Data2006)./3);
DataTop.Data2006 = Data.Data2006(1:Third,:);

%% Mid Decile 2006
CutoffTop = round(height(Data.Data2006)./3);
TwoThird = Third*2;
DataMid.Data2006 = Data.Data2006(Third:TwoThird,:);

%% Bottom Decile 2006
DataBottom.Data2006 = Data.Data2006(TwoThird:end,:);

%% Top Decile 2007
Data.Data2007 = sortrows(Data.Data2007,'Revenue','descend');
Third = round(height(Data.Data2007)./3);
DataTop.Data2007 = Data.Data2007(1:Third,:);

%% Mid Decile 2007
CutoffTop = round(height(Data.Data2007)./3);
TwoThird = Third*2;
DataMid.Data2007 = Data.Data2007(Third:TwoThird,:);

%% Bottom Decile 2007
DataBottom.Data2007 = Data.Data2007(TwoThird:end,:);

%% Top Decile 2008
Data.Data2008 = sortrows(Data.Data2008,'Revenue','descend');
Third = round(height(Data.Data2008)./3);
DataTop.Data2008 = Data.Data2008(1:Third,:);

%% Mid Decile 2008
CutoffTop = round(height(Data.Data2008)./3);
TwoThird = Third*2;
DataMid.Data2008 = Data.Data2008(Third:TwoThird,:);

%% Bottom Decile 2008
DataBottom.Data2008 = Data.Data2008(TwoThird:end,:);

%% Top Decile 2009
Data.Data2000 = sortrows(Data.Data2009,'Revenue','descend');
Third = round(height(Data.Data2009)./3);
DataTop.Data2009 = Data.Data2009(1:Third,:);

%% Mid Decile 2009
CutoffTop = round(height(Data.Data2009)./3);
TwoThird = Third*2;
DataMid.Data2009 = Data.Data2009(Third:TwoThird,:);

%% Bottom Decile 2009
DataBottom.Data2009 = Data.Data2009(TwoThird:end,:);

%% Top Decile 2010
Data.Data2010 = sortrows(Data.Data2010,'Revenue','descend');
Third = round(height(Data.Data2010)./3);
DataTop.Data2010 = Data.Data2010(1:Third,:);

%% Mid Decile 2010
CutoffTop = round(height(Data.Data2010)./3);
TwoThird = Third*2;
DataMid.Data2010 = Data.Data2010(Third:TwoThird,:);

%% Bottom Decile 2010
DataBottom.Data2010 = Data.Data2010(TwoThird:end,:);

%% Top Decile 2011
Data.Data2011 = sortrows(Data.Data2011,'Revenue','descend');
Third = round(height(Data.Data2011)./3);
DataTop.Data2011 = Data.Data2011(1:Third,:);

%% Mid Decile 2011
CutoffTop = round(height(Data.Data2011)./3);
TwoThird = Third*2;
DataMid.Data2011 = Data.Data2011(Third:TwoThird,:);

%% Bottom Decile 2011
DataBottom.Data2011 = Data.Data2011(TwoThird:end,:);

%% Top Decile 2012
Data.Data2012 = sortrows(Data.Data2012,'Revenue','descend');
Third = round(height(Data.Data2012)./3);
DataTop.Data2012 = Data.Data2012(1:Third,:);

%% Mid Decile 2012
CutoffTop = round(height(Data.Data2012)./3);
TwoThird = Third*2;
DataMid.Data2012 = Data.Data2012(Third:TwoThird,:);

%% Bottom Decile 2012
DataBottom.Data2012 = Data.Data2012(TwoThird:end,:);

%% Top Decile 2013
Data.Data2013 = sortrows(Data.Data2013,'Revenue','descend');
Third = round(height(Data.Data2013)./3);
DataTop.Data2013 = Data.Data2013(1:Third,:);

%% Mid Decile 2013
CutoffTop = round(height(Data.Data2013)./3);
TwoThird = Third*2;
DataMid.Data2013 = Data.Data2013(Third:TwoThird,:);

%% Bottom Decile 2013
DataBottom.Data2013 = Data.Data2013(TwoThird:end,:);

%% Top Decile 2014
Data.Data2014 = sortrows(Data.Data2014,'Revenue','descend');
Third = round(height(Data.Data2014)./3);
DataTop.Data2014 = Data.Data2014(1:Third,:);

%% Mid Decile 2014
CutoffTop = round(height(Data.Data2014)./3);
TwoThird = Third*2;
DataMid.Data2014 = Data.Data2014(Third:TwoThird,:);

%% Bottom Decile 2014
DataBottom.Data2014 = Data.Data2014(TwoThird:end,:);

%% Top Decile 2015
Data.Data2015 = sortrows(Data.Data2015,'Revenue','descend');
Third = round(height(Data.Data2015)./3);
DataTop.Data2015 = Data.Data2015(1:Third,:);

%% Mid Decile 2015
CutoffTop = round(height(Data.Data2015)./3);
TwoThird = Third*2;
DataMid.Data2015 = Data.Data2015(Third:TwoThird,:);

%% Bottom Decile 2015
DataBottom.Data2015 = Data.Data2015(TwoThird:end,:);

%% Descriptive table
DescriptiveTable.BottomDecileShare(1) = mean(DataBottom.Data2001.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(2) = mean(DataBottom.Data2002.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(3) = mean(DataBottom.Data2003.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(4) = mean(DataBottom.Data2004.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(5) = mean(DataBottom.Data2005.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(6) = mean(DataBottom.Data2006.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(7) = mean(DataBottom.Data2007.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(8) = mean(DataBottom.Data2008.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(9) = mean(DataBottom.Data2009.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(10) = mean(DataBottom.Data2010.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(11) = mean(DataBottom.Data2011.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(12) = mean(DataBottom.Data2012.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(13) = mean(DataBottom.Data2013.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(14) = mean(DataBottom.Data2014.LargestFamilySumUltOwnership);
DescriptiveTable.BottomDecileShare(15) = mean(DataBottom.Data2015.LargestFamilySumUltOwnership);

DescriptiveTable.MidDecileShare(1) = mean(DataMid.Data2001.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(2) = mean(DataMid.Data2002.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(3) = mean(DataMid.Data2003.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(4) = mean(DataMid.Data2004.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(5) = mean(DataMid.Data2005.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(6) = mean(DataMid.Data2006.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(7) = mean(DataMid.Data2007.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(8) = mean(DataMid.Data2008.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(9) = mean(DataMid.Data2009.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(10) = mean(DataMid.Data2010.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(11) = mean(DataMid.Data2011.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(12) = mean(DataMid.Data2012.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(13) = mean(DataMid.Data2013.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(14) = mean(DataMid.Data2014.LargestFamilySumUltOwnership);
DescriptiveTable.MidDecileShare(15) = mean(DataMid.Data2015.LargestFamilySumUltOwnership);

DescriptiveTable.TopDecileShare(1) = mean(DataTop.Data2001.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(2) = mean(DataTop.Data2002.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(3) = mean(DataTop.Data2003.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(4) = mean(DataTop.Data2004.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(5) = mean(DataTop.Data2005.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(6) = mean(DataTop.Data2006.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(7) = mean(DataTop.Data2007.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(8) = mean(DataTop.Data2008.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(9) = mean(DataTop.Data2009.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(10) = mean(DataTop.Data2010.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(11) = mean(DataTop.Data2011.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(12) = mean(DataTop.Data2012.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(13) = mean(DataTop.Data2013.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(14) = mean(DataTop.Data2014.LargestFamilySumUltOwnership);
DescriptiveTable.TopDecileShare(15) = mean(DataTop.Data2015.LargestFamilySumUltOwnership);


%% Import table to EXCEL
writetable(DescriptiveTable,'DescriptiveTable.xlsx');