Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Demeter/5065944 to your computer and use it in GitHub Desktop.
Save Demeter/5065944 to your computer and use it in GitHub Desktop.
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("plyr", "ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
ANES <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/ANES.csv")
head(ANES)
ANES$PID3 <- factor(ANES$pid7) # Convert to three-level Party ID:
levels(ANES$PID3) <- c("Dem", "Dem", "Dem", "Ind", "Rep", "Rep", "Rep")
# Using plyr to estimate the "Effective numbers of parties" by year and region
ENpid3 <- ddply(.data = ANES,
.progress = "text",
.variables = .(year, south),
summarize, # Calculate an inverse HHI
invHHI = sum(table(PID3))^2 / sum(table(PID3)^2))
zp1 <- ggplot(ENpid3)
zp1 <- zp1 + geom_line(aes(x = year, y = invHHI, colour = factor(south)))
zp1 <- zp1 + ggtitle("Effective Number of Parties-in-the-Electorate")
print(zp1)
@Demeter
Copy link
Author

Demeter commented Mar 2, 2013

Source: Reverse HH Index, R Bloggers

See U.S. Justice Dept public anti-trust guidelines for HH index usage and criteria. There are also numeric values for the HH though limited in scope:

"The following data are from the Economic Census. All of these reports classify industries by the percent of output accounted for by the largest 4, 8, 20 and 50 companies. Only the manufacturing reports include the Herfindahl-Hirschman Index. Data for 2007, 2002 and 1997 are organized and classified by the North American Industry Classification System (NAICS). Data for 1992 and prior years are organized and classified by the Standard Industry Classification (SIC) system..."

For a "lite" treatment, there's always Yahoo! Answers, with several HH-related questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment