I separate input data (in file panel.xlsx) into groups based on 4 conditions (in file criteria.xlsx), namely:
- Province (64 values)
- Number of employees (3 ranges): 2-10; 11-49; 50-10000
- Industry ID (89 values)
- Year (2 ranges): 2005-2007; 2008-2010
Then i want to calculate mean for each group and assign this mean to every observation in each group. Above is my code, could you please point out what's wrong in the code and fix it. Thank you very much! And i already attach two files used for calculation.
clear allclcA=xlsread('criteria.xlsx');B=xlsread('panel.xlsx');for i=1:89 for j=1:64 for k=1:3 for h=1:2 rowsToAverage = (B(:,5) == A(i,1)) && (B(:,4) == A(j,2)) && (A(k,4) > B(:,2) > A(k,3)) && (A(h,5) < B(:,1) < A(h,6)) && ~isnan(B(:,3)); meanOfBigNumbers= mean(B(rowsToAverage, 3)); B(rowsToAverage, 6) = meanOfBigNumbers; end end end endxlswrite('panel.xlsx',B)
Best Answer