Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Translating R code into Stata code

    Hi,
    I came across a paper by Cole et al (2009; doi: 10.1093/ijc/dyp269) in which they provided R code for a MLE appoach. Does anyone have a suggestion on how to write this in Stata code?
    Code:
    int.p1<-function(xx) {
    
    1/(1+exp(-b0-b1*log(xx)))*dlnorm(xx, c0, c1)
    
    }
    
    int.p0<-function(xx) {
    
    1/(1+exp(b0+b1*log(xx)))*dlnorm(xx, c0, c1)
    
    }
    
    logitln <- function(para){
    
    b0 <<- para[1]
    
    b1 <<- para[2]
    
    c0 <<- para[3]
    
    c1 <<- para[4]
    
    px <- 1/(1+exp(-b0-b1*log(x)))
    
    logL.1<-sum((1-delta)*(y*log(px)+(1-y)*log
    
    (1-px)+log(dlnorm(x,c0,c1))))
    
    logL.2<-sum(delta*y*log(integrate(int.p1,
    
    lower=0,upper=LD)$value)+delta*(1-y)*
    
    log(integrate(int.p0,lower=0,upper=LD)$value))
    
    -(logL.1+logL.2)
    
    }
    
    fit <- optim(par=c(-1, 1, 0, 1), fn=logitln,
    
    hessian = T)
    
    rbind(est=fit$par, se=sqrt(diag(solve
    
    (fit$hessian))))
    Kjell Vegard

  • #2
    See "help mlmethod" or "help mf_moptimize##syn_alleval" for first ideas how to implement likelihood-estimators in Stata or Mata.
    The rest should be then rather straightforward. Just translate all the R-commands in Stata-code. I have not tried it myself, but that's at least my naive idea.

    Comment

    Working...
    X