I wrote a function to solve a maximum likelihood optimization using optim in R:
dt<-structure(list(FARM = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3