Skip to content

Instantly share code, notes, and snippets.

@hktosun
Last active April 18, 2021 22:44
Show Gist options
  • Save hktosun/a3c9d81079745e21d25878709f2124c3 to your computer and use it in GitHub Desktop.
Save hktosun/a3c9d81079745e21d25878709f2124c3 to your computer and use it in GitHub Desktop.
Conditional Logit with Capacity Constraints
set.seed(1)
N <- 800
J <- 80
id_firm = 1:J
delta = c(1:J)/J
capacity <- c(rep(10, 7*J/8), rep(100, J/8))
enrollment <- rep(0, J)
for(i in 1:N){
placed <- FALSE
temp_list <- delta + EnvStats::revd(J)
while(!placed){
pref <- which(temp_list == max(temp_list))
if(capacity[pref] <= enrollment[pref]){
temp_list[pref] <- -Inf
} else {
enrollment[pref] <- enrollment[pref] + 1
placed <- TRUE
}
}
}
shares_with_constraint <- enrollment / N
shares_with_constraint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment