Creating a Custom Excel Function to Calculate Gini Coefficients
Hi,
I'm trying to write a custom function to calculate gini coefficients. I've been able to use this function when inputted manually: (Where X is a range) =SUM(ABS(X-TRANSPOSE(X)))/(2*AVERAGE(X)*((COUNT(X))*(COUNT(X)))) ....entered as an array function. What I am interested in creating is a custom function in Visual Basic. So far, I've gotten this far: Function GiniCalculator(Range) GiniCalculator = WorksheetFunction.Sum(Math.Abs(Range - WorksheetFunction.Transpose(Range))) / (2 * WorksheetFunction.Average(Range) * ((WorksheetFunction.Count(Range)) * (WorksheetFunction.Count(Range)))) End Function But when I use this function, I just arrive at the #VALUE! error message. I'm not sure why, but it might has something to do with the fact the above function is an array function. Does anybody have any thoughts on how to write a custom function for gini coefficients so it is not necessary to manually input the array address each time? |
Creating a Custom Excel Function to Calculate Gini Coefficients
|
Creating a Custom Excel Function to Calculate Gini Coefficients
Harlan,
Your code is very helpful. Thanks! I have noticed one thing though. In order for the calculation to be accurate, there cannot be any missing data in the array. At first I thought that maybe the functions are treating the missing values as zeros, but they are not. The effect of the missing values on the gini coefficient is less than zero. Is there something that can be added to function to have it ignore missing values? John |
Creating a Custom Excel Function to Calculate Gini Coefficients
|
All times are GMT +1. The time now is 02:07 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com