Skip to content

Instantly share code, notes, and snippets.

@Protonk
Created December 17, 2010 23:48
Show Gist options
  • Select an option

  • Save Protonk/745924 to your computer and use it in GitHub Desktop.

Select an option

Save Protonk/745924 to your computer and use it in GitHub Desktop.
Theil index code from the lorenz.R gist. Works on those numbers
#Computes a very basic Theil index
i<-1
theil<-matrix(0,4,3)
for (i in i:4) {
theil[i,1]<-0.25*(gini[i,1]/0.25)*log(gini[i,1]/0.25)
theil[i,2]<-0.25*(gini[i,2]/0.25)*log(gini[i,2]/0.25)
theil[i,3]<-0.25*(gini[i,3]/0.25)*log(gini[i,3]/0.25)
}
theil<-rbind(theil,apply(theil,2,sum))
colnames(theil)<-c("Region A","Region B","Region C");
rownames(theil)<-c("Bottom 25%","Lower Middle 25%","Upper Middle 25%","Top 25%","Theil Index")
#Computes the two components of a between region Theil index, with regional income shares of 0.4,0.25 and 0.35.
within.theil<-0.4*theil[5,1]+0.25*theil[5,2]+0.35*theil[5,3]
between.theil<-0.4*log(0.4*3)+0.25*log(0.25*3)+0.35*log(0.35*3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment