Tuesday, June 29, 2010

Multinomial logit in Stata and R

Here is how you can reproduce Stata's -mlogit- in R:
Stata


websuse sysdn1, clear
mlogit insure age male nowhite i.site

R

install.packages("foreign")
library(foreign)
sysdn <- read.dta("D:/programming/r/sandbox/sysdn1.dta", convert.factors=TRUE)
sysdn.multinom <- multinom(insure~age+male+nonwhite+ as.factor(site), data=sysdn)
summary(sysdn.multinom)

And as of today, I am using Revolution R's optimized 64-bit version of R which they have made free for academic use. The function multinom() in R comes from the pre-loaded nnet package. Syntax highlighting for R code here . Still looking for a brush/syntax highlighter for Stata. If anyone knows a good one, please do let me know.

No comments: